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

Side by Side Diff: samplecode/DecodeFile.h

Issue 2333713002: change SkStreams to work with sk_sp<SkData> instead of SkData* (Closed)
Patch Set: fix xpsdevice Created 4 years, 3 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 | « public.bzl ('k') | src/android/SkBitmapRegionDecoder.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 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 #include "SkImage.h" 11 #include "SkImage.h"
12 12
13 static inline bool decode_file(const char* filename, SkBitmap* bitmap, 13 static inline bool decode_file(const char* filename, SkBitmap* bitmap,
14 SkColorType colorType = kN32_SkColorType, 14 SkColorType colorType = kN32_SkColorType,
15 bool requireUnpremul = false) { 15 bool requireUnpremul = false) {
16 SkASSERT(kIndex_8_SkColorType != colorType); 16 SkASSERT(kIndex_8_SkColorType != colorType);
17 sk_sp<SkData> data(SkData::MakeFromFileName(filename)); 17 sk_sp<SkData> data(SkData::MakeFromFileName(filename));
18 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data.get())); 18 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data));
19 if (!codec) { 19 if (!codec) {
20 return false; 20 return false;
21 } 21 }
22 22
23 SkImageInfo info = codec->getInfo().makeColorType(colorType); 23 SkImageInfo info = codec->getInfo().makeColorType(colorType);
24 if (requireUnpremul && kPremul_SkAlphaType == info.alphaType()) { 24 if (requireUnpremul && kPremul_SkAlphaType == info.alphaType()) {
25 info = info.makeAlphaType(kUnpremul_SkAlphaType); 25 info = info.makeAlphaType(kUnpremul_SkAlphaType);
26 } 26 }
27 27
28 if (!bitmap->tryAllocPixels(info)) { 28 if (!bitmap->tryAllocPixels(info)) {
29 return false; 29 return false;
30 } 30 }
31 31
32 return SkCodec::kSuccess == codec->getPixels(info, bitmap->getPixels(), bitm ap->rowBytes()); 32 return SkCodec::kSuccess == codec->getPixels(info, bitmap->getPixels(), bitm ap->rowBytes());
33 } 33 }
34 34
35 static inline sk_sp<SkImage> decode_file(const char filename[]) { 35 static inline sk_sp<SkImage> decode_file(const char filename[]) {
36 sk_sp<SkData> data(SkData::MakeFromFileName(filename)); 36 sk_sp<SkData> data(SkData::MakeFromFileName(filename));
37 return data ? SkImage::MakeFromEncoded(data) : nullptr; 37 return data ? SkImage::MakeFromEncoded(data) : nullptr;
38 } 38 }
OLDNEW
« no previous file with comments | « public.bzl ('k') | src/android/SkBitmapRegionDecoder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698