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 > [NEWBIE] Converting PNG to BIN

#86346 - Spaceface - Tue Jun 06, 2006 3:17 pm

Hey there,

At the moment I'm running through the newbietutorial on http://www.patatersoft.info/manual.html which actually helps a great deal. Within the .ZIP there are several .PNGs and in the /data dir the same amount in .BINs. The manual doesn't seem to cover how to convert from .PNG to .BIN for Windows. What is the right image converter I should use for .BIN conversion and should I use another format than .PNG, if so, what would be better and at which settings?

Sorry if this is a dumb newbie question, but I really searched and couldn't find it.

Thanks very much in advance!

#86350 - Sausage Boy - Tue Jun 06, 2006 4:12 pm

A list of tools can be found at http://www.gbadev.org/tools.php?section=Graphics

However, .bin only means binary data. The DS has many different graphic modes, I don't know which Patater uses in his guide.
_________________
"no offense, but this is the gayest game ever"


Last edited by Sausage Boy on Sat Aug 05, 2006 10:32 pm; edited 1 time in total

#86420 - Patater - Wed Jun 07, 2006 1:58 am

The manual uses mode5 graphics. The sprites are 256 color paletted and tiled. The BGs are mode5 extended rotation backgrounds, bitmapped and thus non-tiled. gfx2gba should be available for both linux and windows. It will do a fine job converting the sprites, but you'll have to modify the output it gives your for the BGs. The GBA BGs do not have an alphabit, so anything you produce with gfx2gba will not have an alpha bit set. You can use a for loop to load the graphics like so, however:

Code:

for (uint16 i = 0; i < Splash_bin_size / sizeof(uint16); ++i) {
   //set bit 15 because gfx2gba is not NDS friendly: we have to set the transparent bit on each pixel
   (uint16*)BG_BMP_RAM_SUB(3) = ((uint16*)Splash_bin)[i] | BIT(15);
}

#86426 - headspin - Wed Jun 07, 2006 3:14 am

..or there is a program called fixbit16 that you can use to set the alpha bit on the raw output from gfx2gba. That way you can use the faster DMACopy to VRAM.
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game

#86453 - Spaceface - Wed Jun 07, 2006 9:28 am

Thanks a lot for the help. As of now I'm not getting completely what I want.
What I did was use the packed PNG and open it in Photoshop. Then I made it indexed color which forces it to 256 colours:
http://img110.imageshack.us/img110/1913/gba2gfxa8vm.jpg

I saved that one as a PCX file and pulled it through gfx2gba as you can see here:
http://img110.imageshack.us/img110/1411/gba2gfxb6jj.jpg

After that I pulled it to fixbit16 (nothing exciting to show ;)) and what suprised me is that the amount of bytes of the file stayed the exact same; 256*192 = 49.152 bytes. But I could be wrong there..

However, once compiled I got this result:
http://img110.imageshack.us/img110/9198/gba2gfxc2ro.jpg

Where the image seem to be tiled exactly twice the size. The .BINs included in the ZIP of the tutorial were twice the size of 49.152 bytes, and I think (!) that causes my image to be half the size in X and Y. Either way, I can't figure this out really on how this is done. Anyone who can lead my way?

#86455 - Dark Knight ez - Wed Jun 07, 2006 10:07 am

First of all, check if the image is of dimension 256x192.
I say this because not only is your picture displayed half the size of the screen in width (and then tiled to the right), but also half the size of the screen in height.
Further more, I'm assuming the green part should be transparent. Using Photoshop, make the LAST palette entry the transparent one. Photoshop saves the palette inverted, making the last palette entry stored in a file as the first palette entry - which is the transparency entry.

#86481 - Spaceface - Wed Jun 07, 2006 2:00 pm

Nah there's no transparency in the image whatsoever.

http://img110.imageshack.us/img110/8594/splash4hm.png
This is the image I'm converting all the time which is 256x192. However when saving as .RAW within Photoshop or converting to it via gfx2gba, it still remains 256 * 192 = 49.152 bytes
The .BINs attached with the tutorial seem twice the size. So what seems the most logical?

#86488 - Spaceface - Wed Jun 07, 2006 3:42 pm

Small update:
After some conversation with Nikolas on IRC it seems to be that the tutorial uses 16 bit gfx which isn't supported by gfx2gba. I have uploaded my code to http://rafb.net/paste/results/uybpn249.html for those interested. Maybe it clears things up why it keeps tiling for me. Probably the 8bit/16bit issue which causes it to be exactly half the size. But that's just a guess..

Maybe someone can tell me how to convert a 16bit image to a .RAW format?

#86490 - parrot_ - Wed Jun 07, 2006 3:58 pm

@Patater: Hrrm, that, and the fact I forgot to add FAT_InitFiles() to my code may be why my GFX won't show

@Spaceface: Use Patater's code, replacing Splash_bin_size and Splash_bin.
_________________
Squak! etc.
My Blog

#86495 - Spaceface - Wed Jun 07, 2006 4:26 pm

Hmmm I'm about to give up on this. Seems like 16 bit images aren't that common on the DS so maybe I shouldn't bother at all. Either way, the for-loop
Code:
void displaySplash(){
   for (uint16 i = 0; i < Splash_bin_size / sizeof(uint16); ++i) {
      //set bit 15 because gfx2gba is not NDS friendly: we have to set the transparent bit on each pixel
      (uint16*)BG_BMP_RAM_SUB(3) = ((uint16*)Splash_bin)[i] | BIT(15);
   }
   //dmaCopy(Splash_bin, BG_BMP_RAM_SUB(0), Splash_bin_size);
   // sub bg is BG_BMP_RAM_SUB(0)
}


Gives me this error
Code:
c:/devkitPro/projects/Manual_1/source/main.c:59: error: 'for' loop initial declaration used outside C99 mode
c:/devkitPro/projects/Manual_1/source/main.c:61: error: invalid lvalue in assignment

#86497 - parrot_ - Wed Jun 07, 2006 4:29 pm

Are you using R19?
_________________
Squak! etc.
My Blog

#86498 - Dark Knight ez - Wed Jun 07, 2006 4:31 pm

I use this code:

Code:
for (i=0; i< (font_32x32_digits_bin_size >> 1); i++)
        SPRITE_GFX_SUB[i] = ((uint16*)font_32x32_digits_bin)[i];


I don't have to set a transparency bit, since my gfx2gba takes good care of that. (There are two programs called gdx2gba. Most prefer the one you are using, I believe.)

#86500 - Spaceface - Wed Jun 07, 2006 4:32 pm

Yeah I think so, downloaded it last Sunday, so I'm guessing I'm using R19..

#86502 - parrot_ - Wed Jun 07, 2006 4:40 pm

DevkitARM or gfx2gba? I'm just about to test my app w/ DKA R19 and gfx2gba 0.13, I'll tell you the results
_________________
Squak! etc.
My Blog

#86504 - Spaceface - Wed Jun 07, 2006 4:45 pm

parrot_ wrote:
DevkitARM or gfx2gba? I'm just about to test my app w/ DKA R19 and gfx2gba 0.13, I'll tell you the results
Code:
=======================
gfx2gba Converter v0.13
-----------------------
(C) 2oo1-2oo2 [TRiNiTY]
=======================


=)

#86507 - parrot_ - Wed Jun 07, 2006 4:54 pm

Dualis murders itself :D I haven't got the opportunity to test on HW, yet
_________________
Squak! etc.
My Blog

#86508 - Sausage Boy - Wed Jun 07, 2006 4:57 pm

Spaceface, in case you havn't solved your compiling problem, rename the file to main.cpp.

This is because C doesn't support declaring variables inside the for loop: "for (uint16 i", but C++ does. If you want, you could alternatively change the code to
Code:

uint16 i;
for (i = 0; i < Splash_bin_size / sizeof(uint16); ++i) {
      //set bit 15 because gfx2gba is not NDS friendly: we have to set the transparent bit on each pixel
      (uint16*)BG_BMP_RAM_SUB(3) = ((uint16*)Splash_bin)[i] | BIT(15);
   }

_________________
"no offense, but this is the gayest game ever"

#86523 - Spaceface - Wed Jun 07, 2006 6:23 pm

Sausage Boy wrote:
Spaceface, in case you havn't solved your compiling problem, rename the file to main.cpp.

This is because C doesn't support declaring variables inside the for loop: "for (uint16 i", but C++ does. If you want, you could alternatively change the code to
Code:

uint16 i;
for (i = 0; i < Splash_bin_size / sizeof(uint16); ++i) {
      //set bit 15 because gfx2gba is not NDS friendly: we have to set the transparent bit on each pixel
      (uint16*)BG_BMP_RAM_SUB(3) = ((uint16*)Splash_bin)[i] | BIT(15);
   }
Holy crap I didn't see that yet (the cpp part ;)). Now I'm wondering, this line
Code:
      (uint16*)BG_BMP_RAM_SUB(3) = ((uint16*)Splash_bin)[i] | BIT(15);


Still gives this error
Code:
c:/devkitPro/projects/Manual_1/source/main.cpp:62: error: invalid lvalue in assignment


It seems to be in the (uint16*)BG_BMP_RAM_SUB(3) part, but I could be wrong. Also removing the typecast didn't help.

#86528 - masscat - Wed Jun 07, 2006 6:43 pm

Change the line to this:
Code:
((uint16*)BG_BMP_RAM_SUB(3))[i] = ((uint16*)Splash_bin)[i] | BIT(15);

This treates the address generated by the macro call and cast (uint16 *)BG_BMP_RAM_SUB(3) as an array indexed by 'i', therefore copying the data pointed to Splash_bin to the GB_BMP_RAM_SUB(3) address.

#86536 - Spaceface - Wed Jun 07, 2006 7:25 pm

Works now--code wise, but for one funny reason it's shifted downwards and still tiles, only halfway. Ah well I give up.. thanks a load though guys. Think this lies beyond my knowledge to properly communicate with you guys..

#86539 - tepples - Wed Jun 07, 2006 7:36 pm

Sausage Boy wrote:
This is because C doesn't support declaring variables inside the for loop

It does if you compile in C99 mode.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#96771 - hmbg - Sat Aug 05, 2006 1:27 pm

well, if you give up ... I don't wanna give up
I followed this thread and I had and have the same problem like Spaceface. After using the code of masscat I even had the BG but also only half or moved downwards
So any Ideas why? Can somebody help me?
I even would like to show the background in a different way (maybe 8 bit pal or sth. like that) but don't know how.

thx hmbg

#96823 - omaremad - Sat Aug 05, 2006 7:00 pm

Well for exrot its best to use jpeg since its the best image compression and its as easy as
Code:

JPEG_DecompressImage((uint8*)gbfs_get_obj(&data_gbfs, "om.jpg", NULL), BG_GFX, 256, 256);


if you are not desprate for 16 bit colours on the other bgs's use 256 colour mode with extened pallets , gfx2gba and usenti work perfect even with direct copies to the vram

#96848 - Sausage Boy - Sat Aug 05, 2006 10:39 pm

hmbg, get on #dsdev on irc.blitzed.org (if you don't have an irc client, I like xchat.

I or someone else there will probably be able to help you with your problem.
_________________
"no offense, but this is the gayest game ever"