flat assembler
Message board for the users of flat assembler.

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

Author
Thread Post new topic Reply to topic
FlierMate



Joined: 21 Jan 2021
Posts: 219
FlierMate 20 Feb 2021, 13:05
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 EDIT: attachment removed
2) HUGI.raw is a raw image (always 64768 bytes) as defined below:

Quote:
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:

Code:
;  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
        .286

        .CODE
        .STARTUP

        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
NextPalette:
        lodsw
        mov     bx, ax
        lodsb
        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
NextImage:
        lodsb
        push    si
        mov     cx, 45
        mov     si, OFFSET FrequencyTable
NextTable:
        mov     bx, [si]
        cmp     bh, al
        jz      Expand
        inc     si
        inc     si
        loop    NextTable
        stosb
        pop     si
        cmp     di, 60480
        jae     Exit
        jmp     NextImage
Expand:
        pop     si
        lodsb
        mov     cl, al
        mov     al, bl
        rep     stosb
        cmp     di, 60480
        jae     Exit
        jmp     NextImage
Exit:
        xor     ax, ax
        int     16h
        mov     ax, 03h
        int     10h
        mov     ah, 4ch
        int     21h

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

        END
    


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!


Last edited by FlierMate on 13 Apr 2021, 16:30; edited 1 time in total
Post 20 Feb 2021, 13:05
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 21 Feb 2021, 09:00
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
FlierMate



Joined: 21 Jan 2021
Posts: 219
FlierMate 02 Mar 2021, 14:02
DimonSoft wrote:
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.


Thank you for the CreateDIBitmap and StretchDIBits functions. I might need to spend some time to write code to experiment with these.
Post 02 Mar 2021, 14:02
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4075
Location: vpcmpistri
bitRAKE 08 Mar 2021, 06:02
Here is an old example algorithmically generating graphic for Win32.
https://board.flatassembler.net/topic.php?p=71049#71049
Post 08 Mar 2021, 06:02
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.