summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/include_lua/blit.lua
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2018-05-28 17:56:06 +0200
committerWilliam Wilgus <me.theuser@yahoo.com>2018-07-22 18:05:02 +0200
commit2daec3d3c3d84e7176a22bc073ca5530e8e44c6d (patch)
tree0f7e64ed5abd305fe80a7fbfabf79d2a9374ed4f /apps/plugins/lua/include_lua/blit.lua
parent19b2964d78b2ad6624a0e7cddd0ac6a49082cca4 (diff)
downloadrockbox-2daec3d3c3d84e7176a22bc073ca5530e8e44c6d.tar.gz
rockbox-2daec3d3c3d84e7176a22bc073ca5530e8e44c6d.zip
Rocklua -- Extend / Fix rliImage
Some devices(1-bit / 2-bit displays) have packed bit formats that need to be unpacked in order to work on them at a pixel level. This caused a few issues on 1 & 2-bit devices: Greatly Oversized data arrays for bitmaps Improper handling of native image data Framebuffer data was near unusable without jumping through hoops Conversion between native addressing and per pixel addressing incurs extra overhead but it is much faster to do it on the 'C' side rather than in lua. Not to mention the advantage of a unified interface for the end programer ------------------------------------------------------------------- Adds a sane way to access each pixel of image data Adds: -------------------------------------------------------------------- img:clear([color],[x1],[y1],[x2],[y2]) (set whole image or a portion to a particular value) -------------------------------------------------------------------- img:invert([x1],[y1],[x2],[y2]) (inverts whole image or a portion) -------------------------------------------------------------------- img:marshal([x1],[y1],[x2],[y2],[funct]) (calls funct for each point defined by rect of x1,y1 x2,y2 returns value and allows setting value of each point return nil to terminate early) -------------------------------------------------------------------- img:points([x1],[y1],[x2],[y2],[dx],[dy]) (returns iterator function that steps delta-x and delta-y pixels each call returns value of pixel each call but doesn't allow setting to a new value compare to lua pairs method) -------------------------------------------------------------------- img:copy(src,[x1],[y1],[x2],[y2],[w],[h],[clip][operation][clr/funct]) (copies all or part of an image -- straight copy or special ops optionally calls funct for each point defined by rect of x1, y1, w, h and x2, y2, w, h for dest and src images returns value of dst and src and allows setting value of each point return nil to terminate early) -------------------------------------------------------------------- img:line(x1, y1, x2, y2, color) -------------------------------------------------------------------- img:ellipse(x1, y1, x2, y2, color, [fillcolor] -------------------------------------------------------------------- Fixed handling of 2-bit vertical integrated screens Added direct element access for saving / restoring native image etc. Added more data to tostring() handler and a way to access individual items Added equals method to see if two variables reference the same image address (doesn't check if two separate images contain the same 'picture') Optimized get and set routines Fixed out of bound x coord access shifting to next line Added lua include files to expose new functionality Finished image saving routine Static allocation of set_viewport struct faster + saves ram over dynamic Cleaned up code Fixed pixel get/set for 1/2 bit devices ------------------------------------------------------------------------- Example lua script to follow on forums ------------------------------------------------------------------------- Change-Id: I7b9c1fd699442fb683760f781021091786c18509
Diffstat (limited to 'apps/plugins/lua/include_lua/blit.lua')
-rw-r--r--apps/plugins/lua/include_lua/blit.lua84
1 files changed, 84 insertions, 0 deletions
diff --git a/apps/plugins/lua/include_lua/blit.lua b/apps/plugins/lua/include_lua/blit.lua
new file mode 100644
index 0000000000..934804b5b3
--- /dev/null
+++ b/apps/plugins/lua/include_lua/blit.lua
@@ -0,0 +1,84 @@
1--[[ Lua Blit Operations
2/***************************************************************************
3 * __________ __ ___.
4 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
5 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
6 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * \/ \/ \/ \/ \/
9 * $Id$
10 *
11 * Copyright (C) 2017 William Wilgus
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22]]
23
24--[[
25copy(dst, src, [dx, dy, sx, sy, offset_x, offset_y, clip, _blit.OP, clr/customfunct])
26 blit allows you to copy a [portion of a] source image to a dest image applying
27 a transformation operation to the pixels as they are copied
28 offsets are auto calculated if left empty or out of range
29 blit will default to copy if operation is empty or out of range
30
31it is slightly faster to use the number directly and you don't really
32 need to define all (any) of these if you don't use them but I put them
33 here for easier use of the blit function
34]]
35if not rb.lcd_framebuffer then rb.splash(rb.HZ, "No Support!") return nil end
36
37local _blit ={} do
38
39 _blit.CUSTOM = 0xFF --user defined blit function func(dst_val, x, y, src_val, x, y)
40 _blit.BCOPY = 0x0 --copy (use :copy() instead it is slightly faster
41 _blit.BOR = 0x1 --OR source and dest pixels
42 _blit.BXOR = 0x2 --XOR source and dest pixels
43 _blit.BNOR = 0x3 --(NOT) (source OR dest pixels)
44 _blit.BSNOR = 0x4 --(NOT source) OR dest pixels
45 _blit.BAND = 0x5 --AND source and dest pixels
46 _blit.BNAND = 0x6 --(NOT) AND source and dest pixels
47 _blit.BNOT = 0x7 --NOT source and dest pixels
48 --blit functions for masks
49 _blit.BSAND = 0x8 --copy color to dest if source pixel <> 0
50 _blit.BSNOT = 0x9 --copy color to dest if source pixel == 0
51 --blit functions for masks with colors
52 _blit.BSORC = 0xA --copy source pixel or color
53 _blit.BSXORC = 0xB --copy source pixel xor color
54 _blit.BNSORC = 0xC --copy ~(src_val | clr)
55 _blit.BSORNC = 0xD --copy src_val | (~clr)
56 _blit.BSANDC = 0xE --copy src_val & clr;
57 _blit.BNSANDC = 0xF --copy (~src_val) & clr
58 _blit.BDORNSORC = 0x10 --copy dst | (~src_val) | clr
59 _blit.BXORSADXORC = 0x11 --copy dst ^ (src_val & (dst_val ^ clr))
60
61 _blit.BSNEC = 0x12 --copy source pixel if source <> color
62 _blit.BSEQC = 0x13 --copy source pixel if source == color
63 _blit.BSGTC = 0x14 --copy source pixel if source > color
64 _blit.BSLTC = 0x15 --copy source pixel if source < color
65 _blit.BDNEC = 0x16 --copy source pixel if dest <> color
66 _blit.BDEQC = 0x17 --copy source pixel if dest == color
67 _blit.BDGTC = 0x18 --copy source pixel if dest > color
68 _blit.BDLTC = 0x19 --copy source pixel if dest < color
69 _blit.BDNES = 0x1A --copy color to dest if dest <> source pixel
70 _blit.BDEQS = 0x1B --copy color to dest if dest == source pixel
71 _blit.BDGTS = 0x1C --copy color to dest if dest > source pixel
72 _blit.BDLTS = 0x1D --copy color to dest if dest < source pixel
73 --Source unused for these blits
74 _blit.BCOPYC = 0x1E --copy color
75 _blit.BORC = 0x1F --OR dest and color
76 _blit.BXORC = 0x20 --XOR dest and color
77 _blit.BNDORC = 0x21 --~(dst_val | clr)
78 _blit.BDORNC = 0x22 --dst_val | (~clr)
79 _blit.BANDC = 0x23 --AND dest and color
80 _blit.BNDANDC = 0x24 --copy (~dst_val) & clr
81 _blit.BDLTS = 0x25 --dest NOT color
82end -- _blit operations
83
84return _blit