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

Side by Side Diff: samplecode/SampleUnpremul.cpp

Issue 1812323003: Remove uses of SkImageDecoder from samplecode (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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 | « samplecode/SampleTextBox.cpp ('k') | samplecode/SampleVertices.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 "gm.h" 8 #include "gm.h"
9 9
10 #include "sk_tool_utils.h" 10 #include "sk_tool_utils.h"
11 #include "DecodeFile.h"
11 #include "Resources.h" 12 #include "Resources.h"
12 #include "SampleCode.h" 13 #include "SampleCode.h"
13 #include "SkBlurMask.h" 14 #include "SkBlurMask.h"
14 #include "SkBlurDrawLooper.h" 15 #include "SkBlurDrawLooper.h"
15 #include "SkCanvas.h" 16 #include "SkCanvas.h"
16 #include "SkColorPriv.h" 17 #include "SkColorPriv.h"
17 #include "SkForceLinking.h"
18 #include "SkImageDecoder.h"
19 #include "SkOSFile.h" 18 #include "SkOSFile.h"
20 #include "SkStream.h" 19 #include "SkStream.h"
21 #include "SkString.h" 20 #include "SkString.h"
22 #include "SkSystemEventTypes.h" 21 #include "SkSystemEventTypes.h"
23 #include "SkTypes.h" 22 #include "SkTypes.h"
24 #include "SkUtils.h" 23 #include "SkUtils.h"
25 #include "SkView.h" 24 #include "SkView.h"
26 25
27 __SK_FORCE_IMAGE_DECODER_LINKING;
28
29 /** 26 /**
30 * Interprets c as an unpremultiplied color, and returns the 27 * Interprets c as an unpremultiplied color, and returns the
31 * premultiplied equivalent. 28 * premultiplied equivalent.
32 */ 29 */
33 static SkPMColor premultiply_unpmcolor(SkPMColor c) { 30 static SkPMColor premultiply_unpmcolor(SkPMColor c) {
34 U8CPU a = SkGetPackedA32(c); 31 U8CPU a = SkGetPackedA32(c);
35 U8CPU r = SkGetPackedR32(c); 32 U8CPU r = SkGetPackedR32(c);
36 U8CPU g = SkGetPackedG32(c); 33 U8CPU g = SkGetPackedG32(c);
37 U8CPU b = SkGetPackedB32(c); 34 U8CPU b = SkGetPackedB32(c);
38 return SkPreMultiplyARGB(a, r, g, b); 35 return SkPreMultiplyARGB(a, r, g, b);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 } 157 }
161 fCurrFile = SkOSPath::Join(fResPath.c_str(), basename.c_str()); 158 fCurrFile = SkOSPath::Join(fResPath.c_str(), basename.c_str());
162 this->decodeCurrFile(); 159 this->decodeCurrFile();
163 } 160 }
164 161
165 void decodeCurrFile() { 162 void decodeCurrFile() {
166 if (fCurrFile.size() == 0) { 163 if (fCurrFile.size() == 0) {
167 fDecodeSucceeded = false; 164 fDecodeSucceeded = false;
168 return; 165 return;
169 } 166 }
170 SkFILEStream stream(fCurrFile.c_str()); 167 fDecodeSucceeded = decode_file(fCurrFile.c_str(), &fBitmap, kN32_SkColor Type, !fPremul);
171 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(&stream));
172 if (nullptr == decoder.get()) {
173 fDecodeSucceeded = false;
174 return;
175 }
176 if (!fPremul) {
177 decoder->setRequireUnpremultipliedColors(true);
178 }
179 fDecodeSucceeded = decoder->decode(&stream, &fBitmap, kN32_SkColorType,
180 SkImageDecoder::kDecodePixels_Mode) != SkImageDecoder::kFailure;
181 this->inval(nullptr); 168 this->inval(nullptr);
182 } 169 }
183 170
184 void togglePremul() { 171 void togglePremul() {
185 fPremul = !fPremul; 172 fPremul = !fPremul;
186 this->decodeCurrFile(); 173 this->decodeCurrFile();
187 } 174 }
188 175
189 typedef SampleView INHERITED; 176 typedef SampleView INHERITED;
190 }; 177 };
191 178
192 ////////////////////////////////////////////////////////////////////////////// 179 //////////////////////////////////////////////////////////////////////////////
193 180
194 static SkView* MyFactory() { 181 static SkView* MyFactory() {
195 return new UnpremulView(GetResourcePath()); 182 return new UnpremulView(GetResourcePath());
196 } 183 }
197 static SkViewRegister reg(MyFactory); 184 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleTextBox.cpp ('k') | samplecode/SampleVertices.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698