PALETTE: why does it take "BGR" colour instead of "RGB"?
#9
Let me show you really fast how the divide or multiply by 4 method doesn't quite hold true:

Code: (Select All)
TYPE Color_Type
    AS INTEGER red, green, blue
END TYPE

DIM AS Color_Type Unchanged(15), Changed(15), Changed2(15)
SCREEN 12

FOR i = 0 TO 15
    Unchanged(i).red = _RED(i)
    Unchanged(i).green = _GREEN(i)
    Unchanged(i).blue = _BLUE(i)
NEXT


PRINT , "Original"; TAB(35); "Changed * 4"; TAB(60); "Changed * 255 / 63"
FOR i = 0 TO 15
    OUT &H3C7, i 'set color attribute to read
    red$ = HEX$(INP(&H3C9) * 4) 'convert port setting to 32 bit values
    grn$ = HEX$(INP(&H3C9) * 4)
    blu$ = HEX$(INP(&H3C9) * 4)
    IF LEN(red$) = 1 THEN red$ = "0" + red$ '2 hex digits required
    IF LEN(grn$) = 1 THEN grn$ = "0" + grn$ 'for low or zero hex values
    IF LEN(blu$) = 1 THEN blu$ = "0" + blu$
    hex32$ = "&HFF" + red$ + grn$ + blu$
    _PALETTECOLOR i, VAL(hex32$) 'VAL converts hex string to a LONG 32 bit value
    Changed(i).red = _RED(i)
    Changed(i).green = _GREEN(i)
    Changed(i).blue = _BLUE(i)
NEXT

FOR i = 0 TO 15
    OUT &H3C7, i 'set color attribute to read
    red$ = HEX$(INP(&H3C9) * 255 / 63) 'convert port setting to 32 bit values
    grn$ = HEX$(INP(&H3C9) * 255 / 63)
    blu$ = HEX$(INP(&H3C9) * 255 / 63)
    IF LEN(red$) = 1 THEN red$ = "0" + red$ '2 hex digits required
    IF LEN(grn$) = 1 THEN grn$ = "0" + grn$ 'for low or zero hex values
    IF LEN(blu$) = 1 THEN blu$ = "0" + blu$
    hex32$ = "&HFF" + red$ + grn$ + blu$
    _PALETTECOLOR i, VAL(hex32$) 'VAL converts hex string to a LONG 32 bit value
    Changed2(i).red = _RED(i)
    Changed2(i).green = _GREEN(i)
    Changed2(i).blue = _BLUE(i)
NEXT




FOR i = 0 TO 15
    PRINT i, Unchanged(i).red; Unchanged(i).blue; Unchanged(i).green;
    PRINT TAB(35); Changed(i).red; Changed(i).blue; Changed(i).green;
    PRINT TAB(60); Changed2(i).red; Changed2(i).blue; Changed2(i).green
NEXT


The above creates a table for us with the Red, Green, Blue values for our 16 colors (from 0 to 15).  The first table is the original, untouched values.  The middle table is the color shades which we'd get if we just used the DAC * 4 color value.  The right table is the color shades which we'd get if we used DAC * 255 / 63 color values.

I think the values speak for themselves.  DAC * 4 or _RGB / 4 isn't going to get you the full range of color which is available for you, nor is it going to match the existing values which our color tables hold for us for the 16 default colors.  Wink
Reply


Messages In This Thread
RE: PALETTE: why does it take "BGR" colour instead of "RGB"? - by SMcNeill - 01-17-2023, 06:29 PM



Users browsing this thread: 3 Guest(s)