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 > displaying raw image

#169143 - Tommmie - Sun Jun 21, 2009 4:27 pm

hey everyone,

it try to display a raw image, but every time i get a black screen. but when i use dsorganize it displays perfect. can anyone tell me how to display a raw image. i'm doing it like this now:
Code:

#include <nds.h>
#include <fat.h>
#include <stdio.h>

int main(void) {
//---------------------------------------------------------------------------------
 
videoSetMode(MODE_5_2D);

vramSetBankA(VRAM_A_MAIN_BG_0x06000000);

int bg = bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0,0);

u16* backBuffer  = (u16*)0x06000000;
fatInitDefault();
FILE * pfile;
pfile = fopen("decoded.raw", "rb");
fread(backBuffer, 1, 256*192*2, pfile);
fclose(pfile);

bgUpdate();

   while(1) {
      swiWaitForVBlank();
   }

}

#169203 - LOst? - Tue Jun 23, 2009 1:17 pm

First make sure you can display ANYTHING on the screen. Even if it is just pixel dirt.

Tommmie wrote:
fread(backBuffer, 1, 256*192*2, pfile);


Then I want to advice you that the area defined as backBuffer is of type u16 for a reason. You are reading 1 byte 256*192*2 times to a memory area that accepts unsigned words. That might give undesirable results. Even if you change this so that fread reads 2 bytes instead, it might still not work.

Better read a word into a local variable of u16 type, and then send that variable to the backBuffer at the correct offset.

If you are looking for drawing speed, don't read images from some kind of a disk drive.
_________________
Exceptions are fun

#169204 - Tommmie - Tue Jun 23, 2009 1:24 pm

thanks, but it was already working

#169205 - elhobbs - Tue Jun 23, 2009 1:33 pm

Tommmie wrote:
thanks, but it was already working
what was the problem? did the raw image data not have the alpha bit set?

#169207 - Tommmie - Tue Jun 23, 2009 3:46 pm

i don know exactly now, i tried to an image, but when i did that i got nothing on the screen. when i changed this in the decoding process:
Code:

RGB15((r >> 3),(g >> 3),(b >> 3))


to this:

Code:
RGB15((r >> 3),(g >> 3),(b >> 3)) |BIT(15) 


it worked. raw image are still not loadable for me(i can decode images and show them on the screen with that bit(15)). but why is that BIT(15) needed?

#169208 - SteveH - Tue Jun 23, 2009 3:49 pm

Bit(15) is the alpha bit:

0 - The color is stored with 0% opacity / 100% transparency
1 - The color is stored with 100% opacity / 0% transparency

in other words it's an on/off alpha just like in a gif file where the transparent bit is one color.

When you made your raw image file, I'm assuming with grit, did you tell grit to set the slpha bit on?

#169209 - kusma - Tue Jun 23, 2009 3:51 pm

Tommmie wrote:
but why is that BIT(15) needed?

Because bit 15 is a 1 bit alpha value. If it's not set to 1, the pixel is transparent. Consider the format as ARGB1555 instead of RGB555.

Edit: Bah, beaten :(

#169210 - Tommmie - Tue Jun 23, 2009 3:52 pm

so it was because the alphabit? all colors where transparent due not doing | BIT(15)? and no it got the raw image, while i decoded it and saved it on my nds(the decoded buffer)