StretchBlit not blitting with transparency in OSX

15 views
Skip to first unread message

Martín Sebastián Wain

unread,
Nov 20, 2009, 4:19:39 PM11/20/09
to wx-u...@googlegroups.com
Hi guys.
I have this code working on Windows but not on Mac OS X:

void EditorCanvas::OnPaint(wxPaintEvent &ev) {
   wxAutoBufferedPaintDC dc(this);
   wxMemoryDC memDC(bmp);        //  bmp is a preloaded png with alpha.

   //...

   //rect, tileDimension are valid, believe me
   dc.StretchBlit(
       rect.x, rect.y,
       rect.width, rect.height,
       &memDC,
       tile*tileDimension, 0, tileDimension, tileDimension,
       wxCOPY,
       true        //useMask
   );
}

Do you know what could be the reason?
Thanks in advance

-Martín

Martín Sebastián Wain

unread,
Nov 20, 2009, 4:53:21 PM11/20/09
to wx-u...@googlegroups.com
I forgot to mention, sorry
I'm using wxMSW trunk-ish and wxMac 2.9

2009/11/20 Martín Sebastián Wain <nitra...@gmail.com>



--
-Martín
Two bananas and milk [ http://www.tbam.com.ar ]

Bryan Petty

unread,
Nov 20, 2009, 6:59:40 PM11/20/09
to wx-u...@googlegroups.com
2009/11/20 Martín Sebastián Wain <nitra...@gmail.com>:

> Hi guys.
> I have this code working on Windows but not on Mac OS X:
>
>    dc.StretchBlit(

You must have been using auto-complete on Windows...

StretchBlit() isn't official public API, it's only meant to be used
internally. Use Blit() instead, or better yet, don't create a
wxMemoryDC, and just use DrawBitmap() directly while setting the user
scale as needed, or just resizing the bitmap before-hand.

Regards,
Bryan Petty

Bryan Petty

unread,
Nov 20, 2009, 7:03:45 PM11/20/09
to wx-u...@googlegroups.com
On Fri, Nov 20, 2009 at 4:59 PM, Bryan Petty <br...@ibaku.net> wrote:
> StretchBlit() isn't official public API, it's only meant to be used
> internally. Use Blit() instead, or better yet, don't create a
> wxMemoryDC, and just use DrawBitmap() directly while setting the user
> scale as needed, or just resizing the bitmap before-hand.

Nevermind, I was looking at 2.8 API. Apparently it is new in 2.9.
Anyway, the workarounds mentioned should still work though.

What is the error you're getting?

Regards,
Bryan Petty

Martín Sebastián Wain

unread,
Nov 20, 2009, 10:19:36 PM11/20/09
to wx-u...@googlegroups.com
Sorry, forgot that.
It all works the same with the exception that the transparent pixels are drawn BLACK.
Other than that, it works the same.

I'll try that changes you suggested and see what happens, thanks!
Although I can't resize the bitmap because the way I'm using it (it's for a tilemap editor).

Regards

Martín Sebastián Wain

unread,
Nov 24, 2009, 10:00:17 AM11/24/09
to wx-u...@googlegroups.com
Ok, I can't use your method with DrawBitmap() because I'm
talking about a lot of sub-bitmaps (perhaps 1000+)
*Windows GDI Bitmaps are limited AFAIK
*Extracting some on each paint is really bad on performance

The way I do it now is blitting sub-rectangles from few bitmaps
(no more than 25).

Also I can't pre-stretch because an image sheet thats
500x500 (1MB), with 3200% zoom will need (32MB).

Does anyone else know about why transparency (useMask=true)
is not working with stretchblit in MacOS X?

Best regards
-Martín


2009/11/21 Martín Sebastián Wain <nitra...@gmail.com>

Bryan Petty

unread,
Nov 24, 2009, 2:44:44 PM11/24/09
to wx-u...@googlegroups.com
2009/11/24 Martín Sebastián Wain <nitra...@gmail.com>:

> Also I can't pre-stretch because an image sheet thats
> 500x500 (1MB), with 3200% zoom will need (32MB).

Actually, a 500x500 32-bit image blown up 3200% is closer to 1GB.

But this is typically where you would actually grab the sub-bitmap
consisting of just what part of the image is actually going to be
shown on screen, and blowing that up, which will only take closer to
3-6MB typically, depending on the size of the window. You don't need
to blow up the entire image.

You are right though, this is still not nearly as efficient as it
could be (but it is a lot more efficient than you think it is if done
right).

Anyway, I've now tested all approaches mentioned in this thread on
both wxOSX/Carbon and wxOSX/Cocoa. Not only does it not work with
StretchBlit() on either Carbon or Cocoa, but it also doesn't work with
Blit() if you change the user scale (it does however work if you don't
change the user scale, but that's not going to help you unless you
want to resize the bitmap first).

What did work on both Carbon and Cocoa though was my initial
suggestion of setting the user scale, and using DrawBitmap(). Note
that this does not involve a single call to resize the bitmap/image.
You simply grab the sub-bitmap (for efficiency) set the user scale
appropriately, and call DrawBitmap() with your sub-bitmap.

It may still be possible to fix whatever the issue is with
StretchBlit()/Blit()/wxMemoryDC on Mac. It would at least be worth
opening a ticket on the wxWidgets tracker anyway.

Regards,
Bryan Petty

Martín Sebastián Wain

unread,
Nov 25, 2009, 11:54:39 AM11/25/09
to wx-u...@googlegroups.com
Wow man, you exceeded yourself there! Thanks a lot!
I must have misunderstood you on the DrawBitmap-scale thing before.
I'll render like that for now, even if it has a performance hit,
until a OS X-savvy can fix Blit/StretchBlit.

Now that I have your confirmation I could open a ticket at trac
or, do you want to do it yourself? Apparently you know better the
internals than I do :D
Just let me know to avoid double tickets.

Best regards and thanks for going through all that just for me.
-Martín
Reply all
Reply to author
Forward
0 new messages