commit adcc014b2c4a81632c624c819f1abf082a180e89
parent 2efce296a641f7d8802b3175e26a6badadf8a6e7
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Sun, 25 Dec 2022 12:10:03 -0500
gr/color: new unit
see doc/color
Diffstat:
7 files changed, 49 insertions(+), 12 deletions(-)
diff --git a/fs/doc/color.txt b/fs/doc/color.txt
@@ -0,0 +1,39 @@
+# Color encodings
+
+The library at gr/color.fs defines color encoding as well as encoding/decoding
+words for them.
+
+At the moment, there's only one supported color encoding, so it has little logic.
+It's mostly a placeholder for a fancier color management library.
+
+## Bits layouts and endianness
+
+The encoding defined here are "above" endianness. We refer to pure 32-bit
+numbers (we don't support encodings above 32bit), regardless of encoding. When
+we refer to bits in the memory layouts described below, we refer to the bits in
+the "pure" number, bit 31 being the most significant bit and bit 0 being the
+least significant bit.
+
+We expect drivers dealing with those colors to be endianness aware and deal
+with writing the correct color in the correct endianness themselves.
+
+Let's use the example of the 24bpp VESA mode. Because it runs on a i386
+architecture, it's always going to deal with little endian. So, if we say that
+Red is b23:16, Green is b15:8 and Blue is b7:0, then we know that this means
+that for a given address "a", Red is the byte at a+2, Green is at a+1 and Blue
+is at a+0.
+
+Let's imagine that we manage the same memory layout from a big endian
+architecture. Then, the driver will have to deal with it. Either it's going to
+specify that its supported color is another encoding (one that has RGB reversed)
+or it takes care, when reading and writing those colors, to reverse those bytes.
+
+## Color encoding list
+
+COLOR_RGB24 = $01
+ 24-bit RGB encoding with Red=b23:16 Green=b15:8 Blue=b7:0
+
+## API
+
+r8g8b8>rgb24 ( r8 g8 b8 -- n )
+ Convert 3 8-bit RGB components into a COLOR_RGB24 encoding.
diff --git a/fs/doc/screen.fs b/fs/doc/screen.fs
@@ -27,9 +27,6 @@ its methods, namely:
:pixel' ( x y self -- a )
Yield the address corresponding to the specified x and y coordinates.
-:rgbcolor ( r8 g8 b8 self -- n )
- Transform the RGB color into a number corresponding to the in-memory format.
-
## API
Fields:
@@ -41,4 +38,4 @@ bpp Screen bits per plane
Methods:
:pixel! ( color a self -- )
- Set a pixel at address "a" (from ":pixel'") to "color" (from ":rgbcolor").
+ Set a pixel at address "a" (from ":pixel'") to "color" (from gr/color).
diff --git a/fs/drv/pc/vesa.fs b/fs/drv/pc/vesa.fs
@@ -115,10 +115,6 @@ extends Screen struct[ VESAScreen
: _pixel' ( x y self -- a ) drop
_curmode pitch * swap pixelbytes * + _curmode framebuffer + ;
- \ TODO: support more than 24bpp
- : _rgbcolor ( r8 g8 b8 self -- color ) drop
- swap 8 lshift or swap 16 lshift or ;
-
: :new ( -- screen )
- :newbase ['] _activate , ['] _deactivate , ['] _pixel' , ['] _rgbcolor , ;
+ :newbase ['] _activate , ['] _deactivate , ['] _pixel' , ;
]struct
diff --git a/fs/emul/uxn/gui.fs b/fs/emul/uxn/gui.fs
@@ -27,7 +27,7 @@ create _fgmask FGMASKSZ allot
0 uxn_dev Device dat 8 + ( 'r )
dup short@ r@ _extract ( 'r r8 )
swap 1+ 1+ dup short@ r@ _extract ( r8 'g g8 )
- swap 1+ 1+ short@ r> _extract ( r8 g8 b8 ) screen :rgbcolor ;
+ swap 1+ 1+ short@ r> _extract ( r8 g8 b8 ) r8g8b8>rgb24 ;
: _drawpixel ( x y pixel -- )
3 and screencolor ( x y color )
rot> screen :pixel' screen :pixel! ;
diff --git a/fs/gr/color.fs b/fs/gr/color.fs
@@ -0,0 +1,5 @@
+\ Color encodings. see doc/color
+
+$01 const COLOR_RGB24
+
+: r8g8b8>rgb24 ( r8 g8 b8 -- n ) swap 8 lshift or swap 16 lshift or ;
diff --git a/fs/gr/draw.fs b/fs/gr/draw.fs
@@ -1,4 +1,5 @@
require /sys/screen.fs
+?f<< /gr/color.fs
\ TODO: "pixelbytes" is specific to drv/pc/vesa and is the wrong approach
\ anyways.
@@ -11,7 +12,7 @@ require /sys/screen.fs
rfree ;
: recttest
- 255 0 0 screen :rgbcolor ( color )
+ 255 0 0 r8g8b8>rgb24 ( color )
42 42 ( color w h )
screen width >> 21 -
screen height >> 21 - ( color w h x y ) drawrect ;
diff --git a/fs/sys/screen.fs b/fs/sys/screen.fs
@@ -7,7 +7,6 @@ struct[ Screen
smethod :activate ( self -- )
smethod :deactivate ( self -- )
smethod :pixel' ( x y self -- a )
- smethod :rgbcolor ( r8 g8 b8 self -- n )
\ Creates the first part of the screen structure, but leaves the method fields
\ to the caller.