18.7 · Thumbnails and orientation, GIF timing, bitmap layout, and colour spaces

Image bugs are usually metadata and arithmetic bugs: a rotation tag nobody applied, a delay nobody clamped, a row that is padded, a colour converted without room for out-of-range values.

Mental model. An image is pixels plus a description of how to read them: orientation, timing and colour space. Lose the description and the pixels are still there but wrong.

ImageIO

Thumbnail options and the orientation tag, and animated-image timing.

  1. Which ImageIO thumbnail options matter, and why does a thumbnail come out sideways or at the wrong size? 18.7.1 · L3
    CGImageSourceCreateThumbnailAtIndex decodes straight to a reduced size without ever building the full bitmap (the point of Q327’s downsampling pipeline). The…
  2. How are animated image frames and delays stored, and what happens to a zero or tiny frame delay? 18.7.2 · L3
    An animated GIF (or APNG, or HEICS) is one CGImageSource with several indexes: CGImageSourceGetCount gives the frame count, each frame is decoded with…

Core Graphics

Bitmap memory layout, premultiplied alpha and colour-space conversion.

  1. How much memory does a bitmap use, why is bytesPerRow not width × 4, and what is premultiplied alpha? 18.7.3 · L5
    A CGContext bitmap costs bytesPerRow × height. Pass bytesPerRow: 0 and Core Graphics chooses it, rounding each row up for alignment: in the check a…
  2. What happens when you convert between sRGB, Display P3 and linear spaces, and why can a component be above 1 or below 0? 18.7.4 · L5
    A colour is numbers plus a colour space. Display P3 has a wider gamut than sRGB, so pure P3 red is more saturated than anything sRGB can name. Converting it to…

More in Media & graphics