Page 1 of 1

how to display bmp or png files on screen

Posted: Mon Jul 25, 2016 7:17 pm
by shashwatsh
Hey,
i have completely added VESA VBE to my OS.now i want to load BITMAP or PNG in it. someone give me the code either in C or ASM

Re: how to display bmp or png files on screen

Posted: Mon Jul 25, 2016 7:29 pm
by gerryg400
shashwatsh wrote:Hey,
i have completely added VESA VBE to my OS.now i want to load BITMAP or PNG in it. someone give me the code either in C or ASM
I can sell you some code to do this. How much money do you have?

If you want free code you could try libpng.

Re: how to display bmp or png files on screen

Posted: Mon Jul 25, 2016 7:37 pm
by SpyderTL
You'll probably not get anyone to give you custom code for free, but we'll give you some tips.

First, BMP files are easy. They have a small header, and then a list of pixels in exactly the same order and format as your video card expects them. If your display format and your BMP format are the same, you can simply copy the pixel data directly to the screen buffer.

Any other format, however, will need to be converted to pixels before the image can be displayed.

This web site targets operating system development, but file formats are a little outside of the scope for this site, unfortunately. I am currently looking at MP3 files, and I'm having to find information elsewhere. I'm trying to find a similar site that describes different file formats, like this one: http://fileformats.wikia.com/wiki/File_ ... _Main_Page

Re: how to display bmp or png files on screen

Posted: Mon Jul 25, 2016 7:46 pm
by ~
You'll find VESA and image loading examples targeted for DOS and DJGPP/Watcom/Turbo C++/Borland C++/NASM. Also for HTML5, which are easier to understand and write for most people. You can use DOSBox and a recent Firefox/Chrome version (if you implement them in JavaScript) to work on them.

Here is some good information and code examples that show how to use VESA to load bitmaps (640x480x256 colors):
Image http://www.retro-games.co.uk/downloads/progvesa.htm

And see this one, which is the easiest example I've found about loading bitmaps (640x480x256 colors, but for other resolutions it's basically the same, additionally to adjusting the color resolution):
Image http://www.retro-games.co.uk/downloads/ex11.zip
Image

________________________________________________
Also, the books Compressed Image File Formats by John Miano and Encyclopedia of Graphics File Formats, Second Edition by Murray and Vanryper, from O'Reilly will help you master those formats much faster. You can find them on the Internet and from Amazon/eBay. Make sure to get them with their CD's because that's where they contain all the valuable image, code and documentation resources.

CompressedImageFileFormatsJohnMiano.iso
Image Compressed-Image-File-Formats.pdf

EGFF2.iso (CD-ROM, Encyclopedia of Graphics File Formats Second Edition)
Book, Encyclopedia of Graphics File Formats Second Edition

Here you can also see an online GIF viewer codec I wrote in JavaScript/HTML5 Canvas which is capable to decompress the vast majority of GIF LZW streams, and show GIFs with one or more image animation frames, its palettes (ald also convert to grayscale nicely):
Image >> Online GIF Explainer and Viewer <<


These are also the file formats that can be visualized, in increasingly difficult order:

- BMP
- PCX
- GIF (they can also display animations, even with movie-like quality, look at cinemagraphs)
- PNG
- JPG
- MJPG (to make Internet streaming of webcams, desktops, etc.)

Re: how to display bmp or png files on screen

Posted: Mon Jul 25, 2016 7:52 pm
by BrightLight
Take a look at specifically decode_bmp24 and blit_buffer.
decode_bmp24 decodes a bitmap and makes a raw 32-bit pixel buffer that can be memcpy'd to the screen. blit_buffer does the latter; but it also works in 24-bit and 16-bit video modes, transparently to the user.
BTW, if I were you, I'd look at the documentation. "BMP/PNG file format" in Google will get you good results.