WarpBlt works better on the 64 bit VM!

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

WarpBlt works better on the 64 bit VM!

Yoshiki Ohshima-3
I was trying to create a grayscale image.  There is of course
Form>>asGrayScale, but it has two problems:

1. It makes a BitBlt call for each vertical 1 pxiel side slice in the
image.
2. It only sees uses green channel, and pretend to be that it is the
gray value.

For the first issue, I thought of using WarpBlt to only make a one
call for the image.  Basically, you reshape the 32-bit depth picture
into 1 pixel wide, (w*h) height bitmap, and then re-interpret that
picture as 8-bit picture of 4 pixel * (w*h) picture. There, column 0
has the R component of all original pixels, column 1 has the G
component of all original pixels, and so on.

Then, by rotating that picture and copy the now row 1, which was
column 1, onto the resultinf form, it becomes the gray scale:

--------------------------
asGrayScale: aForm
        | form8 g h quad w c |
        h := aForm width * aForm height.
        form8 := Form extent: 4@h depth: 8 bits: aForm bits.

        g := Form extent: h@1 depth: 8.
        w := WarpBlt toForm: g.
        quad := {2@0. 3@0. 3@h. 2@h}.
        w sourceForm: form8.
        w colorMap: nil.
        w combinationRule: Form over.
        w copyQuad: quad toRect: g boundingBox.

        c := ColorForm extent: aForm extent depth: 8 bits: g bits.
        c colors: (ColorForm grayScalePalette).
        ^ c
--------------------------

It works!  but then it is not as fast as I hoped. That is because, the
WarpBlt primitive fails and its fallback code gets run (but produces a
correct result).  And the
reason is that p3y and p4y in the WarpBlt object go beyond the
SmallInteger range.

But then, it occured to me that the number, 15099494400, is a
SmallInteger on the 64 bit platform.  Sure enough, the above code just
works and produces 4x performance.

Okay, I might actualy like to do a bit better job of computing
grayscale.  Brightness in HSB is defined as "(R max: G) max: B", and I
can use the combination rule 27 to compute it.  The result is more involving:

--------------------------
asGrayScale2: aForm
        | b b32 form8 g g32 h quad r r32 w c |
        h := aForm width * aForm height.
        form8 := Form extent: 4@h depth: 8 bits: aForm bits.
        r := Form extent: (h@1) depth: 8.
        w := WarpBlt toForm: r.
        quad := {1@0. 2@0. 2@h. 1@h}.
        w sourceForm: form8.
        w colorMap: nil.
        w combinationRule: Form over.
        w copyQuad: quad toRect: r boundingBox.

        g := Form extent: (h@1) depth: 8.
        w := WarpBlt toForm: g.
        quad := {2@0. 3@0. 3@h. 2@h}.
        w sourceForm: form8.
        w colorMap: nil.
        w combinationRule: Form over.
        w copyQuad: quad toRect: g boundingBox.

        b := Form extent: (h@1) depth: 8.
        w := WarpBlt toForm: b.
        quad := {3@0. 4@0. 4@h. 3@h}.
        w sourceForm: form8.
        w colorMap: nil.
        w combinationRule: Form over.
        w copyQuad: quad toRect: b boundingBox.


        g32 := Form extent: (h / 4)@1 depth: 32 bits: g bits.
        r32 := Form extent: (h / 4)@1 depth: 32 bits: r bits.
        b32 := Form extent: (h / 4)@1 depth: 32 bits: b bits.

        ((BitBlt destForm: r32 sourceForm: g32 fillColor: nil combinationRule: 27 destOrigin: 0@0 sourceOrigin: 0@0 extent: g32 extent clipRect: r32 boundingBox) colorMap: nil) copyBits.
        ((BitBlt destForm: r32 sourceForm: b32 fillColor: nil combinationRule: 27 destOrigin: 0@0 sourceOrigin: 0@0 extent: b32 extent clipRect: r32 boundingBox) colorMap: nil) copyBits.
        c := ColorForm extent: aForm extent depth: 8 bits: r32 bits.
        c colors: (ColorForm grayScalePalette).
        ^ c
--------------------------

But this still runs faster than Form>>asGrayScale (but less than
2x) on 64 bit.

I never had a convincing case for 64-bit VM for my small example, but
this was pretty interesting result...  Thank you everybody who made
the 64-bit environment works!

(And I confirmed that the new CameraPlugin works on 64-bit environment MacOS.)

-- Yoshiki







y.jpg (61K) Download Attachment