Search code examples
c++libpnglibjpeg

What are this properties in libjpeg and in libpng?


I'm actually using the libjpeg to read and save JPEG images.
So first what are the possibilities of pixel size (info.output_components;) ?
What are the possibilities of color space (info.out_color_space;) ?
And can a JPEG image have an alpha channel ?

I'm using the libpng too.
So first what is the bit depth (png_get_bit_depth(png, info);) ?
And what is the color type (png_get_color_type(png, info);) ?

Thanks !


Solution

  • So first what are the possibilities of pixel size (info.output_components;) ?

    From the doc

    output_components is 1 (a colormap index) when quantizing colors; otherwise it equals out_color_components. It is the number of JSAMPLE values that will be emitted per pixel in the output arrays.

      int out_color_components;     /* # of color components in out_color_space */
      int output_components;        /* # of color components returned */
      /* output_components is 1 (a colormap index) when quantizing colors;
       * otherwise it equals out_color_components.
    

    What are the possibilities of color space (info.out_color_space;) ?

    From the source

      JCS_UNKNOWN,            /* error/unspecified */
      JCS_GRAYSCALE,          /* monochrome */
      JCS_RGB,                /* red/green/blue as specified by the RGB_RED,
                                 RGB_GREEN, RGB_BLUE, and RGB_PIXELSIZE macros */
      JCS_YCbCr,              /* Y/Cb/Cr (also known as YUV) */
      JCS_CMYK,               /* C/M/Y/K */
      JCS_YCCK,               /* Y/Cb/Cr/K */
      JCS_EXT_RGB,            /* red/green/blue */
      JCS_EXT_RGBX,           /* red/green/blue/x */
      JCS_EXT_BGR,            /* blue/green/red */
      JCS_EXT_BGRX,           /* blue/green/red/x */
      JCS_EXT_XBGR,           /* x/blue/green/red */
      JCS_EXT_XRGB,           /* x/red/green/blue */
      /* When out_color_space it set to JCS_EXT_RGBX, JCS_EXT_BGRX, JCS_EXT_XBGR,
         or JCS_EXT_XRGB during decompression, the X byte is undefined, and in
         order to ensure the best performance, libjpeg-turbo can set that byte to
         whatever value it wishes.  Use the following colorspace constants to
         ensure that the X byte is set to 0xFF, so that it can be interpreted as an
         opaque alpha channel. */
      JCS_EXT_RGBA,           /* red/green/blue/alpha */
      JCS_EXT_BGRA,           /* blue/green/red/alpha */
      JCS_EXT_ABGR,           /* alpha/blue/green/red */
      JCS_EXT_ARGB,           /* alpha/red/green/blue */
      JCS_RGB565              /* 5-bit red/6-bit green/5-bit blue */
    

    And can a JPEG image have an alpha channel ?

    As you can see from the source code above, libjpeg-turbo does support alpha channel for jpegs.


    So first what is the bit depth (png_get_bit_depth(png, info);) ?

    Simply put, number of bits used to represent each pixel in an image. The higher the bit depth, the more colors each pixel can contain.

    From the PNG Spec:

    Color type is a single-byte integer that describes the interpretation of the image data. Color type codes represent sums of the following values: 1 (palette used), 2 (color used), and 4 (alpha channel used). Valid values are 0, 2, 3, 4, and 6.

      Color    Allowed    Interpretation
      Type    Bit Depths
      
      0       1,2,4,8,16  Each pixel is a grayscale sample.
      
      2       8,16        Each pixel is an R,G,B triple.
      
      3       1,2,4,8     Each pixel is a palette index;
                          a PLTE chunk must appear.
      
      4       8,16        Each pixel is a grayscale sample,
                          followed by an alpha sample.
      
      6       8,16        Each pixel is an R,G,B triple,
                          followed by an alpha sample.