Recent

Author Topic: How is the fastest way to convert array to image canvas data?  (Read 16769 times)

Milsa

  • Sr. Member
  • ****
  • Posts: 309
How is the fastest way to convert array to image canvas data?
« on: February 05, 2014, 09:33:00 pm »
I have array[0..919, 0..286] or array[0..264039] and I want fast convert to TBitmap.Canvas (920x267). Maximal time for this operation is around 1/100 of second. I want show this image 50 times per second (emulation of 8-bit computer).

Do you have any multiplatform idea (Windows, Linux)?

I work with Lazarus 2.2.2, FPC 3.2.2, date 2022-05-15
This information is actual to: 28st Dec 2022

Michl

  • Full Member
  • ***
  • Posts: 226
Re: How is the fastest way to convert array to image canvas data?
« Reply #1 on: February 05, 2014, 11:06:49 pm »
I don't know what the fastest way at all, but here is one of some methods (and if you want, you can test all and report it here  ;D).
« Last Edit: February 06, 2014, 01:25:33 am by Michl »
Code: [Select]
type
  TLiveSelection = (lsMoney, lsChilds, lsTime);
  TLive = Array[0..1] of TLiveSelection;

Milsa

  • Sr. Member
  • ****
  • Posts: 309
Re: How is the fastest way to convert array to image canvas data?
« Reply #2 on: February 06, 2014, 12:08:41 pm »
Thank you very much. I will look at it and I will write.
I work with Lazarus 2.2.2, FPC 3.2.2, date 2022-05-15
This information is actual to: 28st Dec 2022

Milsa

  • Sr. Member
  • ****
  • Posts: 309
Re: How is the fastest way to convert array to image canvas data?
« Reply #3 on: February 15, 2014, 10:16:56 pm »
This wiki article is not correct.

This is problems:
- Pixels[] in last code (OpenGL) and RandomImage without Pixels (2 different declaration of TFastBitmap)
- OpenGLBitmap in last 2 codes. What is it?
- many syntax errors in article (function instead of procedure, FPixelData instead of FPixelsData, FreeData instead of FreeMem)

Has somebody functional code from this wiki article with OpenGL?

I appreciate the work of authors of wiki articles but this article is really not correct.  :(

Please help me with this.
I work with Lazarus 2.2.2, FPC 3.2.2, date 2022-05-15
This information is actual to: 28st Dec 2022

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: How is the fastest way to convert array to image canvas data?
« Reply #4 on: February 15, 2014, 11:07:35 pm »
This is 8-bit array, right? Do you have the palette? I guess you'd need 24-bit (r,g,b) TBitmap to be shown of the form?

On the other hand, if you're looking into rendering through OpenGL you won't need TBitmap at all. (having palette is still required, though)

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: How is the fastest way to convert array to image canvas data?
« Reply #5 on: February 15, 2014, 11:42:46 pm »
fast enough?

I guess the truth is not about the fastest way of converting one image format to another, but about fastest way to render. That's OpenGL for cross-platform.
« Last Edit: February 15, 2014, 11:44:26 pm by skalogryz »

Milsa

  • Sr. Member
  • ****
  • Posts: 309
Re: How is the fastest way to convert array to image canvas data?
« Reply #6 on: February 16, 2014, 11:06:58 am »
Thanks for your help but compiler found an error:
unit1.pas(116,10) Error: identifier idents no member "ScanLine"
I work with Lazarus 2.2.2, FPC 3.2.2, date 2022-05-15
This information is actual to: 28st Dec 2022

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: How is the fastest way to convert array to image canvas data?
« Reply #7 on: February 17, 2014, 03:35:47 am »
Thanks for your help but compiler found an error:
unit1.pas(116,10) Error: identifier idents no member "ScanLine"
fair enough, you're on earlier Lazarus version than i am.
Try this one.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How is the fastest way to convert array to image canvas data?
« Reply #8 on: February 17, 2014, 10:37:00 am »
Thank you to whoever (Felipe?) recently added a Scanline property to TRasterImage  :)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: How is the fastest way to convert array to image canvas data?
« Reply #9 on: February 17, 2014, 12:31:33 pm »
fast enough?

I guess the truth is not about the fastest way of converting one image format to another, but about fastest way to render. That's OpenGL for cross-platform.

Drawing/rendering is fast. Uploading bitmaps not so.  IIRC there is not that much difference between blitting a GDI bitmap and opengl if you do it 1:1. Only if you start zooming, opengl becomes faster.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: How is the fastest way to convert array to image canvas data?
« Reply #10 on: February 17, 2014, 04:27:10 pm »
Drawing/rendering is fast. Uploading bitmaps not so.  IIRC there is not that much difference between blitting a GDI bitmap and opengl if you do it 1:1. Only if you start zooming, opengl becomes faster.
ugh.. it depends on the "GDI" implementation.

if GDI is pure CPU, OpenGL could still be a bit faster, since fillrate is typically higher on GPU. Plus CPU would be released for executing the code, rather than copying memory.
These days however, most of "GDI" are using hardware acceleration (through either OpenGL or DirectX).

Oh yes, if OpenGL drivers are not so good, it might be implemented through CPU as well :)

In this particular case (buffer: 0..919, 0..286) there won't be any difference.



Milsa

  • Sr. Member
  • ****
  • Posts: 309
Re: How is the fastest way to convert array to image canvas data?
« Reply #11 on: February 18, 2014, 07:42:09 pm »
It is too slow - maximim is 60 fps for invalidate, 52 fps for paint. 8-bit computers have double scanlines.

Real resolution with double scanlines is 920x574 (640x200 + border + double scanlines). This resolution is too slow - 31 fps for invalidate, 28 fps for paint.

I think that OpenGL is better option.

Thank you for your help.
I work with Lazarus 2.2.2, FPC 3.2.2, date 2022-05-15
This information is actual to: 28st Dec 2022

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: How is the fastest way to convert array to image canvas data?
« Reply #12 on: February 18, 2014, 07:55:30 pm »
GPU does not specialize in moving data from RAM to video memory either. It is fast, but still slow enough to recommend all/most textures to be loaded to GPU when application starts. If you do fullscreen pixel streaming from RAM, you won't have computer resources left for much of anything else. But both are viable methods, as can be said for most mediaplayers. VLC for example has the option to use GPU, but it was never the only way.

Milsa

  • Sr. Member
  • ****
  • Posts: 309
Re: How is the fastest way to convert array to image canvas data?
« Reply #13 on: February 18, 2014, 08:19:39 pm »
And this method?
Creating BMP file in memory and showing it directly with OpenGL? Will it be faster?

My question is on base this answer:
http://forum.lazarus.freepascal.org/index.php/topic,23625.msg141541.html#msg141541
I work with Lazarus 2.2.2, FPC 3.2.2, date 2022-05-15
This information is actual to: 28st Dec 2022

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: How is the fastest way to convert array to image canvas data?
« Reply #14 on: February 19, 2014, 05:24:10 am »
give it a try.
you'll need to have LazOpenGLContext package installed.

It is too slow - maximim is 60 fps for invalidate, 52 fps for paint. 8-bit computers have double scanlines.
You should probably decrease the timer interval, to get a higher FPS? Otherwise I don't understand how an invalidate could be faster than direct paint.

Also, it might be that you won't get a higher rate  than your monitor allows. Modern gui engines are based on GPU and are enforcing VSync for any windowed application.
« Last Edit: February 19, 2014, 05:33:52 am by skalogryz »

 

TinyPortal © 2005-2018