Xcode & wide gamut images - ios

Some related questions around Display P3 (wide gamut) image handing:
Is there a file name convention for wide gamut images, like there was for retina (#2x, #3x)?
Is there a way to add wide gamut versions to xcassets?
If we have have sRGB MyPic.png in our Xcode project, how do we use UIImage to load a P3 version?
Or...
Should we simply replace our sRGB images with Display P3 images, and let older sRGB-based devices do their best to display them?

The answers, from Apple, are here: https://developer.apple.com/videos/play/wwdc2016/712/ with PDF here: http://devstreaming.apple.com/videos/wwdc/2016/712ugi7vg8jznn3pc3u/712/712_working_with_wide_color.pdf
Some notes:
Photoshop:
Use Convert to Profile to convert to Display P3 profile
Don't use Assign Profile
Save for Web doesn't work with wide color.
Use Save As -> PNG from 16-bit source doc
Export assets as 16bit PNG files with embedded “Display P3” ICC profile
Xcode:
16-bit PNGs can be dragged into XCAssets.
Xcode will auto-generate the 8-bit sRGB derivative (or you can supply it yourself)
UIImage will automatically load the correct image for your device's display.
App Slicing will cause only the correct images to be included in your app when downloading to a device.
Way more info in that WWDC session.
Naming:
There's no standard I could find, though Webkit's page of examples uses "-P3", e.g. "MyPic-P3.png". This'd be a useful convention if you want both types of file on a server.

Related

Xcode 9 renders P3 PDF assets into SRGB

I've spent hours in trying to figure this one out.
Goal
Display P3 PDF Asset in UIImageView (the PDF is 100% in P3 Color Space).
Issue
I'm creating a P3 PDF asset and adding into the Xcode. Within the Asset Catalog, the asset appears in the correct P3 color. When using the asset inside UIImageView and running on iPhone X ( physical device, supports P3 Color Space ), the asset showing is SRGB instead of P3.
Does anyone has information on how to resolve this issue?
Any help will be highly appreciated.
Roi
Use PNG directly
You mention you suspect there is a PNG inside the PDF. I would recommend to use PNG directly without a wrapping PDF.
PDFs are rendered by Apple to PNG when they are deployed on a device. This rendering may apply a specific color profile (PDF and color management is a broad topic).
Also the rendering itself might not produce the results you are expecting, see e.g. https://bjango.com/articles/idontusepdfs/
16 bits per pixel (per channel)
Apple's Human Interface Guidelines state one has to use 16 bits per pixel and export images in .png format.
When appropriate, use the Display P3 color profile at 16 bits per pixel (per channel) and export images in .png format.
see here: https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/color/#color-management
Finally, I'd like to mention just two more settings that you are probably already using:
Compression
In the attributes inspector for image assets you should choose 'Lossless'.
Gamut
Swicht Gamut to 'sRGB and Display P3' and then make sure your image is in a 'Display P3' slot in the .xcasset file.
Test with PNG export of Sketch
Taking a look at the chromaticity diagram, one can see that the P3 color space has a larger gamut for greenish colors.
Since I am not sure whether I can recognize the difference between the two color spaces, I have made the following experiment:
inserted a artboard in Sketch
created a green rectangle with the color #00FF00
assigned under <File/Change Color Profile> the Display P3 color profile
selected the rectangle and clicked Exported selected
have chosen .png without interlacing
Then I did the very same but with sRGB ICE61966-2.1 profile.
I checked both .pngs in the ColorSync utility (can be found under /Applications/Utilities). Pressing the image info toolbar button one can see, that the correct ColorSync profiles are assigned.
In Affinity Photo I checked under <Document/Colour Format> the number of bits per channel. It was for both .pngs 8bit per channel, so I created two additional .pngs with 16bits per channel and named it accordingly.
Then I added the 4 .pngs to a .xcassets folder with the following settings:
Compression: 'Lossless'
Scale: 'Single Scale'
Gamut: 'sRGB and Display P3'
assigned the .pngs accordingly to the correct slot (either sRGP or Display P3).
Then I deployed to iPhone X.
Result: Actually I can see a difference between the green rectangles. The 'Display P3' do have indeed a more saturated green.
I exported the same thing to an old iPhone, where I can't spot any differences between the sRGB and Display P3 images.
I found it interesting that the 8-bit variant directly from Sketch also works, so 16 bits per channel doesn't seem to be a hard requirement.
Did you select the gamut setting for your asset?
How did you verifiy that the image is in SRGB on the iPhone X?
Maybe the WWDC16 talk is somethink to check again:
talk slides

jpg or png for user profile pictures?

My app requires that each user has a profile picture of around 140*140px. Right now I am using jpgs, I am wondering if performance wise it will be better to use pngs. I read pngs are good for small UI elements and images, jpg for large images with detail such as photos. Obviously my profile pics are photos but they are small. Would it make much difference switching to png? Thanks
JPEG is best for small file sizes of photos, even for low resolutions.
PNG makes sense when there are many pixels of the exact same color next to each other. This is not the case with photos.
These should be helpful for you.
When to use PNG or JPG in iPhone development?
PNG vs. GIF vs. JPEG vs. SVG - When best to use?
Apple optimizes PNG images that are included in your iPhone app bundle. In fact, the iPhone uses a special encoding in which the color bytes are optimized for the hardware. XCode handles this special encoding for you when you build your project. So, you do see additional benefits to using PNG's on an iPhone other than their size consideration. For this reason it is definitely recommended to use PNG's for any images that appear as part of the interface (in a table view, labels, etc).
As for displaying a full screen image such as a photograph you may still reap benefits with PNG's since they are non-lossy and the visual quality should be better than a JPG not to mention resource usage with decoding the image. You may need to decrease the quality of your JPG's in order to see a real benefit in file size but then you are displaying non-optimal images.
File size is certainly a factor but there are other considerations at play as well when choosing an image format.

Xcode generates png form pdf with different colors

We are following article to use pdf vector resources in iOS project: http://martiancraft.com/blog/2014/09/vector-images-xcode6/
However we faced problems. If we set color in Photoshop/Illustrator to #039AF0 then exported pdf will generate png with #1185ec color.
If we use old png way then colors are fine (please ignore pixelized image, the most important is color):
What can be the cause?
When a new artboard is created in Illustrator it defaults to using Adobe RGB for the color space which doesn't work well with iOS. To make sure the colors remain as close to the original as possible, set the color space to sRGB by selecting "Web" for Profile and RGB for Color Mode under Advanced.
This works well for new artboards. I have an Illustrator file as a deliverable that was created in Adobe RGB. For such cases, I've resorted to copy pasting vector paths on a new artboard that's set to sRGB before saving as PDF for use in Xcode 6.
I got the same problem, and finally I found that set the deployment Target to 7.0 or above solves the problem.
It is possible that Photoshop/Illustrator generates CMYK or other special colors in the PDF file and Xcode uses the PDF rendering engine that is implemented in iOS to convert the PDF files to PNG.
Because the iOS has problems with displaying CMYK colors, your PNG image has distorted colors.
The above is only an assumption because I have not seen a sample PDF file and the process used by Xcode to convert the PDF to PNG is not documented.

images.xcassets size is too large

I am using xcode 6.0.1 and after setting all App Icons and Default Images my app size is jumped by 13 MB.
My App support iOS 5.1.1 and Later. Using Vector image don't support iOS 5.1.1 and iOS 6.x, I am not sure what i can do to reduce the build size.
Check list that might help you
->The first step is to look at your .app bundle and see what files inside it are taking up the most space.Before trying any optimizations, you should measure. This will tell you what to focus on improving.
->Use 8-bit Images Where Possible
Using an 8-bit PNG format where applicable can decrease your image size by a factor of 4 in comparison with 32-bit images. 8-bit images support a maximum of 256 different colors, so they should only be used images which use a small set of colors.
->Use High Compression for 32 bit Images Where Possible
Using Adobe Photoshop’s “Save For Web” feature can reduce the size of JPEG and PNG images considerably. By default, .png images will be compressed with pngcrush by Xcode automatically when the app is built.
->Check Your App, Usually apps contain extra files, like headers or a readme, that are never used.Be sure that you aren’t including any resources that aren’t used in your current project.
->Make sure dead code (code which is defined but never called) is stripped. Check that build setting DEAD_CODE_STRIPPING=YES.(Under your target build settings, then under "Linking" there is an option for "Dead Code Stripping". It defaults to yes for projects created with Xcode.
)
->What type of sounds files are you using? .caf files are incredibly large. As a general rule, you should compress audio using AAC or MP3, and experiment with a reduced bitrate. Quite often a 44.1khz sample is overkill and a lower-bitrate clip won't have a perceptible drop in quality.
->If you do not need to support iOS devices running all iOS versions.Specifying architecture/s to which the binary is TARGETED. This eliminates other architectures and reduces some size.
->Strip the binary of debugging and internal symbols (build settings STRIP_LINKED_PRODUCT=YES, STRIP_STYLE=all, DEPLOYMENT_POSTPROCESSING = YES).
->"Slender" tool will let you know the unused graphics in your app.
http://itunes.apple.com/us/app/slender/id493656257?mt=12
P.S. Before you make changes refer below source once.
Source:https://developer.apple.com/library/mac/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html
and https://developer.apple.com/library/ios/qa/qa1795/_index.html#//apple_ref/doc/uid/DTS40014195-CH1-MEASURE
I observed that when we drag and drop images in Assets folder, the system creates copy of them if you specified the image set to be Device Specific. E.g: If you specified an image "A" for iPhone and same image for iPad (individually), the system will maintain two copies of "A" rather pointing to one same image. In this way the size keeps on increasing because of duplicate images. Check for that also.
images.xcassets size is depends on the image size.Try to reduce the image size if you want to reduce the app size.You can un Zip the ipa file and check which component have larger size.Try to use png images instead of jpeg if used.

App icon displays a black square.

I am having my app icon be displayed as a black square instead of the intended image.
I have placed all of my AppIcons into the folder, Im wondering what could be causing this.
Your image needs to be an opaque PNG. No transparency or anything, as well as being the correct size.
If it already is that, try opening it in Preview and re-saving it as a PNG. That way OS X 'generated' it and it should be compatible. If that helps fix the issue, then your image editing program is saving in the wrong format...see info below.
Apple has this to say on generating PNGs:
For all images and icons, the PNG format is recommended. You should avoid using interlaced PNGs.
The standard bit depth for icons and images is 24 bits—that is, 8 bits each for red, green, and blue—plus an 8-bit alpha channel.
I have had this happen when the app is listed as a .png file, but the system is recognizing it as a .jpg or some other type ... find your icon in "finder" and open it with preview, go to the file menu select "export as" and make sure you choose PNG as the save format. Delete the old version in the application, delete the derived data, clean your project, and rebuild the application.

Resources