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 needed, simple image veiwer app.

#168381 - opearn - Sun Apr 26, 2009 2:03 pm

i'm trying to make a simple image viewer app,

i need to add my integer and u8 string together to use with dmacopy.
i want to use numbers as my imge names so i can easily use code like this:

Code:
if (keysHeld()&KEY_RIGHT){
picno+=1
}


heres my code so far.
Code:
#include <nds.h>
#include <stdio.h>

#include "0.h"
#include "1.h"

picno = 0;

int main(void)
{
    //init video modes
   videoSetMode( MODE_5_2D );
   videoSetModeSub( MODE_5_2D );
   vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000,VRAM_B_MAIN_BG_0x06020000,VRAM_C_SUB_BG_0x06200000,VRAM_D_LCD);

   //init bgs
   int bg3 = bgInit(3, BgType_Bmp8, BgSize_B8_256x256, 0,0);

   dmaCopy(picno+(u8*)"Bitmap", bgGetGfxPtr(bg3), 256*256);
   dmaCopy(picno+(u8*)"Pal", BG_PALETTE, 256*2);

    while(1){
   swiWaitForVBlank();
   }

   return 0;
}


thanks in advance for your help[/code]

#168384 - chebastian - Sun Apr 26, 2009 2:53 pm

just thinking.

cant you just put all your images in a big array
and increase/decrease the current index of the image you display at button down?

EDIT: ofcourse not a great idea if you have alot of images, but you get the point.

#168391 - dovoto - Mon Apr 27, 2009 2:31 am

hrm... well lets ignore for the moment that including a bunch of pictures in your compiled code is probably bad juju (better to use a file system as this way is going to eat up your 4MB of ram pretty fast).

Lets also ignore that the way are you going about it is so fundamentally flawed that explaining why would be poorly suited for a forum post. I highly recommend you take a few days and sit down with a good c book from your library/bookstore/internet.

Lets then assume that 0.h and 1.h have some reference to your palette and bitmap data like such:

Code:
extern u16* _0Data;
extern u16* _0Pal;

extern u16* _1Data;
extern u16* _1Pal;


Then you could do something like:

Code:
typedef struct
{
   u16* data;
   u16* pal;
}Picture;

Picture pics[] = {{_0Data, _0Pal}, {_1Data, _1Pal}};

...

   dmaCopy(pics[picno].data, bgGetGfxPtr(bg3), 256*256);
   dmaCopy(pics[picno].pal, BG_PALETTE, 256*2);

...


A file system with a file browser would be a much saner approach or at least preprocessing the image files into an array as editing the pics[] array by hand would be tedious at best and likely error prone.
_________________
www.drunkencoders.com

#168392 - opearn - Mon Apr 27, 2009 2:43 am

thanks but...
you mentioned loading images from a file system,

can i load bmps directly of FAT?
or do i have to preconvert?

i'd definatly prefer to load from FAT though.

oh and is there libfat documentation?

thanks dovoto.

#168393 - dovoto - Mon Apr 27, 2009 2:50 am

There is an example in the example folder for using fatlib. It really is just a matter of calling fatinit() and then using standard file io. The example even includes some file browsing if i remember correctly.

As for leaving the files as .bmp I think that is a great idea. Not because it is the proper way (.bmp is a pretty crappy format all things considered) but because it would be a useful experience for you if you are just starting out.

BMP files are easy to decode and finding info about them on the internet is very easy. It would be great little project for learning how to access files and display simple graphics on the DS.
_________________
www.drunkencoders.com

#168394 - opearn - Mon Apr 27, 2009 3:22 am

thanks dovoto,

also quick question,
are you planning to finish your dev-scene tuts?

http://dev-scene.com/NDS/Tutorials

i'll try to find some info on decoding bmps later today,
but how do i re-encode into the ds's binarys?