png_set_IHDR(
png_ptr,
info_ptr,
vinfo.xres_virtual,
vinfo.yres_virtual,
8,
PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE,
PNG_FILTER_TYPE_BASE);
png_write_info(png_ptr, info_ptr);
png_bytep png_buffer = malloc(vinfo.xres_virtual * 3 * sizeof(png_byte));
if (png_buffer == NULL)
{
fprintf(stderr, "%s: Unable to allocate buffer\n", program);
exit(EXIT_FAILURE);
}
//--------------------------------------------------------------------
int r_mask = (1 << vinfo.red.length) - 1;
int g_mask = (1 << vinfo.green.length) - 1;
int b_mask = (1 << vinfo.blue.length) - 1;
int bytes_per_pixel = vinfo.bits_per_pixel / 8;
int y = 0;
for (y = 0; y < vinfo.yres_virtual; y++)
{
int x;
for (x = 0; x < vinfo.xres_virtual; x++)
{
int pb_offset = 3 * x;