How load large bitmap to DIB or DDB in windows?

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

Moderators: XnTriq, xnview

Tonal
Posts: 2
Joined: Sat Feb 26, 2005 9:12 am
Location: novosibirsk

How load large bitmap to DIB or DDB in windows?

Post by Tonal »

I try load pcx file into DIB or DDB.
file size ~1.2mb.

I retrive error code 5 - GFL_ERROR_NO_MEMORY (No more memory).

How I load large bitmap into DIB or DDB?

My code:

Code: Select all

GFL_LOAD_PARAMS load_option;
gflGetDefaultLoadParams(&load_option);
load_option.Flags |= GFL_LOAD_SKIP_ALPHA;
load_option.Origin = GFL_BOTTOM_LEFT;
load_option.ColorModel = GFL_BGR;
HBITMAP hbmp;
gflLoadBitmapIntoDDB(fname, &hbmp, &load_option, 0)
Tonal
Posts: 2
Joined: Sat Feb 26, 2005 9:12 am
Location: novosibirsk

Post by Tonal »

I resolved problem.

Functions gflLoadBitmapIntoDDB and gflConvertBitmapIntoDDB do not work correct.

My code for resolve:

Code: Select all

HBITMAP load2DDB(const char fname[]) {
  GFL_FILE_INFORMATION info;
  gflGetFileInformation(fname, -1, &info)

  GFL_LOAD_PARAMS load_option;
  gflGetDefaultLoadParams(&load_option);
  load_option.Flags |= GFL_LOAD_SKIP_ALPHA;
  load_option.FormatIndex = info.FormatIndex;
  load_option.Origin = GFL_TOP_LEFT;
  //Optimisation for memory and speed
  if (info.ColorModel == GFL_CM_RGB &&
      info.BitsPerComponent * info.ComponentsPerPixel == 1
  )
    load_option.ColorModel = GFL_BINARY;
  else
    load_option.ColorModel = GFL_BGR;

  //DDB data aligment 2 bytes
  load_option.LinePadding = 2;

  gflFreeFileInformation(&info);

  HBITMAP hbmp = 0;
  GFL_BITMAP* gfl_tmp = 0;
    
  if (GFL_NO_ERROR != gflLoadBitmap(fname, &gfl_tmp, &load_option, 0)
    return 0;

  //Optimisation for memory and speed
  if (gfl_tmp->Type == GFL_BINARY) 
    hbmp = ::CreateBitmap(gfl_tmp->Width, gfl_tmp->Height, 1, 1, gfl_tmp->Data);
  else {
    hbmp = ::CreateCompatibleBitmap(0, gfl_tmp->Width, gfl_tmp->Height);
    ::SetBitmapBits(
      hbmp, gfl_tmp->Height * gfl_tmp->BytesPerLine, gfl_tmp->Data
    );
  }
  gflFreeBitmap(gfl_tmp);
  return hbmp;
}