<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to UsageLibrary</title><link>https://sourceforge.net/p/gpujpeg/home/UsageLibrary/</link><description>Recent changes to UsageLibrary</description><atom:link href="https://sourceforge.net/p/gpujpeg/home/UsageLibrary/feed" rel="self"/><language>en</language><lastBuildDate>Thu, 29 Mar 2012 10:56:01 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/gpujpeg/home/UsageLibrary/feed" rel="self" type="application/rss+xml"/><item><title>WikiPage UsageLibrary modified by Martin Srom</title><link>https://sourceforge.net/p/gpujpeg/home/UsageLibrary/</link><description>&lt;pre&gt;--- v3 
+++ v4 
@@ -88,9 +88,12 @@
 Next step is to encode uncompressed image data to JPEG compressed data by encoder:
 
     :::c
+    struct gpujpeg_encoder_input encoder_input;
+    gpujpeg_encoder_input_set_image(&amp;encoder_input, image);
+    
     uint8_t* image_compressed = NULL;
     int image_compressed_size = 0;
-    if ( gpujpeg_encoder_encode(encoder, image, &amp;image_compressed, 
+    if ( gpujpeg_encoder_encode(encoder, &amp;encoder_input, &amp;image_compressed, 
              &amp;image_compressed_size) != 0 )
         return -1;
 
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Martin Srom</dc:creator><pubDate>Thu, 29 Mar 2012 10:56:01 -0000</pubDate><guid>https://sourceforge.netf8341a81bf8708fbe4ebe7a65fd572786f95ee1a</guid></item><item><title>WikiPage UsageLibrary modified by Martin Srom</title><link>https://sourceforge.net/p/gpujpeg/home/UsageLibrary/</link><description>&lt;pre&gt;--- v2 
+++ v3 
@@ -10,111 +10,150 @@
       
 Encoding:
 ---------
-For encoding by libgpujpeg library you have to declare two structures and set proper values to them. The first is structure with parameters of input image, and the second is definition of encoding parameters:
-
-    :::c
-    struct gpujpeg_image_parameters param_image;
-    gpujpeg_image_set_default_parameters(&amp;param_image);
-    param_image-&gt;width = 1920;
-    param_image-&gt;height = 1080;
-    param_image-&gt;comp_count = 3;
-    // (for now, it must be 3)
-    param_image-&gt;color_space = GPUJPEG_RGB; 
-    // or GPUJPEG_YCBCR_ITU_R or GPUJPEG_YCBCR_JPEG
-    // (default value is GPUJPEG_RGB)
-    param_image.sampling_factor = GPUJPEG_4_4_4;
-    // or GPUJPEG_4_2_2
-    // (default value is GPUJPEG_4_4_4 )
-  
-    struct gpujpeg_encoder_parameters param_encoder;
-    gpujpeg_encoder_set_default_parameters(&amp;param_encoder);   
-    param_encoder.quality = 80; 
+For encoding by libgpujpeg library you have to declare two structures and set proper values to them. The first is definition of encoding/decoding parameters, and the second is structure with parameters of input image:
+
+    :::c
+    struct gpujpeg_parameters param;
+    gpujpeg_set_default_parameters(&amp;param);   
+    param.quality = 80; 
     // (default value is 75)
-    param_encoder.restart_interval = 16; 
+    param.restart_interval = 16; 
     // (default value is 8)
+    param.interleaved = 1;
+    // (default value is 0)
+      
+    struct gpujpeg_image_parameters param_image;
+    gpujpeg_image_set_default_parameters(&amp;param_image);
+    param_image-&gt;width = 1920;
+    param_image-&gt;height = 1080;
+    param_image-&gt;comp_count = 3;
+    // (for now, it must be 3)
+    param_image-&gt;color_space = GPUJPEG_RGB; 
+    // or GPUJPEG_YCBCR_ITU_R or GPUJPEG_YCBCR_JPEG
+    // (default value is GPUJPEG_RGB)
+    param_image.sampling_factor = GPUJPEG_4_4_4;
+    // or GPUJPEG_4_2_2
+    // (default value is GPUJPEG_4_4_4)
+
+&lt;br/&gt;
+
+If you want to use subsampling in JPEG format call following function, that will set default sampling factors (2x2 for Y, 1x1 for Cb and Cr):
+    
+    :::c
+    // Use default sampling factors
+    gpujpeg_parameters_chroma_subsampling(&amp;param);
+
+&lt;br/&gt;
+      
+Or define sampling factors by hand:
+
+    :::c    
+    // User custom sampling factors
+    param.sampling_factor[0].horizontal = 4;
+    param.sampling_factor[0].vertical = 4;
+    param.sampling_factor[1].horizontal = 1;
+    param.sampling_factor[1].vertical = 2;
+    param.sampling_factor[2].horizontal = 2;
+    param.sampling_factor[2].vertical = 1;
 
 &lt;br/&gt;
 
 Next you have to initialize CUDA device by calling:
     
     :::c  
     gpujpeg_init_device(device_id, 0);
 
 &lt;br/&gt;
         
 where first parameters is CUDA device id and second parameter is flag if verbose output should be used (0 or 1). Next step is to create encoder:
     
     :::c
     struct gpujpeg_encoder* encoder = gpujpeg_encoder_create(&amp;param_image, 
         &amp;param_encoder);
     if ( encoder == NULL )
         return -1;
 
 &lt;br/&gt;
 
 When creating encoder, library allocates all device buffers which will be needed for image encoding and when you encode concrete image, they are already allocated and encoder will used them for every image. Now we need raw image data that we can encode by encoder, for example we can load it from file:
 
     :::c
     int image_size = 0;
     uint8_t* image = NULL;
     if ( gpujpeg_image_load_from_file("input_image.rgb", &amp;image, 
              &amp;image_size) != 0 )
         return -1;
 &lt;br/&gt;
             
 Next step is to encode uncompressed image data to JPEG compressed data by encoder:
 
     :::c
     uint8_t* image_compressed = NULL;
     int image_compressed_size = 0;
     if ( gpujpeg_encoder_encode(encoder, image, &amp;image_compressed, 
              &amp;image_compressed_size) != 0 )
         return -1;
 
 &lt;br/&gt;
             
 Compressed data are placed in internal encoder buffer so we have to save them somewhere else before we start encoding next image, for example we can save them to file:
 
     :::c       
     if ( gpujpeg_image_save_to_file("output_image.jpg", image_compressed, 
              image_compressed_size) != 0 )
         return -1;
 
 &lt;br/&gt;
 
 Now we can load, encode and save next image or finish and move to clean up encoder. Finally we have to clean up so destroy loaded image and destroy the encoder.
 
     :::c
     gpujpeg_image_destroy(image);
     gpujpeg_encoder_destroy(encoder);
         
 Decoding:
 ---------
-For decoding we have to initialize only image parameters structure, we have to initialize CUDA device if we haven't initialized it yet and create decoder:
-
-    :::c      
-    struct gpujpeg_image_parameters param_image;
-    gpujpeg_image_set_default_parameters(&amp;param_image);
-    param_image-&gt;width = 1920;
-    param_image-&gt;height = 1080;
-    // (input image size is optional, when not used buffer allocation is 
-    // postponed to first image)
-    param_image-&gt;comp_count = 3;
-    // (should not be used, is always 3)
-    param_image-&gt;color_space = GPUJPEG_RGB; 
-    // (defines output image color space)
-    param_image.sampling_factor = GPUJPEG_4_4_4;
-    // (defines output image sampling factor)
-        
+For decoding we don't need to initialize two structures of parameters. We only have to initialize CUDA device if we haven't initialized it yet and create decoder:
+
+    :::c        
     gpujpeg_init_device(device_id, 0);
         
     struct gpujpeg_decoder* decoder = gpujpeg_decoder_create(&amp;param_image);
     if ( decoder == NULL )
         return -1;
 
 &lt;br/&gt;
             
-For decoder we have two options when initializing input image parameters. The first is to leave image size to default values. Decoder than will postpone buffer allocations to decoding first image where it determines proper image size and all following images must have the same dimensions. The second option is to provide input image size and the decoder will allocate all buffers when it is creating and it is fully ready when encoding even the first image. Parameter param_image-&gt;comp_count is ignored for decoder (but it is always 3 as for encoder). Pay attention to parameter param_image-&gt;color_space which defines OUTPUT image color space that decoder will produce unlike image size is for input image. Default value for color_space is same as for encoder - GPUJPEG_RGB (rgb color space).
+Now we have two options. The first is to do nothing and decoder will postpone buffer allocations to decoding first image where it determines proper image size and all other parameters. All the following images must have the same parameters. The second option is to provide input image size and optionally other parameters and the decoder will allocate all buffers and it is fully ready when encoding even the first image. 
+    
+    :::c
+    struct gpujpeg_parameters param;
+    gpujpeg_set_default_parameters(&amp;param);
+    param.restart_interval = 16; 
+    param.interleaved = 1;
+      
+    struct gpujpeg_image_parameters param_image;
+    gpujpeg_image_set_default_parameters(&amp;param_image);
+    param_image-&gt;width = 1920;
+    param_image-&gt;height = 1080;
+    param_image-&gt;comp_count = 3;
+    
+    // Pre initialize decoder before decoding
+    gpujpeg_decoder_init(decoder, &amp;param, &amp;param_image);
+
+&lt;br/&gt;
+      
+If you want to specify output image color space and/or subsampling factor, you can use following two parameters. You can specify them though the param structure befor passing it to gpujpeg_decoder_init. But if you postpone this initialization process to the first image, you have no other option than specify them in this way:
+    
+    :::c
+    decoder-&gt;coder.param_image.color_space = GPUJPEG_RGB;
+    // or GPUJPEG_YCBCR_ITU_R or GPUJPEG_YCBCR_JPEG
+    // (default value is GPUJPEG_RGB)
+    decoder-&gt;coder.param_image.sampling_factor = GPUJPEG_4_4_4;
+    // or GPUJPEG_4_2_2
+    // (default value is GPUJPEG_4_4_4)
+
+&lt;br/&gt;
             
 Next we have to load JPEG image data from file and decoded it to raw image data:
 
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Martin Srom</dc:creator><pubDate>Tue, 03 Jan 2012 08:59:56 -0000</pubDate><guid>https://sourceforge.netffede6aa2d698d2d5106a6392571f932a1b1079c</guid></item><item><title>WikiPage UsageLibrary modified by Martin Srom</title><link>https://sourceforge.net/p/gpujpeg/home/UsageLibrary/</link><description>&lt;pre&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Martin Srom</dc:creator><pubDate>Wed, 07 Dec 2011 14:08:06 -0000</pubDate><guid>https://sourceforge.net71eb5cff9d883bd2cf1034c02c98cb8f056a3928</guid></item><item><title>WikiPage Usage of LIBGPUJPEG library modified by Martin Srom</title><link>https://sourceforge.net/p/gpujpeg/home/Usage%2520of%2520LIBGPUJPEG%2520library/</link><description>Usage of LIBGPUJPEG library
===========================

To build libgpujpeg library check Requirements and go to gpujpeg/libgpujpeg/ directory and run 'make' command. The shared library object ./libgpujpeg.so will be build. To use library in your project you have to include library to your sources and linked shared library object to your executable:

    :::c
    #include "libgpujpeg/gpujpeg.h"

[[include ref=Requirements]]
      
Encoding:
---------
For encoding by libgpujpeg library you have to declare two structures and set proper values to them. The first is structure with parameters of input image, and the second is definition of encoding parameters:

    :::c
    struct gpujpeg_image_parameters param_image;
    gpujpeg_image_set_default_parameters(&amp;param_image);
    param_image-&gt;width = 1920;
    param_image-&gt;height = 1080;
    param_image-&gt;comp_count = 3;
    // (for now, it must be 3)
    param_image-&gt;color_space = GPUJPEG_RGB; 
    // or GPUJPEG_YCBCR_ITU_R or GPUJPEG_YCBCR_JPEG
    // (default value is GPUJPEG_RGB)
    param_image.sampling_factor = GPUJPEG_4_4_4;
    // or GPUJPEG_4_2_2
    // (default value is GPUJPEG_4_4_4 )
  
    struct gpujpeg_encoder_parameters param_encoder;
    gpujpeg_encoder_set_default_parameters(&amp;param_encoder);   
    param_encoder.quality = 80; 
    // (default value is 75)
    param_encoder.restart_interval = 16; 
    // (default value is 8)

&lt;br/&gt;

Next you have to initialize CUDA device by calling:
    
    :::c  
    gpujpeg_init_device(device_id, 0);

&lt;br/&gt;
        
where first parameters is CUDA device id and second parameter is flag if verbose output should be used (0 or 1). Next step is to create encoder:
    
    :::c
    struct gpujpeg_encoder* encoder = gpujpeg_encoder_create(&amp;param_image, 
        &amp;param_encoder);
    if ( encoder == NULL )
        return -1;

&lt;br/&gt;

When creating encoder, library allocates all device buffers which will be needed for image encoding and when you encode concrete image, they are already allocated and encoder will used them for every image. Now we need raw image data that we can encode by encoder, for example we can load it from file:

    :::c
    int image_size = 0;
    uint8_t* image = NULL;
    if ( gpujpeg_image_load_from_file("input_image.rgb", &amp;image, 
             &amp;image_size) != 0 )
        return -1;
&lt;br/&gt;
            
Next step is to encode uncompressed image data to JPEG compressed data by encoder:

    :::c
    uint8_t* image_compressed = NULL;
    int image_compressed_size = 0;
    if ( gpujpeg_encoder_encode(encoder, image, &amp;image_compressed, 
             &amp;image_compressed_size) != 0 )
        return -1;

&lt;br/&gt;
            
Compressed data are placed in internal encoder buffer so we have to save them somewhere else before we start encoding next image, for example we can save them to file:

    :::c       
    if ( gpujpeg_image_save_to_file("output_image.jpg", image_compressed, 
             image_compressed_size) != 0 )
        return -1;

&lt;br/&gt;

Now we can load, encode and save next image or finish and move to clean up encoder. Finally we have to clean up so destroy loaded image and destroy the encoder.

    :::c
    gpujpeg_image_destroy(image);
    gpujpeg_encoder_destroy(encoder);
        
Decoding:
---------
For decoding we have to initialize only image parameters structure, we have to initialize CUDA device if we haven't initialized it yet and create decoder:

    :::c      
    struct gpujpeg_image_parameters param_image;
    gpujpeg_image_set_default_parameters(&amp;param_image);
    param_image-&gt;width = 1920;
    param_image-&gt;height = 1080;
    // (input image size is optional, when not used buffer allocation is 
    // postponed to first image)
    param_image-&gt;comp_count = 3;
    // (should not be used, is always 3)
    param_image-&gt;color_space = GPUJPEG_RGB; 
    // (defines output image color space)
    param_image.sampling_factor = GPUJPEG_4_4_4;
    // (defines output image sampling factor)
        
    gpujpeg_init_device(device_id, 0);
        
    struct gpujpeg_decoder* decoder = gpujpeg_decoder_create(&amp;param_image);
    if ( decoder == NULL )
        return -1;

&lt;br/&gt;
            
For decoder we have two options when initializing input image parameters. The first is to leave image size to default values. Decoder than will postpone buffer allocations to decoding first image where it determines proper image size and all following images must have the same dimensions. The second option is to provide input image size and the decoder will allocate all buffers when it is creating and it is fully ready when encoding even the first image. Parameter param_image-&gt;comp_count is ignored for decoder (but it is always 3 as for encoder). Pay attention to parameter param_image-&gt;color_space which defines OUTPUT image color space that decoder will produce unlike image size is for input image. Default value for color_space is same as for encoder - GPUJPEG_RGB (rgb color space).
            
Next we have to load JPEG image data from file and decoded it to raw image data:

    :::c            
    int image_size = 0;
    uint8_t* image = NULL;
    if ( gpujpeg_image_load_from_file("input_image.jpg", &amp;image, 
             &amp;image_size) != 0 )
        return -1;
    
    uint8_t* image_decompressed = NULL;
    int image_decompressed_size = 0;
    if ( gpujpeg_decoder_decode(decoder, image, image_size, 
             &amp;image_decompressed, &amp;image_decompressed_size) != 0 )
        return -1;

&lt;br/&gt;
            
Now we can save decoded raw image data to file and perform cleanup:

    :::c            
    if ( gpujpeg_image_save_to_file("output_image.rgb", image_decompressed, 
             image_decompressed_size) != 0 )
        return -1;
        
    gpujpeg_image_destroy(image);
    gpujpeg_decoder_destroy(decoder);</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Martin Srom</dc:creator><pubDate>Wed, 07 Dec 2011 14:01:32 -0000</pubDate><guid>https://sourceforge.net4aa82b5c41e27f69693f1c8bb51bfd2e00b4518f</guid></item></channel></rss>