Problem with JPG grayscale image

Discussions on GFL SDK, the graphic library for reading and writing graphic files

Moderators: XnTriq, helmut, xnview

Alessandro

Problem with JPG grayscale image

Post by Alessandro »

I've posted a troublesome grayscale bitmap at <!-- removed //--> with no reply then I've found this forum ^^ but I can't post that image here...

The Jpeg was grayscale 1280x1280 and I try to load it as 32bit rgb

The code I use to read it is:

Code: Select all

int GetImageInfo(char *fn, DWORD *dw, DWORD *dh, DWORD *bits, DWORD *ColorModel)
{
GFL_FILE_INFORMATION info;
bool ret=gflGetFileInformation(fn,-1,&info)==GFL_NO_ERROR;
 *dw=info .Width;
 *dh=info.Height;
 *bits=info.BitsPerComponent*info.ComponentsPerPixel;
 *ColorModel=info.ColorModel;
 gflFreeFileInformation(&info);
 return ret ? 1 : 0;
}
 
GFL_BITMAP *MyLoadImage(const char *filename)
{
GFL_LOAD_PARAMS load_params;
GFL_BITMAP *Bmp=NULL;
 
 gflGetDefaultLoadParams(&load_params);
 load_params.Flags |= GFL_LOAD_FORCE_COLOR_MODEL;// | GFL_LOAD_SKIP_ALPHA;
 load_params.Origin = GFL_BOTTOM_LEFT;
DWORD tmp,bits,color;
 if(GetImageInfo((char *)filename,&tmp,&tmp,&bits,&color))
  if(bits=8 && color==GFL_CM_RGB)
   load_params.ColorModel = GFL_ABGR;
  else
   load_params.ColorModel = GFL_BGRA;
 load_params.LinePadding = 4;
 load_params.FormatIndex=-1;
 if(gflLoadBitmap(filename, &Bmp, &load_params, NULL))
  MessageBox(NULL, "Error loading file!", NULL, MB_OK);
  if(load_params.ColorModel == GFL_ABGR)
   A2RGB((DWORD *)Bmp->Data,Bmp->Width,Bmp->Height,Bmp->BytesPerLine);
 return Bmp;
}

GFL_BGRA returns a black image (1st bug?) so
I decided to use a different order of components (GFL_ABGR) that looked working, but I had to use an hack (bits=8 && color==GFL_CM_RGB) to understand if the picture is Grayscale and I'm quite sure it'll lead to mismatches, this is due to the fact that info.ColorModel returns color==GFL_CM_RGB (=0) in place of color==GFL_CM_GRAY (2nd bug?).

What's wrong?

Best regards.

P.S.
I almost forgot:
I can retrieve how many pictures a file contains but how can I load frames (eg: into an animated gif) and how can I retrieve its framerate?

Thanks in advance.
User avatar
xnview
Author of XnView
Posts: 44930
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Re: feedback

Post by xnview »

Alessandro wrote:
GFL_BGRA returns a black image (1st bug?) so
I decided to use a different order of components (GFL_ABGR) that looked working, but I had to use an hack (bits=8 && color==GFL_CM_RGB) to understand if the picture is Grayscale and I'm quite sure it'll lead to mismatches, this is due to the fact that info.ColorModel returns color==GFL_CM_RGB (=0) in place of color==GFL_CM_GRAY (2nd bug?).

What's wrong?
Yes right, there is some problem to load grayscale picture in RGBA!
It's better to load it as grayscale, and convert it in RGBA with gflChangeColorDepth
I can retrieve how many pictures a file contains but how can I load frames (eg: into an animated gif) and how can I retrieve its framerate?
Set load_params.ImageWanted before loading
Pierre.
Alessandro

new bug

Post by Alessandro »

Hi,
thanks for your reply but I think you didn't got everything likely because I'm not that good with english...

GFL_ABGR returns a black image, while GFL_BGRA returns the grayscale bitmap only into 1 of the channels and I duplicate it using the function A2RGB(), but the problem isn't this because I solved it this way, the problem is that info.ColorModel returns color==GFL_CM_RGB (=0) in place of color==GFL_CM_GRAY, so I'm not sure if using the code:

if(bits=8 && color==GFL_CM_RGB)

creates problems... and this should be a bug to be fixed too.

new bug found(?):
I tryed to open an animated gif but info.NumberOfImages returns always 1 so I dunno how many images are stored into it and... about the framerate thing? how do I know the speed of the animation? or maybe for animated gif there's a standard I don't know of?

Best regards.