I am using vbe, mode 0x118 (1024*768*24)
This is a 1024*768*24 bitmap(The link is jpg, but I convert it to bitmap before loading it)
After loading this bitmap into my os, it looks like this
So, weird black horizontal lines and dotted lines coming from no where...
Filling the screen with one color works fine, anyone knows what's wrong with it ?
problems loading a bitmap
Re: problems loading a bitmap
Memory corruption? Using memory after freeing (including using automatic/local arrays after going out of the function scope where they're defined)?
- BrightLight
- Member
- Posts: 901
- Joined: Sat Dec 27, 2014 9:11 am
- Location: Maadi, Cairo, Egypt
- Contact:
Re: problems loading a bitmap
alexfru made it there before me; I was just going to say that it's most likely memory corruption.
EDIT: Notice that the BMP image inside your OS is horizontally inverted; if you'd like BMP parsing code, I have a function for that (only works on 24-bit BMP images, but can easily be extended.)
EDIT: Notice that the BMP image inside your OS is horizontally inverted; if you'd like BMP parsing code, I have a function for that (only works on 24-bit BMP images, but can easily be extended.)
You know your OS is advanced when you stop using the Intel programming guide as a reference.
Re: problems loading a bitmap
Looks like your stack is inside the buffer.
Find out if the picture buffer itself was corrupted or if its the vram
Find out if the picture buffer itself was corrupted or if its the vram
Re: problems loading a bitmap
Ch4ozz wrote:Looks like your stack is inside the buffer.
Find out if the picture buffer itself was corrupted or if its the vram
omarrx024 wrote:alexfru made it there before me; I was just going to say that it's most likely memory corruption.
EDIT: Notice that the BMP image inside your OS is horizontally inverted; if you'd like BMP parsing code, I have a function for that (only works on 24-bit BMP images, but can easily be extended.)
Hi, I think it's not due to memory corruption of the picture buffer, because it's allocated by a heap allocator and does not overlap with the stack, and I never free the heap.omarrx024 wrote:Memory corruption? Using memory after freeing (including using automatic/local arrays after going out of the function scope where they're defined)?
Also, I compared the vram and the picture immediately after the picture buffer was copied to the vram, they're not the same.
(since the actual picture pixels in bmp file are reversed, I've to copy them in the reversed direction)
Code: Select all
void weird_memcpy(void * dest, void * src, uint32_t count) {
char * p1 = dest, * p2 = src;;
while(count-- > 0) {
memcpy(p1, p2-3, 3);
p1 = p1 + 3;
p2 = p2 - 3;
}
}
void bitmap_display(bitmap_t * bmp) {
if(!bmp) return;
void * data = bmp->image_bytes;
char * image = data;
char * screen = (char*)0xfc000000;
weird_memcpy(screen, data + bmp->width * bmp->height * 3, bmp->width * bmp->height);
// Compare the video ram and the data
uint32_t count = bmp->width * bmp->height * 3;
char * p1 = screen, * p2 = image + bmp->width * bmp->height * 3;
while(count-- > 0) {
char first = *(p2-3);
char second = *(p2-2);
char third = *(p2-1);
if(first != *p1)
printf("no no no\n");
if(second != *(p1+1))
printf("no no no\n");
if(third != *(p1+2))
printf("no no no\n");
p1 = p1 + 3;
p2 = p2 - 3;
}
printf("yeah yeah yeah\n");
}
- Kazinsal
- Member
- Posts: 559
- Joined: Wed Jul 13, 2011 7:38 pm
- Libera.chat IRC: Kazinsal
- Location: Vancouver
- Contact:
Re: problems loading a bitmap
The pixels in a BMP are still left-to right, but the rows are stored bottom to top -- the packed pixels are not completely reversed.
Re: problems loading a bitmap
Ohoh I couldn't believe I didn't notice that. but this doesn't explain the black horizontal lines I guessKazinsal wrote:The pixels in a BMP are still left-to right, but the rows are stored bottom to top -- the packed pixels are not completely reversed.
Re: problems loading a bitmap
I've found the bug, it's in my filesystem, thank you guys!