adding alpha to non-alpha image

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

Moderators: helmut, XnTriq, xnview

Post Reply
jesusdz

adding alpha to non-alpha image

Post by jesusdz »

I have one problem with this.
I want load a 24bitsPerPixel image in a 32bit image allocated in memory.
I follow the next steps to do it.

Code: Select all

// get file information
GFL_FILE_INFORMATION fileinfo;
gflGetFileInformation(FILENAME,-1,&fileinfo);
GFL_INT32 w = fileinfo.Width;
GFL_INT32 h = fileinfo.Height;

// allocate 4 byte per pixel image
GFL_BITMAP *bitmap = gflAllockBitmap(GFL_RGBA,w,h,4,NULL);

// set the load params
GFL_LOAD_PARAMS loadparams;
gflGetDefaultLoadParams(&loadparams);
loadparams.Flags |= GFL_LOAD_FORCE_COLOR_MODEL;
loadparams.ColorModel = GFL_RGBA;
loadparams.DefaultAlpha = 255;  // alpha would must be black...

// and then, load the image
gflLoadBitmap(FILENAME, &bitmap, &loadparams, &fileinfo);
well, that results a 32bits per pixel image allocated in memory but with all the alpha components set to 0, when i have put 255 in DefaultAlpha...

someone knows the answer?

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

Re: adding alpha to non-alpha image

Post by xnview »

jesusdz wrote:I have one problem with this.
I want load a 24bitsPerPixel image in a 32bit image allocated in memory.
I follow the next steps to do it.

Code: Select all

// get file information
GFL_FILE_INFORMATION fileinfo;
gflGetFileInformation(FILENAME,-1,&fileinfo);
GFL_INT32 w = fileinfo.Width;
GFL_INT32 h = fileinfo.Height;

// allocate 4 byte per pixel image
GFL_BITMAP *bitmap = gflAllockBitmap(GFL_RGBA,w,h,4,NULL);

// set the load params
GFL_LOAD_PARAMS loadparams;
gflGetDefaultLoadParams(&loadparams);
loadparams.Flags |= GFL_LOAD_FORCE_COLOR_MODEL;
loadparams.ColorModel = GFL_RGBA;
loadparams.DefaultAlpha = 255;  // alpha would must be black...

// and then, load the image
gflLoadBitmap(FILENAME, &bitmap, &loadparams, &fileinfo);
well, that results a 32bits per pixel image allocated in memory but with all the alpha components set to 0, when i have put 255 in DefaultAlpha...

someone knows the answer?

thanks!
First it's not necessary to allocate picture before loading it :-)

Strange, are you sure that your picture is in 24bits?
Pierre.
Guest

Post by Guest »

I think so...

well, in fact that i'm doing is open multiple layers in psd image... not exactly the code y had put before.

My result was that the program crash at first and second layers (first layer is all layer mix and second layer is the deepest layer, isn't?)... this two layers are completely opaque and i had think that the program crash because gfl load this layers as 24 bit per pixel images.

Tomorrow at work i will continue with this task, and will report any advance :-P.

Thanks a lot!
jesusdz

Post by jesusdz »

Hello,

i have take another way to solve this problem.

First, i don't force the load process to take a fixed color depth.

If the loaded layer results to be a 3 byte (RGB) color layer, y convert it in a 4 byte (RGBA) color layer. Then, i fill the alpha value of each color in the image with his greatest value ( i do this with a bucle... ).

I'm sure that it isn't the best way to solve the problem, but at least i can continue with my work now :D

I will thanks a lot other ideas.
Post Reply