News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

palettemaking with masm

Started by daydreamer, August 20, 2018, 07:17:21 PM

Previous topic - Next topic

daydreamer

Hi
I have earlier seen some palettemaking with help of assembler,not sure what assembler its made with
so I want to learn how to make my own
first I want to make a palette data part red,green,blue,white each have 4 parts of it
I have seen some conditional assembly creates palettes ,loops thru db red,green,blue until 256x3 data is created
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

hutch--

Magnus,

It sounds like an array or a table, depends on how many colours you want in your palette. 2, 16 and 256 colour palettes are conventional but you start to need RGB for more colours and RGBA if you want transparency as well.

daydreamer

Quote from: hutch-- on August 20, 2018, 08:13:10 PM
Magnus,
Y
It sounds like an array or a table, depends on how many colours you want in your palette. 2, 16 and 256 colour palettes are conventional but you start to need RGB for more colours and RGBA if you want transparency as well.
Actually first Starcraft manages to cheat transparency in 256 color mode
Your fpu macro thread and jjs average macro inspired me,to learn create palette data with macro capabilities I seen in old 16 bit demos
It makes use of several loops conditional assembly,not sure what assembler it was in?
Like this:
Db I,0,0
I=I+4
Rept 15
; and continues with other colors
Db 63,i,0
I=I+4
Rept 15
Db 63,63,i
I=I+4
Rept 15

And so on
This creates a nice fire palette
Could be good for other uses to learn to create data this way,without of tedious entering data or waste clock cycles for creating simplest lookup tables

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

mineiro

This is just a table, or array  :biggrin:
By default, if rgb have the same values you have gray scale colors, if differs you have a color palete.
Depends about how you show an image on screen, well, file format too. Some jpeg images have a lossy compression while bmp,gif, have lossless compression. Not really, I think they created jpeg2000 to deal with lossless compression.
Lossy compression you lost some data while lossless no. So, the same picture saved as jpeg and gif means that jpeg picture is similar but not 100% equal to gif picture.
Other point about images is that we live on a rectangle or square world. So, to display an image on screen the image size is a multiple of prime numbers. Better words, if you have raw data and want to display on screen so you need get size of raw data and factor to have some possible combinations. This is why we don't see a prime number raw data stored (only if we draw a line). Well, not really, I suppose they created sprites (like tetris) to deal with this.

;--edit
We can use a gif file format as file compressor, just like a zip file. Of course that the image seen is like a noise, but we can call that abstract art.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

daydreamer

I wanted some macro examples minerio but thanks for "greyscale" inspiring me to one way to use palettes for
1: First either import or create greyscale heightmap for terrain procedural
And make palette :start with white and grey for highest value(mountains),  green,brown, yellow,blue(rivers,lakes), optional to add some random noise.
And use it together with heightmap as texture bitmap for that terrain

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

dedndave

this is a "standardized" 256-color palette that i use from time to time
it allows for 20 application defined variable colors
practically any image i have converted using the palette looks good
the 6x6x6 color cube (216 colors) could easily be generated by a loop

Pal256  db 005h,005h,005h,0 ;00 (00h-13h: sepia/application defined)
        db 00Fh,00Fh,00Fh,0 ;01 (00h-08h: application defined: additional dark grays)
        db 019h,019h,019h,0 ;02
        db 024h,024h,024h,0 ;03 (B,G,R,0)
        db 02Eh,02Eh,02Eh,0 ;04
        db 038h,038h,038h,0 ;05
        db 042h,042h,042h,0 ;06
        db 04Ch,04Ch,04Ch,0 ;07
        db 057h,057h,057h,0 ;08
        db 0DFh,0DFh,0DFh,0 ;09 (09h-13h: application defined: outine light grays)
        db 0E4h,0E4h,0E4h,0 ;0A
        db 0E9h,0E9h,0E9h,0 ;0B
        db 0EDh,0EDh,0EDh,0 ;0C
        db 0EFh,0EFh,0EFh,0 ;0D
        db 0F4h,0F4h,0F4h,0 ;0E
        db 0F8h,0F8h,0F8h,0 ;0F
        db 0F9h,0F9h,0F9h,0 ;10
        db 0FBh,0FBh,0FBh,0 ;11
        db 0FDh,0FDh,0FDh,0 ;12
        db 0FEh,0FEh,0FEh,0 ;13
        db 00Ah,00Ah,00Ah,0 ;14 (14h-27h: standard grays)
        db 014h,014h,014h,0 ;15
        db 01Fh,01Fh,01Fh,0 ;16
        db 029h,029h,029h,0 ;17
        db 03Dh,03Dh,03Dh,0 ;18
        db 047h,047h,047h,0 ;19
        db 052h,052h,052h,0 ;1A
        db 05Ch,05Ch,05Ch,0 ;1B
        db 070h,070h,070h,0 ;1C
        db 07Ah,07Ah,07Ah,0 ;1D
        db 085h,085h,085h,0 ;1E
        db 08Fh,08Fh,08Fh,0 ;1F
        db 0A3h,0A3h,0A3h,0 ;20
        db 0ADh,0ADh,0ADh,0 ;21
        db 0B8h,0B8h,0B8h,0 ;22
        db 0C2h,0C2h,0C2h,0 ;23
        db 0D6h,0D6h,0D6h,0 ;24
        db 0E0h,0E0h,0E0h,0 ;25
        db 0EBh,0EBh,0EBh,0 ;26
        db 0F5h,0F5h,0F5h,0 ;27
        db 000h,000h,000h,0 ;28 (28h-FFh: 6x6x6 color cube)
        db 033h,000h,000h,0 ;29 (includes black, white, and 4 other grays)
        db 066h,000h,000h,0 ;2A
        db 099h,000h,000h,0 ;2B
        db 0CCh,000h,000h,0 ;2C
        db 0FFh,000h,000h,0 ;2D
        db 000h,000h,033h,0 ;2E
        db 033h,000h,033h,0 ;2F
        db 066h,000h,033h,0 ;30
        db 099h,000h,033h,0 ;31
        db 0CCh,000h,033h,0 ;32
        db 0FFh,000h,033h,0 ;33
        db 000h,000h,066h,0 ;34
        db 033h,000h,066h,0 ;35
        db 066h,000h,066h,0 ;36
        db 099h,000h,066h,0 ;37
        db 0CCh,000h,066h,0 ;38
        db 0FFh,000h,066h,0 ;39
        db 000h,000h,099h,0 ;3A
        db 033h,000h,099h,0 ;3B
        db 066h,000h,099h,0 ;3C
        db 099h,000h,099h,0 ;3D
        db 0CCh,000h,099h,0 ;3E
        db 0FFh,000h,099h,0 ;3F
        db 000h,000h,0CCh,0 ;40
        db 033h,000h,0CCh,0 ;41
        db 066h,000h,0CCh,0 ;42
        db 099h,000h,0CCh,0 ;43
        db 0CCh,000h,0CCh,0 ;44
        db 0FFh,000h,0CCh,0 ;45
        db 000h,000h,0FFh,0 ;46
        db 033h,000h,0FFh,0 ;47
        db 066h,000h,0FFh,0 ;48
        db 099h,000h,0FFh,0 ;49
        db 0CCh,000h,0FFh,0 ;4A
        db 0FFh,000h,0FFh,0 ;4B
        db 000h,033h,000h,0 ;4C
        db 033h,033h,000h,0 ;4D
        db 066h,033h,000h,0 ;4E
        db 099h,033h,000h,0 ;4F
        db 0CCh,033h,000h,0 ;50
        db 0FFh,033h,000h,0 ;51
        db 000h,033h,033h,0 ;52
        db 033h,033h,033h,0 ;53
        db 066h,033h,033h,0 ;54
        db 099h,033h,033h,0 ;55
        db 0CCh,033h,033h,0 ;56
        db 0FFh,033h,033h,0 ;57
        db 000h,033h,066h,0 ;58
        db 033h,033h,066h,0 ;59
        db 066h,033h,066h,0 ;5A
        db 099h,033h,066h,0 ;5B
        db 0CCh,033h,066h,0 ;5C
        db 0FFh,033h,066h,0 ;5D
        db 000h,033h,099h,0 ;5E
        db 033h,033h,099h,0 ;5F
        db 066h,033h,099h,0 ;60
        db 099h,033h,099h,0 ;61
        db 0CCh,033h,099h,0 ;62
        db 0FFh,033h,099h,0 ;63
        db 000h,033h,0CCh,0 ;64
        db 033h,033h,0CCh,0 ;65
        db 066h,033h,0CCh,0 ;66
        db 099h,033h,0CCh,0 ;67
        db 0CCh,033h,0CCh,0 ;68
        db 0FFh,033h,0CCh,0 ;69
        db 000h,033h,0FFh,0 ;6A
        db 033h,033h,0FFh,0 ;6B
        db 066h,033h,0FFh,0 ;6C
        db 099h,033h,0FFh,0 ;6D
        db 0CCh,033h,0FFh,0 ;6E
        db 0FFh,033h,0FFh,0 ;6F
        db 000h,066h,000h,0 ;70
        db 033h,066h,000h,0 ;71
        db 066h,066h,000h,0 ;72
        db 099h,066h,000h,0 ;73
        db 0CCh,066h,000h,0 ;74
        db 0FFh,066h,000h,0 ;75
        db 000h,066h,033h,0 ;76
        db 033h,066h,033h,0 ;77
        db 066h,066h,033h,0 ;78
        db 099h,066h,033h,0 ;79
        db 0CCh,066h,033h,0 ;7A
        db 0FFh,066h,033h,0 ;7B
        db 000h,066h,066h,0 ;7C
        db 033h,066h,066h,0 ;7D
        db 066h,066h,066h,0 ;7E
        db 099h,066h,066h,0 ;7F
        db 0CCh,066h,066h,0 ;80
        db 0FFh,066h,066h,0 ;81
        db 000h,066h,099h,0 ;82
        db 033h,066h,099h,0 ;83
        db 066h,066h,099h,0 ;84
        db 099h,066h,099h,0 ;85
        db 0CCh,066h,099h,0 ;86
        db 0FFh,066h,099h,0 ;87
        db 000h,066h,0CCh,0 ;88
        db 033h,066h,0CCh,0 ;89
        db 066h,066h,0CCh,0 ;8A
        db 099h,066h,0CCh,0 ;8B
        db 0CCh,066h,0CCh,0 ;8C
        db 0FFh,066h,0CCh,0 ;8D
        db 000h,066h,0FFh,0 ;8E
        db 033h,066h,0FFh,0 ;8F
        db 066h,066h,0FFh,0 ;90
        db 099h,066h,0FFh,0 ;91
        db 0CCh,066h,0FFh,0 ;92
        db 0FFh,066h,0FFh,0 ;93
        db 000h,099h,000h,0 ;94
        db 033h,099h,000h,0 ;95
        db 066h,099h,000h,0 ;96
        db 099h,099h,000h,0 ;97
        db 0CCh,099h,000h,0 ;98
        db 0FFh,099h,000h,0 ;99
        db 000h,099h,033h,0 ;9A
        db 033h,099h,033h,0 ;9B
        db 066h,099h,033h,0 ;9C
        db 099h,099h,033h,0 ;9D
        db 0CCh,099h,033h,0 ;9E
        db 0FFh,099h,033h,0 ;9F
        db 000h,099h,066h,0 ;A0
        db 033h,099h,066h,0 ;A1
        db 066h,099h,066h,0 ;A2
        db 099h,099h,066h,0 ;A3
        db 0CCh,099h,066h,0 ;A4
        db 0FFh,099h,066h,0 ;A5
        db 000h,099h,099h,0 ;A6
        db 033h,099h,099h,0 ;A7
        db 066h,099h,099h,0 ;A8
        db 099h,099h,099h,0 ;A9
        db 0CCh,099h,099h,0 ;AA
        db 0FFh,099h,099h,0 ;AB
        db 000h,099h,0CCh,0 ;AC
        db 033h,099h,0CCh,0 ;AD
        db 066h,099h,0CCh,0 ;AE
        db 099h,099h,0CCh,0 ;AF
        db 0CCh,099h,0CCh,0 ;B0
        db 0FFh,099h,0CCh,0 ;B1
        db 000h,099h,0FFh,0 ;B2
        db 033h,099h,0FFh,0 ;B3
        db 066h,099h,0FFh,0 ;B4
        db 099h,099h,0FFh,0 ;B5
        db 0CCh,099h,0FFh,0 ;B6
        db 0FFh,099h,0FFh,0 ;B7
        db 000h,0CCh,000h,0 ;B8
        db 033h,0CCh,000h,0 ;B9
        db 066h,0CCh,000h,0 ;BA
        db 099h,0CCh,000h,0 ;BB
        db 0CCh,0CCh,000h,0 ;BC
        db 0FFh,0CCh,000h,0 ;BD
        db 000h,0CCh,033h,0 ;BE
        db 033h,0CCh,033h,0 ;BF
        db 066h,0CCh,033h,0 ;C0
        db 099h,0CCh,033h,0 ;C1
        db 0CCh,0CCh,033h,0 ;C2
        db 0FFh,0CCh,033h,0 ;C3
        db 000h,0CCh,066h,0 ;C4
        db 033h,0CCh,066h,0 ;C5
        db 066h,0CCh,066h,0 ;C6
        db 099h,0CCh,066h,0 ;C7
        db 0CCh,0CCh,066h,0 ;C8
        db 0FFh,0CCh,066h,0 ;C9
        db 000h,0CCh,099h,0 ;CA
        db 033h,0CCh,099h,0 ;CB
        db 066h,0CCh,099h,0 ;CC
        db 099h,0CCh,099h,0 ;CD
        db 0CCh,0CCh,099h,0 ;CE
        db 0FFh,0CCh,099h,0 ;CF
        db 000h,0CCh,0CCh,0 ;D0
        db 033h,0CCh,0CCh,0 ;D1
        db 066h,0CCh,0CCh,0 ;D2
        db 099h,0CCh,0CCh,0 ;D3
        db 0CCh,0CCh,0CCh,0 ;D4
        db 0FFh,0CCh,0CCh,0 ;D5
        db 000h,0CCh,0FFh,0 ;D6
        db 033h,0CCh,0FFh,0 ;D7
        db 066h,0CCh,0FFh,0 ;D8
        db 099h,0CCh,0FFh,0 ;D9
        db 0CCh,0CCh,0FFh,0 ;DA
        db 0FFh,0CCh,0FFh,0 ;DB
        db 000h,0FFh,000h,0 ;DC
        db 033h,0FFh,000h,0 ;DD
        db 066h,0FFh,000h,0 ;DE
        db 099h,0FFh,000h,0 ;DF
        db 0CCh,0FFh,000h,0 ;E0
        db 0FFh,0FFh,000h,0 ;E1
        db 000h,0FFh,033h,0 ;E2
        db 033h,0FFh,033h,0 ;E3
        db 066h,0FFh,033h,0 ;E4
        db 099h,0FFh,033h,0 ;E5
        db 0CCh,0FFh,033h,0 ;E6
        db 0FFh,0FFh,033h,0 ;E7
        db 000h,0FFh,066h,0 ;E8
        db 033h,0FFh,066h,0 ;E9
        db 066h,0FFh,066h,0 ;EA
        db 099h,0FFh,066h,0 ;EB
        db 0CCh,0FFh,066h,0 ;EC
        db 0FFh,0FFh,066h,0 ;ED
        db 000h,0FFh,099h,0 ;EE
        db 033h,0FFh,099h,0 ;EF
        db 066h,0FFh,099h,0 ;F0
        db 099h,0FFh,099h,0 ;F1
        db 0CCh,0FFh,099h,0 ;F2
        db 0FFh,0FFh,099h,0 ;F3
        db 000h,0FFh,0CCh,0 ;F4
        db 033h,0FFh,0CCh,0 ;F5
        db 066h,0FFh,0CCh,0 ;F6
        db 099h,0FFh,0CCh,0 ;F7
        db 0CCh,0FFh,0CCh,0 ;F8
        db 0FFh,0FFh,0CCh,0 ;F9
        db 000h,0FFh,0FFh,0 ;FA
        db 033h,0FFh,0FFh,0 ;FB
        db 066h,0FFh,0FFh,0 ;FC
        db 099h,0FFh,0FFh,0 ;FD
        db 0CCh,0FFh,0FFh,0 ;FE
        db 0FFh,0FFh,0FFh,0 ;FF

dedndave

this is a different palette that i generate using code
it is also 256-color, and is used for a height-map as you see in the app picture below

;***********************************************************************************************

PalInit PROC

;                B     G     R     L
;
;black   2040   000   000   000   000
;
;red     1785   000   000   255   029
;
;yellow  1020   000   255   255   226     center
;
;green   0765   000   255   000   160
;
;cyan    0510   255   255   000   095
;
;blue    0255   255   000   000   029
;
;black   0000   000   000   000   000
;
;note: the luminance value stored in the table is 226-L, to simplify palette generation

;--------------------------------------------------

;generate the blue values

        mov     edx,offset PalTable
        mov     ecx,255
        xor     eax,eax

PInit0: mov     [edx],al               ;colors 0 to 254
        add     edx,4                  ;values = 0 to 254
        inc     eax
        dec     ecx
        jnz     PInit0

        mov     ecx,eax                ;ECX = EAX = 255

PInit1: mov     [edx],al               ;colors 255 to 509
        add     edx,4                  ;value = 255
        dec     ecx
        jnz     PInit1

PInit2: mov     [edx],al               ;colors 510 to 764
        add     edx,4                  ;values = 255 to 1
        dec     eax
        jnz     PInit2

;generate the green values

        mov     edx,offset PalTable+4*255+1
        mov     cl,255

PInit3: mov     [edx],al               ;colors 255 to 509
        add     edx,4                  ;values = 0 to 254
        inc     eax
        dec     ecx
        jnz     PInit3

        mov     cx,511

PInit4: mov     [edx],al               ;colors 510 to 1020
        add     edx,4                  ;value = 255
        dec     ecx
        jnz     PInit4

        dec     eax                    ;EAX = 254

PInit5: mov     [edx],al               ;colors 1021 to 1782
        mov     [edx+4],al             ;values = 254 to 1
        mov     [edx+8],al
        add     edx,12
        dec     eax
        jnz     PInit5

;generate the red values

        mov     edx,offset PalTable+4*765+2
        mov     cl,255

PInit6: mov     [edx],al               ;colors 765 to 1019
        add     edx,4                  ;values = 0 to 254
        inc     eax
        dec     ecx
        jnz     PInit6

        mov     cx,765

PInit7: mov     [edx],al               ;colors 1020 to 1784
        add     edx,4                  ;value = 255
        dec     ecx
        jnz     PInit7

PInit8: mov     [edx],al               ;colors 1785 to 2039
        add     edx,4                  ;values = 255 to 1
        dec     eax
        jnz     PInit8

;generate the luminance taper values

        push    esi
        push    edi
        push    ebx
        push    ebp
        mov     esi,offset PalTable+4*1020+3
        xor     edx,edx
        xor     eax,eax
        xor     ebx,ebx
        mov     ecx,41D68F0Ah
        mov     edi,esi
        mov     ebp,765

PInit9: mov     [esi],dl
        mov     [edi],dl
        add     esi,4
        sub     edi,4
        add     eax,ecx
        adc     edx,ebx
        dec     ebp
        jnz     PInit9

        mov     ecx,1D000000h
        mov     ebp,256

PInitA: mov     [esi],dl
        mov     [edi],dl
        add     esi,4
        sub     edi,4
        add     eax,ecx
        adc     edx,ebx
        dec     ebp
        jnz     PInitA

        pop     ebp
        pop     ebx
        pop     edi
        pop     esi

;generate the initial palette and set it into the palette image and HR DIBs

        call    PalGen
        ret

PalInit ENDP

;***********************************************************************************************

felipe

dedndave is that a software made by you? looks pretty nice and cool.  8)  :icon14:

dedndave

yes - my biggest project to date  :P
i could probably make some money on it, if i spent a little more time on it
there is a company here in the Phoenix area that would love to have it (Medtronic Inc)

daydreamer

thanks Dave for sharing  :t,one book I have on game programming meantions that when you run a program in 8bit palette mode,windows don't let you define all 256,but reserves 16 something so it can display its own stuff
but as there are more detailed heightmaps between 0-255,0-65535 and various text encoded files,if you only use it internally in 32bit mode,you can pick custom sized palettes if you want to or for a 0-65535 heightmap have a proc that blends between palette entries for example 100 and 101

I gonna share my research on creating with macros
REPT =old version of REPEAT
remember what you learned first time you programmed that every character Counts and can make a different meaning of statement:
.WHILE
.IF
.ENDIF
etc
is for creating runtime code,highlevel macros that makes it easier for you to use conditional code,without get lost in the many conditional jumps
WHILE ;notice its without beginning "."
IF
ENDM ;uses same ENDM as for macros
etc
is for conditional assembly,so you can create LUT,palettes or any Array that is easily produced with math at assembly time
maybe even possible to start with having some of the first fibonnaci numbers in .data statements,giving your program a headstart compared to your fellow students :P

cool Dave,this is just a hobby Project

is there any way to code in DB binary values?



my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

dedndave

that must be an old book  :lol:

windows would only do that if your display settings were set to 256-colors
that may have been practical back in the win95/98 days, when EGA and VGA adapters were relatively new
(they needed to reserve desktop colors for things like start menu, taskbar, icon text,  etc)

nowdays, almost any display system allows for at least 16-bit color
so, no color index dedication is required

i have had a great deal of success with 256-color code
not surprisingly, working with 256-color DIB's is considerably faster than full-color images
that is why i have spent so much time developing versatile palettes

dedndave

you can use binary values in define statements easily
it will require more work, of course

daydreamer

Quote from: dedndave on August 21, 2018, 03:36:40 AM
i have had a great deal of success with 256-color code
not surprisingly, working with 256-color DIB's is considerably faster than full-color images
that is why i have spent so much time developing versatile palettes
I just want to put together several codings to one complete tiny program
goals I had is make an assembly game and when I came in touch with masm32 programming I also want to make a tiny 1k or 4k or 64k demo
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

aw27

#13
Color palettes are still optionally used by some remote access software, including one title I produce. It really makes a difference if you are on dial-up. Well, I don't think anyone is on dial-up anymore  :badgrin: *, so it is probably a useless features but does not hurt keeping the feature available.

* There are still 2.1 million people on AOL in the USA, but they are too retarded to be considered.

daydreamer

Quote from: AW on August 21, 2018, 09:55:28 PM
Color palettes are still optionally used by some remote access software, including one title I produce. It really makes a difference if you are on dial-up. Well, I don't think anyone is on dial-up anymore  :badgrin: , so it is probably a useless features but does not hurt keeping the feature available.
Hi AW
how is it with your 3dmodelling today?
have you tried make a huge 600mb or more animation?
I recommend mp4 over animated gif,but unfortunatly not allowed to post mp4 everywhere,about the same size but with long animation with many different lightsetting/colors its becomes terrible crappy
and what can happen when you have been enjoying assembly and start 3dmodelling? you have twice the fun in size reduction,first the fun in least amount of bytes are as fun as least amount of polys
second the fun afterwards of seeing your lowpoly object makes hours of difference when rendering an animation
so maybe a (red)martian animation would work better,or a (blue/White)starry starfield would work better for .gif animations?
but sometimes when you model an object,you notice the approach is influenced by your coding and math skills

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding