<?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/"
	xmlns:media="http://search.yahoo.com/mrss/"

	>
<channel>
	<title>
	Comments on: NSImage is dangerous	</title>
	<atom:link href="https://wadetregaskis.com/nsimage-is-dangerous/feed/" rel="self" type="application/rss+xml" />
	<link>https://wadetregaskis.com/nsimage-is-dangerous/</link>
	<description></description>
	<lastBuildDate>Wed, 27 Mar 2024 04:01:26 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>
		By: Wade Tregaskis		</title>
		<link>https://wadetregaskis.com/nsimage-is-dangerous/#comment-3625</link>

		<dc:creator><![CDATA[Wade Tregaskis]]></dc:creator>
		<pubDate>Wed, 27 Mar 2024 04:01:26 +0000</pubDate>
		<guid isPermaLink="false">https://wadetregaskis.com/?p=7501#comment-3625</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://wadetregaskis.com/nsimage-is-dangerous/#comment-3620&quot;&gt;Thomas&lt;/a&gt;.

Ah, thanks for that.  That&#039;s interesting, as it&#039;s not correct (or at least no longer), as my post highlighted - &lt;code&gt;bitmapData&lt;/code&gt; is not an &quot;explicitly mutating method&quot; neither in name, intuition, nor documentation, yet it is &lt;em&gt;not&lt;/em&gt; thread-safe, contrary to what those release notes say.

That section below that, though, is helpful (&quot;NSBitmapImageRep: CoreGraphics impedance matching and performance notes&quot;).  It confirms what I&#039;d suspected based on disassembly and backtraces, that &lt;code&gt;NSBitmapImageRep&lt;/code&gt; is &lt;em&gt;usually&lt;/em&gt; a thin wrapper over a &lt;code&gt;CGImage&lt;/code&gt;.

And I suppose you could try to read between the lines - taking &lt;em&gt;both&lt;/em&gt; those sections in mind - to deduce that maybe &lt;code&gt;bitmapData&lt;/code&gt; et al are in fact mutating as an implementation detail because apparently they require copying the data out of the &lt;code&gt;CGImage&lt;/code&gt; (but apparently in a way not privy to the thread-safety that other mutations are, like caching scaled &amp; format-converted versions for screen rendering).

I know that Apple recommend just drawing the bitmap image to a bitmap context with known pixel format, rather than using &lt;code&gt;bitmapData&lt;/code&gt;, although I&#039;m not convinced that&#039;s the most efficient way in some cases - I haven&#039;t reverse-engineered or benchmarked it exhaustively, but I do that sometimes in one of my current projects, and it&#039;s slower. 🤔]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://wadetregaskis.com/nsimage-is-dangerous/#comment-3620" data-wpel-link="internal">Thomas</a>.</p>
<p>Ah, thanks for that.  That&#8217;s interesting, as it&#8217;s not correct (or at least no longer), as my post highlighted &#8211; <code>bitmapData</code> is not an &#8220;explicitly mutating method&#8221; neither in name, intuition, nor documentation, yet it is <em>not</em> thread-safe, contrary to what those release notes say.</p>
<p>That section below that, though, is helpful (&#8220;NSBitmapImageRep: CoreGraphics impedance matching and performance notes&#8221;).  It confirms what I&#8217;d suspected based on disassembly and backtraces, that <code>NSBitmapImageRep</code> is <em>usually</em> a thin wrapper over a <code>CGImage</code>.</p>
<p>And I suppose you could try to read between the lines &#8211; taking <em>both</em> those sections in mind &#8211; to deduce that maybe <code>bitmapData</code> et al are in fact mutating as an implementation detail because apparently they require copying the data out of the <code>CGImage</code> (but apparently in a way not privy to the thread-safety that other mutations are, like caching scaled &#038; format-converted versions for screen rendering).</p>
<p>I know that Apple recommend just drawing the bitmap image to a bitmap context with known pixel format, rather than using <code>bitmapData</code>, although I&#8217;m not convinced that&#8217;s the most efficient way in some cases &#8211; I haven&#8217;t reverse-engineered or benchmarked it exhaustively, but I do that sometimes in one of my current projects, and it&#8217;s slower. 🤔</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Thomas		</title>
		<link>https://wadetregaskis.com/nsimage-is-dangerous/#comment-3620</link>

		<dc:creator><![CDATA[Thomas]]></dc:creator>
		<pubDate>Tue, 26 Mar 2024 21:35:11 +0000</pubDate>
		<guid isPermaLink="false">https://wadetregaskis.com/?p=7501#comment-3620</guid>

					<description><![CDATA[You might find this interesting, look for &quot;NSImage: Clarifying the contract for threading&quot; in https://developer.apple.com/library/archive/releasenotes/AppKit/RN-AppKitOlderNotes/index.html]]></description>
			<content:encoded><![CDATA[<p>You might find this interesting, look for &#8220;NSImage: Clarifying the contract for threading&#8221; in <a href="https://developer.apple.com/library/archive/releasenotes/AppKit/RN-AppKitOlderNotes/index.html" rel="nofollow ugc external noopener" data-wpel-link="external" target="_blank">https://developer.apple.com/library/archive/releasenotes/AppKit/RN-AppKitOlderNotes/index.html</a></p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
