OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 24, 2024 9:51 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: How to draw Image
PostPosted: Sun Nov 16, 2008 11:11 am 
Offline
User avatar

Joined: Sun Nov 16, 2008 11:08 am
Posts: 10
How can I impliment a script to draw an image (*.bmp) onto screen over VGA?


Top
 Profile  
 
 Post subject: Re: How to draw Image
PostPosted: Sun Nov 16, 2008 11:17 am 
Offline
Member
Member
User avatar

Joined: Fri Apr 18, 2008 4:40 pm
Posts: 1686
Location: Langley, Vancouver, BC, Canada
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


Top
 Profile  
 
 Post subject: Re: How to draw Image
PostPosted: Sun Nov 16, 2008 11:26 am 
Offline
User avatar

Joined: Sun Nov 16, 2008 11:08 am
Posts: 10
Thanks for reply!
And how can I get for example the bytes of the file? Is there any example you know?


Top
 Profile  
 
 Post subject: Re: How to draw Image
PostPosted: Sun Nov 16, 2008 11:35 am 
Offline
Member
Member
User avatar

Joined: Fri Apr 18, 2008 4:40 pm
Posts: 1686
Location: Langley, Vancouver, BC, Canada
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


Top
 Profile  
 
 Post subject: Re: How to draw Image
PostPosted: Sun Nov 16, 2008 11:36 am 
Offline
Member
Member

Joined: Fri Oct 27, 2006 5:11 am
Posts: 155
Location: Oberbayern
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


Top
 Profile  
 
 Post subject: Re: How to draw Image
PostPosted: Sun Nov 16, 2008 11:56 am 
Offline
User avatar

Joined: Sun Nov 16, 2008 11:08 am
Posts: 10
thanks, that works!


Top
 Profile  
 
 Post subject: Re: How to draw Image
PostPosted: Sun Nov 16, 2008 12:44 pm 
Offline
Member
Member
User avatar

Joined: Fri Jan 27, 2006 12:00 am
Posts: 1444
Here this may help a simple load BMP image.
Code:
;**********************************;
; 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



Top
 Profile  
 
 Post subject: Re: How to draw Image
PostPosted: Sun Nov 16, 2008 12:53 pm 
Offline
User avatar

Joined: Sun Nov 16, 2008 11:08 am
Posts: 10
thanks


Top
 Profile  
 
 Post subject: Re: How to draw Image
PostPosted: Sun Nov 16, 2008 1:00 pm 
Offline
Member
Member
User avatar

Joined: Fri Apr 18, 2008 4:40 pm
Posts: 1686
Location: Langley, Vancouver, BC, Canada
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


Top
 Profile  
 
 Post subject: Re: How to draw Image
PostPosted: Sun Nov 16, 2008 1:11 pm 
Offline
User avatar

Joined: Sun Nov 16, 2008 11:08 am
Posts: 10
Can I use this code in my OS? How?


Top
 Profile  
 
 Post subject: Re: How to draw Image
PostPosted: Sun Nov 16, 2008 1:30 pm 
Offline
Member
Member

Joined: Fri Oct 27, 2006 5:11 am
Posts: 155
Location: Oberbayern
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


Top
 Profile  
 
 Post subject: Re: How to draw Image
PostPosted: Sun Nov 16, 2008 1:37 pm 
Offline
Member
Member
User avatar

Joined: Fri Apr 18, 2008 4:40 pm
Posts: 1686
Location: Langley, Vancouver, BC, Canada
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


Top
 Profile  
 
 Post subject: Re: How to draw Image
PostPosted: Sun Nov 16, 2008 1:49 pm 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2111
Location: Bucharest, Romania
Same here.

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 198 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group