Hello guys, Im trying to open/load a sff file from Mugen, a beat em up maker, but im getting a colour error.
Here is the definition of the sff file type:
/*--| SFF file structure
|--------------------------------------------------*\
Version 1.01
HEADER (512 bytes)
------
Bytes
00-11 "ElecbyteSpr\0" signature [12]
12-15 1 verhi, 1 verlo, 1 verlo2, 1 verlo3 [04]
16-19 Number of groups [04]
20-24 Number of images [04]
24-27 File offset where first subfile is located [04]
28-31 Size of subheader in bytes [04]
32 Palette type (1=SPRPALTYPE_SHARED or 0=SPRPALTYPE_INDIV) [01]
33-35 Blank; set to zero [03]
36-511 Blank; can be used for comments [476]
SUBFILEHEADER (32 bytes)
-------
Bytes
00-03 File offset where next subfile in the "linked list" is [04]
located. Null if last subfile
04-07 Subfile length (not including header) [04]
Length is 0 if it is a linked sprite
08-09 Image axis X coordinate [02]
10-11 Image axis Y coordinate [02]
12-13 Group number [02]
14-15 Image number (in the group) [02]
16-17 Index of previous copy of sprite (linked sprites only) [02]
This is the actual
18 True if palette is same as previous image [01]
19-31 Blank; can be used for comments [14]
32- PCX graphic data. If palette data is available, it is the last
768 bytes.
On the basis of this specification AND example code from this site(thx for this)
I came up with this
Sadly, im loading something wrong:/
Here a comparison:
How i should be(taken from another program)
http://up.picr.de/4209914.jpg
my version:
http://up.picr.de/4209907.jpg
As you can see, the face is somewhat there, but somehow it only loads black and white. As far as I can tell, the position within the PCX file is correct, because the other headers have correct values(e.g. correct width or colordepth).
I might load the palette wrong, though the check for "c = 12" should guarantee a palette is there.
Does anyone have a clue?
Thank you very much
Couldn't open your images. The palette in the SFF file may be incorrect. Try loading one of the ACT palettes, instead.
]]>try it now.
I just tried that, but with no effect(ok the background color changed from white to pink)
Oh yeah, there's something about Allegro 4's palettes; only the last 6 bits of the color components are significative, so you'll probably want to divide the MUGEN palette values by 4.
[EDIT:] Also, in case you're interested, there's a SFF loader by spellcaster that is near perfect. You can find it by doing a search in the forum.
]]>Thank you, I just tried this, but it only changes the background color from white to like something redish.
The thing that irritates me is, that my data array, which contains all the bytes of the image, seems to contain only like 2 different values(because if i use bmp -> line[i][k] = data[j]; i get the rough image(see above), which contains only black and white).
I attached my 2 files, hoping it will help someone to help me^^
Ignore the german writing within it and the txt file it creates its just for debugging(it writes down all the colour values).
edit:
Thanks, He was the one I took the basic structures from. Already looked at it, but understanding someone else's code is tough IMO. Thus I will try solving my own problems and if I can't work it out, I'll try his version
Kind of you to point this out
This line seems a bit strange:
bmp -> line[i][k] = makecol(pal[data[j]].r,pal[data[j]].g,pal[data[j]].b);
Since you're creating an 8 bit bitmap, you should just fill it with the corresponding color index, so I see no need for the makecol() call.
[EDIT:] Also, you're not calling set_palette(). That might be the problem.
]]>I thought the value within the pixelbytes in the PCX refer to a palette entry, thus if i got a colourbyte with the value 0, it isnt like colour 0 but the colour of palette[0]?!
Edit:
WOOOOOOOOHOOOOOOO GUYS ITS DONE HAHAHA IT WORKS.
I used set_palette() AND I used the hint to divide the paletteentries by four.
Looks perfect now.
Thank you soooo much
edit2:
one more question about set_palette:what if i have more than one Bitmap and want them to have different palettes?!
I mean the function set_palette doesnt refer to a special bitmap?!
... thus if i got a colourbyte with the value 0, it isnt like colour 0 but the colour of palette[0]?!
Yes, that's the way 8 bit bitmaps work.
The missing set_palette() call seems to be the problem. This is what I get after doing a few small changes to your code:
The changes are basically changing the RGB array for a PALETTE and calling set_palette() before drawing. Also, changing the line I mentioned earlier with:
bmp -> line[i][k] = data[j];
[EDIT:] I was replying as you edited your post.
one more question about set_palette:what if i have more than one Bitmap and want them to have different palettes?! I mean the function set_palette doesnt refer to a special bitmap?!
OK, here's where things can get a bit tricky. As long as you use a color depth of 15 or more bits for your application, you can change the palette and draw a new bitmap with the new palette and they will both be drawn with their corresponding palette each. If you were using an 8 bit color depth, then things would be different.
]]>