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

Side by Side Diff: src/ports/SkImageGenerator_skia.cpp

Issue 919693002: Make SkImageGenerator::getPixels() return an enum. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Stage the change for chromium Created 5 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 | « src/lazy/SkDiscardablePixelRef.cpp ('k') | tests/CachedDecodingPixelRefTest.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 2015 The Android Open Source Project 2 * Copyright 2015 The Android Open Source Project
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 "SkData.h" 8 #include "SkData.h"
9 #include "SkImageDecoder.h" 9 #include "SkImageDecoder.h"
10 #include "SkImageGenerator.h" 10 #include "SkImageGenerator.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 protected: 45 protected:
46 SkData* onRefEncodedData() SK_OVERRIDE { 46 SkData* onRefEncodedData() SK_OVERRIDE {
47 return SkRef(fData.get()); 47 return SkRef(fData.get());
48 } 48 }
49 49
50 virtual bool onGetInfo(SkImageInfo* info) SK_OVERRIDE { 50 virtual bool onGetInfo(SkImageInfo* info) SK_OVERRIDE {
51 *info = fInfo; 51 *info = fInfo;
52 return true; 52 return true;
53 } 53 }
54 54
55 virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBy tes, 55 virtual Result onGetPixelsEnum(const SkImageInfo& info, void* pixels, size_t rowBytes,
56 SkPMColor ctableEntries[], int* ctableCount) SK_OVE RRIDE { 56 SkPMColor ctableEntries[], int* ctableCount) SK_O VERRIDE {
57 SkMemoryStream stream(fData->data(), fData->size(), false); 57 SkMemoryStream stream(fData->data(), fData->size(), false);
58 SkAutoTUnref<BareMemoryAllocator> allocator(SkNEW_ARGS(BareMemoryAllocat or, 58 SkAutoTUnref<BareMemoryAllocator> allocator(SkNEW_ARGS(BareMemoryAllocat or,
59 (info, pixels, ro wBytes))); 59 (info, pixels, ro wBytes)));
60 fDecoder->setAllocator(allocator); 60 fDecoder->setAllocator(allocator);
61 fDecoder->setRequireUnpremultipliedColors(kUnpremul_SkAlphaType == info. alphaType()); 61 fDecoder->setRequireUnpremultipliedColors(kUnpremul_SkAlphaType == info. alphaType());
62 62
63 SkBitmap bm; 63 SkBitmap bm;
64 SkImageDecoder::Result result = fDecoder->decode(&stream, &bm, info.colo rType(), 64 const SkImageDecoder::Result result = fDecoder->decode(&stream, &bm, inf o.colorType(),
65 SkImageDecoder::kDecode Pixels_Mode); 65 SkImageDecoder::k DecodePixels_Mode);
66 switch (result) { 66 if (SkImageDecoder::kFailure == result) {
67 case SkImageDecoder::kSuccess: 67 return kInvalidInput;
68 break;
69 default:
70 return false;
71 } 68 }
72 69
73 SkASSERT(info.colorType() == bm.info().colorType()); 70 SkASSERT(info.colorType() == bm.info().colorType());
74 71
75 if (kIndex_8_SkColorType == info.colorType()) { 72 if (kIndex_8_SkColorType == info.colorType()) {
76 SkASSERT(ctableEntries); 73 SkASSERT(ctableEntries);
77 74
78 SkColorTable* ctable = bm.getColorTable(); 75 SkColorTable* ctable = bm.getColorTable();
79 if (NULL == ctable) { 76 if (NULL == ctable) {
80 return false; 77 return kInvalidConversion;
81 } 78 }
82 const int count = ctable->count(); 79 const int count = ctable->count();
83 memcpy(ctableEntries, ctable->readColors(), count * sizeof(SkPMColor )); 80 memcpy(ctableEntries, ctable->readColors(), count * sizeof(SkPMColor ));
84 *ctableCount = count; 81 *ctableCount = count;
85 } 82 }
86 return true; 83 if (SkImageDecoder::kPartialSuccess == result) {
84 return kIncompleteInput;
85 }
86 return kSuccess;
87 } 87 }
88 88
89 bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], 89 bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
90 SkYUVColorSpace* colorSpace) SK_OVERRIDE { 90 SkYUVColorSpace* colorSpace) SK_OVERRIDE {
91 SkMemoryStream stream(fData->data(), fData->size(), false); 91 SkMemoryStream stream(fData->data(), fData->size(), false);
92 return fDecoder->decodeYUV8Planes(&stream, sizes, planes, rowBytes, colo rSpace); 92 return fDecoder->decodeYUV8Planes(&stream, sizes, planes, rowBytes, colo rSpace);
93 } 93 }
94 94
95 }; 95 };
96 96
(...skipping 10 matching lines...) Expand all
107 107
108 SkBitmap bm; 108 SkBitmap bm;
109 stream.rewind(); 109 stream.rewind();
110 if (!decoder->decode(&stream, &bm, kUnknown_SkColorType, SkImageDecoder::kDe codeBounds_Mode)) { 110 if (!decoder->decode(&stream, &bm, kUnknown_SkColorType, SkImageDecoder::kDe codeBounds_Mode)) {
111 SkDELETE(decoder); 111 SkDELETE(decoder);
112 return NULL; 112 return NULL;
113 } 113 }
114 114
115 return SkNEW_ARGS(SkImageDecoderGenerator, (bm.info(), decoder, data)); 115 return SkNEW_ARGS(SkImageDecoderGenerator, (bm.info(), decoder, data));
116 } 116 }
OLDNEW
« no previous file with comments | « src/lazy/SkDiscardablePixelRef.cpp ('k') | tests/CachedDecodingPixelRefTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698