Note that there are some explanatory texts on larger screens.

plurals
  1. POlibjpeg/CreateDIBSection problem
    primarykey
    data
    text
    <p>I'm writing a Win32-based application that displays jpeg images from a database. I picked libjpeg as the decoder, but most images display incorrectly. It can be fixed by increasing or decreasing the width of image by one, however, images that have been displayed correctly before display incorrectly after this fix. Here's part of my code (excluding RGB to BGR conversion):</p> <pre><code>int JpegToRaw(BYTE *input, int insize, BYTE *output, int &amp;width, int &amp;height) { struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; cinfo.err = jpeg_std_error(&amp;jerr); jpeg_create_decompress(&amp;cinfo); jpeg_mem_src(&amp;cinfo, input, insize); jpeg_read_header(&amp;cinfo, TRUE); jpeg_start_decompress(&amp;cinfo); //--cinfo.output_width; or ++cinfo.output_width; int row_stride = cinfo.output_width * 3; int outsize = row_stride * cinfo.output_height; output = (BYTE *)malloc(outsize * sizeof(BYTE)); BYTE *pos = output; while (cinfo.output_scanline &lt; cinfo.output_height) { jpeg_read_scanlines(&amp;cinfo, &amp;pos, 1); pos += row_stride; } width = cinfo.output_width; height = cinfo.output_height; jpeg_finish_decompress(&amp;cinfo); jpeg_destroy_decompress(&amp;cinfo); return outsize; } HBITMAP RawToBitmap(BYTE *input, int size, int width, int height) { BITMAPINFO bi; bi.bmiHeader.biSize = sizeof(bi24BitInfo.bmiHeader); bi.bmiHeader.biWidth = width; bi.bmiHeader.biHeight = -height; bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = 24; bi.bmiHeader.biCompression = BI_RGB; HBITMAP hBitmap = CreateDIBSection(NULL, &amp;bi, DIB_RGB_COLORS, NULL, NULL, 0); SetBitmapBits(hBitmap, size, input); return hBitmap; } </code></pre> <p>I'm sure I pass valid jpeg arrays to <code>JpegToRaw()</code>, but I have no idea why do the images display different. Can someone help me to get it?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload