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

Side by Side Diff: samplecode/DecodeFile.h

Issue 2206633004: Move off SK_SUPPORT_LEGACY_DATA_FACTORIES. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Gotta catch 'em all. Created 4 years, 4 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
OLDNEW
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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkCodec.h" 9 #include "SkCodec.h"
10 #include "SkData.h" 10 #include "SkData.h"
11 11
12 inline bool decode_file(const char* filename, SkBitmap* bitmap, 12 inline bool decode_file(const char* filename, SkBitmap* bitmap,
13 SkColorType colorType = kN32_SkColorType, bool requireUnpremul = false) { 13 SkColorType colorType = kN32_SkColorType, bool requireUnpremul = false) {
14 SkASSERT(kIndex_8_SkColorType != colorType); 14 SkASSERT(kIndex_8_SkColorType != colorType);
15 SkAutoTUnref<SkData> data(SkData::NewFromFileName(filename)); 15 sk_sp<SkData> data(SkData::MakeFromFileName(filename));
16 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data)); 16 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data.get()));
17 if (!codec) { 17 if (!codec) {
18 return false; 18 return false;
19 } 19 }
20 20
21 SkImageInfo info = codec->getInfo().makeColorType(colorType); 21 SkImageInfo info = codec->getInfo().makeColorType(colorType);
22 if (requireUnpremul && kPremul_SkAlphaType == info.alphaType()) { 22 if (requireUnpremul && kPremul_SkAlphaType == info.alphaType()) {
23 info = info.makeAlphaType(kUnpremul_SkAlphaType); 23 info = info.makeAlphaType(kUnpremul_SkAlphaType);
24 } 24 }
25 25
26 if (!bitmap->tryAllocPixels(info)) { 26 if (!bitmap->tryAllocPixels(info)) {
27 return false; 27 return false;
28 } 28 }
29 29
30 return SkCodec::kSuccess == codec->getPixels(info, bitmap->getPixels(), bitm ap->rowBytes()); 30 return SkCodec::kSuccess == codec->getPixels(info, bitmap->getPixels(), bitm ap->rowBytes());
31 } 31 }
OLDNEW
« include/core/SkData.h ('K') | « public.bzl ('k') | samplecode/SampleLua.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698