Page 1 of 1

small bmp image problem

Posted: Wed Oct 22, 2008 3:35 am
by lonesamurai5
hi there,

I've developed my os for quite a while and recently decided to work a little on the GUI before continuing further. I've setup a vesa mode (1024x768x32) and can draw text and stuff, however I'm kind of stuck at this one problem, I try drawing 24 bit bitmaps but the output the image is like 1/4th of the original size.

Uncommenting the commented code, I get the original image dimensions, however the image quality goes down cos I stretch the image.

I've attached a picture of the output I get when I try to draw a background image.

This is the code I use to draw the image

Code: Select all

		y=y/3;
		for(i=0;i<x;i++)
		{
			for(j=0;j<y;j++)
			{
				rgb = (u32)*pbmp;
				rgb = (rgb | 0xff000000);

				pbmp += 3;

				*pAddr = (u32)rgb;
				pAddr += 1;

				//*pAddr = (u32)rgb;
				//pAddr += 1;
				//*pAddr = (u32)rgb;
				//pAddr += 1;
				//*pAddr = (u32)rgb;
				//pAddr += 1; 
			}
		}
Could you tell me what i'm doing wrong here, I cant seem to figure it out.

Thanks,
Sanchan M

Re: small bmp image problem

Posted: Wed Oct 22, 2008 4:09 am
by Masterkiller
I don't see what type of pointer you use, but in C/C++ pointer if you add 1 to pointer to u32, it increase the address by 4, not by one. There is no 3 byte format to work with memory, so instead of that you could do following:

Code: Select all

#define BYTE unsigned char

BYTE *pbmp;
u32 pixel;
for(y=767; y<0; y--) {
	for(x=0; x<1024; x++) {
		pixel = (0xFF000000) | (pbmp[x*y*3]) | (pbmp[x*y*3+1]<<8) | (pbmp[x*y*3+2]<<16);
		//write pixel to flat video buffer
	}
}
As far as I know 24-bit .bmp saved from paint are bottom-up so Y dimension goes backwards, while writing in the video buffer goes upwards. Y dimension must be loopen in the outer loop. And 24-bit .bmp saved from paint has memory as BB GG RR, but video buffer is XX RR GG BB, so that way should display it normal.

Re: small bmp image problem

Posted: Wed Oct 22, 2008 4:18 am
by c0x
Masterkiller wrote:

Code: Select all

#define BYTE unsigned char

BYTE *pbmp;
u32 pixel;
for(y=767; y<0; y--) {
	for(x=0; x<1024; x++) {
		pixel = (0xFF000000) | (pbmp[x*y*3]) | (pbmp[x*y*3+1]<<8) | (pbmp[x*y*3+2]<<16);
		//write pixel to flat video buffer
	}
}
Calculating the offset of pbmp every time in the inner for loop this way will cause an extremely poor performance :)

Re: small bmp image problem

Posted: Wed Oct 22, 2008 4:49 am
by lonesamurai5
Masterkiller wrote:I don't see what type of pointer you use, but in C/C++ pointer if you add 1 to pointer to u32, it increase the address by 4, not by one. There is no 3 byte format to work with memory, so instead of that you could do following:
Can't believe I overlooked that :D changing it to u8 * works, thanks a lot masterkiller..
Masterkiller wrote:As far as I know 24-bit .bmp saved from paint are bottom-up so Y dimension goes backwards, while writing in the video buffer goes upwards. Y dimension must be loopen in the outer loop. And 24-bit .bmp saved from paint has memory as BB GG RR, but video buffer is XX RR GG BB, so that way should display it normal.


Ah yea I kinda flip the row order of the images in photoshop before saving to bmp format. Thats why i coded it that way. :P

Cheers,
Sanchan M