Converting Jpeg images to Bmp - some images come out blue

前端 未结 4 1035
忘了有多久
忘了有多久 2020-12-14 12:33

There are some Jpg images which Delphi doesn\'t seem to like. It appears to be specific with the files I\'m loading. And the procedure is simple - a) load Jpg image to

4条回答
  •  失恋的感觉
    2020-12-14 12:40

    The reason your file is blue is because the encoding is BGR isntead of RGB.
    If you modify the jpeg.pas source file and use the pixel swapping (remove {.$IFDEF JPEGSO} in TJPEGImage.GetBitmap) you'll see your sample file correctly brown.

    So, I guess the bottom line is that the stock jpeg source does not detect the correct (reverse) encoding; probably in jc.d.out_color_space...

    Update:
    The C source file (and jpeg.pas) should declare (and use) the Color Spaces with the new Extensions JCS_EXT_...:

    enum J_COLOR_SPACE {
      JCS_UNKNOWN, JCS_GRAYSCALE, JCS_RGB, JCS_YCbCr,
      JCS_CMYK, JCS_YCCK, JCS_EXT_RGB, JCS_EXT_RGBX,
      JCS_EXT_BGR, JCS_EXT_BGRX, JCS_EXT_XBGR, JCS_EXT_XRGB
    }
    

    Update 2:
    jpeg.pas can be found (XE) in C:...\RAD Studio\8.0\source\vcl with the C files in the jpg subfolder.

    If you're ready to bet that all Adobe files with an RGB colorspace need to have their bits swapped, you can easily hack the jpeg.pas source to detect your special files and conditionnally do the swap mentioned above in TJPEGImage.GetBitmap

    {.$IFDEF JPEGSO}
              if (jc.c.in_color_space=JCS_RGB)and
                (smallint(jc.c.jpeg_color_space)=Ord(JCS_UNKNOWN))and   //comes 1072693248 = $3FF00000 = 111111111100000000000000000000
                jc.d.saw_Adobe_marker  and
                (PixelFormat = jf24bit) then
              begin
    

提交回复
热议问题