how to display bmp or png files on screen

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
shashwatsh
Posts: 5
Joined: Mon Jul 25, 2016 7:09 pm

how to display bmp or png files on screen

Post 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
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: how to display bmp or png files on screen

Post 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.
If a trainstation is where trains stop, what is a workstation ?
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: how to display bmp or png files on screen

Post 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
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: how to display bmp or png files on screen

Post 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.)
Last edited by ~ on Tue Jul 26, 2016 11:04 am, edited 21 times in total.
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: how to display bmp or png files on screen

Post 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.
Attachments
gdi.asm
(27.72 KiB) Downloaded 111 times
You know your OS is advanced when you stop using the Intel programming guide as a reference.
Post Reply