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

Side by Side Diff: src/codec/SkAndroidCodec.cpp

Issue 1519843002: Change computeOutputColorType() to mimic old behavior (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Match old behavior for GIF and WBMP Created 5 years 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 | no next file » | 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 Google Inc. 2 * Copyright 2015 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 "SkAndroidCodec.h" 8 #include "SkAndroidCodec.h"
9 #include "SkCodec.h" 9 #include "SkCodec.h"
10 #include "SkCodecPriv.h" 10 #include "SkCodecPriv.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 SkAndroidCodec* SkAndroidCodec::NewFromData(SkData* data, SkPngChunkReader* chun kReader) { 45 SkAndroidCodec* SkAndroidCodec::NewFromData(SkData* data, SkPngChunkReader* chun kReader) {
46 if (!data) { 46 if (!data) {
47 return nullptr; 47 return nullptr;
48 } 48 }
49 49
50 return NewFromStream(new SkMemoryStream(data), chunkReader); 50 return NewFromStream(new SkMemoryStream(data), chunkReader);
51 } 51 }
52 52
53 SkColorType SkAndroidCodec::computeOutputColorType(SkColorType requestedColorTyp e) { 53 SkColorType SkAndroidCodec::computeOutputColorType(SkColorType requestedColorTyp e) {
54 // The legacy GIF and WBMP decoders always decode to kIndex_8_SkColorType.
55 // We will maintain this behavior.
56 SkEncodedFormat format = this->getEncodedFormat();
57 if (kGIF_SkEncodedFormat == format || kWBMP_SkEncodedFormat == format) {
58 return kIndex_8_SkColorType;
59 }
60
54 SkColorType suggestedColorType = this->getInfo().colorType(); 61 SkColorType suggestedColorType = this->getInfo().colorType();
55 switch (requestedColorType) { 62 switch (requestedColorType) {
56 case kARGB_4444_SkColorType: 63 case kARGB_4444_SkColorType:
57 case kN32_SkColorType: 64 case kN32_SkColorType:
58 return kN32_SkColorType; 65 return kN32_SkColorType;
59 case kIndex_8_SkColorType: 66 case kIndex_8_SkColorType:
60 if (kIndex_8_SkColorType == suggestedColorType) { 67 if (kIndex_8_SkColorType == suggestedColorType) {
61 return kIndex_8_SkColorType; 68 return kIndex_8_SkColorType;
62 } 69 }
63 break; 70 break;
64 case kAlpha_8_SkColorType: 71 case kAlpha_8_SkColorType:
65 // Fall through to kGray_8. Before kGray_8_SkColorType existed, 72 // Fall through to kGray_8. Before kGray_8_SkColorType existed,
66 // we allowed clients to request kAlpha_8 when they wanted a 73 // we allowed clients to request kAlpha_8 when they wanted a
67 // grayscale decode. 74 // grayscale decode.
68 case kGray_8_SkColorType: 75 case kGray_8_SkColorType:
69 if (kGray_8_SkColorType == suggestedColorType) { 76 if (kGray_8_SkColorType == suggestedColorType) {
70 return kGray_8_SkColorType; 77 return kGray_8_SkColorType;
71 } 78 }
72 break; 79 break;
73 case kRGB_565_SkColorType: 80 case kRGB_565_SkColorType:
74 if (kOpaque_SkAlphaType == this->getInfo().alphaType()) { 81 if (kOpaque_SkAlphaType == this->getInfo().alphaType()) {
75 return kRGB_565_SkColorType; 82 return kRGB_565_SkColorType;
76 } 83 }
77 break; 84 break;
78 default: 85 default:
79 break; 86 break;
80 } 87 }
81 88
89 // Android has limited support for kGray_8 (using kAlpha_8). We will not
90 // use kGray_8 for Android unless they specifically ask for it.
91 if (kGray_8_SkColorType == suggestedColorType) {
92 return kN32_SkColorType;
93 }
94
95 // This may be kN32_SkColorType or kIndex_8_SkColorType.
82 return suggestedColorType; 96 return suggestedColorType;
83 } 97 }
84 98
85 SkAlphaType SkAndroidCodec::computeOutputAlphaType(bool requestedUnpremul) { 99 SkAlphaType SkAndroidCodec::computeOutputAlphaType(bool requestedUnpremul) {
86 if (kOpaque_SkAlphaType == this->getInfo().alphaType()) { 100 if (kOpaque_SkAlphaType == this->getInfo().alphaType()) {
87 return kOpaque_SkAlphaType; 101 return kOpaque_SkAlphaType;
88 } 102 }
89 return requestedUnpremul ? kUnpremul_SkAlphaType : kPremul_SkAlphaType; 103 return requestedUnpremul ? kUnpremul_SkAlphaType : kPremul_SkAlphaType;
90 } 104 }
91 105
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 175 }
162 } 176 }
163 177
164 return this->onGetAndroidPixels(info, pixels, rowBytes, *options); 178 return this->onGetAndroidPixels(info, pixels, rowBytes, *options);
165 } 179 }
166 180
167 SkCodec::Result SkAndroidCodec::getAndroidPixels(const SkImageInfo& info, void* pixels, 181 SkCodec::Result SkAndroidCodec::getAndroidPixels(const SkImageInfo& info, void* pixels,
168 size_t rowBytes) { 182 size_t rowBytes) {
169 return this->getAndroidPixels(info, pixels, rowBytes, nullptr); 183 return this->getAndroidPixels(info, pixels, rowBytes, nullptr);
170 } 184 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698