Displaying 16-bit bitmaps

support for the ARM toolchain
Post Reply
godofthunder101
Posts: 2
Joined: Wed Mar 11, 2009 4:44 am

Displaying 16-bit bitmaps

Post by godofthunder101 » Wed Mar 11, 2009 5:09 am

Hey all,

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);
This is the code to display the bitmap

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];
	}
	
}
Last of all this is the main function which sets everything up and calls DisplayBmp().

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;
}
Extremely sorry fo the long post...very new at this so i'm having trouble narrowing down the problem. Would apreciate any suggestions.

ty

WinterMute
Site Admin
Posts: 1986
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Displaying 16-bit bitmaps

Post by WinterMute » Wed Mar 11, 2009 3:49 pm

In 16 bit mode bit 15 is an opaque bit - if this bit is zero, the pixel is transparent and will not display.
Help keep devkitPro toolchains free, Donate today

Personal Blog

godofthunder101
Posts: 2
Joined: Wed Mar 11, 2009 4:44 am

Re: Displaying 16-bit bitmaps

Post by godofthunder101 » Thu Mar 12, 2009 1:16 am

Thanx heaps WinterMute, So my problem is that the file structure is different. Ive looked all over the web for a descrition of 16-bit bitmaps. Any one got an idea where to find one.

Thanx again man

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests