1 year ago
#355045
look_up
libpng library - write data to row_pointer variable
I am trying to write a monochrome image to PNG file using libpng
library. PNG specification says that you can use grayscale type, since I do not need shades I want to use only grayscale, without alpha channel. So, the color_type
parameter is PNG_COLOR_TYPE_GRAY
.
I am having trouble to figure out how to write data from array of pixels to row_pointer
. So that I can use png_write_image(png, row_pointer);
.
If I have image pixels as array of bytes byte imagePixels[25] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0};
. This should represent image that is 5x5 pixel dimension. Pixel with value 1 should be black - #000000
, and pixel with value 0 should be white - #FFFFFF
.
In libpng
library specification, it states that row_pointer
is a array of rows. For my imagePixels
variable array should be array of the five elements - row_pointer[5]
.
How do I write pixels from imagePixels
to row_pointer
array? I can not figure it out how to write data to row_pointer
array.
Definition of row_pointer
is:
typedef unsigned char png_byte;
typedef png_byte * png_bytep;
png_bytep *row_pointer;
Thanks for any kind of help or suggestion.
Edit:
Code is:
row_pointers = (png_bytep *)malloc(sizeof(png_bytep) * m_height);
for (int y = 0; y < m_height; y++) {
row_pointers[y] = (png_byte *)malloc(png_get_rowbytes(png, infoPng));
row_pointers[y] = (png_bytep)&(imagePixels[y * m_widht]);
}
png_write_image(png, row_pointers);
c++
arrays
libpng
0 Answers
Your Answer