<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>
<channel>
	<title>Comments on: NSImage: Deceivingly Simple or Just Deceiving?</title>
	<atom:link href="http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/feed/" rel="self" type="application/rss+xml" />
	<link>http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/</link>
	<description>If I could put reflection under this header, I would.</description>
	<pubDate>Wed, 07 Jan 2009 20:52:25 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: blake</title>
		<link>http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/comment-page-1/#comment-55524</link>
		<dc:creator>blake</dc:creator>
		<pubDate>Wed, 28 Feb 2007 01:28:13 +0000</pubDate>
		<guid isPermaLink="false">http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/#comment-55524</guid>
		<description>You can calculate the scaled rect size in three lines or so, and then draw into that rect - is that what you're trying to do? Calculating the offset to center it is fairly easy as well - but maybe I'm not understanding what you're trying to do.</description>
		<content:encoded><![CDATA[<p>You can calculate the scaled rect size in three lines or so, and then draw into that rect - is that what you&#8217;re trying to do? Calculating the offset to center it is fairly easy as well - but maybe I&#8217;m not understanding what you&#8217;re trying to do.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jim Hillhouse</title>
		<link>http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/comment-page-1/#comment-55360</link>
		<dc:creator>Jim Hillhouse</dc:creator>
		<pubDate>Tue, 27 Feb 2007 09:22:03 +0000</pubDate>
		<guid isPermaLink="false">http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/#comment-55360</guid>
		<description>This was a great posting. What has gotten me about NSImage is its limitations. For example, let's say I want to both draw an image from the center of the view as well as scale that image down so that it fits the smallest dimension of the rect that the image will be drawn to. 

One call to CGRectApplyAffineTransform, plus some other code, and you're in business. Sadly, I have not found an equivalent call for NSImage, NSAffineTransform, etc.

I started on Cocoa to be a Cocoa programmer. But sometimes I'm forced by NSImage's, and perhaps my own, limitations reluctantly back into the arms of Quartz. Yuck!

BTW, if anyone has some suggestions on solving the above mentioned issue in NSImage, I'm open for it.</description>
		<content:encoded><![CDATA[<p>This was a great posting. What has gotten me about NSImage is its limitations. For example, let&#8217;s say I want to both draw an image from the center of the view as well as scale that image down so that it fits the smallest dimension of the rect that the image will be drawn to. </p>
<p>One call to CGRectApplyAffineTransform, plus some other code, and you&#8217;re in business. Sadly, I have not found an equivalent call for NSImage, NSAffineTransform, etc.</p>
<p>I started on Cocoa to be a Cocoa programmer. But sometimes I&#8217;m forced by NSImage&#8217;s, and perhaps my own, limitations reluctantly back into the arms of Quartz. Yuck!</p>
<p>BTW, if anyone has some suggestions on solving the above mentioned issue in NSImage, I&#8217;m open for it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathon Mah</title>
		<link>http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/comment-page-1/#comment-49162</link>
		<dc:creator>Jonathon Mah</dc:creator>
		<pubDate>Thu, 04 Jan 2007 07:57:31 +0000</pubDate>
		<guid isPermaLink="false">http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/#comment-49162</guid>
		<description>Helpful post Blake, thanks!

"NSString, and itâ€™s deceivingly simple", and
"it looks at itâ€™s underlying NSImageRep" both to "its"</description>
		<content:encoded><![CDATA[<p>Helpful post Blake, thanks!</p>
<p>&#8220;NSString, and itâ€™s deceivingly simple&#8221;, and<br />
&#8220;it looks at itâ€™s underlying NSImageRep&#8221; both to &#8220;its&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shamyl Zakariya</title>
		<link>http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/comment-page-1/#comment-17789</link>
		<dc:creator>Shamyl Zakariya</dc:creator>
		<pubDate>Wed, 15 Nov 2006 16:54:40 +0000</pubDate>
		<guid isPermaLink="false">http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/#comment-17789</guid>
		<description>My biggest gripe with NSImage -- and this seems to apply to CoreGraphics's CGImage as well -- is that if you load a PNG ( or some other file type ) with an alpha channel, you get premultiplied bitmap data. Oddly, if you read the CGBitmapContextCreate docs, there are constants you can pass to request non-premultiplied data. However, and this was corroborated by folks on the mac-opengl and cocoa-dev list -- those constants are ignored, and you get a null bitmap context.

I know that's super useful for compositing, but frankly, sometimes you want your image data unmodified. In my case, I wanted the straight up image data for opengl texturing, and while I know you can swizzle the blend function in gl to work nicely with premultiplied data, I also wanted to use the alpha channel in textures as a lookup table for the other three channels ( for terrain texturing ).

As far as I can tell, Cocoa/Quartz simply don't let you get this data, so I had to use libPNG directly. How annoying!</description>
		<content:encoded><![CDATA[<p>My biggest gripe with NSImage &#8212; and this seems to apply to CoreGraphics&#8217;s CGImage as well &#8212; is that if you load a PNG ( or some other file type ) with an alpha channel, you get premultiplied bitmap data. Oddly, if you read the CGBitmapContextCreate docs, there are constants you can pass to request non-premultiplied data. However, and this was corroborated by folks on the mac-opengl and cocoa-dev list &#8212; those constants are ignored, and you get a null bitmap context.</p>
<p>I know that&#8217;s super useful for compositing, but frankly, sometimes you want your image data unmodified. In my case, I wanted the straight up image data for opengl texturing, and while I know you can swizzle the blend function in gl to work nicely with premultiplied data, I also wanted to use the alpha channel in textures as a lookup table for the other three channels ( for terrain texturing ).</p>
<p>As far as I can tell, Cocoa/Quartz simply don&#8217;t let you get this data, so I had to use libPNG directly. How annoying!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mr Pedanto</title>
		<link>http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/comment-page-1/#comment-17732</link>
		<dc:creator>Mr Pedanto</dc:creator>
		<pubDate>Wed, 15 Nov 2006 05:22:47 +0000</pubDate>
		<guid isPermaLink="false">http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/#comment-17732</guid>
		<description>I believe the title of this article should be:

NSImage: Deceptively Simple or Just Deceptive?</description>
		<content:encoded><![CDATA[<p>I believe the title of this article should be:</p>
<p>NSImage: Deceptively Simple or Just Deceptive?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: blake</title>
		<link>http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/comment-page-1/#comment-1658</link>
		<dc:creator>blake</dc:creator>
		<pubDate>Tue, 16 May 2006 16:56:00 +0000</pubDate>
		<guid isPermaLink="false">http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/#comment-1658</guid>
		<description>I'm not familiar with the DIB format, so I can't say for sure. However, if it's a format that Quicktime supports, you can use QT methods to do the conversion. Or, if you really understand the format, I'm sure you could get access to the bits inside an NSImage, and do the conversion "by hand" - although, I'm sure that doesn't sound appealing in the least!</description>
		<content:encoded><![CDATA[<p>I&#8217;m not familiar with the DIB format, so I can&#8217;t say for sure. However, if it&#8217;s a format that Quicktime supports, you can use QT methods to do the conversion. Or, if you really understand the format, I&#8217;m sure you could get access to the bits inside an NSImage, and do the conversion &#8220;by hand&#8221; - although, I&#8217;m sure that doesn&#8217;t sound appealing in the least!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vipin Thazhissery</title>
		<link>http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/comment-page-1/#comment-1652</link>
		<dc:creator>Vipin Thazhissery</dc:creator>
		<pubDate>Tue, 16 May 2006 07:43:47 +0000</pubDate>
		<guid isPermaLink="false">http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/#comment-1652</guid>
		<description>read the article. very useful. but, my doubt is, how can i convert NSImage to DIB (Device Independantant Bitmap) format. Actually, i am in new one in Cocoa. Can I get some help from any one ?</description>
		<content:encoded><![CDATA[<p>read the article. very useful. but, my doubt is, how can i convert NSImage to DIB (Device Independantant Bitmap) format. Actually, i am in new one in Cocoa. Can I get some help from any one ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bloody Fingers &#124; Aperture, Fireballs and Mugshot</title>
		<link>http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/comment-page-1/#comment-1273</link>
		<dc:creator>Bloody Fingers &#124; Aperture, Fireballs and Mugshot</dc:creator>
		<pubDate>Sun, 30 Apr 2006 10:20:39 +0000</pubDate>
		<guid isPermaLink="false">http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/#comment-1273</guid>
		<description>[...] Through John Gruber&#8217;s post echoing the same concerns, I discovered Blake Seely&#8217;s web site. I&#8217;ve never heard of this guy, but he apparently has a deep mastery of Cocoa that has secured him a job at Apple, in the Aperture team. Reading through his blog, I discovered his Mugshot application. [...]</description>
		<content:encoded><![CDATA[<p>[...] Through John Gruber&#8217;s post echoing the same concerns, I discovered Blake Seely&#8217;s web site. I&#8217;ve never heard of this guy, but he apparently has a deep mastery of Cocoa that has secured him a job at Apple, in the Aperture team. Reading through his blog, I discovered his Mugshot application. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Troy Stephens</title>
		<link>http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/comment-page-1/#comment-745</link>
		<dc:creator>Troy Stephens</dc:creator>
		<pubDate>Sat, 01 Apr 2006 01:51:46 +0000</pubDate>
		<guid isPermaLink="false">http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/#comment-745</guid>
		<description>Interesting to see the kinds of issues people run into with NSImage.  As you rightly point out, it's a complex body of code that treads the line between abstraction and exposure of internal parts, and partly as a result its behaviors can unfortunately be a bit obscure at times.

For obtaining an NSBitmapImageRep from an arbitrary NSImage on pre-Tiger systems, you might find NSBitmapImageRep's often-overlooked -initWithFocusedViewRect: initializer useful.  It's available all the way back to 10.0, and saves you the unnecessary overhead of encoding to TIFF, then unpacking again, then re-encoding to JPEG as your second code clipping above does.  Use it after you complete your drawing, while focus is still locked on your NSImage (or anytime later, after locking focus on the image again), and it will extract the pixel data for the requested rect right out of the NSImage's offscreen window backing store.  You then have an NSBitmapImageRep that you can encode however you want.

There's an example of doing this in the "Reducer" code sample from WWDC '05.  Look for the BitmapImageRepFromNSImage() function at the bottom of ImageReducer.m:

http://developer.apple.com/samplecode/Reducer/listing16.html

Hope this helps, and thanks for the interesting post!</description>
		<content:encoded><![CDATA[<p>Interesting to see the kinds of issues people run into with NSImage.  As you rightly point out, it&#8217;s a complex body of code that treads the line between abstraction and exposure of internal parts, and partly as a result its behaviors can unfortunately be a bit obscure at times.</p>
<p>For obtaining an NSBitmapImageRep from an arbitrary NSImage on pre-Tiger systems, you might find NSBitmapImageRep&#8217;s often-overlooked -initWithFocusedViewRect: initializer useful.  It&#8217;s available all the way back to 10.0, and saves you the unnecessary overhead of encoding to TIFF, then unpacking again, then re-encoding to JPEG as your second code clipping above does.  Use it after you complete your drawing, while focus is still locked on your NSImage (or anytime later, after locking focus on the image again), and it will extract the pixel data for the requested rect right out of the NSImage&#8217;s offscreen window backing store.  You then have an NSBitmapImageRep that you can encode however you want.</p>
<p>There&#8217;s an example of doing this in the &#8220;Reducer&#8221; code sample from WWDC &#8216;05.  Look for the BitmapImageRepFromNSImage() function at the bottom of ImageReducer.m:</p>
<p><a href="http://developer.apple.com/samplecode/Reducer/listing16.html" rel="nofollow">http://developer.apple.com/samplecode/Reducer/listing16.html</a></p>
<p>Hope this helps, and thanks for the interesting post!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Red Sweater Links &#187; Blog Archive &#187; Deceptively Simple NSImage</title>
		<link>http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/comment-page-1/#comment-743</link>
		<dc:creator>Red Sweater Links &#187; Blog Archive &#187; Deceptively Simple NSImage</dc:creator>
		<pubDate>Sat, 01 Apr 2006 00:52:41 +0000</pubDate>
		<guid isPermaLink="false">http://blakeseely.com/blog/archives/2006/03/31/nsimage-deceivingly-simple-or-just-deceiving/#comment-743</guid>
		<description>[...] Blake Seely reflects on the simplicity of NSImage, and a couple of the most common gotchas that come along with that simplicity. A good read for anybody who has struggled with NSImage or just wants to know more about how it works. Link. [...]</description>
		<content:encoded><![CDATA[<p>[...] Blake Seely reflects on the simplicity of NSImage, and a couple of the most common gotchas that come along with that simplicity. A good read for anybody who has struggled with NSImage or just wants to know more about how it works. Link. [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
