When loading a single-color image, png_get_rows() returns a pointer to only 1 color

63 views Asked by At

When loading a single-color image, png_get_rows() returns a pointer to only 1 color. A should return a pointer to the colors of all pixels, even if they are the same. How can I do this or check that the image is one color? I need exactly this kind of logic

String path = PathHelper::GetAssetsPath();
path += name; // white.png

png_uint_32 width, height;
png_structp pngStruct{};
png_infop pngInfo{};
FILE* file = 0;
unsigned char* data = 0;

file = fopen(path, "rb");
FOG_ASSERT(file != 0);

pngStruct = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
FOG_ASSERT(pngStruct != 0);

pngInfo = png_create_info_struct(pngStruct);
FOG_ASSERT(pngInfo != 0);


if (setjmp(png_jmpbuf(pngStruct))) 
{
    png_destroy_read_struct(&pngStruct, &pngInfo, 0);
    fclose(file);
    FOG_ASSERT(false);
}

png_init_io(pngStruct, file);

int numBytes = 0;
png_set_sig_bytes(pngStruct, numBytes);

png_read_png(pngStruct, pngInfo, PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_EXPAND, NULL);
png_get_IHDR(pngStruct, pngInfo, &width, &height, 0, 0, 0, 0, 0);

size_t row_bytes = png_get_rowbytes(pngStruct, pngInfo);
data = new unsigned char[row_bytes * height];

png_bytepp row_pointers = png_get_rows(pngStruct, pngInfo); // return 0xFF
0

There are 0 answers