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" |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
12 #include "SkCodec.h" | 12 #include "SkCodec.h" |
13 #include "SkColorSpace_Base.h" | 13 #include "SkColorSpace_Base.h" |
| 14 #include "SkColorSpace_XYZTRC.h" |
14 #include "SkCommandLineFlags.h" | 15 #include "SkCommandLineFlags.h" |
15 #include "SkForceLinking.h" | 16 #include "SkForceLinking.h" |
16 #include "SkImageEncoder.h" | 17 #include "SkImageEncoder.h" |
17 #include "SkMatrix44.h" | 18 #include "SkMatrix44.h" |
18 #include "SkOSFile.h" | 19 #include "SkOSFile.h" |
19 | 20 |
20 __SK_FORCE_IMAGE_DECODER_LINKING; | 21 __SK_FORCE_IMAGE_DECODER_LINKING; |
21 | 22 |
22 DEFINE_string(input, "input.png", "A path to the input image."); | 23 DEFINE_string(input, "input.png", "A path to the input image."); |
23 DEFINE_string(output, "output.png", "A path to the output image."); | 24 DEFINE_string(output, "output.png", "A path to the output image."); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 SkBitmap gamut; | 135 SkBitmap gamut; |
135 if (!GetResourceAsBitmap("gamut.png", &gamut)) { | 136 if (!GetResourceAsBitmap("gamut.png", &gamut)) { |
136 SkDebugf("Program failure.\n"); | 137 SkDebugf("Program failure.\n"); |
137 return -1; | 138 return -1; |
138 } | 139 } |
139 SkCanvas canvas(gamut); | 140 SkCanvas canvas(gamut); |
140 | 141 |
141 // Draw the sRGB gamut if requested. | 142 // Draw the sRGB gamut if requested. |
142 if (FLAGS_sRGB) { | 143 if (FLAGS_sRGB) { |
143 sk_sp<SkColorSpace> sRGBSpace = SkColorSpace::NewNamed(SkColorSpace::kSR
GB_Named); | 144 sk_sp<SkColorSpace> sRGBSpace = SkColorSpace::NewNamed(SkColorSpace::kSR
GB_Named); |
144 draw_gamut(&canvas, as_CSB(sRGBSpace)->toXYZD50(), "sRGB", 0xFFFF9394, f
alse); | 145 draw_gamut(&canvas, as_CSXYZ(sRGBSpace)->toXYZD50(), "sRGB", 0xFFFF9394,
false); |
145 } | 146 } |
146 | 147 |
147 // Draw the Adobe RGB gamut if requested. | 148 // Draw the Adobe RGB gamut if requested. |
148 if (FLAGS_adobeRGB) { | 149 if (FLAGS_adobeRGB) { |
149 sk_sp<SkColorSpace> adobeRGBSpace = SkColorSpace::NewNamed(SkColorSpace:
:kAdobeRGB_Named); | 150 sk_sp<SkColorSpace> adobeRGBSpace = SkColorSpace::NewNamed(SkColorSpace:
:kAdobeRGB_Named); |
150 draw_gamut(&canvas, as_CSB(adobeRGBSpace)->toXYZD50(), "Adobe RGB", 0xFF
31a9e1, false); | 151 draw_gamut(&canvas, as_CSXYZ(adobeRGBSpace)->toXYZD50(), "Adobe RGB", 0x
FF31a9e1, false); |
151 } | 152 } |
152 | 153 |
153 // Draw gamut for the input image. | 154 // Draw gamut for the input image. |
154 sk_sp<SkColorSpace> colorSpace = sk_ref_sp(codec->getInfo().colorSpace()); | 155 sk_sp<SkColorSpace> colorSpace = sk_ref_sp(codec->getInfo().colorSpace()); |
155 if (!colorSpace) { | 156 if (!colorSpace) { |
156 SkDebugf("Image had no embedded color space information. Defaulting to
sRGB.\n"); | 157 SkDebugf("Image had no embedded color space information. Defaulting to
sRGB.\n"); |
157 colorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); | 158 colorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
158 } | 159 } |
159 draw_gamut(&canvas, as_CSB(colorSpace)->toXYZD50(), input, 0xFF000000, true)
; | 160 draw_gamut(&canvas, as_CSXYZ(colorSpace)->toXYZD50(), input, 0xFF000000, tru
e); |
160 | 161 |
161 // Finally, encode the result to the output file. | 162 // Finally, encode the result to the output file. |
162 sk_sp<SkData> out(SkImageEncoder::EncodeData(gamut, SkImageEncoder::kPNG_Typ
e, 100)); | 163 sk_sp<SkData> out(SkImageEncoder::EncodeData(gamut, SkImageEncoder::kPNG_Typ
e, 100)); |
163 if (!out) { | 164 if (!out) { |
164 SkDebugf("Failed to encode gamut output.\n"); | 165 SkDebugf("Failed to encode gamut output.\n"); |
165 return -1; | 166 return -1; |
166 } | 167 } |
167 SkFILEWStream stream(output); | 168 SkFILEWStream stream(output); |
168 bool result = stream.write(out->data(), out->size()); | 169 bool result = stream.write(out->data(), out->size()); |
169 if (!result) { | 170 if (!result) { |
(...skipping 22 matching lines...) Expand all Loading... |
192 SkFILEWStream bitmapStream(FLAGS_uncorrected[0]); | 193 SkFILEWStream bitmapStream(FLAGS_uncorrected[0]); |
193 result = bitmapStream.write(out->data(), out->size()); | 194 result = bitmapStream.write(out->data(), out->size()); |
194 if (!result) { | 195 if (!result) { |
195 SkDebugf("Failed to write uncorrected image output.\n"); | 196 SkDebugf("Failed to write uncorrected image output.\n"); |
196 return -1; | 197 return -1; |
197 } | 198 } |
198 } | 199 } |
199 | 200 |
200 return 0; | 201 return 0; |
201 } | 202 } |
OLD | NEW |