Support and General Use > Plugins/Viewers

RockLua! RliImage Update

(1/2) > >>

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: Added to dev builds as of (072318)

Example scripts here:

Included in the example scripts are the image demos, fileviewer, browser, hex viewer and more


--- Code: ---






--- End code ---

Copy also allows both custom functions and builtin blit functions

--- Code: ---    _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

--- End code ---


* 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
    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


[0] Message Index

[#] Next page

Go to full version