【问题标题】:What are this properties in libjpeg and in libpng?libjpeg 和 libpng 中的这些属性是什么?
【发布时间】:2020-11-22 09:05:18
【问题描述】:

我实际上是在使用 libjpeg 来读取和保存 JPEG 图像。
那么首先像素大小的可能性是什么(info.output_components;)?
色彩空间有哪些可能性(info.out_color_space;)?
JPEG 图像可以有 alpha 通道吗?

我也在使用 libpng。
那么首先什么是位深度(png_get_bit_depth(png, info);)?
以及颜色类型是什么(png_get_color_type(png, info);)?

谢谢!

【问题讨论】:

标签: c++ libpng libjpeg


【解决方案1】:

那么首先像素大小(info.output_components;)的可能性是什么?

来自doc

output_components 在量化颜色时为 1(颜色图索引);否则它 等于out_color_components。它将是 JSAMPLE 值的数量 在输出数组中按像素发射。

  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.

色彩空间有哪些可能性(info.out_color_space;)?

来自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 */

JPEG 图像可以有 alpha 通道吗?

从上面的源代码可以看出,libjpeg-turbo 确实支持 jpeg 的 alpha 通道。


那么首先什么是位深度 (png_get_bit_depth(png, info);)?

简单地说,用于表示图像中每个像素的位数。位深越高,每个像素可以包含的颜色越多。

来自PNG Spec

颜色类型是描述图像数据解释的单字节整数。颜色类型代码表示以下值的总和:1(使用调色板)、2(使用颜色)和 4(使用 Alpha 通道)。有效值为 0、2、3、4 和 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.

【讨论】:

  • 感谢您的精彩回答!有没有办法在 libpng 中获取像素大小?
  • libjpeg 中是否有这样的颜色空间:monochrome/alpha
  • @PacCol 看起来不像。
  • JCS_EXT_RGBX 中的 X 值是多少?
  • X 表示它有一个 alpha 通道,但它被忽略了,并且始终设置为 255。
猜你喜欢
  • 1970-01-01
  • 2014-08-10
  • 2022-01-08
  • 2014-10-23
  • 1970-01-01
  • 2019-07-31
  • 1970-01-01
  • 1970-01-01
  • 2019-06-12
相关资源
最近更新 更多