flat assembler
Message board for the users of flat assembler.

Index > Tutorials and Examples > How to display raw image in Win32?

Thread Post new topic Reply to topic

Joined: 21 Jan 2021
Posts: 29
Location: Malaysia
Hi, I am nearly one month on FASM message board.

I have both an example to share and a question to ask fellow coders:

Example to share:

1) ENTRY.com is a DOS program that display the attached raw image
2) HUGI.raw is a raw image (always 64768 bytes) as defined below:

Raw Image:

The file consist of 768 bytes of palette data immediately followed by 64000
bytes of raw image data.

The palette is in the standard VGA format:

- 256 colour triplets
- a triplet is 3 bytes (1 Red, 1 Green, 1 Blue)
- each byte has the range 00 to 3F hex (0 to 63 decimal)

= 768 bytes

The image is in the standard VGA 320 x 200 x 256 format:

- 320 pixels/bytes per line
- 200 lines high
- 256 colours

= 64000 bytes

The ENTRY.com has HUGI.RAW embedded and compressed, that is why the program is smaller than the size of RAW image itself.

ENTRY.com was my old code for an Asm size-optimizing contest many years ago:

;  This is my own compression technique.
;  Two different compression techniques employed here.
;  The palette is compact through 8-to-6 bit transformation.
;  The image data is compact through frequency table.

        .MODEL Tiny


        push    cs
        pop     ds
        push    0a000h
        pop     es
        mov     al, 13h
        int     10h
        mov     dx, 03c8h
        xor     ax, ax
        out     dx, al
        inc     dx
        mov     cx, 192
        mov     si, OFFSET Palette
        mov     bx, ax
        mov     ah, al
        mov     al, bl
        shr     al, 2
        out     dx, al
        shl     bl, 6
        shr     bl, 2
        mov     al, bh
        shr     al, 4
        or      al, bl
        out     dx, al
        shl     bh, 4
        shr     bh, 2
        mov     al, ah
        shr     al, 6
        or      al, bh
        out     dx, al
        mov     al, ah
        and     al, 03fh
        out     dx, al
        loop    NextPalette
        xor     di, di
        add     si, 90
        push    si
        mov     cx, 45
        mov     si, OFFSET FrequencyTable
        mov     bx, [si]
        cmp     bh, al
        jz      Expand
        inc     si
        inc     si
        loop    NextTable
        pop     si
        cmp     di, 60480
        jae     Exit
        jmp     NextImage
        pop     si
        mov     cl, al
        mov     al, bl
        rep     stosb
        cmp     di, 60480
        jae     Exit
        jmp     NextImage
        xor     ax, ax
        int     16h
        mov     ax, 03h
        int     10h
        mov     ah, 4ch
        int     21h

        Palette         db      576 DUP(?)
        FrequencyTable  dw      45 DUP(?)


My question! How do I display the abovesaid raw image in Windows ? Do I need to use Win32 API (since I cannot use BIOS interrupt anymore)?

Can someone please share an Asm example for Win32 equivalent? Thanks!

Description: Example program to display the raw image in DOS
Filename: ENTRY.zip
Filesize: 15.78 KB
Downloaded: 13 Time(s)

Post 20 Feb 2021, 13:05
View user's profile Send private message Reply with quote

Joined: 03 Mar 2010
Posts: 891
Location: Belarus
This function might be a good start. The BMP format is just a bit more complicated than your RAW one, but this function just wants you to supply relevant parts of data. I guess, you’ll only need to scale the R, G and B values in the palette since they’re now 0…255.

Painting the bitmap may be performed in many different ways. In fact, if you only want to paint the bitmap and have no intent to use it anywhere else, plain StretchDIBits might be just enough and maybe even too cool.
Post 21 Feb 2021, 09:00
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  

< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.