On-screen drawing from lua - now possible.

  • 32 Replies
  • 4378 Views
Re: On-screen drawing from lua - now possible.
« Reply #30 on: 30 / June / 2012, 07:53:00 »
Advertisements
Ok, forgive my ignorance, now I understand, what kind of reasons are for hang/crash.

But this doesn't explain the above draw_ellipse behavior.

I suspect that the only place, were bug is born is here:

in gui_draw.c, start at line 155:
Code: (c) [Select]
    if (xMax>=camera_screen.width) xMax=camera_screen.width-1;
    if (xMin>=camera_screen.width) xMin=camera_screen.width-1;
    if (yMax>=camera_screen.height) yMax=camera_screen.height-1;
    if (yMin>=camera_screen.height) yMin=camera_screen.height-1;

Above assumes, that when xMax is > camera_screen.width then it must be max. But having unsigned value also xMin<0 appears to be >camera_screen.width and then is set to max possible. So such rectangle:

  • -10, -10, 100, 100

will be shown as:

  • camera_screen.width, camera_screen.height, 100, 100

exactly the same as:

  • 100, 100, camera_screen.width, camera_screen.height

And experiment confirms that. Any ideas how to improve that?

I think it could be done like this:
Code: (c) [Select]
    if (xMax>=camera_screen.width) xMax=camera_screen.width-1;
    if (xMin>=camera_screen.width) xMin=0;
    if (yMax>=camera_screen.height) yMax=camera_screen.height-1;
    if (yMin>=camera_screen.height) yMin=0;

I can rather assume, that xMin>camera_screen.height means xMin<0 rather.

I didn't check this, I have to run my XP to compile CHDK. I can play with adding the limits, but first I like to know whether my thought seem to be correct (to not play in the dark;) ).

Thank you!
« Last Edit: 30 / June / 2012, 08:24:48 by outslider »
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

*

Offline philmoz

  • *****
  • 2936
    • Photos
Re: On-screen drawing from lua - now possible.
« Reply #31 on: 30 / June / 2012, 09:04:02 »
Ok, forgive my ignorance, now I understand, what kind of reasons are for hang/crash.

But this doesn't explain the above draw_ellipse behavior.

I suspect that the only place, were bug is born is here:

in gui_draw.c, start at line 155:
Code: (c) [Select]
    if (xMax>=camera_screen.width) xMax=camera_screen.width-1;
    if (xMin>=camera_screen.width) xMin=camera_screen.width-1;
    if (yMax>=camera_screen.height) yMax=camera_screen.height-1;
    if (yMin>=camera_screen.height) yMin=camera_screen.height-1;

Above assumes, that when xMax is > camera_screen.width then it must be max. But having unsigned value also xMin<0 appears to be >camera_screen.width and then is set to max possible. So such rectangle:

  • -10, -10, 100, 100

will be shown as:

  • camera_screen.width, camera_screen.height, 100, 100

exactly the same as:

  • 100, 100, camera_screen.width, camera_screen.height

And experiment confirms that. Any ideas how to improve that?

I think it could be done like this:
Code: (c) [Select]
    if (xMax>=camera_screen.width) xMax=camera_screen.width-1;
    if (xMin>=camera_screen.width) xMin=0;
    if (yMax>=camera_screen.height) yMax=camera_screen.height-1;
    if (yMin>=camera_screen.height) yMin=0;

I can rather assume, that xMin>camera_screen.height means xMin<0 rather.

I didn't check this, I have to run my XP to compile CHDK. I can play with adding the limits, but first I like to know whether my thought seem to be correct (to not play in the dark;) ).

Thank you!

The use of unsigned int values is fundamentally broken.
It works ok when you are only drawing withing the screen boundary; but doesn't handle arbitrary drawing with clipping.

Trying to fix it using unsigned values is probably not worth the effort - you'll end up writing special cases everywhere to try and work out the correct values.

The whole thing should be changed to use signed values for all screen co-ordinates, with proper range checking in all the functions.

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 #32 on: 30 / June / 2012, 09:15:45 »
Ok, I'll read more of the code to better understand the way it draws on the screen and maybe I'll play with that. I think the whole gui_draw is too much complicated, but rewrie it would take a lot of effort. For now it looks like:

draw_some_thing calls draw_other_thing, which calls draw_something_else which calls draw_pixel many times:)

Meanwhile I try to make on-camera grid editor, that's why I face the problems...

Regards!
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

 

Related Topics