Fixed graphicsContextWithBitmapImageRep:

In case you want to put ARGB into a BIR through a GC


Description

NSGraphicsContext's +graphicsContextWithBitmapImageRep: method has a bug wherein it doesn't correctly map the NSBitmapFormat of the NSBitmapImageRep passed into it to a CGBitmapInfo for CGBitmapContext.

This is a custom implementation that does the same thing, but does not have the bug.


Bugs

There is one bug: This implementation does not support planar data. It would need to be mixed to chunky (the opposite of planar) first, but then it would not affect the NSBitmapImageRep, since it would be a separate buffer (otherwise I would have to set the planar attribute of the BIR to NO, which is not possible).

On the other hand, given that I see no way to connect a CGBitmapContext with planar data in the first place (otherwise I'd have done that), perhaps the Apple implementation doesn't support it either. So far, I haven't had the need to try.

If you can figure out a way, feel free to submit a patch.


Downloads

FixedGraphicsContextWithBIR-r4.zip
Objective-C source code, in a zip archive
128-bit FNV1 hash: 0e6e925467e4bebd82c48be7b2c3e7e5
MD5 hash: c00c284bb6880ae4d52364d706604bff
SHA-1 hash: e1cf68fe727326283f33de1ae02fa9a9732860a5

MD5 and SHA1 signatures were created using the md5sum(1) and sha1sum(1) utilities from GNU coreutils.


Version history

r4


2006-08-17 http://oocities.com/iamtheboredzo/fixedgraphicscontextwithbir
Valid XHTML 1.0! Valid CSS!