我正在尝试使用LibPNG c库将png图像加载到图形缓冲区中,如此
//m_pBuffer is the graphics buffer
//row_pointers is the data from png
//width is width of image
//height height of image
//y = 100
//x = 100
//ScreenWidth = 1024
//channel_num = 4
int pDst = (y + height - 1) * ScreenWidth + x;
for (y = height - 1; y >= 0 ; y--)
{
png_bytep row = row_pointers[y];
u32 *pBuffer = m_pBuffer + pDst;
for(x = 0; x < width; x++) {
png_bytep px = &(row[x * channel_num]);
*pBuffer++ = RGBA(px[3], px[2], px[1], px[0]);
}
pDst -= ScreenWidth;
}
如何摆脱淡黄色背景和白色边框?
这就是row_pointers的填充方式
png_bytep row_pointers[height];
int row = 0;
for (row = 0; row < height; row++)
row_pointers[row] = NULL;
for (row = 0; row < height; row++)
row_pointers[row] = (png_byte*)png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr));
int pass = 0;
int number_passes = 1;
for (pass = 0; pass < number_passes; pass++)
{
for (int j = 0; j < height; j++)
{
png_read_rows(png_ptr, NULL, &row_pointers[j], 1);
}
}
png_read_end(png_ptr, info_ptr);