19,468
社区成员
发帖
与我相关
我的任务
分享
int nHeight = cinfo.image_height;
int nWidth = cinfo.image_width;
int nBits = cinfo.num_components;
unsigned char * pRGB = new unsigned char[cinfo.image_width *cinfo.image_height * cinfo.num_components];
jpeg_start_decompress(&cinfo);
JSAMPROW row_pointer[1];
while(cinfo.output_scanline < cinfo.output_height)
{
row_pointer[0]=&pRGB[cinfo.output_scanline*cinfo.image_width*cinfo.num_components];
jpeg_read_scanlines(&cinfo, row_pointer, 1);
}
int nWidthEx = WIDTHBYTES( 24 * nWidth);
int nLineTailDest = nWidthEx - 3 * nWidth;
unsigned char * pRGBA = new unsigned char[nHeight * nWidthEx];
memset(pRGBA, 0, nHeight * nWidthEx);
BYTE *p1 = (BYTE*)pRGBA;
for (unsigned int i = 0; i < nHeight; i++)
{
unsigned char * pStart = pRGB + i * nWidth * cinfo.num_components; //num_components等于3
for (unsigned int j = 0; j < nWidth; j++)
{
UINT b = *pStart++;
UINT g = *pStart++;
UINT r = *pStart++;
*p1++ = r;
*p1++ = g;
*p1++ = b;
}
p1 += nLineTailDest;
}