small bmp image problem

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
lonesamurai5
Posts: 3
Joined: Sun May 11, 2008 4:19 am

small bmp image problem

Post 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
Attachments
BG Image Drawn in my os
BG Image Drawn in my os
User avatar
Masterkiller
Member
Member
Posts: 153
Joined: Sat May 05, 2007 6:20 pm

Re: small bmp image problem

Post 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.
ALCA OS: Project temporarity suspended!
Current state: real-mode kernel-FS reader...
c0x
Member
Member
Posts: 26
Joined: Sun Apr 20, 2008 2:16 am

Re: small bmp image problem

Post 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 :)
User avatar
lonesamurai5
Posts: 3
Joined: Sun May 11, 2008 4:19 am

Re: small bmp image problem

Post 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
Post Reply