On 18 feb 2008, at 09:30, Jack Jansen wrote:
>> Are you sure your mask is actually greyscale? If I looks as if
>> there's a repeating pattern in your result image. Maybe you could
>> also use an assert to make sure bitsPerComponent() ==
>> bitsPerPixel() and #components==1.
The mask.tif file checks for 8 bit grayscale in photoshop.
When I load the image first, this works:
bitsPerPixel = imgMask.getBitsPerPixel()
bytesPerRow = imgMask.getBytesPerRow()
assert bitsPerComponent == bitsPerPixel
cs = imgMask.getColorSpace()
print "img getNumberOfComponents", cs.getNumberOfComponents()
>> img getNumberOfComponents 1
When I build the mask object, this works as well:
maskObject = CGImageMaskCreate(width, height,
bitsPerComponent, bitsPerPixel,
bytesPerRow, maskProvider,
decode, shouldInterpolate)
bitsPerComponent = maskObject.getBitsPerComponent()
bitsPerPixel = maskObject.getBitsPerPixel()
assert bitsPerComponent == bitsPerPixel
The mask object returns None for getColorSpace(). So, the image checks
for 1 component and 8 bits, but I don't know whether the mask itself
should.
I've posted the updated test script here:
http://erik.letterror.com/cg/cgMaskTestPost.py
Thanks for looking though! :)
Erik
>> On 16-Feb-2008, at 13:45 , Erik van Blokland wrote:
>>
>>>
>>> Folks,
>>>
>>> I've been wrestling with some CoreGraphics stuff, OSX 10.5.2,
>>> stock Python 2.5.1. I want to load a RGB image, then load a
>>> grayscale image, draw one while using the other as a mask. I can
>>> build all the required objects. I can draw with "masking-like
>>> things" happening to the image. But the masking appears to be
>>> according to a (random) piece of memory, rather than the pixels
>>> from the mask image.
>>>
>>> The RGB image:
>>> http://erik.letterror.com/cg/picture.png
>>>
>>> The grayscale mask:
>>> http://erik.letterror.com/cg/mask.tif
>>>
>>> The resulting image:
>>> http://erik.letterror.com/cg/results.png
>>>
>>> The script:
>>> http://erik.letterror.com/cg/cgMaskTestPost.py
>>>
>>> The script which draws this file is below. Yellow background, rgb
>>> image of a neon sign, mask. I get the impression I'm somehow not
>>> making the right kind of mask. Or perhaps the parameters I'm
>>> passing to it are wrong. Perhaps the mask image is wrong. I've
>>> tried black/white bitmaps, tiff, jpeg, png, grayscale 8 bit, 24
>>> bit. Different formats result in different patterns being used as
>>> a mask - so there is some correlation between the file and the
>>> result. Is this anywhere close to how it needs to be done?
>>>
>>> Any pointers are most welcome, thanks!
>>>
>>> Erik van Blokland
>>>
>>>
_______________________________________________
Pythonmac-SIG maillist - Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig