Board index » delphi » Storing/restoring pixels from behind objects on a canvas...

Storing/restoring pixels from behind objects on a canvas...


2003-09-19 07:25:17 AM
delphi35
Hi all, I want to be able to store/retrieve the pixels from behind some
objects I want to move around on a canvas...
This is to speed up the redrawing of the diagram - I don't have to redraw
all of it...
They will either be circles - I can just store the box around it, or bezier
curves - I can store the area inside the convex hull (I think) of the end
points +control points...
The bezier curves can be either straight lines - can be converted to an
array of pixels the length of the line or
a polygon formed by the end points + control points...
I'm not quite sure how to efficiently store the area of a canvas given the
end points + control points of the bezier curve if it is curved and not a
straight line?
any ideas?
thanks in advance,
Paul Nicholls (Delphi 5/6 Professional)
"See No Evil, Hear No Evil, EMail No Evil !" - Paul Nicholls
XXXX@XXXXX.COM
Replace '-' with '_' to reply
 
 

Re:Storing/restoring pixels from behind objects on a canvas...

"Paul Nicholls" <XXXX@XXXXX.COM>writes
Quote
I'm not quite sure how to efficiently store the area of a canvas given the
end points + control points of the bezier curve if it is curved and not a
straight line?

any ideas?
The only thing I can think of is to implement manual double-buffering; draw
to an in-memory bitmap when changes are made, then copy it to the screen
when painting.
Cheers,
Ignacio
 

Re:Storing/restoring pixels from behind objects on a canvas...

I am going to store the pixels under each object as an in-memory bitmap
behind the scenes, but I was hoping I could store/retrieve the polygon
instead of the rectangle to save memory...but perhaps it would be faster to
store/retrieve the rectangle instead, and ignore memory usage?
"Ignacio Vazquez" <ivazquezATorioncommunications.com>writes
Quote
"Paul Nicholls" <XXXX@XXXXX.COM>writes
news:3f6a3edd$XXXX@XXXXX.COM...
>I'm not quite sure how to efficiently store the area of a canvas given
the
>end points + control points of the bezier curve if it is curved and not
a
>straight line?
>
>any ideas?

The only thing I can think of is to implement manual double-buffering;
draw
to an in-memory bitmap when changes are made, then copy it to the screen
when painting.

Cheers,
Ignacio


 

Re:Storing/restoring pixels from behind objects on a canvas...

Hi Paul,
The bezier curve is said to lay within the convex hull of the control points
(actually this is a proven concept and it makes Beziers useful to begin
with). So in theory you could create a convex hull from your 4 control
points and store that region.
*If* you want to go this way then have a look at convex hull algo's. With 4
points it should not be difficult in fact but there might be some pitfalls
with zigzagging points if you would just blindly use them for
CreatePolygonRgn without a reorder.
But in practice I think it is easiest and fastest to create a rectangle that
just contains your 4 control points and use that as an update region. This
because all blitting of video buffer behind the scene is probably also
easiest with rectangular regions in the first place.
Hope that helps,
Nils Haeck
www.simdesign.nl
"Paul Nicholls" <XXXX@XXXXX.COM>writes
Quote
Hi all, I want to be able to store/retrieve the pixels from behind some
objects I want to move around on a canvas...
This is to speed up the redrawing of the diagram - I don't have to redraw
all of it...

They will either be circles - I can just store the box around it, or
bezier
curves - I can store the area inside the convex hull (I think) of the end
points +control points...

The bezier curves can be either straight lines - can be converted to an
array of pixels the length of the line or
a polygon formed by the end points + control points...

I'm not quite sure how to efficiently store the area of a canvas given the
end points + control points of the bezier curve if it is curved and not a
straight line?

any ideas?

thanks in advance,
Paul Nicholls (Delphi 5/6 Professional)
"See No Evil, Hear No Evil, EMail No Evil !" - Paul Nicholls
XXXX@XXXXX.COM

Replace '-' with '_' to reply


 

Re:Storing/restoring pixels from behind objects on a canvas...

"Nils Haeck" <XXXX@XXXXX.COM>writes
Quote
Hi Paul,

The bezier curve is said to lay within the convex hull of the control
points
(actually this is a proven concept and it makes Beziers useful to begin
with). So in theory you could create a convex hull from your 4 control
points and store that region.

*If* you want to go this way then have a look at convex hull algo's. With
4
points it should not be difficult in fact but there might be some pitfalls
with zigzagging points if you would just blindly use them for
CreatePolygonRgn without a reorder.
If it helps, the points will never zigzag - the bezier curve will either be
a straight line, a line with a curve (maximum/minimum) at the midpoint, with
both control points on the same side of the straight line between the end
points, or as a loop with both end points at the same point and the control
points off at an angle on either side of the vector between the end points
and the mid point...
Quote
But in practice I think it is easiest and fastest to create a rectangle
that
just contains your 4 control points and use that as an update region. This
because all blitting of video buffer behind the scene is probably also
easiest with rectangular regions in the first place.
I agree that it would be easiest, but in most cases it would be very
wastefull, memory wise, wouldn't it?
Quote
Hope that helps,

Nils Haeck
www.simdesign.nl
 

Re:Storing/restoring pixels from behind objects on a canvas...

"Paul Nicholls" <XXXX@XXXXX.COM>writes
Quote
I am going to store the pixels under each object as an in-memory bitmap
behind the scenes, but I was hoping I could store/retrieve the polygon
instead of the rectangle to save memory...but perhaps it would be faster
to
store/retrieve the rectangle instead, and ignore memory usage?
Ah, the good old speed-vs.-space issue. A classic, that one.
Nils does bring up an interesting point though; many videocards are
optimized for transfers of a rectangular shape and might work better with
them anyways.
Cheers,
Ignacio
 

Re:Storing/restoring pixels from behind objects on a canvas...

Ok Nils and Ignacio, I will try the rectangle version and see how I go :-)
Cheers,
Paul.
"Ignacio Vazquez" <ivazquezATorioncommunications.com>writes
Quote
"Paul Nicholls" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...
>I am going to store the pixels under each object as an in-memory bitmap
>behind the scenes, but I was hoping I could store/retrieve the polygon
>instead of the rectangle to save memory...but perhaps it would be faster
to
>store/retrieve the rectangle instead, and ignore memory usage?

Ah, the good old speed-vs.-space issue. A classic, that one.

Nils does bring up an interesting point though; many videocards are
optimized for transfers of a rectangular shape and might work better with
them anyways.

Cheers,
Ignacio