Re: premultiplying alpha

2010-05-05 Thread Thomas Davie

On 5 May 2010, at 06:05, Ken Ferry wrote:

 
 On Tue, May 4, 2010 at 9:30 AM, David Duncan david.dun...@apple.com wrote:
 On May 4, 2010, at 8:57 AM, Thomas Davie wrote:
 
  After much searching about, I discovered (contrary to what the docs say), 
  that NSBitmapImageReps do not always premultiply their r/g/b by their 
  alpha.  
 
 I think you're misreading something.  NSAlphaNonpremultipliedBitmapFormat 
 exists. :-)

Indeed, but nearly the first thing the documentation says is:
If a coverage (alpha) plane exists, a bitmap’s color components are 
premultiplied with it. If you modify the contents of the bitmap, you are 
therefore responsible for premultiplying the data. For this reason, though, if 
you want to manipulate the actual data, an NSBitmapImageRep object is not 
recommended for storage. If you need to work with data that is not 
premultiplied, you should use Quartz, specificallyCGImageCreate with 
kCGImageAlphaLast.

This is repeated variously through the documentation, with no mention of the 
alphaNonPremultiplied format except in the constants section.

I've filed a documentation bug report :)

Bob___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: premultiplying alpha

2010-05-04 Thread David Duncan
On May 4, 2010, at 8:57 AM, Thomas Davie wrote:

 After much searching about, I discovered (contrary to what the docs say), 
 that NSBitmapImageReps do not always premultiply their r/g/b by their alpha.  
 Because of this, I've dived in, and attempted to write my own 
 premultiplication, but something is going very wrong.  Some images are coming 
 out a quarter of the width they went in, others coming out completely empty...


Before diving too deeply into you code, why do you want to do this manually? 
Why not just create a second NSBitmapImageRep with the geometry that you 
desire, then draw the first into the second? This should do the 
premultiplication for you as well as cover any format that NSBitmapImageRep 
supports, rather than the ones that you manually code (as well as being more 
efficient since we've spent the effort to performance optimize those 
conversions).
--
David Duncan
Apple DTS Animation and Printing

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: premultiplying alpha

2010-05-04 Thread Ken Ferry
On Tue, May 4, 2010 at 9:30 AM, David Duncan david.dun...@apple.com wrote:

 On May 4, 2010, at 8:57 AM, Thomas Davie wrote:

  After much searching about, I discovered (contrary to what the docs say),
 that NSBitmapImageReps do not always premultiply their r/g/b by their alpha.



I think you're misreading something.  NSAlphaNonpremultipliedBitmapFormat
exists. :-)

Other than that, what David said.  You should never be calling -bitmapData
on an NSBitmapImageRep that you did not create explicitly yourself in a
known pixel format.

The 10.6 AppKit release
noteshttp://developer.apple.com/mac/library/releasenotes/cocoa/appkit.htmlhave
a long discussion of such things, concerning performance and
correctness.

-Ken


 Because of this, I've dived in, and attempted to write my own
 premultiplication, but something is going very wrong.  Some images are
 coming out a quarter of the width they went in, others coming out completely
 empty...


 Before diving too deeply into you code, why do you want to do this
 manually? Why not just create a second NSBitmapImageRep with the geometry
 that you desire, then draw the first into the second? This should do the
 premultiplication for you as well as cover any format that NSBitmapImageRep
 supports, rather than the ones that you manually code (as well as being more
 efficient since we've spent the effort to performance optimize those
 conversions).
 --
 David Duncan
 Apple DTS Animation and Printing

 ___

 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com

 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/cocoa-dev/kenferry%40gmail.com

 This email sent to kenfe...@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com