flat assembler
Message board for the users of flat assembler.
Index
> DOS > loading image fie |
Author |
|
mns 17 Jan 2010, 12:07
Can some one please tell me how to a load image (like bitmap,pix,tga...) in mode 13h or mode 12h or any vesa mode using assembly? (sorry for my bad english)
|
|||
17 Jan 2010, 12:07 |
|
mns 17 Jan 2010, 13:55
actualy still I'm new to the programming (still early stage) .Please tell me how can I find a good tutorial about that(disply picture) in assembly or can some one give a example code(in mode 13h,or mode12h or any vesa mode)
|
|||
17 Jan 2010, 13:55 |
|
baldr 17 Jan 2010, 14:12
mns,
You may find FreeVGA Project useful. Richard Wilton's reference was my first book on VGA programming. As a rule of thumb: source file is a description of the picture in some format, output device expects picture in some (possible different) format. You need to parse former format and convert it to latter. This can be as simple as affine transformation and as complex as DCT. If all that you need is ready-made source, use Google. |
|||
17 Jan 2010, 14:12 |
|
mns 17 Jan 2010, 14:33
actualy I have searched all over the net couldn't find a simple source which could understand .
Last edited by mns on 17 Jan 2010, 14:48; edited 1 time in total |
|||
17 Jan 2010, 14:33 |
|
baldr 17 Jan 2010, 14:43
mns,
Stick with mode 13h and BMPs, then. The formats are almost self-explanatory (only bottom-up BMP feature and palette will hinder). |
|||
17 Jan 2010, 14:43 |
|
mns 17 Jan 2010, 14:49
I gess that I have to be patient and need to read more (but my 3day vacation will end to day and there will be hardly any time for a week) by the way Thank you very much baldr for your kind help:).
|
|||
17 Jan 2010, 14:49 |
|
Picnic 17 Jan 2010, 15:41
Hi mns,
Here is a simple load bmp demo (video mode13h) written by Dex.
|
|||||||||||
17 Jan 2010, 15:41 |
|
mns 17 Jan 2010, 16:04
Very much thank you Picnic.
|
|||
17 Jan 2010, 16:04 |
|
bitshifter 17 Jan 2010, 21:23
When learning VGA you should take smaller steps.
The learning curve would go like this... 1) Make program framework first. 2) Learn how change color of single pixel. 3) Use this knowledge to draw horizontal/vertical lines. 4) Use that knowledge to draw filled rectangles. 5) Use that knowledge to draw bitmapped rectangles. Once you know the foundation then no matter what we throw at you, you will immediately identify with the code. |
|||
17 Jan 2010, 21:23 |
|
bitshifter 17 Jan 2010, 22:40
Here is a program that show 320x200 VGA basics...
It even have my infamous skull icon! Code: ;============================================================================ ; ; VGA 320x200 Basics by bitshifter ; ;============================================================================ use16 org 0x0100 ;============================================================================ ; ; code ; ;============================================================================ start: ; Ensure stuff is initialized cli mov ax,cs ; code,data,stack share same segment mov ds,ax mov ss,ax xor sp,sp add ax,0x1000 ; Offscreen buffer segment mov fs,ax mov ax,0xA000 ; Video memory segment mov gs,ax sti ; Setup normal string direction flag so ; string instructions increment pointers cld ; DF = 0 ; Enter 320x200 graphics video mode mov ax,0x0013 ; AH = sub-function (set video mode) ; AL = desired video mode int 0x10 ; invoke BIOS VIDEO service ; Main loop runs here mloop: ; Get offscreen buffer segment into ES mov ax,fs mov es,ax ; Clear offscreen buffer to black xor di,di ; initial destination offset xor ax,ax ; bk-fg pixel color (twice) mov cx,0x7D00 ; number of words in display memory (320 * 200 / 2) rep stosw ; write two pixels each pass ; Paint single pixel into offscreen buffer mov al,0x0F ; color (white on black) mov bx,1 ; y mov di,1 ; x call SetPixel ; Render top line into offscreen buffer mov al,0x0F ; color (white on black) mov bx,0 ; y mov di,0 ; x mov cx,320 ; length call HorzLine ; Render bottom line into offscreen buffer mov al,0x0F ; color (white on black) mov bx,199 ; y mov di,0 ; x mov cx,320 ; length call HorzLine ; render left line into offscreen buffer mov al,0x0F ; color (white on black) mov bx,0 ; y mov di,0 ; x mov cx,200 ; length call VertLine ; Render right line into offscreen buffer mov al,0x0F ; color (white on black) mov bx,0 ; y mov di,319 ; x mov cx,200 ; length call VertLine ; Render solid rectangle into offcreen buffer mov bx,2 ; y mov di,2 ; x mov cx,2 ; width mov dx,2 ; height mov al,0x02 ; color (green on black) call FillRect ; Render bitmap in offscreen buffer (palette dependant) mov bx,200/2-g_icon_height/2 ; y mov di,320/2-g_icon_width/2 ; x mov cx,g_icon_width ; width mov dx,g_icon_height ; height mov si,g_icon_data ; pointer to bitmap data call DrawIcon ; Preload registers for fast swap ; once vertical reset is detected mov ax,fs ; Offscreen buffer segment mov ds,ax xor si,si mov ax,gs ; Video memory segment mov es,ax xor di,di mov cx,0x7D00 ; number of words to move (320 * 200 / 2) ; Wait for vertical reset if 0 ; 0=disabled, 1=enabled mov dx,0x03DA vend: in al,dx test al,0x08 jz vend vres: in al,dx test al,0x08 jnz vres end if ; Copy offscreen buffer into video memory rep movsw ; move two pixels each pass ; Restore data segment register mov ax,cs mov ds,ax ; Check keyboard buffer for keystroke mov ah,0x01 ; AH = sub-function (check for keystroke) int 0x16 ; invoke BIOS KEYBOARD service jz mloop ; continue to loop until keystroke is found ; Remove keystroke from keyboard buffer mov ah,0x00 ; AH = sub-function (remove keystroke) int 0x16 ; invoke BIOS KEYBOARD service ; Enter 80x25 text video mode mov ax,0x0003 ; AH = sub-function (set video mode) ; AL = desired video mode int 0x10 ; invoke BIOS VIDEO service ; Return to operating system int 0x20 jmp $ ; just in case ;======================================================================== ; ; SetPixel - Render single pixel into offscreen buffer ; ; Input: ; AL = color ; BX = y ; DI = x ; ES = offscreen buffer segment ; ;======================================================================== SetPixel: pusha shl bx,6 add di,bx shl bx,2 add di,bx mov byte[es:di],al popa ret ;======================================================================== ; ; HorzLine - Render horizontal line into offscreen buffer ; ; Input: ; AL = color ; BX = y ; DI = x ; CX = length ; ES = offscreen buffer segment ; ;======================================================================== HorzLine: pusha shl bx,6 add di,bx shl bx,2 add di,bx rep stosb popa ret ;======================================================================== ; ; VertLine - Render vertical line into offscreen buffer ; ; Input: ; AL = color ; BX = y ; DI = x ; CX = length ; ES = offscreen buffer segment ; ;======================================================================== VertLine: pusha shl bx,6 add di,bx shl bx,2 add di,bx .loop: mov byte[es:di],al add di,320 loop .loop popa ret ;======================================================================== ; ; FillRect - Renders color filled recatngle into offscreen buffer ; ; Input: ; BX = y ; DI = x ; CX = width ; DX = height ; AL = color ; ES = offscreen buffer segment ; ;======================================================================== FillRect: pusha mov si,320 sub si,cx ; SI = offset to next scan line start shl bx,6 add di,bx shl bx,2 add di,bx .loop: push cx rep stosb pop cx add di,si ; advance offset to next scan line start sub dx,1 ; move up to the next y position jnz .loop popa ret ;======================================================================== ; ; DrawIcon - Renders 256 color bitmap into offscreen buffer ; ; Input: ; BX = y ; DI = x ; CX = width ; DX = height ; ES = offscreen buffer segment ; SI = pointer to bitmap data ; DS = data segment ; ;======================================================================== DrawIcon: pusha mov ax,320 sub ax,cx ; AX = offset to next scan line start shl bx,6 add di,bx shl bx,2 add di,bx .loop: push cx rep movsb pop cx add di,ax ; advance offset to next scan line start sub dx,1 ; move up to the next y position jnz .loop popa ret ;============================================================================ ; ; data ; ;============================================================================ W = 0x0F ; WHITE L = 0x07 ; LIGHT GRAY D = 0x08 ; DARK GRAY g_icon_data: db 0,0,0,0,0,0,0,D,D,D,D,0,0,0,0,0,0,0 g_icon_width = $ - g_icon_data db 0,0,0,0,0,0,D,L,W,L,W,W,L,0,0,0,0,0 db 0,0,0,0,D,L,W,W,W,W,W,W,W,W,D,0,0,0 db 0,0,0,D,W,W,W,W,W,W,W,W,W,W,W,D,0,0 db 0,0,D,W,W,W,W,W,W,W,W,W,W,W,W,W,D,0 db 0,D,W,W,W,W,W,W,W,W,W,W,W,W,W,W,L,0 db 0,L,W,W,W,W,W,W,W,W,W,W,W,W,W,W,W,D db 0,L,W,W,W,W,W,W,W,W,W,W,W,W,W,W,W,L db 0,L,W,W,W,W,W,W,W,W,W,W,W,W,W,W,W,L db 0,L,L,W,W,W,W,W,W,W,W,W,W,W,W,W,L,D db 0,D,D,W,W,W,W,W,W,W,W,W,W,W,W,W,D,D db 0,D,L,W,W,W,W,W,W,W,W,W,W,W,W,W,D,0 db 0,D,D,D,D,L,W,W,W,W,W,W,W,L,D,L,L,0 db 0,D,0,0,0,0,L,L,D,D,W,L,D,0,0,0,D,0 db 0,L,0,0,0,0,0,D,L,L,D,0,0,0,0,0,D,0 db 0,L,0,0,0,0,0,D,W,W,D,0,0,0,0,0,L,D db D,W,D,0,0,0,D,L,W,W,L,D,0,0,0,D,W,0 db L,W,L,D,D,L,L,W,L,L,W,W,L,D,D,W,W,0 db D,L,L,L,D,D,L,D,0,0,L,L,L,W,W,W,W,D db 0,0,0,0,0,D,D,0,0,0,D,D,D,0,D,D,L,0 db 0,0,0,0,D,D,D,0,0,0,D,L,D,0,0,0,0,0 db 0,0,0,0,D,D,L,D,L,D,L,L,D,0,0,0,0,0 db 0,0,0,0,D,L,W,W,L,W,W,W,L,0,0,0,0,0 db 0,0,0,0,D,L,L,L,W,W,L,L,L,0,0,0,0,0 db 0,0,0,0,0,D,D,L,L,L,L,D,D,0,0,0,0,0 db 0,0,0,0,0,0,D,D,D,L,D,D,0,0,0,0,0,0 db 0,0,0,0,0,0,0,D,0,D,0,0,0,0,0,0,0,0 g_icon_height = ($ - g_icon_data) / g_icon_width _________________ Coding a 3D game engine with fasm is like trying to eat an elephant, you just have to keep focused and take it one 'byte' at a time. |
|||
17 Jan 2010, 22:40 |
|
Coddy41 22 Jan 2010, 16:25
> It even have my infamous skull icon!
Of witch you use at the DexOS board Hmm, good code bitshifter That explains a good bit, I think I will try some VGA graphics. |
|||
22 Jan 2010, 16:25 |
|
Picnic 23 Jan 2010, 00:36
mns wrote: Very much thank you Picnic. Nice program bitshifter, below the Commodore-64 balloon sprite Code: ;================================================= ; ; data ; ;================================================= W = 0x0F ; WHITE L = 0x00 ; BLACK ;D = 0x08 ; DARK GRAY g_icon_data: db L,L,L,L,L,L,L,L,L,W,W,W,W,W,W,W,L,L,L,L,L,L,L,L g_icon_width = $ - g_icon_data db L,L,L,L,L,L,L,W,W,W,W,W,W,W,W,W,W,W,L,L,L,L,L,L db L,L,L,L,L,L,W,W,W,W,W,W,W,W,W,W,W,W,W,L,L,L,L,L db L,L,L,L,L,L,W,W,W,W,W,L,L,W,W,W,W,W,W,L,L,L,L,L db L,L,L,L,L,W,W,W,W,W,L,W,W,L,L,W,W,W,W,W,L,L,L,L db L,L,L,L,L,W,W,W,W,W,L,W,W,W,W,W,W,W,W,W,L,L,L,L db L,L,L,L,L,W,W,W,W,W,L,W,W,L,L,W,W,W,W,W,L,L,L,L db L,L,L,L,L,L,W,W,W,W,W,L,L,W,W,W,W,W,W,L,L,L,L,L db L,L,L,L,L,L,W,W,W,W,W,W,W,W,W,W,W,W,W,L,L,L,L,L db L,L,L,L,L,L,W,W,W,W,W,W,W,W,W,W,W,W,W,L,L,L,L,L db L,L,L,L,L,L,W,L,W,W,W,W,W,W,W,W,W,L,W,L,L,L,L,L db L,L,L,L,L,L,L,W,L,W,W,W,W,W,W,W,L,W,L,L,L,L,L,L db L,L,L,L,L,L,L,W,L,L,W,W,W,W,W,L,L,W,L,L,L,L,L,L db L,L,L,L,L,L,L,L,W,L,L,W,W,W,L,L,W,L,L,L,L,L,L,L db L,L,L,L,L,L,L,L,W,L,L,W,W,W,L,L,W,L,L,L,L,L,L,L db L,L,L,L,L,L,L,L,L,W,L,L,W,L,L,W,L,L,L,L,L,L,L,L db L,L,L,L,L,L,L,L,L,W,L,L,W,L,L,W,L,L,L,L,L,L,L,L db L,L,L,L,L,L,L,L,L,L,W,W,W,W,W,L,L,L,L,L,L,L,L,L db L,L,L,L,L,L,L,L,L,L,W,W,W,W,W,L,L,L,L,L,L,L,L,L db L,L,L,L,L,L,L,L,L,L,W,W,W,W,W,L,L,L,L,L,L,L,L,L db L,L,L,L,L,L,L,L,L,L,L,W,W,W,L,L,L,L,L,L,L,L,L,L g_icon_height = ($ - g_icon_data) / g_icon_width |
|||
23 Jan 2010, 00:36 |
|
bitshifter 23 Jan 2010, 10:15
I am glad to see people playing with my code
I learn from other peoples code so can you! That why sharing knowledge so important. An old wiseman once told me: Experience is cheap, when it is second hand. |
|||
23 Jan 2010, 10:15 |
|
DOS386 24 Jan 2010, 09:31
mns wrote: actualy I have searched all over the net couldn't find a simple source which could understand There is (almost) no FASM source "all over the net" ... so: 1. Search "all over the net" for image fileformats (BMP, PNG, JPG) ... or just visit http://www.wotsit.org 2. Search this forum for graphics code (VGA and VESA) or check the FAQ on the top (there are examples here in) 3. Start with VGA mode $13 and BMP (as you already did), ASS'ume "no useless RLE compression", BMP's are filled from bottom to the top as already pointed 4. Start with BMP's exactly filling the screen and matching the screen pixel format (320x200x8bpp) 5. Learn how to center a smaller BMP on the screen 6. Learn how to convert pixel formats (palette -> truecolor is easy, truecolor -> palette less) 7. Add VESA support (VGA $12 mode has ugly "planes") 8. Add support for PNG format (difficult, uses Filters+Deflate+Chunk's, search forum, check PNG spec, Deflate spec) 9. Add support for JPG format (difficult, uses YUV+subsampling+DCT+quantization+Huffman+RLE, search forum, check JPEG spec, example code in C or BASIC or PASCAL) 10. Your app will land here |
|||
24 Jan 2010, 09:31 |
|
mns 27 Jan 2010, 08:12
hey, thank you every one(DOS386,bitshifter,Picnic,Coddy41,baldr) .It's realy nice of you I think I got what needed.
|
|||
27 Jan 2010, 08:12 |
|
rain_storm 27 Jan 2010, 22:39
You might like what this code does. Sorry it is only loosely commented. Its a bmp file viewer that can handle files up to 320*200 and in the following bit depths 1bpp, 4bpp, 8bpp and 24bpp (24bpp is approximated from R8G8B8 to R3G3B2)
Code: org 0x100 KEYBRD = 0x0060 CONSOL = 0xB800 SCREEN = 0xA000 PALLET = 0x03C8 READ_ONLY = 0x00 WRITE_ONLY = 0x01 READ_WRITE = 0x02 START_FILE = 0x00 CURRENT_FILE = 0x01 END_FILE = 0x02 ;macros that make the source code more readable... macro SetVideoMode [Mode] { mov ax, Mode int 0x10 } macro SetCursorMode [Mode] { mov ch, Mode mov ah, 0x01 int 0x10 } macro Print [lpStr] { mov dx, lpStr mov ah, 0x09 int 0x21 } macro InKey { xor ax, ax int 0x16 } macro Exit { mov ah, 0x4C int 0x21 } macro OpenFile [lpFileName, hHandle, bAccess] { mov dx, lpFileName mov al, bAccess mov ah, 0x3D int 0x21 mov [hHandle], ax } macro CloseFile [hHandle] { mov bx, [hHandle] mov ah, 0x3E int 0x21 } macro ReadFile [hHandle, lpBuffer, dNumBytes] { mov bx, [hHandle] mov dx, lpBuffer mov cx, dNumBytes mov ah, 0x3F int 0x21 } macro WriteFile [hHandle, lpBuffer, dNumBytes] { mov bx, [hHandle] mov dx, lpBuffer mov cx, dNumBytes mov ah, 0x40 int 0x21 } macro SeekFile [hHandle, bOrigin, dOffsetH, dOffsetL] { mov bx, [hHandle] mov al, bOrigin mov cx, dOffsetH mov dx, dOffsetL mov ah, 0x42 int 0x21 } macro GetCommandLine [lpBuffer] { xor ax, ax mov si, 0x0080 mov di, lpBuffer lodsb dec di xchg ax, cx jecxz .@@ rep movsb .@@: xor ax, ax stosb mov al, '$' stosb } ;================= ; Start of program ;================= Start: GetCommandLine szCmdLine ; file to open should be on the command line SetVideoMode 0x03 ; enter text mode in case we need to display an error message SetCursorMode 0x20 ; Print szCmdLine ; print the commandline (should be the file name) Print szNewLine ; and a carriage return in case we need to add that error message call LoadBmpFile ; attempt to load the bitmap file jc Error ; carry flag is set on error Success: ; if successful... InKey ; wait for keyboard input Exit ; exit to DOS Error: ; else... Print szErrorMsg ; print the error message InKey ; wait for keyboard input Exit ; exit to DOS LoadBmpFile: ;Open bitmap file for reading OpenFile szCmdLine, hFileHandle, READ_ONLY jc .OpenError ;Read file header from file ReadFile hFileHandle, BMP.Header, 0x36 jc .ReadError ;Verify BMP Signiture cmp word [BMP.eMagic], 'BM' jnz .CorruptError ;Verify Width <= 320 Pixels cmp word [BMP.Width + 0x02], 0x0000 jnz .SizeError cmp word [BMP.Width], 0x0140 ja .SizeError ;Verify Height <= 200 Pixels cmp word [BMP.Height + 0x02], 0x0000 jnz .SizeError cmp word [BMP.Height], 0x00C8 ja .SizeError ;Verify That Bitmap Has Not Been Compressed cmp word [BMP.Compression + 0x02], 0x0000 jnz .CompressedError cmp word [BMP.Compression], 0x0000 jnz .CompressedError ;Verify Bit Depth mov ax, word [BMP.BitsPerPixel] cmp ax, 0x0001 ; if bit depth is 1bpp... jz .BMP1Bit ; load a 1bpp bmp file cmp ax, 0x0004 ; elsif bit depth is 4bpp... jz .BMP4Bit ; load a 4bpp bmp file cmp ax, 0x0008 ; elsif bit depth is 8bpp... jz .BMP8Bit ; load an 8bpp bmp file cmp ax, 0x0010 ; elsif bit depth is 16bpp... jz .BMP16Bit ; unsupported (just sets the carry flag and returns) cmp ax, 0x0018 ; elsif bit depth is 24bpp... jz .BMP24Bit ; load a 24bpp bmp file cmp ax, 0x0032 ; elsif bit depth is 32bpp... jz .BMP32Bit ; unsupported (just sets the carry flag and returns) ; ;============== ;error messages (i know this bit is very sloppy) ;============== .UnsupportedError: ; Print szUnsupported ; bit depth is definately not supported ; .Failed: ; CloseFile hFileHandle ; close the open file stc ; set the carry flag (indicates an error) ret ; return ; .CompressedError: ; Print szCompressErr ; print file was compressed error message jmp .Failed ; return with carry flag set ; .SizeError: ; Print szSizeErr ; print pixel size is too large error message jmp .Failed ; return with carry flag set ; .CorruptError: ; Print szCorruptErr ; print file was corrup error message jmp .Failed ; ; .ReadError: ; Print szReadErr ; jmp .Failed ; ; .OpenError: ; Print szOpenErr ; jmp .Failed ; ; ; Call the functions that actually load the file ; .BMP1Bit: call Load1BitBMP jc .Failed jmp .Success .BMP4Bit: call Load4BitBMP jc .Failed jmp .Success .BMP8Bit: call Load8BitBMP jc .Failed jmp .Success .BMP16Bit: call Load16BitBMP jc .Failed jmp .Success .BMP24Bit: call Load24BitBMP jc .Failed jmp .Success .BMP32Bit: call Load32BitBMP jc .Failed jmp .Success .Success: CloseFile hFileHandle clc ret Load1BitBMP: SetVideoMode 0x13 ; enter mode 0x13 call LoadPallet ; generate black and white pallet jc .Failed ; ;set file pointer to bitmap data... SeekFile hFileHandle, START_FILE, [BMP.lpBitmap + 0x02], [BMP.lpBitmap] jc .Failed ;Center Vertical mov bp, 0x00C8 mov bx, word [BMP.Height] sub bp, bx shr bp, 0x01 .CopyScanLine: pusha mov cx, word [BMP.Width] test cx, 0x0007 jz .LoadScanLine shr cx, 0x03 add cx, 0x0004 and cx, 1111111111111100b .LoadScanLine: mov dx, ScanLine mov bx, word [hFileHandle] mov ax, 0x3F00 int 0x21 popa jc .Failed mov di, SafeScan mov si, ScanLine add si, 0x0002 mov cx, word [BMP.Width] shr cx, 0x03 .ConvertScanLine: push cx mov cx, 0x08 lodsb xchg ax, dx .Unpack: rol dx, 0x01 mov al, dl and al, 0x01 stosb loop .Unpack pop cx loop .ConvertScanLine mov si, SafeScan ;mov cx, word [BMP.Width] mov ax, bx add ax, bp imul ax, 0x0140 mov di, ax ;Center Horizontally mov cx, word [BMP.Width] mov ax, 0x0140 sub ax, cx shr ax, 0x01 add di, ax push es push 0xA000 pop es rep movsb pop es dec bx jns .CopyScanLine .Success: clc ret .Failed: stc ret Load4BitBMP: SetVideoMode 0x13 call LoadPallet jc .Failed SeekFile hFileHandle, START_FILE, [BMP.lpBitmap + 0x02], [BMP.lpBitmap] jc .Failed ;Center Vertical mov bp, 0x00C8 mov bx, word [BMP.Height] sub bp, bx shr bp, 0x01 .CopyScanLine: pusha mov cx, word [BMP.Width] shr cx, 0x01 test cx, 0x0003 jz .LoadScanLine add cx, 0x0004 and cx, 1111111111111100b .LoadScanLine: mov dx, ScanLine mov bx, word [hFileHandle] mov ax, 0x3F00 int 0x21 popa jc .Failed mov di, SafeScan mov si, ScanLine mov cx, word [BMP.Width] shr cx, 0x01 .ConvertScanLine: push cx lodsb aam 0x10 xchg ah, al stosw pop cx loop .ConvertScanLine mov si, SafeScan ;mov cx, word [BMP.Width] mov ax, bx add ax, bp imul ax, 0x0140 mov di, ax ;Center Horizontally mov cx, word [BMP.Width] mov ax, 0x0140 sub ax, cx shr ax, 0x01 add di, ax push es push 0xA000 pop es rep movsb pop es dec bx jns .CopyScanLine .Success: clc ret .Failed: stc ret Load8BitBMP: SetVideoMode 0x13 call LoadPallet jc .Failed SeekFile hFileHandle, START_FILE, [BMP.lpBitmap + 0x02], [BMP.lpBitmap] jc .Failed ;Center Vertical mov bp, 0x00C8 mov bx, word [BMP.Height] sub bp, bx shr bp, 0x01 .CopyScanLine: pusha mov cx, word [BMP.Width] test cx, 0x0003 jz .LoadScanLine add cx, 0x0004 and cx, 1111111111111100b .LoadScanLine: mov dx, ScanLine mov bx, word [hFileHandle] mov ax, 0x3F00 int 0x21 popa jc .Failed mov di, SafeScan mov si, ScanLine mov cx, word [BMP.Width] .ConvertScanLine: push cx lodsb stosb pop cx loop .ConvertScanLine mov si, SafeScan mov ax, bx add ax, bp imul ax, 0x0140 mov di, ax ;Center Horizontally mov cx, word [BMP.Width] mov ax, 0x0140 sub ax, cx shr ax, 0x01 add di, ax push es push 0xA000 pop es rep movsb pop es dec bx jns .CopyScanLine .Success: clc ret .Failed: stc ret Load16BitBMP: stc ret Load24BitBMP: SeekFile hFileHandle, START_FILE, [BMP.lpBitmap + 0x02], [BMP.lpBitmap] jc .Failed SetVideoMode 0x13 call RGB8Bit ;Center Vertical mov bp, 0x00C8 mov bx, word [BMP.Height] sub bp, bx shr bp, 0x01 .CopyScanLine: pusha mov cx, word [BMP.Width] mov ax, cx shl ax, 0x01 add cx, ax test cx, 0x0003 jz .LoadScanLine add cx, 0x0004 and cx, 1111111111111100b .LoadScanLine: mov dx, ScanLine mov bx, word [hFileHandle] mov ax, 0x3F00 int 0x21 popa jc .Failed mov di, SafeScan mov si, ScanLine mov cx, word [BMP.Width] .ConvertScanLine: lodsb and al, 11100000b shr al, 0x06 mov dl, al lodsb and al, 11100000b shr al, 0x03 or dl, al lodsb and al, 11100000b or al, dl stosb loop .ConvertScanLine mov ax, bx add ax, bp imul ax, 0x0140 mov di, ax ;Center Horizontally mov cx, word [BMP.Width] mov ax, 0x0140 sub ax, cx shr ax, 0x01 add di, ax mov si, SafeScan push es push 0xA000 pop es rep movsb pop es dec bx jns .CopyScanLine .Success: clc ret .Failed: stc ret Load32BitBMP: stc ret LoadPallet: pusha mov cx, [BMP.BitsPerPixel] cmp cx, 0x01 jz .LoadMonotone cmp cx, 0x04 jz .Load16Colours cmp cx, 0x08 jz .Load256Colours jmp .Failed .PalletIndex: mov dx, PALLET xor ax, ax out dx, al inc dx mov si, Pallet .LoadRGB: lodsb push ax lodsb push ax lodsb shr al, 0x02 out dx, al pop ax shr al, 0x02 out dx, al pop ax shr al, 0x02 out dx, al inc si loop .LoadRGB popa clc ret .LoadMonotone: ReadFile hFileHandle, Pallet, 0x08 mov cx, 0x0002 jc .Failed jmp .PalletIndex .Load16Colours: ReadFile hFileHandle, Pallet, 0x40 mov cx, 0x0010 jc .Failed jmp .PalletIndex .Load256Colours: ReadFile hFileHandle, Pallet, 0x400 mov cx, 0x0100 jnc .PalletIndex .Failed: popa stc ret ; ;Generate a r3 g3 b2 8bit pallet that approximates true r8 g8 b8 colors ; RGB8Bit: pusha mov dx, PALLET xor ax, ax out dx, al inc dx xor si, si ; Red mov cx, 0x0008 .Red: push cx xor di, di ; Green mov cx, 0x0008 .Green: push cx xor bx, bx ; Blue mov cx, 0x0004 .Blue: mov ax, si ; Red 3 Bits mov al, ah shr al, 0x02 out dx, al mov ax, di ; Green 3 Bits mov al, ah shr al, 0x02 out dx, al mov al, bh ; Blue 2 Bits shr al, 0x02 out dx, al add bx, 0x5555 loop .Blue pop cx add di, 0x2492 loop .Green pop cx add si, 0x2492 loop .Red popa ret szOpenErr db 'Could not open file!',0x0D,0x0A,'$' szReadErr db 'Could not read from file!',0x0D,0x0A,'$' szCorruptErr db 'Bitmap file is corrupt!',0x0D,0x0A,'$' szSizeErr db 'Pixel dimensions are beyond range (320 x 200)!',0x0D,0x0A,'$' szCompressErr db 'Bitmap file has been compressed!',0x0D,0x0A,'$' szUnsupported db 'Unsupported bit depth!',0x0D,0x0A,'$' szErrorMsg db 'Error loading bmp file!',0x0D,0x0A,'$' szNewLine db 0x0D,0x0A,'$',0 szCmdLine db 0x80 dup ? hFileHandle dw ? BMP: .Header:; Size = 0x36 bytes .eMagic dw ? ; EMAGIC BMP NUMBER 'BM' .FileSize dw ?,? ; SIZE OF BMP FILE IN BYTES .Reserved1 dw ?,? ; RESERVED .lpBitmap dw ?,? ; OFFSET IN BYTES OF BITMAP DATA WITHIN BMP FILE .SizeHeader dw ?,? ; SIZE OF THIS HEADER (40 BYTES 28h) .Width dw ?,? ; BITMAP WIDTH IN PIXELS (SIGNED INTEGER) .Height dw ?,? ; BITMAP HEIGHT IN PIXELS (SIGNED INTEGER) .NumPlanes dw ? ; NUMBER OF COLOUR PLANES BEING USED (MUST BE SET TO 1) .BitsPerPixel dw ? ; NUMBER OF BITS PER PIXEL (COLOUR DEPTH IN BPP) 1,4,8,16,24 OR 32 .Compression dw ?,? ; COMPRESSION METHOD BEING USED (0 FOR NO COMPRESSION) .ImageSize dw ?,? ; IMAGE SIZE IN BYTES (NOT THE FILE SIZE) .Horizontal dw ?,? ; HORIZONTAL RESOLUTION OF THE IMAGE IN PIXELS PER METER (SIGNED INTEGER) .Vertical dw ?,? ; VERTICAL RESOLUTION OF THE IMAGE IN PIXELS PER METER (SIGNED INTEGER) .NumColours dw ?,? ; NUMBER OF COLOURS IN THE COLOUR PALLET (0 = 256 COLOURS) .ImportantCol dw ?,? ; NUMBER OF IMPORTANT COLOURS USED OR 0 WHEN EVERY COLOUR IS IMPORTANT (GENERALLY IGNORED) Pallet db 0x0400 dup ? ; Support Indexed Pallet Formats ScanLine dd 0x0140 dup ? ; Supports up to 320 pixels wide and 32bit colour depth SafeScan db 0x0140 dup ? ; Scan line converted to 8 bit 256 colour format
|
|||||||||||
27 Jan 2010, 22:39 |
|
DOS386 29 Jan 2010, 10:08
rain_storm wrote: You might like what this code does. Sorry it is only loosely commented. Its a bmp file viewer that can handle files up to 320*200 and in the following bit depths 1bpp, 4bpp, 8bpp and 24bpp (24bpp is approximated from R8G8B8 to R3G3B2) Nice (minimal test only) BUG's: - Doesn't restore text screen and cursor ON Well, when playing with this code you will quickly find out that 320x200 is a bit too little space. What now ? 1. VESA instead VGA (see FAQ) 2. Scroll (not easy, needs memory (16-bit -> 32-bit) or rereading from the file (as LXPIC does) 3. ZOOM down (integer factor + nearest neighbor algo easy, Lanczos algo difficult) |
|||
29 Jan 2010, 10:08 |
|
rain_storm 30 Jan 2010, 14:36
DOS386 wrote:
Looks like all those 256b demos have been giving me bad habits. Now that you mention it I think I might look into zooming the image. |
|||
30 Jan 2010, 14:36 |
|
mns 03 Jul 2010, 17:56
at last with free time from work and frequent experiments, I've just managed to write a programme which display image in vesa mode.but only 256 colour.If you are interested attached source and the programme.Also included a programme to find out support for different vesa mode which written by me .forgive me if you find errors in the source (there will be lot as still i'm in early days of learning assembly)
|
|||||||||||
03 Jul 2010, 17:56 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.