Allegro.cc - Online Community

Allegro.cc Forums » Game Design & Concepts » load_PE_bmp

This thread is locked; no one can reply to it. rss feed Print
 1   2 
load_PE_bmp
jeroen valk
Member #12,087
July 2010

Hey i was working on loading .egf files desmond had a topic about this and lenny made a system for it i was testing it and i didnt get any errors but when i start the program it says "PE file doesnt have any resources" but i just used gfx025.egf 102 does maybe anyone knows the solution?

???

LennyLen
Member #5,313
December 2004
avatar

If you can email me the *.egf file to lennylen AT woosh DOT co DOT nz, I'll take a look at it.

edit: On second thoughts, it's probably too big to email, so you'll need to host it online somewhere.

Desmond Taylor
Member #11,943
May 2010
avatar

This is the GFX file that he's on about. I'm also going to test that file for an error too.

http://www.mediafire.com/?y0kfildmdry

Edit:
Nope it works fine for me... You must have done something wrong yourself.

I used

#SelectExpand
1ALLEGRO_BITMAP *bmp = load_PE_bmp("gfx/gfx025.egf", 102);

And it worked perfectly.

jeroen valk
Member #12,087
July 2010

well i dont know what im doing wrong at the moment i use allegro 4.4.0.2 and i just use exactly the same code as you released

ow wait i puted the .c file and the .h again into my source and now i get those errors:'(:

Compiler: Default compiler
Building Makefile: "C:\Documents and Settings\Wil\Bureaublad\addict\eogfx\project van gfx\src\Makefile.win"
Executing make...
make.exe -f "C:\Documents and Settings\Wil\Bureaublad\addict\eogfx\project van gfx\src\Makefile.win" all
g++.exe -D__DEBUG__ -c load_PE_bmp.c -o load_PE_bmp.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -g3

load_PE_bmp.c: In function `BITMAP* load_PE_bmp(const char*, int)':
load_PE_bmp.c:84: error: invalid conversion from `void*' to `IMAGE_RESOURCE_DIRECTORY_ENTRY*'

load_PE_bmp.c:122: error: invalid conversion from `void*' to `IMAGE_RESOURCE_DIRECTORY_ENTRY*'

load_PE_bmp.c:130: error: invalid conversion from `void*' to `IMAGE_RESOURCE_DIRECTORY*'
load_PE_bmp.c:131: error: invalid conversion from `void*' to `IMAGE_RESOURCE_DIRECTORY_ENTRY*'
load_PE_bmp.c:143: error: invalid conversion from `void*' to `IMAGE_RESOURCE_DATA_ENTRY*'

make.exe: *** [load_PE_bmp.o] Error 1

Execution terminated

its about this line:
root_entries = malloc(sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY) * (root.NumberOfNamedEntries + root.NumberOfIdEntries));

LennyLen
Member #5,313
December 2004
avatar

Those errors are because you're compiling C code as C++, which is a lot stricter on casting.

You can either fix it yourself by changing each of the offending lines like this:

root_entries = (IMAGE_RESOURCE_DIRECTORY_ENTRY*)malloc(sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY) * (root.NumberOfNamedEntries + root.NumberOfIdEntries));

Or wait until I get around to doing it myself, which will probably take longer.

jeroen valk
Member #12,087
July 2010

Its working now really your the best :D
im so happy with this thx :D
;D

GullRaDriel
Member #3,861
September 2003
avatar

That silly error which isn't one made me ask why to one of our old coding boss.

He told me that story:

Initially, malloc was returning a (char *) pointer, which, as far as he remember, wasn't guaranteed to have the same size everywhere, hence the cast.
Since C98 (or 99 he do not remember exactly) malloc return was changed to return a (void *) ptr, avoiding the cast (in C).

So, as Lenny said, this isn't an error in C because (void *) can be casted to whatever pointer you have, but as you saw, the behavior isn't the same in C++.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

jeroen valk
Member #12,087
July 2010

well it's working i load them from .egf files the only problem i got now when i load a picture the color changes is this because im using allegro 4.4? ( i see this is because i have to change the background color to 255,0,255 that's why the color changes so if it's possible to change that 255,0,255 to 0,0,0 my problem is over;D)

also i got an other question when i have for example a picture and i wanna only have the picture and not the background with the color: 255,0,255 it won't view.
can i change that 255,0,255 in to 0,0,0 in allegro 4.4?

GullRaDriel
Member #3,861
September 2003
avatar

I don't really understand your questions, anyway what I know is that from the first allegro version I used I was able to make a function which convert colors easily.

#SelectExpand
1/* function */ 2int convert_spr_to_color( BITMAP *spr , int color , int mask ) 3{ 4 register int x , y ; 5 6 if( !spr ) 7 return false ; 8 9 for( x = 0 ; x < spr -> w ; x ++ ) 10 { 11 for( y = 0 ; x < spr -> h ; y ++ ) 12 { 13 if( _getpixel( spr , x , y ) == mask ) 14 _putpixel( spr , x , y , color ); 15 } 16 } 17 return true ; 18} 19 20/* use */ 21BITMAP *bmp ; 22 23/* 24 ... here you do whatever to fill your bmp with some data ... 25*/ 26 27/*converting !*/ 28convert_spr_to_color( spr , makecol( 255 , 255 , 255 ) , makecol( 0 , 0 , 0 ) );

Well, untested !

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

LennyLen
Member #5,313
December 2004
avatar

anyway what I know is that from the first allegro version I used I was able to make a function which convert colors easily

The only problem with this approach is that because the background colour is black, any black pixels that aren't part of the background will also be converted.

Doing floodfill(bmp, 0, 0, makecol(255, 0, 255)); on each image should do the trick, but will probably be a bit slow and will have odd results on any images that has black pixels along the edge of the background.

Desmond Taylor
Member #11,943
May 2010
avatar

This is wy I upgraded to 4.9.20 as it has a built in function to convert to alpha :)

GullRaDriel
Member #3,861
September 2003
avatar

A floodfill like Lenny proposed would work. Better in some case (you use pure black in the sprite's body) worse in other (i.e you also have parts to fill inside the body of the sprite).

It's really a thing to think before starting to draw.

Edit: I also think the OP don't use the right function for displaying his sprites.

Just a reminder for him:
masked_blit for 255,0,255 masked sprites
draw_sprite for 0,0,0 masked sprites
blit for non-masked sprites.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

jeroen valk
Member #12,087
July 2010

K so with allegro it isnt possible to change that 255,0,255
and if i go to allegro 4.9 it is?
but if i upgrade to 4.9 will my old code still work? with allegro 4.9???

GullRaDriel
Member #3,861
September 2003
avatar

jeroen said:

K so with allegro it isnt possible to change that 255,0,255

We never said that !

jeroen said:

and if i go to allegro 4.9 it is?

I don't know since I don't exactly know what is your problem. Not enough informations.

We need:

  • The shortest piece of code showing the problem

  • The complete description of the problem

  • Some screenshots are welcome

  • Finally, the data you used if any and if < 10 MB (else you'll be forced to upload it elsewhere than allegro.cc)

jeroen said:

but if i upgrade to 4.9 will my old code still work? with allegro 4.9???

Not without some major API change in your code, since 4.2/4.4 and 4.9 have very different ones.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Desmond Taylor
Member #11,943
May 2010
avatar

I had to make my own function to do this and here is what I did but I now use ALlegro5 so I'm sorry if the code within is wrong.

I do know that this is about the same speed of allegro5's built in function so there is no need to change really.

#SelectExpand
1// Convert a color to allegro alpha. 2void convert_color_to_alpha(BITMAP *bmp, int color) 3{ 4 for (int x=0; x<=bmp->w; x++) 5 { 6 for (int y=0; y<=bmp->h; y++) 7 { 8 if (getpixel(bmp, x, y) == color) 9 putpixel(bmp, x, y, makecol(255, 0, 255)) 10 } 11 } 12} 13 14// Load the bitmap. 15BITMAP *tile = load_bitmap("tile.bmp", NULL); 16 17// Make black transparent. 18convert_color_to_alpha(tile, makecol(0, 0, 0));

Note: This code is untested but it should work fine :)

LennyLen
Member #5,313
December 2004
avatar

Note: This code is untested but it should work fine

Doesn't that make all black pixels in the image transparent then? Or do they just not use black except for the background?

GullRaDriel
Member #3,861
September 2003
avatar

Perhaps they use a tiny 1,1,1 black ^^

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

LennyLen
Member #5,313
December 2004
avatar

Perhaps they use a tiny 1,1,1 black

I just checked with a bmp from one of the .egf files I was sent, and they do use 0, 0, 0. I also noticed, while I was checking, that my floodfill idea wouldn't have worked as is. It would take up to 4 floodfills, as there is not a complete border of black around the subject of the picture, as I had believed.

GullRaDriel
Member #3,861
September 2003
avatar

Which come down to the following: their sprites aren't suited for that type of display and they're better adapting the existing using their favorite's paint proggy.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

jeroen valk
Member #12,087
July 2010

well desmond it's working ^^ only a bit bad i have to do this for each bmp but it's working well :p thx

Desmond Taylor
Member #11,943
May 2010
avatar

Yea it's 0 0 0 for each image with Endless Online.

You would have to call the function all the time.

Either call the following with Allegro 4.2.x/4.4.x

#SelectExpand
1convert_color_to_alpha(bmp, makecol(0, 0, 0));

Or this for allegro 4.9.x

#SelectExpand
1al_convert_mask_to_alpha(bmp, al_map_rgb(0, 0, 0));

It's still an extra line what ever you do.

jeroen valk
Member #12,087
July 2010

Ey also i saw it's not possible to load compressed .egf files but the normal eo client can do this?
is there a fix for this that would be awesome :D ::)

LennyLen
Member #5,313
December 2004
avatar

Ey also i saw it's not possible to load compressed .egf files but the normal eo client can do this?

If you can provide any info on the format, I could probably add support for it. Until now, I didn't know there were compressed files (I've never played EO myself).

jeroen valk
Member #12,087
July 2010

It's compressed with a .exe compresser
main EO didn't add this but Pserver are using it to protect there files from stealing the custome graphics i just wanna load them in the project but i saw it wasnt possible ( Main eo can load them ) Here's a link to the file im talking about: http://www.mediafire.com/?xmmwjxjxjfz
it's compressed if i'm right it's compressed with a program called PEID
also i'm working with allegro5 ;D
it would be cool if you made support for it :o

LennyLen
Member #5,313
December 2004
avatar

it's compressed if i'm right it's compressed with a program called PEID

PEid is a program for identifying what compressor was used. It failed to detect it for the file you provided.

 1   2 


Go to: