DIBSection from ByteArray

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

DIBSection from ByteArray

Udo Schneider
Hi,

I'm having a few performance problems with Canvas>>#pixelAt:put: to fill
a large canvas pixel by pixel (using C doesn't help here ... SetPixelV
seems to be the problem here).

My approach is now to use an ByteArray of x*y*Bpp entries and to fill it
in directly. The question now is how to get a DIBSection from this?

Thanks,

Udo


Reply | Threaded
Open this post in threaded view
|

Re: DIBSection from ByteArray

Jochen Riekhof-3
Maybe an easier way is to create the DIBSection of choice and then access
the internal data (an ExternalAddress) directly with myBmp>>imageBits..

Beware that there are extra bytes at the end of each row as the data is
word-aligned. For clean coding you can query the rowsize with
bmp getInfo bmWidthBytes

Ciao

...Jochen


Reply | Threaded
Open this post in threaded view
|

Re: DIBSection from ByteArray

Jeffrey D. Panici-3
In reply to this post by Udo Schneider
Udo Schneider <[hidden email]> wrote in message news:<[hidden email]>...

> Hi,
>
> I'm having a few performance problems with Canvas>>#pixelAt:put: to fill
> a large canvas pixel by pixel (using C doesn't help here ... SetPixelV
> seems to be the problem here).
>
> My approach is now to use an ByteArray of x*y*Bpp entries and to fill it
> in directly. The question now is how to get a DIBSection from this?
>
> Thanks,
>
> Udo

Udo --

How about this:

| dib dibSize bits |
dibSize := (32 * 32) * 4.    " Four bytes for 32bpp "
dib := DIBSection width: 32 height: 32 depth: 32.
KernelLibrary open zeroMemory: (dib imageBits) length: dibSize.
bits := ByteArray fromAddress: (dib imageBits) length: dibSize.
0 to: (dibSize - 4) do: [:idx | bits dwordAtOffset: idx put: idx].
bits inspect.

Regards,
Jeffrey D. Panici
Worker Bee Solutions, Inc.