LUA Drawing: how to set background color

  • 22 Replies
  • 1867 Views
*

Offline srsa_4c

  • ******
  • 3464
Re: LUA Drawing: how to set background color
« Reply #10 on: 03 / December / 2016, 18:37:38 »
Advertisements
If I understand the dependencies and my test results, it is possible to distribute a compiled .flt file for a module so people can use it without compiling anything themselves.
Yes, as long as the CHDK core is compatible.
See the ModuleInfo struct in modules/flt.h (and its usage in existing modules).

*

Offline otosclerosi

  • *
  • 22
  • Canon IXUS160 with CHDK 1.5
Re: LUA Drawing: how to set background color
« Reply #11 on: 04 / December / 2016, 03:23:51 »
so if i got it right...
studying the structure of the ftl file and the codes of the core i can develop modules which work like software on the camera...and that's the goal
surely more difficult than writing LUA code, but also way more challenging and delicious

edit: not related questions:
1) is there a way to display an image on the screen? something like show_image(PATH) (<---just for example)?
2) function is_key(...): how can i get the pressed key? I mean, i don't know how it's called a certain key so...also not listed in "Script_commands_stub" page
« Last Edit: 04 / December / 2016, 05:27:11 by otosclerosi »
Can a kangaroo jump higher than a house?
Of course, a house doesn’t jump at all.

*

Offline srsa_4c

  • ******
  • 3464
Re: LUA Drawing: how to set background color
« Reply #12 on: 04 / December / 2016, 05:55:02 »
modules which work like software on the camera
Modules are extensions of CHDK, with all its limitations. We can't draw the screen like the Canon firmware can.

Quote
1) is there a way to display an image on the screen? something like show_image(PATH) (<---just for example)?
No. While it would be possible to overwrite the current Canon overlay and viewport buffers, we can't (easily) prevent the firmware from erasing it. Also, overlays are paletted on pre-DIGIC 6 cameras, and palettes change from model to model. You can find information about the various frame buffers here.
Quote
2) function is_key(...): how can i get the pressed key? I mean, i don't know how it's called a certain key so...also not listed in "Script_commands_stub" page
See modules/script_key_funcs.c for key names.

*

Offline otosclerosi

  • *
  • 22
  • Canon IXUS160 with CHDK 1.5
Re: LUA Drawing: how to set background color
« Reply #13 on: 04 / December / 2016, 08:58:01 »
So it will be much easier to use LUA, as far as i develop something simple without excessive usage of memory and functions...
thanks to the extraordinary man which ported a lua interpreter in chdk...
regarding the show image function, i understood why it's not currently possible...
maybe it could be possible to open a .bmp file in binary mode in LUA and draw each pixel with the color described in the bmp file? it would be a bmp reader...just wondering

edit (as usual): so frustrating that each time i have to try my script i have to swap the sd card from pc to the camera, hope i had an emulator!
« Last Edit: 04 / December / 2016, 10:13:22 by otosclerosi »
Can a kangaroo jump higher than a house?
Of course, a house doesn’t jump at all.


Re: LUA Drawing: how to set background color
« Reply #14 on: 04 / December / 2016, 10:24:01 »
modules which work like software on the camera
Modules are extensions of CHDK, with all its limitations. We can't draw the screen like the Canon firmware can.
In addition,  there are things you might want to do with CHDK that cannot be done in a module.  Many things can require a change to the core (non-module) code to implement.

1) is there a way to display an image on the screen? something like show_image(PATH) (<---just for example)?
While we currently have no easy way to display a standard image file (like a BMP, GIF, JPG, or PNG) from a Lua script, there are a few tricks.  Check out the colored icon supported in the CHDK OSD for example.  Or the CHDK splash screen - it's encoded in a simple RLE format.  Adding a Lua function to access that code should be fairly easy and might be useful for scripts other than just games (i.e. ones with GUI functionality).

Quote
While it would be possible to overwrite the current Canon overlay and viewport buffers, we can't (easily) prevent the firmware from erasing it.
This can be somewhat mitigated by having the camera in playback as Canon does not seem to do as much writing to the LCD buffers in that mode.  Which should not be a big limitation for a game.

Quote
2) function is_key(...): how can i get the pressed key? I mean, i don't know how it's called a certain key so...also not listed in "Script_commands_stub" page
Sounds like an easy wiki edit to fix this.  Thanks for pointing it out.
Ported : A1200  SD940  G10  Powershot N  G16*

Re: LUA Drawing: how to set background color
« Reply #15 on: 04 / December / 2016, 10:30:43 »
So it will be much easier to use LUA, as far as i develop something simple without excessive usage of memory and functions...
There is some cost in speed and functionality using scripts vs core code.  But for most applications its not noticeable, and certainly not enough to justify the increase development time effort and complexity.  Never mind support issues.

Quote
thanks to the extraordinary man which ported a lua interpreter in chdk...
I wasn't here at the time but I believe reyalp had a lot to do with that.

Quote
edit (as usual): so frustrating that each time i have to try my script i have to swap the sd card from pc to the camera, hope i had an emulator!
I would rather drive pins into my eyeballs than develop scripts that way.   

First of all, there is a really good emulator available - Execute Lua scripts with hostlua & notepad++ .  Props to rudi & msl

And secondly, if you use chdkptp (reyalp again) to connect your camera to your PC,  it's trivial to load scripts over USB.  I use a small script on both my Windows and Linux boxes to do all the work.

Edit :  see also  Lua Development Environment - including the links to forum threads.
« Last Edit: 04 / December / 2016, 10:41:28 by waterwingz »
Ported : A1200  SD940  G10  Powershot N  G16*

*

Offline otosclerosi

  • *
  • 22
  • Canon IXUS160 with CHDK 1.5
Re: LUA Drawing: how to set background color
« Reply #16 on: 04 / December / 2016, 10:43:34 »
OMG that emulator just made my day and probably my next months, now everything is brighter and happier :o
so, i didn't understand very well the thing of images, i mean, i feel i'm not able to implement a function to read images in LUA right now, but i wonder if the BMP fact would work, 'cause basically BMP describes each pixel, so a while loop could read the bmp table and draw the pixels that way...

edit (seriously, again?): i will build some kind of monument to that man
Can a kangaroo jump higher than a house?
Of course, a house doesn’t jump at all.

Re: LUA Drawing: how to set background color
« Reply #17 on: 04 / December / 2016, 10:49:34 »
OMG that emulator just made my day and probably my next months, now everything is brighter and happier :o
FWIW, I've do a couple of little scripts every now and then and I have to confess I don't use the emulator.  Once chdkptp is running, I find that it's just as fast to load & go on a real camera. But that's just my personal preference as many of the things I've done don't lend themselves well to emulator testing.

Quote
so, i didn't understand very well the thing of images, i mean, i feel i'm not able to implement a function to read images in LUA right now, but i wonder if the BMP fact would work, 'cause basically BMP describes each pixel, so a while loop could read the bmp table and draw the pixels that way...
That's one way to do it certainly.  But I rather suspect that it's going to be too slow to be usable for what you want to do.  So this is one of the few cases where a built-in script function would be better (i.e. faster) - even though its going to have to draw pixel-by-pixel as well.  If we use the existing RLE code as the "file format" somebody will probably need to develop a simple PC based converter or WYSIWYG editor for that file format though.

Quote
edit (seriously, again?): i will build some kind of monument to that man
I think there already is one.  ;)
« Last Edit: 04 / December / 2016, 10:52:02 by waterwingz »
Ported : A1200  SD940  G10  Powershot N  G16*


*

Offline otosclerosi

  • *
  • 22
  • Canon IXUS160 with CHDK 1.5
Re: LUA Drawing: how to set background color
« Reply #18 on: 04 / December / 2016, 11:01:19 »
Quote
That's one way to do it certainly.  But I rather suspect that it's going to be too slow to be usable for what you want to do.  So this is one of the few cases where a built-in script function would be better (i.e. faster) - even though its going to have to draw pixel-by-pixel as well.  If we use the existing RLE code as the "file format" somebody will probably need to develop a simple PC based converter or WYSIWYG editor for that file format though.


fast google search:
http://www.files-conversion.com/image/jpg it states that can convert jpg to rle
http://www.ivanview.com/convert/jpg/jpg-to-rle.html same as above (shareware)
it seems to be achievable...but i wouldn't know how to start
Can a kangaroo jump higher than a house?
Of course, a house doesn’t jump at all.

Re: LUA Drawing: how to set background color
« Reply #19 on: 04 / December / 2016, 11:14:45 »
fast google search:
http://www.files-conversion.com/image/jpg it states that can convert jpg to rle
http://www.ivanview.com/convert/jpg/jpg-to-rle.html same as above (shareware)
it seems to be achievable...but i wouldn't know how to start
I suspect the actual CHDK run length encoding (RLE) is custom to CHDK.  So you will really need to find a project that shares source code if you want to take a short cut here.  But you're getting a little ahead of yourself - you can actually hand code simple images into RLE with a little patience.  That's how the CHDK logo was done AFAIK.  Having the script support to load those images is more important at this point.  I'll wait for reyalp to weigh-in on whether he'd support such an addition.

Ported : A1200  SD940  G10  Powershot N  G16*

 

Related Topics