problems loading a bitmap

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
szhou42
Member
Member
Posts: 67
Joined: Thu Apr 28, 2016 12:40 pm
Contact:

problems loading a bitmap

Post by szhou42 »

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)
Image

After loading this bitmap into my os, it looks like this

Image

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 ?
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: problems loading a bitmap

Post by alexfru »

Memory corruption? Using memory after freeing (including using automatic/local arrays after going out of the function scope where they're defined)?
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: problems loading a bitmap

Post by BrightLight »

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.)
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
Ch4ozz
Member
Member
Posts: 170
Joined: Mon Jul 18, 2016 2:46 pm
Libera.chat IRC: esi

Re: problems loading a bitmap

Post by Ch4ozz »

Looks like your stack is inside the buffer.
Find out if the picture buffer itself was corrupted or if its the vram
szhou42
Member
Member
Posts: 67
Joined: Thu Apr 28, 2016 12:40 pm
Contact:

Re: problems loading a bitmap

Post by szhou42 »

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.)
omarrx024 wrote:Memory corruption? Using memory after freeing (including using automatic/local arrays after going out of the function scope where they're defined)?
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.

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");
}
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: problems loading a bitmap

Post by Kazinsal »

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.
szhou42
Member
Member
Posts: 67
Joined: Thu Apr 28, 2016 12:40 pm
Contact:

Re: problems loading a bitmap

Post by szhou42 »

Kazinsal 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.
Ohoh I couldn't believe I didn't notice that. but this doesn't explain the black horizontal lines I guess
szhou42
Member
Member
Posts: 67
Joined: Thu Apr 28, 2016 12:40 pm
Contact:

Re: problems loading a bitmap

Post by szhou42 »

:shock: I've found the bug, it's in my filesystem, thank you guys!
szhou42
Member
Member
Posts: 67
Joined: Thu Apr 28, 2016 12:40 pm
Contact:

Re: problems loading a bitmap

Post by szhou42 »

Fixed :) :) :) :P :P :P :P :P
Image
Post Reply