GFL SDK v2.90 gflResize Error

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

Moderators: XnTriq, xnview

Post Reply
Zai++
Posts: 21
Joined: Fri Nov 18, 2005 4:57 pm
Location: Moscow

GFL SDK v2.90 gflResize Error

Post by Zai++ » Wed Oct 29, 2008 12:24 pm

This code worked successfully on 267 version, but it fails on 290:

Code: Select all

 GFL_BITMAP* Dst=NULL;
//Src - pointer to existing bitmap 
 gflResize(Src, &Dst, SaveW, SaveH, .., ..);
Access violation in module LIBGFL290.DLL
:(

User avatar
dominique
Posts: 72
Joined: Thu Nov 08, 2007 9:22 am

Post by dominique » Thu Oct 30, 2008 8:31 am

If you didn't read the help or for other user with similar problem :
I use gflResize without problem. You should write NULL directly to resize in the Src bitmap (written in the help). Here, &Dst is not NULL, just the pointer Dst is NULL so the lib may try to do something with a nowhere pointer.
I made a similar mistake writing the same bitmap in Src and Dest.
Dom

Zai++
Posts: 21
Joined: Fri Nov 18, 2005 4:57 pm
Location: Moscow

Post by Zai++ » Wed Nov 05, 2008 3:36 pm

>I made a similar mistake writing the same bitmap in Src and Dest.
It's not a mistake. In previous version when gflResize got a pointer to NULL in Dst parametr it created a new GFL_BITMAP object
and now it fails.

>You should write NULL directly to resize in the Src bitmap (written in the help).
I don't need to resize Src. I need to get a resized copy of Src in Dst.

PS. The resizing of Src (as you suggested) also fails!

Code: Select all

gflResize(Src, NULL, SaveWSync, SaveHSync, GFL_RESIZE_BILINEAR, 0);
Access violation in module LIBGFL290.DLL

Help! :(

User avatar
xnview
Author of XnView
Posts: 30260
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Post by xnview » Wed Nov 05, 2008 3:56 pm

Zai++ wrote:

Code: Select all

gflResize(Src, NULL, SaveWSync, SaveHSync, GFL_RESIZE_BILINEAR, 0);
Access violation in module LIBGFL290.DLL
??? Your Src is a good bitmap?
Pierre.

User avatar
dominique
Posts: 72
Joined: Thu Nov 08, 2007 9:22 am

Post by dominique » Thu Nov 06, 2008 10:32 am

I didn't realize you want to resize in an other Bitmap :)
I try this code without problem :

Code: Select all

        gflLibraryInit();
        AnsiString lFileIn = "TestResize.tif";
        GFL_LOAD_PARAMS         lLoadOption;
        GFL_FILE_INFORMATION    lDestImageInfo;
        GFL_BITMAP*             lSrcBitmap;
        GFL_BITMAP*             lDestBitmap;
        gflGetDefaultLoadParams(&lLoadOption);
        GFL_ERROR lError = gflLoadBitmap(lFileIn.c_str(), &lSrcBitmap, &lLoadOption, &lDestImageInfo);
        if (lError != GFL_NO_ERROR)
                ExitProcess(lError);
        lDestBitmap = NULL;
        lError = gflResize(lSrcBitmap, &lDestBitmap, lSrcBitmap->Width / 2, lSrcBitmap->Height / 2, GFL_RESIZE_BILINEAR, 0);
        if (lError != GFL_NO_ERROR)
                ExitProcess(lError);
        gflFreeFileInformation(&lDestImageInfo);
        gflFreeBitmap(lSrcBitmap);
        gflFreeBitmap(lDestBitmap);
        gflLibraryExit();
Perhaps you should check the error on the gflLoadBitmap.
Rgds
Dom

Zai++
Posts: 21
Joined: Fri Nov 18, 2005 4:57 pm
Location: Moscow

Post by Zai++ » Thu Nov 06, 2008 2:28 pm

Thanks for your cooperation :)
The problem is solved! The description is below (if you are interested in)

gflResize works correct when the function uses GFL_BITMAPs with their own data, I mean, GFL_BITMAP::Data points to a memory created with gflAllockBitmap, gflLoadBitmap etc.

But I use GFL_BITMAP with alien data, that is GFL_BITMAP::Data points to a memory of WinAPI DIBSection. This allows me to load and save windows bitmaps. So I have a wrap class over the GFL_BITMAP. It fills GFL_BITMAP like this:

Code: Select all

 G.Data=reinterpret_cast<GFL_UINT8>(const_cast<void>(Saveable->GetDataAddress()));
 G.LinePadding=Saveable->AlignRow;
 G.BytesPerLine=Saveable->VB;
 switch(dpp)
 {
  case 32:
                 G.Type=           GFL_BGRA;
                 G.ComponentsPerPixel=G.BytesPerPixel=4;
                 break;
  case 24:
                 G.Type=           GFL_BGR;
                 G.ComponentsPerPixel=G.BytesPerPixel=3;
                 break;
  case 8:
                 G.Type=           GFL_GREY;
                 G.ComponentsPerPixel=G.BytesPerPixel=1;
                 break;
...and so on
Previous versions of GFL had small error. I need to write

Code: Select all

 G.LinePadding=G.BytesPerLine;
instead of
 G.LinePadding=4;//real padding
Otherwise GFL failed (save, resize and others)

Now this error is fixed, but because of this old code with (G.LinePadding=G.BytesPerLine;) doesn't work correct and resize operation fails, while other (save for example) works correct!

I spent several hours to find it. So the solution is "G.LinePadding=4;"

PS. GFL help says:

Code: Select all

GFL_BITMAP::LinePadding 	Internal use, do not modify.
I'm laughing :mrgreen: :mrgreen: :mrgreen:

PPS. sorry for taking your time

User avatar
dominique
Posts: 72
Joined: Thu Nov 08, 2007 9:22 am

Post by dominique » Thu Nov 06, 2008 2:59 pm

But I use GFL_BITMAP with alien data, that is GFL_BITMAP::Data points to a memory of WinAPI DIBSection
I'm not shure but you have special functions to translate this kind of Bitmap. From the doc :
gflConvertBitmapIntoDIB

The gflConvertBitmapIntoDIB function converts a GFL_BITMAP in a Windows Device Independant Bitmap
and
gflConvertDIBIntoBitmap

The gflConvertDIBIntoBitmap function converts a Windows Device Independant Bitmap into GFL_BITMAP.
If the help says not to change a value I think it's better to do not. LinePadding should be calculated internally while building a specific bitmap with a given type and count of pixel. I imagine it's to have a specific BytesPerLine to faster pixel access or algorithm calculation.
So I use to make wrappers with other libs and I prefer to use libs to allocate bitmaps specifying size and pixels'type. And then you can copy from one buffer to an other using one index/pointer for each buffer. So libs can correclty managed memory and "protected" members ;)
Dom

Zai++
Posts: 21
Joined: Fri Nov 18, 2005 4:57 pm
Location: Moscow

Post by Zai++ » Fri Nov 07, 2008 12:09 pm

> you have special functions to translate this kind of Bitmap

translating needs much time and memory, especially with large images
I don't want to waste resources just copying megabytes

I prefer to use undocumented features and .. :) .. am ready for future troubles

Post Reply