LibPng读入结构
LibPng Read Into Struct
我似乎无法让libpng将其数据转储到我的结构中。我不知道我做错了什么。我正在尝试翻转字节,因为PNG的存储方式是自上而下,而我需要数据自下而上,向上。
首先我的结构看起来像:
typedef union RGB
{
uint32_t Color;
struct
{
unsigned char B, G, R, A;
} RGBA;
} *PRGB;
然后我创建了一个如下的向量:
png_init_io(PngPointer, hFile);
png_set_sig_bytes(PngPointer, 8);
png_read_info(PngPointer, InfoPointer);
uint32_t width, height;
int bitdepth, colortype, interlacetype, channels;
png_set_strip_16(PngPointer);
channels = png_get_channels(PngPointer, InfoPointer);
png_get_IHDR(PngPointer, InfoPointer, &width, &height, &bitdepth, &colortype, &interlacetype, nullptr, nullptr);
uint32_t RowBytes = png_get_rowbytes(PngPointer, InfoPointer);
unsigned char** RowPointers = png_get_rows(PngPointer, InfoPointer);
std::vector<RGB> Pixels(RowBytes * height); //Amount of bytes in one row * height of image.
//Crashes in the for loop below :S
for (int I = 0; I < height; I++)
{
for (int J = 0; J < width; J++)
{
Pixels[(height - 1 - I) * width + J].RGBA.B = *(RowPointers[J]++);
Pixels[(height - 1 - I) * width + J].RGBA.G = *(RowPointers[J]++);
Pixels[(height - 1 - I) * width + J].RGBA.R = *(RowPointers[J]++);
}
}
std::fclose(hFile);
png_destroy_read_struct(&PngPointer, &InfoPointer, nullptr);
我做错了什么?我怎样才能得到PNG的像素并将它们上下颠倒?我对位图使用了相同的技术,但PNG就是不起作用:l
Pixels[(height - 1 - I) * width + J].RGBA.B = *(RowPointers[J]++);
索引RowPointers
通过I
代替?
相关文章:
- 如何循环打印顶点结构
- 通过方法访问结构
- 使用不带参数的函数访问结构元素
- 预处理器:插入结构名称中的前一个行号
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 孤立代码块在结构中引发异常
- 有什么方法可以遍历结构吗
- 如何在 C# 中映射双 C 结构指针?
- 如何在C++中使用结构生成映射
- 无法将结构注册为增强几何体3D点
- 多成员Constexpr结构初始化
- C++将文本文件中的数据读取到结构数组中
- 如何重构类层次结构以避免菱形问题
- 如何在C++中序列化结构数据
- std::vector的包装器,使数组的结构看起来像结构的数组
- 没有为自己的结构调用列表推回方法
- 奇怪的结构&GCC&clang(void*返回类型)
- 在 c++ 中拥有一组结构的正确方法是什么?
- Libpng |结构的重复符号
- LibPng读入结构