Hi Matt,

On 26-11-11 04:09, mattschinkel wrote:
Are you sure we need to check weather we are writing outside the GLCD
boundaries?

Drawing pixels outside the visible area doesn't seem very useful to me. You might argue if it is the responsibility of the user to prevent it. That is reasonable for a line or box where the user can easily check if the figure is within display boudaries. But with an ellipse this check is not so easy for the user. And even when the user can check the limits, without clipping he is limited to draw only full ellipses or circles. When he wants to draw parts of an ellipse or circle clipping is required, otherwise 'invisible' pixels may appear at undesired places. It depends on the commandset where 'invisible' pixels will appear on the display.

It seems like a waste of cycles in most cases, the user should insure
this on his own. These if statements will run every time a pixel is
drawn, and graphics have a lot of pixels.

I always work with: "make it work first, optimize later".
But yes, you are right, it takes cycles for every pixel within the visible area, but on the other it saves (probably more) cycles for pixels outside the visible area. So the ultimate result will depend on the ratio visible/clipped pixels.

If you wish, I can run a speed comparison.

OLD:

       glcd_write_pixel(byte(cx + x), byte(cy + y))
       glcd_write_pixel(byte(cx - x), byte(cy + y))
       glcd_write_pixel(byte(cx - x), byte(cy - y))
       glcd_write_pixel(byte(cx + x), byte(cy - y))


NEW:

procedure _glcd_write_4_ellipse_pixels(byte*GLCD_X_SIZE in cx, sbyte*3
in dx,
    byte*GLCD_Y_SIZE in cy, sbyte*3 in dy) is
    if (cx + dx)>= 0&  (cx + dx)<  GLCD_X_PIXELS  then
       if (cy + dy)>= 0&  (cy + dy)<  GLCD_Y_PIXELS  then
          glcd_write_pixel(byte*GLCD_X_SIZE(cx + dx),
byte*GLCD_Y_SIZE(cy + dy))
       end if
       if (cy - dy)>= 0&  (cy - dy)<  GLCD_Y_PIXELS  then
         glcd_write_pixel(byte*GLCD_X_SIZE(cx + dx),
byte*GLCD_Y_SIZE(cy - dy))
       end if
    end if
    if (cx - dx)>= 0&  (cx - dx)<  GLCD_X_PIXELS  then
       if (cy + dy)>= 0&  (cy + dy)<  GLCD_Y_PIXELS  then
         glcd_write_pixel(byte*GLCD_X_SIZE(cx - dx),
byte*GLCD_Y_SIZE(cy + dy))
       end if
       if (cy - dy)>= 0&  (cy - dy)<  GLCD_Y_PIXELS  then
          glcd_write_pixel(byte*GLCD_X_SIZE(cx - dx),
byte*GLCD_Y_SIZE(cy - dy))
       end if
    end if
end procedure


This procedure can be streamlined a bit: reducing cycles for example by using variables for intermediate results for cx+dx, cx-dx, cy+dy and cy-dy, but that would cost a little more RAM. Difficult to find the balance for all situations.

Another option: we could introduce a 'GLCD_CLIPPING' constant or variable, which allows the user to select between clipping and no clipping. When not declared by the user it should be declared in glcd_common and set to FALSE by default. This matches the old situation (before I added clipping), and it is appropriate for displays which have the clipping function built-in.

Regards, Rob.


--
R. Hamerling, Netherlands --- http://www.robh.nl

--
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en.

Reply via email to