Rockbox Technical Forums
Support and General Use => Plugins/Viewers => Topic started by: Bilgus on July 17, 2018, 12:32:53 AM
-
I've been working for a few months on an update to the image functionalities for Lua on Rockbox.
RliImage adds much needed consistency to the image handling between targets with some nice features too...
Functions added directly to the lua binary include:
- img:clear([color],[x1],[y1],[x2],[y2])
- img:invert([x1],[y1],[x2],[y2])
- img:marshal([x1],[y1],[x2],[y2],[funct])
- img:points([x1],[y1],[x2],[y2],[dx],[dy])
- img:copy(src,[x1],[y1],[x2],[y2],[w],[h],[clip][operation][clr/funct])
- img:line(x1, y1, x2, y2, color)
- img:ellipse(x1, y1, x2, y2, color, [fillcolor]
In addition I have also created some extensions through the use of the new functions in some Lua include modules
- blit.lua
- color.lua
- draw.lua
- image.lua
- lcd.lua
- math_ex.lua
- print.lua
- timer.lua
Find the latest patch here:
http://gerrit.rockbox.org/r/#/c/1847/ Added to dev builds as of (072318)
Example scripts here:
http://www.mediafire.com/?a33zry9r5vr6d
Included in the example scripts are the image demos, fileviewer, browser, hex viewer and more
-
_clr.inc
_clr.set
Constants:
IS_COLOR_TARGET
_draw.circle
_draw.circle_filled
_draw.ellipse
_draw.ellipse_filled
_draw.ellipse_rect_filled
_draw.ellipse_rect
_draw.flood_fill
_draw.hline
_draw.image
_draw.line
_draw.polygon
_draw.polyline
_draw.rect
_draw.rect_filled
_draw.rounded_rect
_draw.rounded_rect_filled
_draw.text
_draw.vline
_img.save
_img.search
_img.rotate
_img.resize
_img.tile
_img.new
_img.load
Constants:
_img.RLI_INFO_ALL
_img.RLI_INFO_TYPE
_img.RLI_INFO_WIDTH
_img.RLI_INFO_HEIGHT
_img.RLI_INFO_ELEMS
_img.RLI_INFO_BYTES
_img.RLI_INFO_DEPTH
_img.RLI_INFO_FORMAT
_img.RLI_INFO_ADDRESS
_lcd.clear
_lcd.duplicate
_lcd.image
_lcd.set_viewport
_lcd.splashf
_lcd.text_extent
_lcd.update
_lcd.update_rect
Constants:
_lcd.CX
_lcd.CY
_lcd.DEPTH
_lcd.W
_lcd.H
_lcd
_LCD
_math.clamp
_math.clamp_roll
_math.d_sin
_math.d_cos
_math.d_tan
_math.i_sqrt
_print.clear
_print.f
_print.opt
_print.opt.area
_print.opt.autoupdate
_print.opt.color
_print.opt.column
_print.opt.defaults
_print.opt.get
_print.opt.justify
_print.opt.line
_print.opt.overflow
_print.opt.sel_line
_print.opt.set
_timer.active
_timer.check
_timer.split
_timer.start
_timer.stop
-
Copy also allows both custom functions and builtin blit functions
_blit.CUSTOM = 0xFF --user defined blit function func(dst_val, x, y, src_val, x, y)
_blit.BCOPY = 0x0 --copy (use :copy() instead it is slightly faster
_blit.BOR = 0x1 --OR source and dest pixels
_blit.BXOR = 0x2 --XOR source and dest pixels
_blit.BNOR = 0x3 --(NOT) (source OR dest pixels)
_blit.BSNOR = 0x4 --(NOT source) OR dest pixels
_blit.BAND = 0x5 --AND source and dest pixels
_blit.BNAND = 0x6 --(NOT) AND source and dest pixels
_blit.BNOT = 0x7 --NOT source and dest pixels
--blit functions for masks
_blit.BSAND = 0x8 --copy color to dest if source pixel <> 0
_blit.BSNOT = 0x9 --copy color to dest if source pixel == 0
--blit functions for masks with colors
_blit.BSORC = 0xA --copy source pixel or color
_blit.BSXORC = 0xB --copy source pixel xor color
_blit.BNSORC = 0xC --copy ~(src_val | clr)
_blit.BSORNC = 0xD --copy src_val | (~clr)
_blit.BSANDC = 0xE --copy src_val & clr;
_blit.BNSANDC = 0xF --copy (~src_val) & clr
_blit.BDORNSORC = 0x10 --copy dst | (~src_val) | clr
_blit.BXORSADXORC = 0x11 --copy dst ^ (src_val & (dst_val ^ clr))
_blit.BSNEC = 0x12 --copy source pixel if source <> color
_blit.BSEQC = 0x13 --copy source pixel if source == color
_blit.BSGTC = 0x14 --copy source pixel if source > color
_blit.BSLTC = 0x15 --copy source pixel if source < color
_blit.BDNEC = 0x16 --copy source pixel if dest <> color
_blit.BDEQC = 0x17 --copy source pixel if dest == color
_blit.BDGTC = 0x18 --copy source pixel if dest > color
_blit.BDLTC = 0x19 --copy source pixel if dest < color
_blit.BDNES = 0x1A --copy color to dest if dest <> source pixel
_blit.BDEQS = 0x1B --copy color to dest if dest == source pixel
_blit.BDGTS = 0x1C --copy color to dest if dest > source pixel
_blit.BDLTS = 0x1D --copy color to dest if dest < source pixel
--Source unused for these blits
_blit.BCOPYC = 0x1E --copy color
_blit.BORC = 0x1F --OR dest and color
_blit.BXORC = 0x20 --XOR dest and color
_blit.BNDORC = 0x21 --~(dst_val | clr)
_blit.BDORNC = 0x22 --dst_val | (~clr)
_blit.BANDC = 0x23 --AND dest and color
_blit.BNDANDC = 0x24 --copy (~dst_val) & clr
_blit.BDLTS = 0x25 --dest NOT color
-
- img:clear([color],[x1],[y1],[x2],[y2])
Sets an image to a color either in whole or in part, you could consider this a rect routine for solid filled rectangles
- img:invert([x1],[y1],[x2],[y2])
inverts an image in whole or in part
- img:marshal([x1],[y1],[x2],[y2],[funct])
Allows you to specify a function that will receive every pixel in the defined rect or whole image if you don't specify coordinates
you may then alter the pixels or pass them back unchanged or return nil to quit early
- img:points([x1],[y1],[x2],[y2],[dx],[dy])
Similar to the lua pairs function you can even specify the number of pixels to jump each iteration with dx, dy
you can call this in a loop to iterate over every pixel in the in the defined rect or whole image if you don't specify coordinates
this is similar to marshal but it is a one way interaction you can only read pixels from the image instead of read/write
- img:copy(src,[x1],[y1],[x2],[y2],[w],[h],[clip][operation][clr/funct])
Copy is just as it sounds but it also doubles as the blit function and you can even use it with your own custom function
or even as marshal for two images at the same time if so desired.
There are quite a few built in blit functions available and when speed is of the essence I'd suggest you look at these before
you call a custom function since the overhead from lua => C => lua slows it down quite a bit
- img:line(x1, y1, x2, y2, color)
Just a simple line draw
- img:ellipse(x1, y1, x2, y2, color, [fillcolor]
This is a pretty fast ellipse algorithm it is a derivative of work by
Alois Zingl http://members.chello.at/easyfilter/bresenham.html (http://members.chello.at/easyfilter/bresenham.html)
he was gracious enough to give us permission to use it
Not only do the built-in functions make this a much more powerful language but with them
I've added quite a few extra functions that are now included with every lua build
see /.rockbox/rocks/viewers/lua/ for all the included libraries
As always if you have improvements or find bugs let me know and we can add/fix them but do try and keep them backwards compatible
-
I just updated RliImage to use less space in the binary and the include (require) files
This breaks some backwards compatibility so I updated the examples files as well
http://www.mediafire.com/?a33zry9r5vr6d
-
file , hex view and file browser example:
http://forums.rockbox.org/index.php/topic,52895.msg244321
-
Thanks for all your work on the Lua stuff @Bilgus! It is much appreciated
-
Hey, no problem I had fun messing with it
Don't forget to see the wiki for some documentation
Graphics is a bit wonky still but still FAR better than it was
https://www.rockbox.org/wiki/PluginLua
https://www.rockbox.org/wiki/PluginLuaModules