load_PE_bmp
jeroen valk

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

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

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

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

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

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

GullRaDriel

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++.

jeroen valk

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

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 !

LennyLen

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

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

GullRaDriel

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.

jeroen valk

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
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.

Desmond Taylor

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

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

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

LennyLen

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

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.

jeroen valk

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

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

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

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

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

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.

jeroen valk

It's compressed in Expressor
I hope you can support it ^^

Desmond Taylor

You do know that Arvid will get pissed at you for editing his GFX files. The only way I can stop him being a twit is by not giving the *.egf files with my client downloads. The only way people can play with my client is by downloading the original client and copying the files from that. It's the only way you cant get sued my friend. Vult-R doesn't care but as he has said before in countless emails. Arvid will not change his mind and as you also should know Sausage had to wipe half of his forums because of arvid threatening him with copyright laws.

I would strongly recomend you use the original *.egf files and not include them with the download.

Would be a big shame if you got sued over this so strong advice is just don't use these private server edit's they still contain original Endless Online stuff and you know the rest.

jeroen valk

I know i won't add them in my download but i just want to know how to load compressed gfx files because it's pretty useful for other people too

Desmond Taylor

That is true if they want to use you're client for their server

jeroen valk

I hope you can support it, it would be awesome
also i don't understand why normaly eo client support it but this doesnt

Desmond Taylor

Some of the graphics are 8bit and load_PE_bmp dont load them correctly.

jeroen valk

Ok :D
you think it's hard to fix it?

LennyLen

you think it's hard to fix it?

No, it's a pretty easy fix. I just haven't gotten around to doing it yet. I already have the necessary code for loading every type of DIB format in my .cur library, I just need to add it to this function.

I'll try to have it done by the end of the week.

jeroen valk

Ok thank you :)
your really helpful to me :P;D

Desmond Taylor

jeroen valk, I told you on EOServ's forums that I will let you know when LennyLen has added the code for that as I have already messaged him about it.

I ain't in a rush since I'm not bothered about readin EGF files atm. I wan't the game to just run nice so the graphics I have extracted like you did in you're first clone release :P

Thread #604527. Printed from Allegro.cc