OSDev.org
https://forum.osdev.org/

Picture Support (BMP,JPG,..)
https://forum.osdev.org/viewtopic.php?f=1&t=378
Page 1 of 1

Author:  stafe [ Sat Aug 27, 2005 11:00 pm ]
Post subject:  Picture Support (BMP,JPG,..)

Hello,

now my floppy driver works well and I can execute simple programs in my OS ... now I would like to create a GUI for my OS ... Window's, Buttons,... works fine ... but I'd like to show Pictures in my OS ... now i try to load a 24-Bit BMP file in the memory and show it on the Background ... i can read the header informations of the file ( Width,Height,...) but I couldn't finde the correct color out ...

Can somebody help me ... maybe sombody can show me an simple example for a BMP or JPGE picture ... JPGE will be much better because it doesn't need so much memory on the floppy disk ...

I hope somebody can help me ... thanks

Author:  Legend [ Sat Aug 27, 2005 11:00 pm ]
Post subject:  Re: Picture Support (BMP,JPG,..)

Well, probably libjpeg doesn't need that much runtime support if compiled correctly ...

Author:  gaf [ Sat Aug 27, 2005 11:00 pm ]
Post subject:  Re: Picture Support (BMP,JPG,..)

Hello,
the big advantage of a raw bmp file compared to jpeg is its great simplicity, especially with 24bit colors as in this case a color-table isn't needed. The whole file-format thus only consists of two simple header structures followed directly by the raw 24bit pixeldata.

BitmapFileHeader
BitmapInfoHeader

You can also assume that the image-data in the bitmap isn't compressed but only consists of RGB triplets which each represent a pixel. For some reason the image is stored bottom-up, that means that the first pixel is in the lower left corner and that the last pixel is in the upper right corner.

5 -> 6 -> 7 -> 8
1 -> 2 -> 3 -> 4

Apart from that each scan-line is aligned to a 32bit boundary which means that a padding is added if [pixels_per_line*24bits)%32bits != 0]. As you know the scanline lenght from the headers it's no big deal to calculate where the next line start. Assuming that you have set your display adapter to a 24bit mode all you have to do in order to display the image is to copy the data bottom-up and with respect the the padding to the linear frame-buffer.

Code:
xres = infoheader.biWidth;
yres = biWidth.biHeight;

p_rgb_data = bitmap_location + fileheader.bfOffBits;
p_framebuffer = 0x12345678;

for(i=yres; i>0; i--)
{
    for(j=0; j<xres; j++)
    {
        p_framebuffer[i*xres*3 + j*3 + 0] = &p_rgd_data;  // red
        p_rgd_data++;
       
        p_framebuffer[i*xres*3 + j*3 + 1] = &p_rgd_data;  // green
        p_rgd_data++;

        p_framebuffer[i*xres*3 + j*3 + 2] = &p_rgd_data;  // blue
        p_rgd_data++;
    }
   
    ; jump over the padding at the end of the scanline
    if(p_rgd_data%4 != 0)
    {
        p_rgd_data += (4 - p_rgd_data%4)
    }
}


This is just some pseudo-code and as I haven't tested it you shouldn't be too surpised if it contains some bugs ;)

regards,
gaf

Author:  bubach [ Sun Aug 28, 2005 11:00 pm ]
Post subject:  Re: Picture Support (BMP,JPG,..)

For more information about BMP:
http://www.g615.co.uk/riftor/bmpstructure.txt

Author:  earlz [ Thu Sep 08, 2005 11:00 pm ]
Post subject:  Re: Picture Support (BMP,JPG,..)

if your using mode 13h(or its equivalent in pmode or whatever) or anything less than 24 bit color than you will need to convert device indepent bitmaps into device dependent pixel data but if your in 24bit or 32bit mode than it should be simple

Author:  Devil [ Sun Sep 25, 2005 11:00 pm ]
Post subject:  Re: Picture Support (BMP,JPG,..)

hmm.. i am showing pictures at the moment, too. And i think, you have to go into the vesa mode, too show more than 256 colours..

Author:  AltCtrlDel [ Sun Sep 25, 2005 11:00 pm ]
Post subject:  Re: Picture Support (BMP,JPG,..)

check this out

http://www.wotsit.org/

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/