| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "Resources.h" | 8 #include "Resources.h" |
| 9 | 9 |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 DEFINE_bool(adobeRGB, false, "Draws the Adobe RGB gamut."); | 25 DEFINE_bool(adobeRGB, false, "Draws the Adobe RGB gamut."); |
| 26 DEFINE_string(uncorrected, "", "A path to reencode the uncorrected input image."
); | 26 DEFINE_string(uncorrected, "", "A path to reencode the uncorrected input image."
); |
| 27 | 27 |
| 28 /** | 28 /** |
| 29 * Loads the triangular gamut as a set of three points. | 29 * Loads the triangular gamut as a set of three points. |
| 30 */ | 30 */ |
| 31 static void load_gamut(SkPoint rgb[], const SkMatrix44& xyz) { | 31 static void load_gamut(SkPoint rgb[], const SkMatrix44& xyz) { |
| 32 // rx = rX / (rX + rY + rZ) | 32 // rx = rX / (rX + rY + rZ) |
| 33 // ry = rX / (rX + rY + rZ) | 33 // ry = rX / (rX + rY + rZ) |
| 34 // gx, gy, bx, and gy are calulcated similarly. | 34 // gx, gy, bx, and gy are calulcated similarly. |
| 35 float rSum = xyz.get(0, 0) + xyz.get(0, 1) + xyz.get(0, 2); | 35 float rSum = xyz.get(0, 0) + xyz.get(1, 0) + xyz.get(2, 0); |
| 36 float gSum = xyz.get(1, 0) + xyz.get(1, 1) + xyz.get(1, 2); | 36 float gSum = xyz.get(0, 1) + xyz.get(1, 1) + xyz.get(2, 1); |
| 37 float bSum = xyz.get(2, 0) + xyz.get(2, 1) + xyz.get(2, 2); | 37 float bSum = xyz.get(0, 2) + xyz.get(1, 2) + xyz.get(2, 2); |
| 38 rgb[0].fX = xyz.get(0, 0) / rSum; | 38 rgb[0].fX = xyz.get(0, 0) / rSum; |
| 39 rgb[0].fY = xyz.get(0, 1) / rSum; | 39 rgb[0].fY = xyz.get(1, 0) / rSum; |
| 40 rgb[1].fX = xyz.get(1, 0) / gSum; | 40 rgb[1].fX = xyz.get(0, 1) / gSum; |
| 41 rgb[1].fY = xyz.get(1, 1) / gSum; | 41 rgb[1].fY = xyz.get(1, 1) / gSum; |
| 42 rgb[2].fX = xyz.get(2, 0) / bSum; | 42 rgb[2].fX = xyz.get(0, 2) / bSum; |
| 43 rgb[2].fY = xyz.get(2, 1) / bSum; | 43 rgb[2].fY = xyz.get(1, 2) / bSum; |
| 44 } | 44 } |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * Calculates the area of the triangular gamut. | 47 * Calculates the area of the triangular gamut. |
| 48 */ | 48 */ |
| 49 static float calculate_area(SkPoint abc[]) { | 49 static float calculate_area(SkPoint abc[]) { |
| 50 SkPoint a = abc[0]; | 50 SkPoint a = abc[0]; |
| 51 SkPoint b = abc[1]; | 51 SkPoint b = abc[1]; |
| 52 SkPoint c = abc[2]; | 52 SkPoint c = abc[2]; |
| 53 return 0.5f * SkTAbs(a.fX*b.fY + b.fX*c.fY - a.fX*c.fY - c.fX*b.fY - b.fX*a.
fY); | 53 return 0.5f * SkTAbs(a.fX*b.fY + b.fX*c.fY - a.fX*c.fY - c.fX*b.fY - b.fX*a.
fY); |
| 54 } | 54 } |
| 55 | 55 |
| 56 static void draw_gamut(SkCanvas* canvas, const SkMatrix44& xyz, const char* name
, SkColor color, | 56 static void draw_gamut(SkCanvas* canvas, const SkMatrix44& xyz, const char* name
, SkColor color, |
| 57 bool label) { | 57 bool label) { |
| 58 // Report the XYZ values. | 58 // Report the XYZ values. |
| 59 SkDebugf("%s\n", name); | 59 SkDebugf("%s\n", name); |
| 60 SkDebugf(" X Y Z\n"); | 60 SkDebugf(" R G B\n"); |
| 61 SkDebugf("Red %.3f %.3f %.3f\n", xyz.get(0, 0), xyz.get(0, 1), xyz.get(0,
2)); | 61 SkDebugf("X %.3f %.3f %.3f\n", xyz.get(0, 0), xyz.get(0, 1), xyz.get(0, 2))
; |
| 62 SkDebugf("Green %.3f %.3f %.3f\n", xyz.get(1, 0), xyz.get(1, 1), xyz.get(1,
2)); | 62 SkDebugf("Y %.3f %.3f %.3f\n", xyz.get(1, 0), xyz.get(1, 1), xyz.get(1, 2))
; |
| 63 SkDebugf("Blue %.3f %.3f %.3f\n", xyz.get(2, 0), xyz.get(2, 1), xyz.get(2,
2)); | 63 SkDebugf("Z %.3f %.3f %.3f\n", xyz.get(2, 0), xyz.get(2, 1), xyz.get(2, 2))
; |
| 64 | 64 |
| 65 // Calculate the points in the gamut from the XYZ values. | 65 // Calculate the points in the gamut from the XYZ values. |
| 66 SkPoint rgb[4]; | 66 SkPoint rgb[4]; |
| 67 load_gamut(rgb, xyz); | 67 load_gamut(rgb, xyz); |
| 68 | 68 |
| 69 // Report the area of the gamut. | 69 // Report the area of the gamut. |
| 70 SkDebugf("Area of Gamut: %.3f\n\n", calculate_area(rgb)); | 70 SkDebugf("Area of Gamut: %.3f\n\n", calculate_area(rgb)); |
| 71 | 71 |
| 72 // Magic constants that help us place the gamut triangles in the appropriate
position | 72 // Magic constants that help us place the gamut triangles in the appropriate
position |
| 73 // on the canvas. | 73 // on the canvas. |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 SkFILEWStream bitmapStream(FLAGS_uncorrected[0]); | 192 SkFILEWStream bitmapStream(FLAGS_uncorrected[0]); |
| 193 result = bitmapStream.write(out->data(), out->size()); | 193 result = bitmapStream.write(out->data(), out->size()); |
| 194 if (!result) { | 194 if (!result) { |
| 195 SkDebugf("Failed to write uncorrected image output.\n"); | 195 SkDebugf("Failed to write uncorrected image output.\n"); |
| 196 return -1; | 196 return -1; |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 | 199 |
| 200 return 0; | 200 return 0; |
| 201 } | 201 } |
| OLD | NEW |