On-screen drawing from lua - now possible. - page 3 - General Discussion and Assistance - CHDK Forum  

On-screen drawing from lua - now possible.

  • 32 Replies
  • 8016 Views
Re: On-screen drawing from lua - now possible.
« Reply #20 on: 10 / December / 2011, 19:03:39 »
Advertisements
Ok - icon colors are added. If camera doesn't supprt it other colors (mainly from histo) are taken. There are a few placeholders to avoid further mess in color numbers order.

I made two-dimensional array for collors in both modes.

I've also changed drawings module to make it consistent with current version of lua drawing commands.

I think, that we should rename colors to avoid strange names like color_histo_r_play and color_ply_icon_red. There should be universal naming style, such as:

color_ply_red
color_rec_red
color_ply_yellow_dk

and so on. This is a good time to do these changes, before we need more colors. And it will be simple no name further colors.

Nevertheless I still believe, that there must be canon firmware function that calculates apropriate colors from palette, since in all modes there are so many colors. Maybe if we could find this we would be able to use a kind of rgb system...
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

*

Offline philmoz

  • *****
  • 3107
    • Photos
Re: On-screen drawing from lua - now possible.
« Reply #21 on: 12 / December / 2011, 00:37:22 »
Ok - icon colors are added. If camera doesn't supprt it other colors (mainly from histo) are taken. There are a few placeholders to avoid further mess in color numbers order.

I made two-dimensional array for collors in both modes.

I've also changed drawings module to make it consistent with current version of lua drawing commands.

I think, that we should rename colors to avoid strange names like color_histo_r_play and color_ply_icon_red. There should be universal naming style, such as:

color_ply_red
color_rec_red
color_ply_yellow_dk

and so on. This is a good time to do these changes, before we need more colors. And it will be simple no name further colors.

Nevertheless I still believe, that there must be canon firmware function that calculates apropriate colors from palette, since in all modes there are so many colors. Maybe if we could find this we would be able to use a kind of rgb system...

I've added this to SVN in changeset 1479.

Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)

*

Offline msl

  • *****
  • 1262
  • A720 IS, SX220 HS 1.01a
    • CHDK-DE links
Re: On-screen drawing from lua - now possible.
« Reply #22 on: 12 / December / 2011, 05:17:14 »
Thx for this great job! Draw functions works now also fine with CHDK-DE (rev899).

The test script runs fine. Only the 1000 lines test gives me for the SX220 a "not enough memory" message. But that was to be expected.

Sorry, a little bit of criticism: The new functions need a little bit more descriptions. The lua draw modul description has not been updated.

msl
CHDK-DE:  CHDK-DE links

Re: On-screen drawing from lua - now possible.
« Reply #23 on: 12 / December / 2011, 06:57:38 »
Yes, I'll update the descriptions, I forgot about this. I'll also add Lua functions to wikia and add a wikia page designed to describe whole drawing process. But I need some time;)
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick


Re: On-screen drawing from lua - now possible.
« Reply #24 on: 13 / December / 2011, 18:02:40 »
New drawings Lua functions are now added to wikia:
http://chdk.wikia.com/wiki/Lua/Lua_Reference#Drawings

Drawings module has its own wikia page on CHDK wikia. This page might be used as readme.
http://chdk.wikia.com/wiki/Lua/Drawings
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

*

Offline msl

  • *****
  • 1262
  • A720 IS, SX220 HS 1.01a
    • CHDK-DE links
Re: On-screen drawing from lua - now possible.
« Reply #25 on: 14 / December / 2011, 05:40:37 »
 

Thanks for the complement of the wiki pages. These are one of the best lua function descriptions which I've read.

msl
CHDK-DE:  CHDK-DE links

Re: On-screen drawing from lua - now possible.
« Reply #26 on: 30 / June / 2012, 02:37:51 »
Not sure whether post it here, but I have some problems with drawings. When I set some shapes that can't be fully displayed on the screen, for example elipse with x,y=10,10 and r1,r2=20,20 some strange things appear on the screen (long rects, totally drawed screen and so on).

I believe that this is because CHDK drawing codes try to poke some values to bad places in memory. Has CHDK drawing code some safety checks, whether the position of the pixel it tries to draw is still on the screen?
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

*

Offline philmoz

  • *****
  • 3107
    • Photos
Re: On-screen drawing from lua - now possible.
« Reply #27 on: 30 / June / 2012, 03:11:42 »
Not sure whether post it here, but I have some problems with drawings. When I set some shapes that can't be fully displayed on the screen, for example elipse with x,y=10,10 and r1,r2=20,20 some strange things appear on the screen (long rects, totally drawed screen and so on).

I believe that this is because CHDK drawing codes try to poke some values to bad places in memory. Has CHDK drawing code some safety checks, whether the position of the pixel it tries to draw is still on the screen?

There are some checks in some routines; but no guarantee that all cases are handled correctly.

The draw_pixel routine checks that the X & Y co-ordinates are less than the screen width and height (the parameters are unsigned so negative values are larger than the screen size). So it should never write outside the screen memory.

The more complex functions like ellipse probably don't have correct clipping code in them.

Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)


Re: On-screen drawing from lua - now possible.
« Reply #28 on: 30 / June / 2012, 04:44:24 »
Yes, but as far as I can see in the gui_draw.c more complex functions just draw shapes pixel by pixel, so if draw_pixel  no one part of the shape should cause any problems.

However, it obviously works bad. Just try such script:

Code: (lua) [Select]
draw_ellipse_filled( 10, 10, 30, 30, 20)
wait_click(0)

And this will cause camera hang and crash:

Code: (lua) [Select]
draw_line( -30, -30, 100, 100, 20)
wait_click(0)

20 is a value for grey on my sx130is.

I tried to understand why this is like that, I think there's some bug in draw_pixel checks. But I can't find it. Maybe only my camera is affected (bad size of the buffer?). Could you try above codes?
« Last Edit: 30 / June / 2012, 04:46:26 by outslider »
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

*

Offline philmoz

  • *****
  • 3107
    • Photos
Re: On-screen drawing from lua - now possible.
« Reply #29 on: 30 / June / 2012, 05:58:09 »

And this will cause camera hang and crash:

Code: (lua) [Select]
draw_line( -30, -30, 100, 100, 20)
wait_click(0)


The parameters to the draw functions are 'unsigned int' values - so -30 is actually 4,294,967,266.
The draw_line function assumes it's parameters are reasonably valid and does not do any checking - up until the draw functions were added to Lua it was only used for the CHDK UI.
Trying to draw a line this long is going to take a very long time - the Lua script is running in the kbd task so it blocks all button presses while drawing. Eventually the watchdog timer in the camera will decide something is wrong and shutdown the camera.

Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)

 

Related Topics