libpng - libpng 在什么颜色空间中传递 png_read_image() 中的像素?
问题描述
我的目标是加载 PNG 文件以供查看。我做了以下仪式:
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
&color_type, &interlace_type, NULL, NULL);
if (bit_depth == 16)
{
/* strip it down to 8-bit */
png_set_strip_16(png_ptr);
}
/* we do not want interlaced image data */
png_set_interlace_handling(png_ptr);
if (color_type == PNG_COLOR_TYPE_PALETTE)
{
/* we need raw color values, no palette */
png_set_palette_to_rgb(png_ptr);
}
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
{
/* always expand 1, 2 or 4 bit grey maps to full 8-bits */
png_set_expand_gray_1_2_4_to_8(png_ptr);
}
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
{
/* realize transparency in the alpha */
png_set_tRNS_to_alpha(png_ptr);
}
if (color_type == PNG_COLOR_TYPE_RGB
|| color_type == PNG_COLOR_TYPE_GRAY
|| color_type == PNG_COLOR_TYPE_PALETTE)
{
/* if the color type does not have an alpha, make it have an alpha of 0xFF */
png_set_add_alpha(png_ptr, 0xFF, PNG_FILLER_AFTER);
}
if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
{
/* expand grey to RGB */
png_set_gray_to_rgb(png_ptr);
}
我猜测 usingpng_read_image()
将提供 sRGB 中的像素,但我不知道。我也看到了函数png_set_sRGB()
,但我猜那是写PNG文件的时候。
解决方案
推荐阅读
- python-3.x - ModuleNotFoundError:没有名为“win32com”的模块
- xaml - 更改 AutoSuggestBox (UWP Xaml) 中文本的对齐方式
- c - 如何在 C 中使用 while 循环添加数组元素?
- css - 如何通过 3d css 变换实现“深度”
- react-redux - 使用 Redux 后是否鼓励使用 this.state?
- ruby-on-rails - 从我的数据库中的表中获取一些数据 - Ruby on rails
- python - 将两个熊猫数据框与公共列合并
- django - 从多域字段中检索用户列表,其中包含来自中间表的信息
- python - 按日期和每天的最大小时数对行进行排序 - Python 中的 groupby 函数
- mysql - MySql 索引(B+ 树)中的指针如何保持有效,而索引可能存储在磁盘中并在另一个页面中返回?