Page 1 of 1

problems loading a bitmap

Posted: Fri Aug 19, 2016 4:30 am
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 ?

Re: problems loading a bitmap

Posted: Fri Aug 19, 2016 4:51 am
by alexfru
Memory corruption? Using memory after freeing (including using automatic/local arrays after going out of the function scope where they're defined)?

Re: problems loading a bitmap

Posted: Fri Aug 19, 2016 5:07 am
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.)

Re: problems loading a bitmap

Posted: Fri Aug 19, 2016 5:57 am
by Ch4ozz
Looks like your stack is inside the buffer.
Find out if the picture buffer itself was corrupted or if its the vram

Re: problems loading a bitmap

Posted: Fri Aug 19, 2016 9:21 pm
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");
}

Re: problems loading a bitmap

Posted: Fri Aug 19, 2016 9:32 pm
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.

Re: problems loading a bitmap

Posted: Fri Aug 19, 2016 10:03 pm
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

Re: problems loading a bitmap

Posted: Fri Aug 19, 2016 10:25 pm
by szhou42
:shock: I've found the bug, it's in my filesystem, thank you guys!

Re: problems loading a bitmap

Posted: Sat Aug 20, 2016 12:59 pm
by szhou42
Fixed :) :) :) :P :P :P :P :P
Image