OLD | NEW |
---|---|
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 "SkWebpCodec.h" | 8 #include "SkWebpCodec.h" |
9 #include "SkTemplates.h" | 9 #include "SkTemplates.h" |
10 | 10 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 SkCodec* SkWebpCodec::NewFromStream(SkStream* stream) { | 75 SkCodec* SkWebpCodec::NewFromStream(SkStream* stream) { |
76 SkAutoTDelete<SkStream> streamDeleter(stream); | 76 SkAutoTDelete<SkStream> streamDeleter(stream); |
77 SkImageInfo info; | 77 SkImageInfo info; |
78 if (webp_parse_header(stream, &info)) { | 78 if (webp_parse_header(stream, &info)) { |
79 return SkNEW_ARGS(SkWebpCodec, (info, streamDeleter.detach())); | 79 return SkNEW_ARGS(SkWebpCodec, (info, streamDeleter.detach())); |
80 } | 80 } |
81 return NULL; | 81 return NULL; |
82 } | 82 } |
83 | 83 |
84 static bool conversion_possible(const SkImageInfo& dst, const SkImageInfo& src) { | 84 static bool conversion_possible(const SkImageInfo& dst, const SkImageInfo& src) { |
85 if (dst.profileType() != src.profileType()) { | |
86 return false; | |
87 } | |
85 switch (dst.colorType()) { | 88 switch (dst.colorType()) { |
86 // Both byte orders are supported. | 89 // Both byte orders are supported. |
87 case kBGRA_8888_SkColorType: | 90 case kBGRA_8888_SkColorType: |
88 case kRGBA_8888_SkColorType: | 91 case kRGBA_8888_SkColorType: |
89 break; | 92 break; |
93 case kRGB_565_SkColorType: | |
94 if (src.alphaType() == kOpaque_SkAlphaType | |
95 && dst.alphaType() == kOpaque_SkAlphaType) | |
96 { | |
msarett
2015/08/06 19:30:03
nit: I think the bracket should go on the previous
scroggo
2015/08/06 20:42:44
Maybe? In general the { does not get its own line,
| |
97 return true; | |
98 } | |
90 default: | 99 default: |
91 return false; | 100 return false; |
92 } | 101 } |
93 if (dst.profileType() != src.profileType()) { | |
94 return false; | |
95 } | |
96 if (dst.alphaType() == src.alphaType()) { | 102 if (dst.alphaType() == src.alphaType()) { |
97 return true; | 103 return true; |
98 } | 104 } |
99 return kPremul_SkAlphaType == dst.alphaType() && | 105 return kPremul_SkAlphaType == dst.alphaType() && |
100 kUnpremul_SkAlphaType == src.alphaType(); | 106 kUnpremul_SkAlphaType == src.alphaType(); |
101 } | 107 } |
102 | 108 |
103 SkISize SkWebpCodec::onGetScaledDimensions(float desiredScale) const { | 109 SkISize SkWebpCodec::onGetScaledDimensions(float desiredScale) const { |
104 SkISize dim = this->getInfo().dimensions(); | 110 SkISize dim = this->getInfo().dimensions(); |
105 // SkCodec treats zero dimensional images as errors, so the minimum size | 111 // SkCodec treats zero dimensional images as errors, so the minimum size |
106 // that we will recommend is 1x1. | 112 // that we will recommend is 1x1. |
107 dim.fWidth = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fWidth)); | 113 dim.fWidth = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fWidth)); |
108 dim.fHeight = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fHeight)); | 114 dim.fHeight = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fHeight)); |
109 return dim; | 115 return dim; |
110 } | 116 } |
111 | 117 |
112 static WEBP_CSP_MODE webp_decode_mode(SkColorType ct, bool premultiply) { | 118 static WEBP_CSP_MODE webp_decode_mode(SkColorType ct, bool premultiply) { |
113 switch (ct) { | 119 switch (ct) { |
114 case kBGRA_8888_SkColorType: | 120 case kBGRA_8888_SkColorType: |
115 return premultiply ? MODE_bgrA : MODE_BGRA; | 121 return premultiply ? MODE_bgrA : MODE_BGRA; |
116 case kRGBA_8888_SkColorType: | 122 case kRGBA_8888_SkColorType: |
117 return premultiply ? MODE_rgbA : MODE_RGBA; | 123 return premultiply ? MODE_rgbA : MODE_RGBA; |
124 case kRGB_565_SkColorType: | |
125 return MODE_RGB_565; | |
118 default: | 126 default: |
119 return MODE_LAST; | 127 return MODE_LAST; |
120 } | 128 } |
121 } | 129 } |
122 | 130 |
123 // The WebP decoding API allows us to incrementally pass chunks of bytes as we r eceive them to the | 131 // The WebP decoding API allows us to incrementally pass chunks of bytes as we r eceive them to the |
124 // decoder with WebPIAppend. In order to do so, we need to read chunks from the SkStream. This size | 132 // decoder with WebPIAppend. In order to do so, we need to read chunks from the SkStream. This size |
125 // is arbitrary. | 133 // is arbitrary. |
126 static const size_t BUFFER_SIZE = 4096; | 134 static const size_t BUFFER_SIZE = 4096; |
127 | 135 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 // Break out of the switch statement. Continue the loop. | 253 // Break out of the switch statement. Continue the loop. |
246 break; | 254 break; |
247 default: | 255 default: |
248 return kInvalidInput; | 256 return kInvalidInput; |
249 } | 257 } |
250 } | 258 } |
251 } | 259 } |
252 | 260 |
253 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream) | 261 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream) |
254 : INHERITED(info, stream) {} | 262 : INHERITED(info, stream) {} |
OLD | NEW |