How to draw Image

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
User avatar
sadisoft
Posts: 10
Joined: Sun Nov 16, 2008 11:08 am
Contact:

How to draw Image

Post by sadisoft »

How can I impliment a script to draw an image (*.bmp) onto screen over VGA?
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: How to draw Image

Post by Troy Martin »

Well, it needs to fit the exact screen size, you need to load the image off of a floppy or drive via the filesystem (probably the hardest part), get rid of the headers, and draw it on the screen. There are probably other things I've missed though.

Good luck!
Troy
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
sadisoft
Posts: 10
Joined: Sun Nov 16, 2008 11:08 am
Contact:

Re: How to draw Image

Post by sadisoft »

Thanks for reply!
And how can I get for example the bytes of the file? Is there any example you know?
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: How to draw Image

Post by Troy Martin »

I don't know exactly how to do it, but I'll ask you this: can your OS load files off of a disk?
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
M-Saunders
Member
Member
Posts: 155
Joined: Fri Oct 27, 2006 5:11 am
Location: Oberbayern
Contact:

Re: How to draw Image

Post by M-Saunders »

Without knowing the type of OS you're using (16-bit real mode? 32-bit protected mode?) or programming language, it's hard to say. My OS project includes a program which displays 320x200 PCX images to the screen using real mode x86 assembly language: see pcxview.asm in the programs directory from the downloads at http://mikeos.berlios.de

I know you're trying to use BMPs, but many of the concepts are the same, so it might be useful.

M
MikeOS -- simple, well-documented x86 real-mode OS written in assembly language
http://mikeos.sourceforge.net
User avatar
sadisoft
Posts: 10
Joined: Sun Nov 16, 2008 11:08 am
Contact:

Re: How to draw Image

Post by sadisoft »

thanks, that works!
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: How to draw Image

Post by Dex »

Here this may help a simple load BMP image.

Code: Select all

 ;**********************************;
 ; Simple load bmp demo             ;
 ; Assemble like this:              ;
 ; c:\fasm BmpDemo.asm BmpDemo.com  ;
 ;                                  ;
 ; By  Dex.                15/06/07 ;
 ;**********************************;
	org   100h	
	use16
start:
	mov	[LoadAddress],0 	   ; this is the offset of the top corner of image on screen.
					   ; So to put mario in middle of screem you would do this
					   ; mov     [LoadAddress],320*100+160
	mov	ax,0013h		   ; set video mode13h
	int	10h
	mov	ax,image		   ; move the address of our image into ax
	mov	[ImageBase],ax		   ; load ax into the var "ImageBase"
	call	DisplayBmp		   ; call the bmp display function.
	jc	error			   ; check for errors

	mov	ah,00h			   ; wait for key press.
	int	16h
error:
	mov	ax,0003h		   ; change to text mode
	int	10h
	ret				   ; return to dos

DisplayBmp:
	pusha				   ; save the regs
	push	ds
	push	es
	mov	si,[ImageBase]		   ; make sure si as the image address
	cmp	word [si+00h],4D42h	   ; test for 'BM' to make sure its a BMP file.
	jnz	BmpError		   ; if jump to exit with error
	mov	bx,[si+12h]		   ; start of header + 18 = width
	mov	bp,[si+16h]		   ; start of header + 22 = depth
	cmp	bx,320
	ja	BmpError
	cmp	bp,200
	ja	BmpError
	cmp	word [si+1Ch],8 	   ; start of header + 28 = bpp
	jnz	BmpError
	mov	si,0036h		   ;start of header + 54 = start of palette
	add	si,[ImageBase]
	mov	cx,256			   ;number of colors for patette
	mov	dx,03C8h
	mov	al,0
	out	dx,al
	inc	dx

SetPalete:
	mov	al,[si+2]		   ; red
	shr	al,2
	out	dx,al
	mov	al,[si+1]		   ; green
	shr	al,2
	out	dx,al
	mov	al,[si] 		   ; blue
	shr	al,2
	out	dx,al
	add	si,4
	loop	SetPalete

	push	0A000h
	pop	es
	lea	dx,[bx+3]		   ; round bmp width ;)
	and	dx,-4
	imul	di,bp,320
	add	di,[LoadAddress]	   ; this is the X Y offset of the screen
new_line:
	sub	di,320
	pusha
	mov	cx,bx
	rep	movsb
	popa
	add	si,dx
	dec	bp
	jnz	new_line
ExitOK:
	clc
	pop	es
	pop	ds
	popa
	ret

BmpError:
	stc
	pop	es
	pop	ds
	popa
	ret

 ;----------------------------------------------------;
 ; Data                                               ;
 ;----------------------------------------------------;
LoadAddress dw 0
ImageBase   dw 0
; you can include a bmp or file like this with fasm
; (NOTE: You can only use upto 64k with a com file).
image:
file 'mario.bmp'	; image1

User avatar
sadisoft
Posts: 10
Joined: Sun Nov 16, 2008 11:08 am
Contact:

Re: How to draw Image

Post by sadisoft »

thanks
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: How to draw Image

Post by Troy Martin »

If you're using NASM basically all you have to do is change the file 'mario.bmp' to %incbin "mario.bmp".
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
sadisoft
Posts: 10
Joined: Sun Nov 16, 2008 11:08 am
Contact:

Re: How to draw Image

Post by sadisoft »

Can I use this code in my OS? How?
M-Saunders
Member
Member
Posts: 155
Joined: Fri Oct 27, 2006 5:11 am
Location: Oberbayern
Contact:

Re: How to draw Image

Post by M-Saunders »

sadisoft wrote:Can I use this code in my OS? How?
By learning to program computers.

Seriously, if you don't understand the relationship/differences between C/asm and 32-bit protected mode/real mode, you are not ready to write an operating system. Sorry, but it's true. I have absolutely no idea why people think OS development is just like writing an MS Paint clone or something like that -- it's much, much more complex and involved.

Then again, maybe we're just being trolled on a large scale :-)

M
MikeOS -- simple, well-documented x86 real-mode OS written in assembly language
http://mikeos.sourceforge.net
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: How to draw Image

Post by Troy Martin »

I think part of what sadisoft meant was "Am I allowed to use this in my OS?"

But the how is another lead to trolling. This is getting fun! I'd love to be a temporary mod and smash the hammer a few times right now!
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: How to draw Image

Post by Love4Boobies »

Same here.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
Post Reply