I'm completley new at developing for the ds (and anything else thats not a pc 4 that matter). Was having trouble getting a 16-bit bitmap to display. I can get the same image to display in 8-bit depth with little change to the code. I created a class to overlay on the file structure for the bitmap. Because this overlay is for 8-bit i guess thats the problem. But i dont know what to change.
This is the code used to create the overlay object.
Code: Select all
typedef struct
{
char signature[2];
unsigned int fileSize;
unsigned int reserved;
unsigned int offset;
}__attribute__ ((packed)) BmpHeader;
typedef struct
{
unsigned int headerSize;
unsigned int width;
unsigned int height;
unsigned short planeCount;
unsigned short bitDepth;
unsigned int compression;
unsigned int compressedImageSize;
unsigned int horizontalResolution;
unsigned int verticalResolution;
unsigned int numColors;
unsigned int importantColors;
}__attribute__ ((packed)) BmpImageInfo;
typedef struct
{
unsigned char blue;
unsigned char green;
unsigned char red;
unsigned char reserved;
}__attribute__ ((packed)) Rgb;
typedef struct
{
BmpHeader header;
BmpImageInfo info;
Rgb colors[256];
unsigned short image[1];
}__attribute__ ((packed)) BmpFile;
extern void DisplayBmp(u16* video_buffer, u16* backgroundPalette, BmpFile* bmp);
Code: Select all
void DisplayBmp(u16* video_buffer, u16* backgroundPalette, BmpFile* bmp)
{
int i, ix, iy;
//copy the palette
for(i = 0; i < 256; i++)
{
backgroundPalette[i] = RGB15(bmp->colors[i].red >> 11, bmp->colors[i].green >> 11, bmp->colors[i].blue >> 11);
}
//copy the image
for(iy = 0; iy < bmp->info.height; iy++)
{
for(ix = 0; ix < bmp->info.width / 2; ix++)
video_buffer[iy * 128 + ix] = bmp->image[(bmp->info.height - 1 - iy) * ((bmp->info.width + 3) & ~3) / 2 + ix];
}
}
Code: Select all
#include <nds.h>
#include <stdio.h>
#include <bitmap.h>
#include <myPic_bmp.h>
int main(void) {
//point our video buffer to the start of bitmap background video
u16* video_buffer = (u16*)BG_BMP_RAM(0);
//set video mode to mode 5 with background 3 enabled
videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
//map vram to start of main background graphics memory
vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
//initialize the background
BACKGROUND.control[3] = BG_BMP16_256x256 | BG_BMP_BASE(0);
BACKGROUND.bg3_rotation.xdy = 0;
BACKGROUND.bg3_rotation.xdx = 1 << 8;
BACKGROUND.bg3_rotation.ydx = 0;
BACKGROUND.bg3_rotation.ydy = 1 << 8;
BmpFile* bmp = (BmpFile*)myPic_bmp;
consoleDemoInit();
printf("%c%c\n", bmp->header.signature[0], bmp->header.signature[1]);
printf("bit depth: %i\n", bmp->info.bitDepth);
printf("width: %i\n", bmp->info.width);
printf("height: %i\n", bmp->info.height);
DisplayBmp(video_buffer, BG_PALETTE, bmp);
return 0;
}
ty