Recent

Author Topic: How can I Draw 2D array of TColor on canvas within a 30th of a second?  (Read 8113 times)

DanNineOne

  • New Member
  • *
  • Posts: 46
Hi,
My application loads lots of images that are frames of a video, I have them loaded into memory in the form of a 3D array of TColor (Defined like this...)
Code: [Select]
smallBuffer: array of array of array of tcolor;
it's like an array of frames, each frame being a 2D array of colours, that has already been scaled down to the desired size, my question is, How can I draw these pixels on to a canvas and display them within one 30th of a second? (to display a 29.5 fps video)

ScanLine seems to be the preferred way in delphi but this isn't such an easily implemented option in Laz it seems.  (I'm sure many people here are sick of hearing, "How can I do a ScanLine in Laz?")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>   Win 7 64 bit with Lazarus 1.0.6            <<
>>  danieljabailey@googlemail.com             <<
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: How can I Draw 2D array of TColor on canvas within a 30th of a second?
« Reply #1 on: August 11, 2011, 09:56:44 pm »
The basic way is creating a TCustomControl descendent, which is documented here: http://wiki.lazarus.freepascal.org/Developing_with_Graphics#Create_a_custom_control_which_draws_itself

Together with TLazIntfImage: http://wiki.lazarus.freepascal.org/Developing_with_Graphics#Working_with_TLazIntfImage

If it is still not fast enough you can try BGRABitmap

DanNineOne

  • New Member
  • *
  • Posts: 46
Re: How can I Draw 2D array of TColor on canvas within a 30th of a second?
« Reply #2 on: August 12, 2011, 12:04:38 am »
the BGRA Bitmap looks promising, just what I was after so long as it performs well, it could be complicated integrating it with the code I've written so far but hopefully it's worth doing.
I'll see how it goes but Thanks very much for this advice,
Cheers, Dan.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>   Win 7 64 bit with Lazarus 1.0.6            <<
>>  danieljabailey@googlemail.com             <<
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DanNineOne

  • New Member
  • *
  • Posts: 46
Re: How can I Draw 2D array of TColor on canvas within a 30th of a second?
« Reply #3 on: August 12, 2011, 10:02:32 am »
Using the latest BGRABitmap I have managed to get my application to the desired speed, the problem now is that the resample function doesn't work,

From what I understand, the following lines should resize a newly loaded image to 800x450, it does nothing, when I use the draw function on a canvas on the form it is still at the original size.

This is the code that loads the image...

Code: [Select]
BGRABuffer[i] := TBGRABitmap.Create(strFileName);
BGRABuffer[i].ResampleFilter:=rfLinear;
BGRABuffer[i].Resample(800,450, rmSimpleStretch);
BGRABuffer is an array of TBGRABitmaps.

this code draws the image on to a tImge on the form...
Code: [Select]
BGRABuffer[frameNum].Draw(imgAnim.Canvas,0,0, true);
imgAnim.Invalidate;

Thanks for any help.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>   Win 7 64 bit with Lazarus 1.0.6            <<
>>  danieljabailey@googlemail.com             <<
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: How can I Draw 2D array of TColor on canvas within a 30th of a second?
« Reply #4 on: August 12, 2011, 01:40:48 pm »
Moved because the topic driffited to BGRABitmap

DanNineOne

  • New Member
  • *
  • Posts: 46
Re: How can I Draw 2D array of TColor on canvas within a 30th of a second?
« Reply #5 on: August 12, 2011, 02:16:50 pm »
Sorry, got it now, silly me, didn't use the result of the function.

Thanks for help, runs perfectly now.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>   Win 7 64 bit with Lazarus 1.0.6            <<
>>  danieljabailey@googlemail.com             <<
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

circular

  • Hero Member
  • *****
  • Posts: 4221
    • Personal webpage
Re: How can I Draw 2D array of TColor on canvas within a 30th of a second?
« Reply #6 on: August 13, 2011, 12:32:47 pm »
@DanNineOne: Don't forget to free memory. To do this you can use BGRAReplace :
Quote
BGRAReplace(BGRABuffer, BGRABuffer.Resample(800,450, rmSimpleStretch));
You do not need to specify rfLinear beacuse rmSimpleStretch does not use any filter.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018