gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Help with image/palette converter

#83838 - Daniel[Nordigic] - Thu May 18, 2006 9:56 pm

I'm making an image/palette converter to ouput a loaded image/palette to a binary file. Since i'm not sure how to output the data to the bin file I got a little confused..

If I have a palette index like this
R=31
G=0
B=31

The famous purple everyone hates.. as a colorvalue this is
31775
and as binary
0111 1100 0001 1111

I've tried writing the Ascii of the colorvalue to a textfile but I'm not sure thats the right approach... Does anyone know how to write theese values to bin files??

If i get the help I need I'll release it here on the forums later...

Thanks

/Daniel

#83846 - SteveH - Thu May 18, 2006 11:04 pm

Daniel[Nordigic] wrote:
I'm making an image/palette converter to ouput a loaded image/palette to a binary file. Since i'm not sure how to output the data to the bin file I got a little confused..

If I have a palette index like this
R=31
G=0
B=31

The famous purple everyone hates.. as a colorvalue this is
31775
and as binary
0111 1100 0001 1111

I've tried writing the Ascii of the colorvalue to a textfile but I'm not sure thats the right approach... Does anyone know how to write theese values to bin files??

If i get the help I need I'll release it here on the forums later...

Thanks

/Daniel


What I would do is convert the WORD 3C1F in to the BYTE pair of 3C 1F then write them out in the correct format for the DS, which in this case is :

1F 3C

Little Endian style :D

#83865 - Daniel[Nordigic] - Fri May 19, 2006 3:24 am

Ok... Why the word 3C1F...?
0111 1100 0001 1111 is 7C1F...

#83889 - SteveH - Fri May 19, 2006 10:28 am

Lets call that a "I've just come on from work and my brain is half dead" typo..

#83892 - Daniel[Nordigic] - Fri May 19, 2006 11:21 am

Righto ;D
I'm gonna give it a try tonight when i get home... i'll let you know how it turns out..

#83909 - Mighty Max - Fri May 19, 2006 2:55 pm

What language are you using?

On C/C++ just use a write(&value16bit,2,1,file) ;

On Basic do something (long time no do for me, so i might have little errors here) like

OPEN $filename FOR BINARY AS #n
PUT #n,bytelow
PUT #n,bytehigh
_________________
GBAMP Multiboot

#83912 - ecurtz - Fri May 19, 2006 4:03 pm

Remember to set the high bit (at least if you're using them as 3d textures) it's used to mark opaque/transparent.

#83940 - Daniel[Nordigic] - Fri May 19, 2006 8:31 pm

Mighty Max wrote:
On C/C++ just use a write(&value16bit,2,1,file) ;


Correct me if I'm wrong.. But as far as I know the write command only has 2 parameters... The string and the number of chars to write...

If this is some other function not related to ofstream, please go further into the code and teach me...

ecurtz wrote:
Remember to set the high bit (at least if you're using them as 3d textures) it's used to mark opaque/transparent.


Thanks... did'nt think about that

#83943 - SteveH - Fri May 19, 2006 8:47 pm

I think he's onabout fwrite( value, size, num, file );

The only problem with fwrite is that it's specific to the CPU, luckily in the case of intel and the ds they are the same, but some processors are big-endian, so using write would not work...

#83944 - Mighty Max - Fri May 19, 2006 9:02 pm

Indeed, i missed the f, sorry.

It simply writes the content pointed to by the first parameter to the file, no matter if it is a string (pointer to an 0 terminated char array), or pointer to any other datatype.

Little/Big-Endian shouldnt be a problem here, as Steve noted, thanks :) forgot to think about it
_________________
GBAMP Multiboot

#83951 - Daniel[Nordigic] - Fri May 19, 2006 9:44 pm

Thanks... I just figured it out myself though... This shouldn't be a problem now... thanks mate!

#83971 - Daniel[Nordigic] - Fri May 19, 2006 11:46 pm

BTW if the high bit is set it's opaque right?

#83972 - SteveH - Fri May 19, 2006 11:50 pm

Yes, stupid thing - took 3 days to find that "bug"

#83985 - Daniel[Nordigic] - Sat May 20, 2006 12:28 am

hehe ;)

#83986 - Daniel[Nordigic] - Sat May 20, 2006 12:30 am

Uhm... another stupid question... if the image is used as a 2d sprite is the high bit ignored?

#84152 - Daniel[Nordigic] - Sat May 20, 2006 8:07 pm

Someone....please...

#84159 - tepples - Sat May 20, 2006 8:36 pm

If nobody replies, then it's likely that nobody who has read your question knows the answer. Is there anything specific that prevents you from investigating this yourself and reporting it to us?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#84164 - Daniel[Nordigic] - Sat May 20, 2006 8:53 pm

Ok...
They just sounded so sure about this kind of stuff before...

My deepest apologies!

#84317 - Daniel[Nordigic] - Sun May 21, 2006 10:10 pm

Yet another question... How does texture mode 5, compressed work?
Also did anyone know if the high-bit (bit 16) of colorpalettes is ignored on 2D sprites?

#84434 - Daniel[Nordigic] - Mon May 22, 2006 4:08 pm

ok...major problem... when an image is saved to binary... how is this done?...
I tried reading it from topleft to bottomright, but that turned out very ugly... Anyone with experience in this area?

#84437 - waruwaru - Mon May 22, 2006 4:33 pm

Perhaps you should compare your results against something produced by gfx2gba, then you will know what the differences are.
_________________
DSLua - a scripting language for your DS!

#84439 - Daniel[Nordigic] - Mon May 22, 2006 4:37 pm

Problem is that the first thing i'm trying is mode 2, 4color images... gfx2gba doesn't support that...or does it?

#84441 - waruwaru - Mon May 22, 2006 4:42 pm

Code:

=======================
gfx2gba Converter v0.15
-----------------------
(C) 2oo1-2oo3 [TRiNiTY]
=======================

Usage: gfx2gba [options] bmp/pcx/tga/tim/spr files ...

Options are:

 -pPalettename                  -m generate map (optimized)
 -oOutputdir                    -M generate map (not optimized)
 -fOutput format                -mm generate metatiled map (optimized)
 -sSection                      -MM generate metatiled map (not optimized)
 -SpSuffix for palette          -bBank for map
 -SmSuffix for map              -mc save map in column order
 -StSuffix for tiledata         -F turn off check for flipped tiles
 -TMetatilesize                 -rs output a rotate/scale BG screen map
 -tTilesize                     -P don't save palette data
 -tc save tiles as columns      -G don't save tile/image data
 -cColordepth                   -D don't save map data
 -CColor-Offset                 -X don't save anything
 -A force color offset add      -Z compress everything
 -aTransparent color            -zt compress tile/bitmap data
 -vVRAM-Offset                  -zp compress palette data
 -x don't merge palettes        -zm compress map data
 -q quiet mode                  -ap use aPLib as compressor
 -B only optimize blank tiles   -aps use aPLib (safe) as compressor
 -extern add extern to arrays   -align add alignment info for GCC


There is a color depth switch.... Never tried a 4 color image myself, so dunno for sure.
_________________
DSLua - a scripting language for your DS!

#84442 - Daniel[Nordigic] - Mon May 22, 2006 4:45 pm

Ok.. will try this when I get home later... thanks mate!

#84496 - Daniel[Nordigic] - Mon May 22, 2006 10:33 pm

Gfx2Gba didn't help much but I solved it anyway... yay.. :D