Recent

Author Topic: 10 frame/second animation of a 600x512 pixel image  (Read 9267 times)

Curt Carpenter

  • Full Member
  • ***
  • Posts: 109
10 frame/second animation of a 600x512 pixel image
« on: September 14, 2011, 05:10:38 pm »
I have a 600x512 pixel virtual oscilloscope screen on  my main form that I want to update at ten re-draws per second.  I currently draw the new screen image off-view, and then use copy rectangle to move the updated screen image onto my form.   The screen is basically black, with colored traces, grid marks and so on.

Right now, I'm getting a white bar that rolls vertically through my screen image, and this is not going to be acceptable.   (the bar seems to occur at some kind of a beat frequency, perhaps with the whole windows screen update cycle).

Can anybody suggest what I need to do to eliminate the rolling bar?  Or am I just not going to be able to update my 600x512 screen at 10cps?

All suggestions appreciated.

Blaazen

  • Hero Member
  • *****
  • Posts: 2782
  • POKE 54296,15
    • Eye-Candy Controls
Re: 10 frame/second animation of a 600x512 pixel image
« Reply #1 on: September 14, 2011, 05:58:17 pm »
I don't fully understand.
1) Can you attach screenshot of the wite bar ?
2) @ I currently draw the new screen image off-view, and then use copy rectangle to move the updated screen image onto my form.
  Do you paint to TBitmap and then you use CopyRect to Form.Canvas ? Do you use a trasparency ?
Lazarus 2.1.0 r59757M FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.11.2, Plasma 5.14.2
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Scoops

  • Jr. Member
  • **
  • Posts: 83
Re: 10 frame/second animation of a 600x512 pixel image
« Reply #2 on: September 14, 2011, 08:28:13 pm »
Try setting Doublebuffered to True for the image component ??? i have never programmed
an application using images, but this worked ok for a stringgrid that i had flicker problems with.

Curt Carpenter

  • Full Member
  • ***
  • Posts: 109
Re: 10 frame/second animation of a 600x512 pixel image
« Reply #3 on: September 16, 2011, 12:30:13 am »
Thank you for the suggestions.

I haven't been able to find a property for double buffering using an image component, scoops.  But I may not have gone far enough down the hierarchy. 

I haven't been able to get a screen shot showing the white bar rolling across my bitmap either.    Every time I capture a screen image to the clipboard, it doesn't show the bar.    The speed at which the bar rolls vertically is a function of how rapidly I try to redraw my 600x512 bitmap though.   

I've tried turning the transparency property on and off, but it has no effect. 

I think I'm going to have to do some more experiments with this:  I'm obviously overlooking something.   My screen redraw works fine if I shrink my bitmaps from 600x512 to 400x256.

Thanks again for the suggestions.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: 10 frame/second animation of a 600x512 pixel image
« Reply #4 on: September 16, 2011, 01:08:19 am »
Did you try using standard TChart?
It does have DoubleBuffered property, and if you will still encounter flicker using it,
I may me interested to help :-)

Scoops

  • Jr. Member
  • **
  • Posts: 83
Re: 10 frame/second animation of a 600x512 pixel image
« Reply #5 on: September 16, 2011, 01:21:26 am »
Ooops, sorry about thinking an image component had adoublebuffered property, i hav'nt
got lazarus installed at the moment, so i did'nt check.

User137

  • Hero Member
  • *****
  • Posts: 1790
    • Nxpascal home
Re: 10 frame/second animation of a 600x512 pixel image
« Reply #6 on: September 16, 2011, 01:34:09 am »
DoubleBuffered is not property that shows in Object inspector window, you have to type it. If TImage didn't have it, form has for sure, and maybe TPanel and some else.

Curt Carpenter

  • Full Member
  • ***
  • Posts: 109
Re: 10 frame/second animation of a 600x512 pixel image
« Reply #7 on: September 16, 2011, 03:09:49 am »
I'll try these ideas and report back.  Meanwhile, I can view a 640x480 image from my webcam with no difficulty or roll, so it's clearly something I'm overlooking and not my hardware.  I really appreciate the suggestions -- I'm sort of flailing around here  :)

Curt Carpenter

  • Full Member
  • ***
  • Posts: 109
Re: 10 frame/second animation of a 600x512 pixel image
« Reply #8 on: September 16, 2011, 09:38:48 pm »
I have two TImage components, one named imScope which is visible := true, and one named imScopeBase which is visible := false.

I draw my 600x512 'scope screen updates on the not-visible imScopeBase canvas and then use

     imScope.canvas.CopyRect(imScope.clientrect,imScopeBase.canvas,imScopeBase.ClientRect);     

to make it visible on my monitor. 

It looks to me like my visible image in imScope is being cleared at the start of each copyrect procedure execution, and then actually copied into with my updated scope data.  This causes the image on my monitor to flash very briefly.  As I try to call copyrect more and more frequently, the momentary flash becomes what looks like a white bar that rolls through my image.


User137

  • Hero Member
  • *****
  • Posts: 1790
    • Nxpascal home
Re: 10 frame/second animation of a 600x512 pixel image
« Reply #9 on: September 16, 2011, 11:27:20 pm »
If you want to use image in memory, you should use TBitmap, not a hidden TImage. Then Canvas.Draw method is more suitable than Canvas.CopyRect if. This because TImage can scale it if needed.
Adapting your code would become:
Code: [Select]
imScope.canvas.Draw(0,0,imScopeBaseBitmap);
But most importantly did you try the earlier mentioned (if form1 is the parent to your TImage):
Code: [Select]
form1.DoubleBuffered:=true;

Curt Carpenter

  • Full Member
  • ***
  • Posts: 109
Re: 10 frame/second animation of a 600x512 pixel image
« Reply #10 on: September 17, 2011, 03:05:45 am »
For the sake of appearances, my TImage components sit on a TPanel, so following the advice of User137 and Scoops, I tried setting the Tpanel's DoubleBuffered property to True in my main form's OnCreate handler.

Bingo.  Problem solved.   Everything is working perfectly now.

User137, I would urge you to share this solution on the "Using Graphics" wiki article -- I never would have figured it out without your help.   If you don't want to submit the edit, let me know and I'll try to write and submit something  -- but it would be far better coming from you (since I still really don't understand exactly -why- this worked -- but am overjoyed that it DID!)

Boundless thanks to everyone -- I can get on with my life now :)

User137

  • Hero Member
  • *****
  • Posts: 1790
    • Nxpascal home
Re: 10 frame/second animation of a 600x512 pixel image
« Reply #11 on: September 17, 2011, 11:07:13 am »
I haven't written wiki pages, but i found something similar with Google:
http://delphi.about.com/library/bluc/text/uc052102g.htm

Curt Carpenter

  • Full Member
  • ***
  • Posts: 109
Re: 10 frame/second animation of a 600x512 pixel image
« Reply #12 on: September 17, 2011, 05:09:13 pm »
Yes, that is an excellent article.  I'll see if it is possible to include a link to it in the Lazarus wiki on graphics.  Thanks again.