Slide 1

Slide 1 text

UNDERSTANDING COLOR @romainguy

Slide 2

Slide 2 text

UNDERSTANDING COLOR @romainguy

Slide 3

Slide 3 text

What is color?

Slide 4

Slide 4 text

A visual perception that can be described by hue, brightness and colorfulness

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

⚛ ☢ ☀ ♨ 10-16 108 wavelength (m)

Slide 7

Slide 7 text

⚛ ☢ ☀ ♨ 10-16 108 wavelength (m) 380 700 nanometers

Slide 8

Slide 8 text

0 1 Short Medium Long

Slide 9

Slide 9 text

0 1

Slide 10

Slide 10 text

×

Slide 11

Slide 11 text

0 1

Slide 12

Slide 12 text

Slide 13

Slide 13 text

☀ ×

Slide 14

Slide 14 text

× ☀ ×

Slide 15

Slide 15 text

× ☀ ×

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

What is color?

Slide 18

Slide 18 text

For developers, a tuple of numbers in a color model with a color space

Slide 19

Slide 19 text

RGB CMYK L*a*b*

Slide 20

Slide 20 text

RGB

Slide 21

Slide 21 text

#ff436d

Slide 22

Slide 22 text

255,67,109

Slide 23

Slide 23 text

1.0,0.26,0.43

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

COLOR SPACE?

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

3 primaries

Slide 29

Slide 29 text

3 primaries white point

Slide 30

Slide 30 text

transfer functions 3 primaries white point

Slide 31

Slide 31 text

sRGB AdobeRGB ProPhotoRGB

Slide 32

Slide 32 text

Transfer functions?

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

sRGB P3 Adobe RGB sRGB

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

What you saw is how Android handles color spaces Colors are unmanaged

Slide 41

Slide 41 text

Source COLOR MANAGEMENT

Slide 42

Slide 42 text

Source Destination COLOR MANAGEMENT

Slide 43

Slide 43 text

New in O! Source Destination COLOR MANAGEMENT

Slide 44

Slide 44 text

Assign Convert

Slide 45

Slide 45 text

When in doubt… sRGB!

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

// ARGB in sRGB @ColorInt int c = 0xfff436d;

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

// Color instance in sRGB
 Color c = Color.valueOf(1.0f, 0.26f, 0.43f);

Slide 53

Slide 53 text

// Color instance in sRGB
 Color c = Color.valueOf(1.0f, 0.26f, 0.43f);

Slide 54

Slide 54 text

// Color instance in sRGB
 Color c = Color.valueOf(1.0f, 0.26f, 0.43f); // Color instance in Adobe RGB
 Color c = Color.valueOf(1.0f, 0.26f, 0.43f, 1.0f,
 ColorSpace.get(ColorSpace.Named.ADOBE_RGB));

Slide 55

Slide 55 text

// Color instance in sRGB
 Color c = Color.valueOf(1.0f, 0.26f, 0.43f); // Color instance in Adobe RGB
 Color c = Color.valueOf(1.0f, 0.26f, 0.43f, 1.0f,
 ColorSpace.get(ColorSpace.Named.ADOBE_RGB));

Slide 56

Slide 56 text

// Color instance in sRGB
 Color c = Color.valueOf(1.0f, 0.26f, 0.43f); // Color instance in Adobe RGB
 Color c = Color.valueOf(1.0f, 0.26f, 0.43f, 1.0f,
 ColorSpace.get(ColorSpace.Named.ADOBE_RGB)); // From Adobe RGB to Display P3
 Color r = c.convert(
 ColorSpace.get(ColorSpace.Named.DISPLAY_P3));

Slide 57

Slide 57 text

// RGBA in Adobe RGB
 @ColorLong long c = Color.pack(1.0f, 0.26f, 0.43f, 1.0f,
 ColorSpace.get(ColorSpace.Named.ADOBE_RGB));

Slide 58

Slide 58 text

Red, 16 bits Green, 16 bits Blue, 16 bits Alpha, 10 bits Colorspace, 6 bits @ColorLong

Slide 59

Slide 59 text

Red, 16 bits Green, 16 bits Blue, 16 bits Alpha, 10 bits Colorspace, 6 bits @ColorLong See android.util.Half

Slide 60

Slide 60 text

ColorSpace cs = ColorSpace.get(ColorSpace.Named.ADOBE_RGB);
 cs.isWideGamut(); // Returns true
 cs.getModel(); // Returns ColorSpace.Model.RGB // Cast to ColorSpace.Rgb to get primaries, white point, etc.

Slide 61

Slide 61 text

// Use connectors for conversions
 ColorSpace.Connector c = ColorSpace.connect(
 ColorSpace.get(ColorSpace.Named.SRGB),
 ColorSpace.get(ColorSpace.Named.ADOBE_RGB)
 );
 float[] adobeRGB = c.transform(1.0f, 0.26f, 0.43f);

Slide 62

Slide 62 text

// Change the white point with chromatic adaptation
 ColorSpace d50 = ColorSpace.adapt(
 ColorSpace.get(ColorSpace.Named.SRGB),
 ColorSpace.ILLUMINANT_D50
 );

Slide 63

Slide 63 text

Bitmap b = BitmapFactory.decodeStream(…);
 ColorSpace cs = b.getColorSpace();
 // Most likely, cs.isSrgb() == true

Slide 64

Slide 64 text

Bitmap b = BitmapFactory.decodeStream(…);
 ColorSpace cs = b.getColorSpace();
 // Most likely, cs.isSrgb() == true Bitmaps are always in the RGB color model

Slide 65

Slide 65 text

BitmapFactory.Options opts = new BitmapFactory.Options();
 // What a silly name opts.inJustDecodeBounds = true;
 
 Bitmap b = BitmapFactory.decodeStream(…, opts);
 ColorSpace cs = opts.outColorSpace;

Slide 66

Slide 66 text

BitmapFactory.Options opts = new BitmapFactory.Options();
 // Convert at load time opts.inPreferredColorSpace =
 ColorSpace.get(ColorSpace.Named.SRGB);
 
 Bitmap b = BitmapFactory.decodeStream(…, opts);

Slide 67

Slide 67 text

BitmapFactory.Options opts = new BitmapFactory.Options();
 // Convert at load time opts.inPreferredColorSpace =
 ColorSpace.get(ColorSpace.Named.SRGB);
 
 Bitmap b = BitmapFactory.decodeStream(…, opts); 16 bit bitmaps are always in linear extended sRGB

Slide 68

Slide 68 text

// Let’s create a wide gamut bitmap Bitmap b = Bitmap.createBitmap(
 1920, 1080,
 Bitmap.Config.ARGB_8888, false,
 ColorSpace.get(ColorSpace.Named.ADOBE_RGB)
 );

Slide 69

Slide 69 text

// sRGB out @ColorInt int c = b.getPixel(0, 0); // sRGB in
 b.setPixel(0, 0, 0xfff436d);

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

// Preserve color space
 ByteBuffer dst = ByteBuffer.allocate(b.getByteCount());
 b.copyPixelsToBuffer(dst);
 dst.rewind();


Slide 72

Slide 72 text

// Preserve color space
 ByteBuffer dst = ByteBuffer.allocate(b.getByteCount());
 b.copyPixelsToBuffer(dst);
 dst.rewind();
 // If the bitmap’s config is RGBA_F16
 // the byte buffer contains half floats
 // See android.util.Half

Slide 73

Slide 73 text

sRGB

Slide 74

Slide 74 text

non-sRGB sRGB

Slide 75

Slide 75 text

[Color Space] [Color space]

Slide 76

Slide 76 text

Slide 77

Slide 77 text

non-sRGB sRGB sRGB No wide gamut support ARGB_8888

Slide 78

Slide 78 text

non-sRGB extended sRGB sRGB Wide gamut support RGBA_F16

Slide 79

Slide 79 text

Extended sRGB? (scRGB)

Slide 80

Slide 80 text

res/*-widecg

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

Configuration c = getResources().getConfiguration();
 c.isScreenWideColorGamut();


Slide 83

Slide 83 text

Configuration c = getResources().getConfiguration();
 c.isScreenWideColorGamut();
 Display d = view.getDisplay();
 d.isWideColorGamut()

Slide 84

Slide 84 text

DON’T PANIC

Slide 85

Slide 85 text

DON’T PANIC —— — — — — — —— —

Slide 86

Slide 86 text

https://goo.gl/aeJc06 Learn more about transfer functions Starts at minute 29 android.graphics.ColorSpace.Rgb

Slide 87

Slide 87 text

https://goo.gl/5w7AQ2 Learn about banding and dithering Starts at minute 36

Slide 88

Slide 88 text

Questions