<?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:media="http://search.yahoo.com/mrss/"><channel><title>Wide Color – IMG.LY Blog</title><description>Posts tagged Wide Color on the IMG.LY blog.</description><link>https://img.ly/blog/tag/wide-color/</link><language>en-us</language><image><url>https://img.ly/apple-touch-icon.png</url><title>Wide Color – IMG.LY Blog</title><link>https://img.ly/blog/tag/wide-color/</link></image><atom:link href="https://img.ly/blog/tag/wide-color/rss.xml" rel="self" type="application/rss+xml"/><generator>Astro</generator><lastBuildDate>Wed, 14 Oct 2026 14:42:51 GMT</lastBuildDate><ttl>60</ttl><item><title>Bringing Wide Color to PhotoEditor SDK</title><link>https://img.ly/blog/bringing-wide-color-to-photoeditor-sdk-a6ce8bb19ef7/</link><guid isPermaLink="true">https://img.ly/blog/bringing-wide-color-to-photoeditor-sdk-a6ce8bb19ef7/</guid><pubDate>Tue, 10 Jan 2017 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Inspired by &lt;a href=&quot;https://medium.com/@mikekrieger&quot;&gt;Mike Krieger&lt;/a&gt;’s &lt;a href=&quot;https://instagram-engineering.com/bringing-wide-color-to-instagram-5a5481802d7d#.2gjnzpdeb&quot;&gt;great post&lt;/a&gt; on supporting wide color images in Instagram, I decided to challenge myself by introducing the same wide color support into our &lt;a href=&quot;https://img.ly/products/photo-sdk/&quot;&gt;PhotoEditor SDK&lt;/a&gt; within a day.&lt;/p&gt;
&lt;p&gt;Mike did an excellent job describing everything that is needed to support wide color images so I am not going to reiterate his explanation. Instead, here I’m going to share two findings I made in the process.&lt;/p&gt;
&lt;h2 id=&quot;image-export&quot;&gt;Image Export&lt;/h2&gt;
&lt;p&gt;Mike suggests that in order to preserve the color space while converting an &lt;code&gt;UIImage&lt;/code&gt; into a JPEG, the &lt;code&gt;UIImageJPEGRepresentation(_:_:)&lt;/code&gt; method has to be replaced with the new &lt;code&gt;UIGraphicsImageRenderer.jpegData(withCompressionQuality:actions:)&lt;/code&gt; method. Checking the color profile of the generated JPEG by &lt;code&gt;UIImageJPEGRepresentation(_:)&lt;/code&gt; I noticed that it seemed unnecessary and resulting in more work than needed. To verify this, I started &lt;a href=&quot;https://www.hopperapp.com&quot;&gt;Hopper&lt;/a&gt; and took a look at the internals of the new method. Here’s what it basically does:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;It passes &lt;code&gt;actions&lt;/code&gt; to &lt;code&gt;UIGraphicsRenderer.runDrawingActions(_:completionActions:)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;It obtains the resulting image using &lt;code&gt;UIGraphicsImageRendererContext.currentImage&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;It passes that image to &lt;code&gt;UIImageJPEGRepresentation(_:_:)&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;As you can see, it makes use of &lt;code&gt;UIImageJPEGRepresentation(_:_:)&lt;/code&gt; internally too, so there really is no need to go the extra mile. If you are actually doing any drawing within the &lt;code&gt;actions&lt;/code&gt; block using wide color &lt;code&gt;UIColor&lt;/code&gt;s it absolutely makes sense to use Mike’s apoproach. But if you only want to convert an &lt;code&gt;UIImage&lt;/code&gt; into a JPEG image, using the old method is far easier.&lt;/p&gt;
&lt;h2 id=&quot;core-image&quot;&gt;Core Image&lt;/h2&gt;
&lt;p&gt;We are using &lt;code&gt;CIImage&lt;/code&gt;, &lt;code&gt;CIFilter&lt;/code&gt; and &lt;code&gt;CIContext&lt;/code&gt; for most of our processing. In our live preview we use a &lt;code&gt;CIContext&lt;/code&gt; to directly render a &lt;code&gt;CIImage&lt;/code&gt; into a &lt;code&gt;GLKView&lt;/code&gt; and I’ve run into exactly the same problem as Mike has, namely not being able to get that view to be color space-aware. Using the offscreen buffer workaround that he suggested was going to be too much work though and also I didn’t want to sacrifice any performance.&lt;/p&gt;
&lt;p&gt;After doing some research and digging further into the GLKit and Core Image assembly I found a nice solution. It looks like in order to render wide color images into OpenGL, OpenGLES 3 and a &lt;code&gt;GLKViewDrawableColorFormat&lt;/code&gt; (that is currently not defined as an &lt;code&gt;enum&lt;/code&gt; case) has to be used. The following code works like a charm for me:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;let api: EAGLRenderingAPI&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;let colorFormat: GLKViewDrawableColorFormat&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;if #available(iOS 10.0, *) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  if UIScreen.main.traitCollection.displayGamut == .P3 {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    api = .openGLES3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    colorFormat = GLKViewDrawableColorFormat(rawValue: 10)!&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  } else {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    api = .openGLES2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    colorFormat = .RGBA8888&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;} else {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  api = .openGLES2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  colorFormat = .RGBA8888&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;let context = EAGLContext(api: api)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;let previewView = GLKView(frame: CGRect.zero, context: context!)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;previewView.delegate = self&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;previewView.drawableColorFormat = colorFormat&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This code creates a &lt;code&gt;GLKView&lt;/code&gt; that is backed by a &lt;code&gt;CAEAGLLayer&lt;/code&gt; with the following &lt;code&gt;drawableProperties&lt;/code&gt; set:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; &quot;EAGLDrawablePropertyRetained&quot;: 0,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; &quot;EAGLDrawablePropertyColorFormat&quot;: EAGLColorFormatRGBA_XR10_64BPP&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Unfortunately &lt;code&gt;EAGLColorFormatRGBA_XR10_64BPP&lt;/code&gt; also doesn’t seem to be documented at this point, but my guess is that setting this color format on Instagram’s &lt;code&gt;EAGLView&lt;/code&gt; would also solve their problem of making the view color space-aware.&lt;/p&gt;
&lt;p&gt;Thanks to Core Image we can just switch to OpenGLES 3 without having to do any other modifications to our code. However, I am currently not sure if this is considered a private API use. I would greatly appreciate if anyone could shed some light on this.&lt;/p&gt;
&lt;p&gt;I have not yet been able to test this on any device other than the iPhone 7 Plus, but I will update this post if I run into any problems with future tests.&lt;/p&gt;
&lt;h2 id=&quot;final-thoughts&quot;&gt;Final Thoughts&lt;/h2&gt;
&lt;p&gt;Getting an app to support wide color images is definitely worth it and not as difficult as I had imagined. Unfortunately, it currently looks like iOS is still missing (public) support for wide color in some parts of its frameworks. I hope that Apple addresses these problems soon. Nevertheless we’re optimistic that we’ll be able to include wide color image support in the next release of our SDK. Feel free to check out our &lt;a href=&quot;https://apps.apple.com/de/app/img-ly-camera-pro-photo-sharing/id589839231&quot;&gt;demo app&lt;/a&gt; in the App Store which we will update as soon as possible.&lt;/p&gt;</content:encoded><dc:creator>Sascha</dc:creator><media:content url="https://blog.img.ly/2020/03/1-VF6BW_zDoIaklWdM3u98Tw.jpeg" medium="image"/><category>iOS</category><category>Swift</category><category>Instagram</category><category>Wide Color</category><category>Core Image</category><category>Tech</category><category>How-To</category><category>Insights</category></item></channel></rss>