지금 당분간이 문제를 해결하고 있습니다.
libjpeg가있는 프로그램에 JPEG 지원을 추가하려고합니다.
대부분의 경우 상당히 잘 작동하지만 일부 JPEG의 경우 왼쪽 그림처럼 표시됩니다. C : WinAPI CreateDIBitmap() from byte [] 문제
Original Image http://www.recipehawk.com/media/failsample.png
그것은 분명하지 않을 수도 있지만, 배경은 적색, 녹색, 청색의 행을 번갈아 나타난다. 누군가가 이전에 이러한 행동을 보았고 가능한 원인을 알고 있다면, 나는 모든 의견을 고맙게 생각합니다.4 바이트의 배수가되도록 행이 패딩되어있어 문제가 해결되지 않았습니다.
코드 :
rowSize = cinfo.output_width * cinfo.num_components;
/* Windows needs bitmaps to be defined on Four Byte Boundaries */
winRowSize = (rowSize + 3) & -4;
imgSize = (cinfo.output_height * winRowSize + 3) & -4;
while(cinfo.output_scanline < cinfo.output_height){
jpeg_read_scanlines(&cinfo, &row_pointer, 1);
/* stagger read to get lines Bottom->Top (As BMP Requires) */
location = (imgSize) - (cinfo.output_scanline * winRowSize);
rowsRead++;
for(i = 0; i < winRowSize; i++){
rawImage[location++] = row_pointer[i];
}
}
/* Convert BGR to RGB */
if(cinfo.num_components == 3){
for(i = 0; i < imgSize; i += 3){
tmp = rawImage[i+2];
rawImage[i+2] = rawImage[i];
rawImage[i] = tmp;
}
}
biSize = sizeof(BITMAPINFOHEADER);
if(cinfo.num_components == 1){ /* Greyscale */
biPallete = 32 * 256;
biSize += biPallete;
}
bitInf = (BITMAPINFO *)malloc(biSize);
bitInf->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitInf->bmiHeader.biWidth = cinfo.output_width;
bitInf->bmiHeader.biHeight = cinfo.output_height;
bitInf->bmiHeader.biPlanes = 1;
bitInf->bmiHeader.biBitCount = 8*cinfo.num_components;
bitInf->bmiHeader.biCompression = BI_RGB;
bitInf->bmiHeader.biSizeImage = 0;
bitInf->bmiHeader.biXPelsPerMeter = 0;
bitInf->bmiHeader.biYPelsPerMeter = 0;
bitInf->bmiHeader.biClrUsed = 0;
bitInf->bmiHeader.biClrImportant = 0;
if(cinfo.num_components == 1){
for(i = 0; i < 256; i++){
bitInf->bmiColors[i].rgbBlue = i;
bitInf->bmiColors[i].rgbGreen = i;
bitInf->bmiColors[i].rgbRed = i;
bitInf->bmiColors[i].rgbReserved = 0;
}
}
/* Loads rawImage into an HBITMAP */
/* retval = CreateDIBitmap(inDC, &bitInf->bmiHeader, CBM_INIT, rawImage, bitInf, DIB_RGB_COLORS); */
retval = CreateCompatibleBitmap(inDC, cinfo.output_width, cinfo.output_height);
errorCode = SetDIBits(inDC, retval, 0, cinfo.output_height, rawImage, bitInf, DIB_RGB_COLORS);
솔루션 :이에 RGB/BGR 계산기 변경 :
if(cinfo.num_components == 3){
for(i = 0; i < cinfo.output_height; i++){
location = (i * winRowSize);
for(j = 0; j < rowSize; j += 3){
tmp = rawImage[location+2];
rawImage[location+2] = rawImage[location];
rawImage[location] = tmp;
location += 3;
}
}
}
을 그리고 그것은 마법처럼 일했다. roygbiv에게 감사드립니다.
어쩌면 우리가 문제를 진단하는 데 유용한 코드를 게시. –
origianl 문제 jpeg에 대한 링크를 게시하는 것도 유용 할 수 있습니다. – SteelBytes