.PIC images

Anything QL Software or Programming Related.
Dec
ROM Dongle
Posts: 21
Joined: Sun Dec 20, 2020 2:28 pm

Re: .PIC images

Post by Dec »

BTW. I can't find information on how the palette used is converted to RGB888. For example, for mode 16, I use this palette:
Image
But what is the real palette?

Modes 32 and 33 use 5 and 6 bit colors, but how to correctly convert these colors to RGB888?


User avatar
BSJR
Trump Card
Posts: 186
Joined: Sun Oct 18, 2015 12:53 pm
Location: Amsterdam
Contact:

Re: .PIC images

Post by BSJR »

Dec wrote: Sat Apr 08, 2023 12:29 am Lets compare internal file header structure of astronaut.pic4 and astronaut.pic8.
The confusing part is that the x/y resolution is given as mode 4 pixels (e.g. 512x256).
For mode 8 (or 1) only half of the x pixels is defined and the pixel is written twice, giving an effective resolution of 256x256 pixels. This way a BBQL mode 4 or mode 8 screen can be 32KB for both.

There are also modes defined in GD2 sprites as 8 & 15 that give 8 or 16 colours at full resolution (no double pix) but these are seldom seen in the wild and only work on high-res displays.

Apart from the Photon package, Dilwyn's BMP can translate most QL/GD2 modes to another QL/GD2 mode.
Aurora's mode 16 is RGB with 3 bits per sample, combining the lowest R & B bits into one, to fit into the byte.
BMP and my SQRview calculate this byte, unlike SMSQ/E which contains a lookup palette for this.
That is not the one accessed with PALETTE_PAL that can be set with the PALETTE_8 command but is used by the GD2/mode15 sprite.

BSJR


User avatar
pjw
QL Wafer Drive
Posts: 1316
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: .PIC images

Post by pjw »

Dec wrote: Sat Apr 08, 2023 2:27 am BTW. I can't find information on how the palette used is converted to RGB888. <>
Here is one way to convert Aurora mode 16 colours to 24 bit RGB, using a table:

Code: Select all

* Native colour conversion
*
* V0.01, ©pjwitte 2oi8+
*
* Compatible with all GD2 modes
*


        section code

        xdef ut_cv16to24
        xdef cv_16to24


*
ut_cv16to24
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* entry:
*       d3.b = grbgrbgx                 - Aur (mode 16) colour code
*
* exit:
*       d3.l = 0 R G B                  - 24 bit colour code <> mode 64!
*       a3 smashed
*
*       no errors; always "suceeds"

        lea.l tab_aur8rgb,a3
        andi.w #$00ff,d3        byte -> word

*
cv_16to24
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This routine employs a table of all 256 possible Aurora RGB values groups
* of 3 bytes per value, one each for R, G & B.
*
* entry:
*       d3.w = 00000000 grbgrbgx        - Aur (mode 16) byte in a word
*       a3 ->  tab_aur8rgb              - RGB conversion table
*
* exit:
*       d3.l = 0 R G B                  - 24 bit colour code <> mode 64!
*
* No other registers affected
*
* No errors; always "suceeds"

        adda.w d3,a3
        adda.w d3,a3
        adda.w d3,a3
        moveq #0,d3
        move.b (a3)+,d3
        lsl.w #8,d3
        move.b (a3)+,d3
        lsl.l #8,d3
        move.b (a3)+,d3

        rts


*
tab_aur8rgb
        dc.b $00,$00,$00,$20,$00,$00,$00,$20,$00,$20,$20,$00,$00,$00,$40,$00,$00,$60,$00,$20,$40,$00,$20,$60
        dc.b $40,$00,$00,$60,$00,$00,$40,$20,$00,$60,$20,$00,$40,$00,$40,$60,$00,$60,$40,$20,$40,$60,$20,$60
        dc.b $00,$40,$00,$20,$40,$00,$00,$60,$00,$20,$60,$00,$00,$40,$40,$00,$40,$60,$00,$60,$40,$00,$60,$60
        dc.b $40,$40,$00,$60,$40,$00,$40,$60,$00,$60,$60,$00,$40,$40,$40,$60,$40,$60,$40,$60,$40,$60,$60,$60
        dc.b $00,$00,$80,$00,$00,$A0,$00,$20,$80,$00,$20,$A0,$00,$00,$C0,$00,$00,$E0,$00,$20,$C0,$00,$20,$E0
        dc.b $40,$00,$80,$60,$00,$A0,$40,$20,$80,$60,$20,$A0,$40,$00,$C0,$60,$00,$E0,$40,$20,$C0,$60,$20,$E0
        dc.b $00,$40,$80,$00,$40,$A0,$00,$60,$80,$00,$60,$A0,$00,$40,$C0,$00,$40,$E0,$00,$60,$C0,$00,$60,$E0
        dc.b $40,$40,$80,$60,$40,$A0,$40,$60,$80,$60,$60,$A0,$40,$40,$C0,$60,$40,$E0,$40,$60,$C0,$60,$60,$E0
        dc.b $80,$00,$00,$A0,$00,$00,$80,$20,$00,$A0,$20,$00,$80,$00,$40,$A0,$00,$60,$80,$20,$40,$A0,$20,$60
        dc.b $C0,$00,$00,$E0,$00,$00,$C0,$20,$00,$E0,$20,$00,$C0,$00,$40,$E0,$00,$60,$C0,$20,$40,$E0,$20,$60
        dc.b $80,$40,$00,$A0,$40,$00,$80,$60,$00,$A0,$60,$00,$80,$40,$40,$A0,$40,$60,$80,$60,$40,$A0,$60,$60
        dc.b $C0,$40,$00,$E0,$40,$00,$C0,$60,$00,$E0,$60,$00,$C0,$40,$40,$E0,$40,$60,$C0,$60,$40,$E0,$60,$60
        dc.b $80,$00,$80,$A0,$00,$A0,$80,$20,$80,$A0,$20,$A0,$80,$00,$C0,$A0,$00,$E0,$80,$20,$C0,$A0,$20,$E0
        dc.b $C0,$00,$80,$E0,$00,$A0,$C0,$20,$80,$E0,$20,$A0,$C0,$00,$C0,$E0,$00,$E0,$C0,$20,$C0,$E0,$20,$E0
        dc.b $80,$40,$80,$A0,$40,$A0,$80,$60,$80,$A0,$60,$A0,$80,$40,$C0,$A0,$40,$E0,$80,$60,$C0,$A0,$60,$E0
        dc.b $C0,$40,$80,$E0,$40,$A0,$C0,$60,$80,$E0,$60,$A0,$C0,$40,$C0,$E0,$40,$E0,$C0,$60,$C0,$E0,$60,$E0
        dc.b $00,$80,$00,$20,$80,$00,$00,$A0,$00,$20,$A0,$00,$00,$80,$40,$00,$80,$60,$00,$A0,$40,$00,$A0,$60
        dc.b $40,$80,$00,$60,$80,$00,$40,$A0,$00,$60,$A0,$00,$40,$80,$40,$60,$80,$60,$40,$A0,$40,$60,$A0,$60
        dc.b $00,$C0,$00,$20,$C0,$00,$00,$E0,$00,$20,$E0,$00,$00,$C0,$40,$00,$C0,$60,$00,$E0,$40,$00,$E0,$60
        dc.b $40,$C0,$00,$60,$C0,$00,$40,$E0,$00,$60,$E0,$00,$40,$C0,$40,$60,$C0,$60,$40,$E0,$40,$60,$E0,$60
        dc.b $00,$80,$80,$00,$80,$A0,$00,$A0,$80,$00,$A0,$A0,$00,$80,$C0,$00,$80,$E0,$00,$A0,$C0,$00,$A0,$E0
        dc.b $40,$80,$80,$60,$80,$A0,$40,$A0,$80,$60,$A0,$A0,$40,$80,$C0,$60,$80,$E0,$40,$A0,$C0,$60,$A0,$E0
        dc.b $00,$C0,$80,$00,$C0,$A0,$00,$E0,$80,$00,$E0,$A0,$00,$C0,$C0,$00,$C0,$E0,$00,$E0,$C0,$00,$E0,$E0
        dc.b $40,$C0,$80,$60,$C0,$A0,$40,$E0,$80,$60,$E0,$A0,$40,$C0,$C0,$60,$C0,$E0,$40,$E0,$C0,$60,$E0,$E0
        dc.b $80,$80,$00,$A0,$80,$00,$80,$A0,$00,$A0,$A0,$00,$80,$80,$40,$A0,$80,$60,$80,$A0,$40,$A0,$A0,$60
        dc.b $C0,$80,$00,$E0,$80,$00,$C0,$A0,$00,$E0,$A0,$00,$C0,$80,$40,$E0,$80,$60,$C0,$A0,$40,$E0,$A0,$60
        dc.b $80,$C0,$00,$A0,$C0,$00,$80,$E0,$00,$A0,$E0,$00,$80,$C0,$40,$A0,$C0,$60,$80,$E0,$40,$A0,$E0,$60
        dc.b $C0,$C0,$00,$E0,$C0,$00,$C0,$E0,$00,$E0,$E0,$00,$C0,$C0,$40,$E0,$C0,$60,$C0,$E0,$40,$E0,$E0,$60
        dc.b $80,$80,$80,$A0,$80,$A0,$80,$A0,$80,$A0,$A0,$A0,$80,$80,$C0,$A0,$80,$E0,$80,$A0,$C0,$A0,$A0,$E0
        dc.b $C0,$80,$80,$E0,$80,$A0,$C0,$A0,$80,$E0,$A0,$A0,$C0,$80,$C0,$E0,$80,$E0,$C0,$A0,$C0,$E0,$A0,$E0
        dc.b $80,$C0,$80,$A0,$C0,$A0,$80,$E0,$80,$A0,$E0,$A0,$80,$C0,$C0,$A0,$C0,$E0,$80,$E0,$C0,$A0,$E0,$E0
        dc.b $C0,$C0,$80,$E0,$C0,$A0,$C0,$E0,$80,$E0,$E0,$A0,$C0,$C0,$C0,$E0,$C0,$E0,$C0,$E0,$C0,$E0,$E0,$E0

*

        end
You could probably use calculation rather than a table, but I was not very satisfied with the result..


Per
dont be happy. worry
- ?
User avatar
pjw
QL Wafer Drive
Posts: 1316
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: .PIC images

Post by pjw »

Here is another way, using a 3x3 nybble table. Its more labour-intensive. It could perhaps be optimised somewhat.

Code: Select all

* Native colour conversion
*
* V0.01, ©pjwitte 2oi8+
* V0.02, pjw, Nov 21 2018, Nybble-based Aurora RGB table
*
* Compatible with all GD2 modes
*


        section code

        xdef ut_cv16to24
        xdef cv_16to24

*
ut_cv16to24
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* entry:
*       d3.b = grbgrbgx                 - Aur (mode 16) colour code
*
* exit:
*       d3.l = 0 R G B                  - 24 bit colour <> mode 64!
*
*       d0/d5/d6/a1/a3 smashed
*
*       no errors; always "suceeds"

        lea.l tab_aur8rgbn,a3

*
cv_16to24
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This version uses a smaller RGB table, taking advantage of the fact that
* only the MS nybble of each colour element is significant. Thus the table
* consists of the Aurora RGB palette in 3 x 3 nybble format - a 50% space
* saving, although computationally more demanding.
*
* entry:
*       d3.b = grbgrbgx        - Aur (mode 16) colour code
*
* exit:
*       d3.l = 0 R G B         - 24 bit colour <> mode 64!
*
*       d0/d5/d6/a1 smashed
*
* No errors; always "suceeds"

        move.l #$ff,d6          clear out (most of) d6
        and.w d6,d3             byte -> word
        move.w d3,d5            00 CC
        add.w d3,d5             cc cc
        add.w d3,d5             CC CC
        lsr.w #1,d5             0C CC

        lea.l (a3,d5.w),a1      od   ev
        move.b (a1)+,d6         xR / RG
        move.b (a1),d0          GB / Bx

        btst #0,d3
        beq.s even

odd
        lsl.b #4,d6             R0
        move.b d0,d3            GB
        andi.b #$f0,d3          G0
        andi.b #$0f,d0          0B
        lsl.b #4,d0             B0
        bra.s finalise

even
        move.b d6,d3            rG
        lsl.b #4,d3             G0
        andi.b #$f0,d6          R0
        andi.b #$f0,d0          B0

finalise
        swap d6                 00R0 | xxxx
        move.b d3,d6
        lsl.w #8,d6             00R0 | G0xx
        move.b d0,d6            00R0 | G0B0

done
        move.l d6,d3            fudge
        rts


*
* Aurora RGB palette in a 3 x 3 nybble format
*
tab_aur8rgbn
        dc.b $00,$02,$00,$02,$02,$20,$00,$40,$06,$02,$40,$26
        dc.b $40,$06,$00,$42,$06,$20,$40,$46,$06,$42,$46,$26
        dc.b $04,$02,$40,$06,$02,$60,$04,$40,$46,$06,$40,$66
        dc.b $44,$06,$40,$46,$06,$60,$44,$46,$46,$46,$46,$66
        dc.b $00,$80,$0A,$02,$80,$2A,$00,$C0,$0E,$02,$C0,$2E
        dc.b $40,$86,$0A,$42,$86,$2A,$40,$C6,$0E,$42,$C6,$2E
        dc.b $04,$80,$4A,$06,$80,$6A,$04,$C0,$4E,$06,$C0,$6E
        dc.b $44,$86,$4A,$46,$86,$6A,$44,$C6,$4E,$46,$C6,$6E
        dc.b $80,$0A,$00,$82,$0A,$20,$80,$4A,$06,$82,$4A,$26
        dc.b $C0,$0E,$00,$C2,$0E,$20,$C0,$4E,$06,$C2,$4E,$26
        dc.b $84,$0A,$40,$86,$0A,$60,$84,$4A,$46,$86,$4A,$66
        dc.b $C4,$0E,$40,$C6,$0E,$60,$C4,$4E,$46,$C6,$4E,$66
        dc.b $80,$8A,$0A,$82,$8A,$2A,$80,$CA,$0E,$82,$CA,$2E
        dc.b $C0,$8E,$0A,$C2,$8E,$2A,$C0,$CE,$0E,$C2,$CE,$2E
        dc.b $84,$8A,$4A,$86,$8A,$6A,$84,$CA,$4E,$86,$CA,$6E
        dc.b $C4,$8E,$4A,$C6,$8E,$6A,$C4,$CE,$4E,$C6,$CE,$6E
        dc.b $08,$02,$80,$0A,$02,$A0,$08,$40,$86,$0A,$40,$A6
        dc.b $48,$06,$80,$4A,$06,$A0,$48,$46,$86,$4A,$46,$A6
        dc.b $0C,$02,$C0,$0E,$02,$E0,$0C,$40,$C6,$0E,$40,$E6
        dc.b $4C,$06,$C0,$4E,$06,$E0,$4C,$46,$C6,$4E,$46,$E6
        dc.b $08,$80,$8A,$0A,$80,$AA,$08,$C0,$8E,$0A,$C0,$AE
        dc.b $48,$86,$8A,$4A,$86,$AA,$48,$C6,$8E,$4A,$C6,$AE
        dc.b $0C,$80,$CA,$0E,$80,$EA,$0C,$C0,$CE,$0E,$C0,$EE
        dc.b $4C,$86,$CA,$4E,$86,$EA,$4C,$C6,$CE,$4E,$C6,$EE
        dc.b $88,$0A,$80,$8A,$0A,$A0,$88,$4A,$86,$8A,$4A,$A6
        dc.b $C8,$0E,$80,$CA,$0E,$A0,$C8,$4E,$86,$CA,$4E,$A6
        dc.b $8C,$0A,$C0,$8E,$0A,$E0,$8C,$4A,$C6,$8E,$4A,$E6
        dc.b $CC,$0E,$C0,$CE,$0E,$E0,$CC,$4E,$C6,$CE,$4E,$E6
        dc.b $88,$8A,$8A,$8A,$8A,$AA,$88,$CA,$8E,$8A,$CA,$AE
        dc.b $C8,$8E,$8A,$CA,$8E,$AA,$C8,$CE,$8E,$CA,$CE,$AE
        dc.b $8C,$8A,$CA,$8E,$8A,$EA,$8C,$CA,$CE,$8E,$CA,$EE
        dc.b $CC,$8E,$CA,$CE,$8E,$EA,$CC,$CE,$CE,$CE,$CE,$EE

*

        end


Per
dont be happy. worry
- ?
User avatar
dilwyn
Mr QL
Posts: 2761
Joined: Wed Dec 01, 2010 10:39 pm

Re: .PIC images

Post by dilwyn »

I will try to do this when I get home tonight. I should have thought of the fact that JPG is lossy compression, sorry.


User avatar
dilwyn
Mr QL
Posts: 2761
Joined: Wed Dec 01, 2010 10:39 pm

Re: .PIC images

Post by dilwyn »

Dec wrote: Sat Apr 08, 2023 2:27 am BTW. I can't find information on how the palette used is converted to RGB888. For example, for mode 16, I use this palette:
Image
But what is the real palette?

Modes 32 and 33 use 5 and 6 bit colors, but how to correctly convert these colors to RGB888?
There is some (old) documentation by Tony Tebby here: https://www.dilwyn.qlforum.co.uk/docs/s ... index.html
(scroll down to the SMSQ/E Documents section).


User avatar
dilwyn
Mr QL
Posts: 2761
Joined: Wed Dec 01, 2010 10:39 pm

Re: .PIC images

Post by dilwyn »

Dec wrote: Sat Apr 08, 2023 1:23 am
dilwyn wrote: Fri Apr 07, 2023 6:58 pmI rendered them on a QL-compatible display in QPC2 (mode 4 and mode 8)
Could you provide renders in PNG or BMP format. Jpeg images have compression artifacts and I can't see all the pixels. I don't need all the images. I will be satisfied with one render of the mode 4, and one render of the mode 8.
2 PNG renders of the tiger_pic4 and tiger_pic8 renders.
Attachments
pngrenders.zip
Rendered PNG mode 4 and 8 PICs
(261.97 KiB) Downloaded 29 times


Dec
ROM Dongle
Posts: 21
Joined: Sun Dec 20, 2020 2:28 pm

Re: .PIC images

Post by Dec »

pjw wrote: Sat Apr 08, 2023 12:07 pmHere is one way to convert Aurora mode 16 colours to 24 bit RGB, using a table
I'm not familiar with assembler and I can't understand this code. Is it possible to translate this into pseudo-code?

I may be wrong, correct me if so. The general color scheme is as follows:

Code: Select all

----------     ------------------     -----------
|        |     |                |     |         |
| Memory | --> |      GPU       | --> | Monitor |
|        |     | (6bit VGA DAC) |     |         |
----------     ------------------     -----------
Mode 16. In this mode, the color is encoded as grbgrbgx. The GPU performs the following transformations:

1) Converts grbgrbgx to 3-bit rrr, ggg and bbb values.
2) Converts 3-bit rrr, ggg and bbb values to 6-bit rrrrrr, gggggg and bbbbbb values.

I'm interested in the second transformation. How are 3-bit values converted to 6-bit ones?

Mode 32. In this mode, the color is encoded as rrrrrgggggggbbbbb. The GPU performs the following transformation:

1) Converts rrrrrrggggggbbbbb to 6-bit rrrrrr, gggggg and bbbbbb values.

How are 5-bit rrrrr and bbbbb values converted to 6-bit values?


User avatar
pjw
QL Wafer Drive
Posts: 1316
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: .PIC images

Post by pjw »

Forget grbgrbgx! After all, in practice all it amounts to is a byte with a value of 0 to 255. The code just looks up the offset that number represents, N x 3 in the byte table, and N x 3/2 in the nybble table. Those values are then inserted into the top three bytes of a longword to get the colour_24 code. One could do the same for mode 16 -> 32/33 with suitable tables.

I didnt find a good enough algorithm to do these conversions by calculation. The colours didnt seem right. Perhaps I didnt try hard enough..

Going the other way, ie 24, 32, 33 -> 16 calculated values seem fine.


Per
dont be happy. worry
- ?
Dec
ROM Dongle
Posts: 21
Joined: Sun Dec 20, 2020 2:28 pm

Re: .PIC images

Post by Dec »

pjw wrote: Sun Apr 09, 2023 1:36 pmN x 3 in the byte table, and N x 3/2 in the nybble table
The main question is - are you sure that the tables contain the correct values? How were these values obtained?


Post Reply