gflLoadBitmapFromMemory problem under linux ??

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

Moderators: XnTriq, xnview

tiboy08
Posts: 10
Joined: Tue Feb 15, 2011 6:56 pm

gflLoadBitmapFromMemory problem under linux ??

Post by tiboy08 » Tue Feb 15, 2011 7:05 pm

Hi,

I have a problem when loading a gflBitmap (from a standard unsigned char * buffer) using the gflLoadBitmapFromMemory function. The function call returns the error code 6 ("Unknown format") only under linux, under windows there is no problem ... I post the tested code below :
#include <iostream>
#include <libgfl.h>

void PgmRead(int & sx, int & sy, unsigned char ** buffer, const char * filename){

FILE * fic = fopen(filename, "rb");
fscanf(fic, "P5\n");
fscanf(fic, "%d %d\n", &sx, &sy);
fscanf(fic, "255\n");
(*buffer) = new unsigned char[sx*sy];
fread((*buffer), sizeof(unsigned char), sx*sy, fic);
fclose(fic);

}

int main(int argc, char ** argv){

gflLibraryInit();

unsigned char * image = 0;
int sx, sy;
PgmRead(sx, sy, &image, "test.pgm");

GFL_LOAD_PARAMS load_params;
gflGetDefaultLoadParams(&load_params);
load_params.FormatIndex = gflGetFormatIndexByName("raw");
load_params.Origin = GFL_TOP_LEFT;
load_params.Width = sx;
load_params.Height = sy;
load_params.Offset = 0;
load_params.ChannelOrder = GFL_CORDER_INTERLEAVED;
load_params.ChannelType = GFL_CTYPE_GREYSCALE;

GFL_BITMAP * bitmap = 0;
bitmap = gflAllockBitmap(GFL_GREY, sx, sy, 1, NULL);

••• SPAM •••::cout << gflGetErrorString(gflLoadBitmapFromMemory(image, sx*sy, &bitmap, &load_params, NULL)) << ••• SPAM •••::endl;

gflLibraryExit();

return 0;

}
returns "Unknown format". Can you please give me some information about this problem ??

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

Re: gflLoadBitmapFromMemory problem under linux ??

Post by xnview » Tue Feb 15, 2011 8:19 pm

Why you don't load ppm data and use gflGetFormatIndexByName("ppm")?
Pierre.

tiboy08
Posts: 10
Joined: Tue Feb 15, 2011 6:56 pm

Re: gflLoadBitmapFromMemory problem under linux ??

Post by tiboy08 » Tue Feb 15, 2011 8:52 pm

Because, in my program (not in this little test code), the greyscale buffer is computed during by a previous step and is already in memory ....

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

Re: gflLoadBitmapFromMemory problem under linux ??

Post by xnview » Tue Feb 15, 2011 8:54 pm

tiboy08 wrote:Because, in my program (not in this little test code), the greyscale buffer is computed during by a previous step and is already in memory ....
So perhaps the better way is to create GFL_BITMAP structure, and to copy data only
Pierre.

tiboy08
Posts: 10
Joined: Tue Feb 15, 2011 6:56 pm

Re: gflLoadBitmapFromMemory problem under linux ??

Post by tiboy08 » Tue Feb 15, 2011 8:57 pm

Ok, so i create an GFL_BITMAP instance using the gflAllockBitmap function, then operate a memcpy on the GFL_BITMAP::Data ??

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

Re: gflLoadBitmapFromMemory problem under linux ??

Post by xnview » Tue Feb 15, 2011 8:59 pm

tiboy08 wrote:Ok, so i create an GFL_BITMAP instance using the gflAllockBitmap function, then operate a memcpy on the GFL_BITMAP::Data ??
yes, more simple :)
Pierre.

tiboy08
Posts: 10
Joined: Tue Feb 15, 2011 6:56 pm

Re: gflLoadBitmapFromMemory problem under linux ??

Post by tiboy08 » Tue Feb 15, 2011 9:00 pm

ok thank you, i will try this now ....

tiboy08
Posts: 10
Joined: Tue Feb 15, 2011 6:56 pm

Re: gflLoadBitmapFromMemory problem under linux ??

Post by tiboy08 » Tue Feb 15, 2011 9:09 pm

Ok, seems to work correctly now. Thank you !! I will contact you in case of further issues.

tiboy08
Posts: 10
Joined: Tue Feb 15, 2011 6:56 pm

Re: gflLoadBitmapFromMemory problem under linux ??

Post by tiboy08 » Tue Feb 15, 2011 9:48 pm

Ok, so the first problem is solved. But it remains one, i work on a image compression program so this is what I need to do :

1) compress an unsigned char * buffer in PNG format into a memory buffer (using GFL_BITMAP & gflSaveBitmapIntoMemory) (seems to work)
2) From the PNG bitstream, retrieve the original unsigned char * buffer using (gflLoadBitmapFromMemory) (produces segfault)

This is the resulting C++ code :
int main(int argc, char * argv[]){

gflLibraryInit();

unsigned char * image = 0;
unsigned char * imagePNG = 0;
unsigned int imagePNGSize = 0;
unsigned char * image_decomp = 0;

int sx, sy;
PgmRead(sx, sy, &image, "test.pgm");

GFL_SAVE_PARAMS save_params;
gflGetDefaultSaveParams(&save_params);
save_params.FormatIndex = gflGetFormatIndexByName("png");
save_params.Compression = GFL_NO_COMPRESSION;
save_params.CompressionLevel = 7;

GFL_LOAD_PARAMS load_params2;
gflGetDefaultLoadParams(&load_params2);
load_params2.FormatIndex = gflGetFormatIndexByName("png");
load_params2.Origin = GFL_TOP_LEFT;
load_params2.Width = sx;
load_params2.Height = sy;
load_params2.Offset = 0;
load_params2.ChannelOrder = GFL_CORDER_INTERLEAVED;
load_params2.ChannelType = GFL_CTYPE_GREYSCALE;


//Creating a bitmap for PNG compression into memory
GFL_BITMAP * bitmap = 0;
bitmap = gflAllockBitmap(GFL_GREY, sx, sy, 1, NULL);
bitmap->Data = new GFL_UINT8[sx*sy];
memcpy(bitmap->Data, image, sx*sy*sizeof(unsigned char));
gflSaveBitmapIntoMemory(&imagePNG, &imagePNGSize, bitmap, &save_params);

//Retrieve an unsigned char * buffer from the PNG bitstream
GFL_BITMAP * bitmap2 = 0;
bitmap2 = gflAllockBitmap(GFL_GREY, sx, sy, 1, NULL);
gflLoadBitmapFromMemory(imagePNG, imagePNGSize, &bitmap2, &load_params2, NULL); // ---> produces segfault

image_decomp = new unsigned char[sx*sy];
memcpy(image_decomp, bitmap2->Data, sx*sy*sizeof(unsigned char));

gflLibraryExit();

return 0;

}

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

Re: gflLoadBitmapFromMemory problem under linux ??

Post by xnview » Wed Feb 16, 2011 7:42 am

No need to allocate bitmap before to load it

Code: Select all

bitmap2 = gflAllockBitmap(GFL_GREY, sx, sy, 1, NULL);
Do you use the last version?
Pierre.

tiboy08
Posts: 10
Joined: Tue Feb 15, 2011 6:56 pm

Re: gflLoadBitmapFromMemory problem under linux ??

Post by tiboy08 » Wed Feb 16, 2011 1:45 pm

Ok for the allocation, still resulting in seg fault. I use the version 3.40 of the library, is there a newer ?? Or is this bug not present in older versions ??

tiboy08
Posts: 10
Joined: Tue Feb 15, 2011 6:56 pm

Re: gflLoadBitmapFromMemory problem under linux ??

Post by tiboy08 » Thu Feb 17, 2011 4:07 pm

any clue ??

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

Re: gflLoadBitmapFromMemory problem under linux ??

Post by xnview » Thu Feb 17, 2011 9:01 pm

I've tried, but no crash

One thing

Code: Select all

bitmap = gflAllockBitmap(GFL_GREY, sx, sy, 1, NULL);
bitmap->Data = new GFL_UINT8[sx*sy];
memcpy(bitmap->Data, image, sx*sy*sizeof(unsigned char));
gflSaveBitmapIntoMemory(&imagePNG, &imagePNGSize, bitmap, &save_params);
No need to make a new, gflAllockBitmap allocate data

Could you send me PgmRead & test.pgm?
Pierre.

tiboy08
Posts: 10
Joined: Tue Feb 15, 2011 6:56 pm

Re: gflLoadBitmapFromMemory problem under linux ??

Post by tiboy08 » Thu Feb 17, 2011 10:37 pm

Here is my code for the test program with the .pgm test file ... Have you made the test under windows or linux ?? I'm using ubuntu 10.04 32bits ...
test_GFL.tar.gz
(219.02 KiB) Downloaded 123 times

tiboy08
Posts: 10
Joined: Tue Feb 15, 2011 6:56 pm

Re: gflLoadBitmapFromMemory problem under linux ??

Post by tiboy08 » Thu Feb 17, 2011 10:43 pm

Here is the stack trace from my debugger ...
stack-trace.jpeg
stack-trace.jpeg (46.21 KiB) Viewed 2212 times

Post Reply