Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: gm/colorspace.cpp

Issue 1707033002: parse icc profiles Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | resources/Lower_Left.jpg » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Intel Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "gm.h"
9 #include "Resources.h"
10 #include "SkImage.h"
11 #include "SkData.h"
12 #include "SkColorSpace.h"
13
14 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
15
16 #ifdef SK_BUILD_FOR_MAC
17 #include <ApplicationServices/ApplicationServices.h>
18 #endif
19
20 #ifdef SK_BUILD_FOR_IOS
21 #include <CoreGraphics/CoreGraphics.h>
22 #endif
23
24 static void release_data(void* info, const void*, size_t len) {
25 SkData* data = (SkData*)info;
26 SkASSERT(data->size() == len);
27 data->unref();
28 }
29
30 static SkColorSpace* extract_cs(SkImage* img) {
31 SkData* data = img->refEncoded();
32 if (!data) {
33 return nullptr;
34 }
35
36 CGDataProviderRef provider = CGDataProviderCreateWithData(data, data->data() , data->size(),
37 release_data);
38 CGImageRef cgimg = CGImageCreateWithJPEGDataProvider(provider, nullptr, fals e,
39 kCGRenderingIntentDefau lt);
40 CFDataRef cfdata = CGColorSpaceCopyICCProfile(CGImageGetColorSpace(cgimg));
41
42 SkColorSpace* cs = SkColorSpace::NewICCProfile(CFDataGetBytePtr(cfdata),
43 CFDataGetLength(cfdata));
44
45 CFRelease(cfdata);
46 CGImageRelease(cgimg);
47 CGDataProviderRelease(provider);
48 return cs;
49 }
50 #else
51 static SkColorSpace* extract_cs(SkImage* img) { return nullptr; }
52 #endif
53
54 // test images from http://www.color.org/version4html.xalter
55 //
56 DEF_SIMPLE_GM(colorspace, canvas, 570, 440) {
57 SkImage* image[] = {
58 GetResourceAsImage("Upper_Left.jpg"),
59 GetResourceAsImage("Upper_Right.jpg"),
60 GetResourceAsImage("Lower_Left.jpg"),
61 GetResourceAsImage("Lower_Right.jpg"),
62 };
63
64 canvas->translate(10, 10);
65
66 const SkScalar w = SkIntToScalar(image[0]->width());
67 const SkScalar h = SkIntToScalar(image[0]->height());
68
69 canvas->drawImage(image[0], 0, 0, nullptr);
70 canvas->drawImage(image[1], w, 0, nullptr);
71 canvas->drawImage(image[2], 0, h, nullptr);
72 canvas->drawImage(image[3], w, h, nullptr);
73
74 SkAutoTUnref<SkColorSpace> dev(SkColorSpace::NewNamed(SkColorSpace::kSRGB_Na med));
75
76 for (auto img : image) {
77 SkAutoTUnref<SkColorSpace> cs(extract_cs(img));
78 if (cs) {
79 enum Result {
80 kFailure_Result,
81 kIdentity_Result,
82 kNormal_Result,
83 };
84
85 SkFloat3x3 matrix;
86 SkColorSpace::Result res = SkColorSpace::Concat(cs, dev, &matrix);
87 SkDebugf("result[%d] ", res);
88 matrix.dump();
89 }
90 img->unref();
91 }
92 }
OLDNEW
« no previous file with comments | « no previous file | resources/Lower_Left.jpg » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698