aboutsummaryrefslogtreecommitdiff
path: root/slof
diff options
context:
space:
mode:
authorThomas Huth <thuth@linux.vnet.ibm.com>2015-02-26 13:32:40 +0100
committerAlexey Kardashevskiy <aik@ozlabs.ru>2015-03-12 18:25:35 +1100
commit088baa0de49f9b97000609d3066b292b426cbb3c (patch)
treeef8126f0d9b087b90b97c6e58e7adc534a703ea8 /slof
parent21d5f489c2e311227f2a72cc7149066714398ae0 (diff)
downloadSLOF-088baa0de49f9b97000609d3066b292b426cbb3c.zip
SLOF-088baa0de49f9b97000609d3066b292b426cbb3c.tar.gz
SLOF-088baa0de49f9b97000609d3066b292b426cbb3c.tar.bz2
Fix rectangle drawing functions to work also with higher bit depths
draw-rectangle, fill-rectangle and read-rectangle were only working with 8-bit color depth displays so far. This is fixed now for 16-bit, 24-bit and 32-bit color depths, too, by taking the "screen-depth" into account. And while we're at it, consolidate all the same copies of these functions into one common file (graphics.fs) so that we do not have to do these modifications multiple times in different files. Signed-off-by: Thomas Huth <thuth@linux.vnet.ibm.com> Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Diffstat (limited to 'slof')
-rw-r--r--slof/fs/graphics.fs62
1 files changed, 62 insertions, 0 deletions
diff --git a/slof/fs/graphics.fs b/slof/fs/graphics.fs
new file mode 100644
index 0000000..d9407b6
--- /dev/null
+++ b/slof/fs/graphics.fs
@@ -0,0 +1,62 @@
+\ *****************************************************************************
+\ * Copyright (c) 2015 IBM Corporation
+\ * All rights reserved.
+\ * This program and the accompanying materials
+\ * are made available under the terms of the BSD License
+\ * which accompanies this distribution, and is available at
+\ * http://www.opensource.org/licenses/bsd-license.php
+\ *
+\ * Contributors:
+\ * IBM Corporation - initial implementation
+\ ****************************************************************************/
+
+\ Provide some of the functions that are defined in the
+\ "OF Recommended Practice: 8bit Graphics Extension" document
+
+: draw-rectangle ( adr x y w h -- )
+ frame-buffer-adr 0= IF 4drop drop EXIT THEN
+ 0 ?DO
+ 4dup drop ( adr x y w adr x y )
+ \ calculate offset into framebuffer: ((y + i) * width + x) * depth
+ i + screen-width * + screen-depth * ( adr x y w adr offs )
+ frame-buffer-adr + ( adr x y w adr fb_adr )
+ over 3 pick screen-depth * i * + ( adr x y w adr fb_adr src )
+ swap 3 pick screen-depth * ( adr x y w adr src fb_adr len )
+ rmove \ copy line ( adr x y w adr )
+ drop ( adr x y w )
+ LOOP
+ 4drop
+;
+
+: fill-rectangle ( col x y w h -- )
+ frame-buffer-adr 0= IF 4drop drop EXIT THEN
+ 0 ?DO
+ 4dup drop ( col x y w col x y )
+ \ calculate offset into framebuffer: ((y + i) * width + x) * depth
+ i + screen-width * + screen-depth * ( col x y w col offs )
+ frame-buffer-adr + ( col x y w col adr )
+ 2 pick screen-depth * 2 pick ( col x y w col adr len col )
+ rfill \ draw line ( col x y w col )
+ drop ( col x y w )
+ LOOP
+ 4drop
+;
+
+: read-rectangle ( adr x y w h -- )
+ frame-buffer-adr 0= IF 4drop drop EXIT THEN
+ 0 ?DO
+ 4dup drop ( adr x y w adr x y )
+ \ calculate offset into framebuffer: ((y + i) * width + x) * depth
+ i + screen-width * + screen-depth * ( adr x y w adr offs )
+ frame-buffer-adr + ( adr x y w adr fb_adr )
+ over 3 pick screen-depth * i * + ( adr x y w adr fb_adr dst )
+ 3 pick ( adr x y w adr fb_adr dst w )
+ rmove \ copy line ( adr x y w adr )
+ drop ( adr x y w )
+ LOOP
+ 4drop
+;
+
+: dimensions ( -- width height )
+ screen-width screen-height
+;