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

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

Issue 1820073002: Add SkEncodedInfo to report properties of encoded image data (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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
« src/codec/SkPngCodec.cpp ('K') | « src/codec/SkWebpCodec.h ('k') | 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 "SkCodecPriv.h" 8 #include "SkCodecPriv.h"
9 #include "SkWebpCodec.h" 9 #include "SkWebpCodec.h"
10 #include "SkTemplates.h" 10 #include "SkTemplates.h"
(...skipping 13 matching lines...) Expand all
24 // WEBP starts with the following: 24 // WEBP starts with the following:
25 // RIFFXXXXWEBPVP 25 // RIFFXXXXWEBPVP
26 // Where XXXX is unspecified. 26 // Where XXXX is unspecified.
27 const char* bytes = static_cast<const char*>(buf); 27 const char* bytes = static_cast<const char*>(buf);
28 return bytesRead >= 14 && !memcmp(bytes, "RIFF", 4) && !memcmp(&bytes[8], "W EBPVP", 6); 28 return bytesRead >= 14 && !memcmp(bytes, "RIFF", 4) && !memcmp(&bytes[8], "W EBPVP", 6);
29 } 29 }
30 30
31 // Parse headers of RIFF container, and check for valid Webp (VP8) content. 31 // Parse headers of RIFF container, and check for valid Webp (VP8) content.
32 // NOTE: This calls peek instead of read, since onGetPixels will need these 32 // NOTE: This calls peek instead of read, since onGetPixels will need these
33 // bytes again. 33 // bytes again.
34 static bool webp_parse_header(SkStream* stream, SkImageInfo* info) { 34 static bool webp_parse_header(SkStream* stream, SkEncodedInfo* info) {
35 unsigned char buffer[WEBP_VP8_HEADER_SIZE]; 35 unsigned char buffer[WEBP_VP8_HEADER_SIZE];
36 SkASSERT(WEBP_VP8_HEADER_SIZE <= SkCodec::MinBufferedBytesNeeded()); 36 SkASSERT(WEBP_VP8_HEADER_SIZE <= SkCodec::MinBufferedBytesNeeded());
37 37
38 const size_t bytesPeeked = stream->peek(buffer, WEBP_VP8_HEADER_SIZE); 38 const size_t bytesPeeked = stream->peek(buffer, WEBP_VP8_HEADER_SIZE);
39 if (bytesPeeked != WEBP_VP8_HEADER_SIZE) { 39 if (bytesPeeked != WEBP_VP8_HEADER_SIZE) {
40 // Use read + rewind as a backup 40 // Use read + rewind as a backup
41 if (stream->read(buffer, WEBP_VP8_HEADER_SIZE) != WEBP_VP8_HEADER_SIZE 41 if (stream->read(buffer, WEBP_VP8_HEADER_SIZE) != WEBP_VP8_HEADER_SIZE
42 || !stream->rewind()) 42 || !stream->rewind())
43 return false; 43 return false;
44 } 44 }
(...skipping 10 matching lines...) Expand all
55 if (!sk_64_isS32(size)) { 55 if (!sk_64_isS32(size)) {
56 return false; 56 return false;
57 } 57 }
58 // now check that if we are 4-bytes per pixel, we also don't overflow 58 // now check that if we are 4-bytes per pixel, we also don't overflow
59 if (sk_64_asS32(size) > (0x7FFFFFFF >> 2)) { 59 if (sk_64_asS32(size) > (0x7FFFFFFF >> 2)) {
60 return false; 60 return false;
61 } 61 }
62 } 62 }
63 63
64 if (info) { 64 if (info) {
65 // FIXME: Is N32 the right type? 65 SkEncodedInfo::Color color = SkToBool(features.has_alpha) ? SkEncodedInf o::kYUVA_Color :
66 // Is unpremul the right type? Clients of SkCodec may assume it's the 66 SkEncodedInfo::kYUV_Color;
67 // best type, when Skia currently cannot draw unpremul (and raster is fa ster 67 SkEncodedInfo::Alpha alpha = SkToBool(features.has_alpha) ? SkEncodedInf o::kUnpremul_Alpha :
scroggo 2016/03/23 14:48:50 How does alpha work for a YUV image? Is "unpremul"
msarett 2016/03/24 16:20:44 Thanks for questioning this. I dug a little deepe
68 // with premul). 68 SkEncodedInfo::kOpaque_Alpha;
69 *info = SkImageInfo::Make(features.width, features.height, kN32_SkColorT ype, 69 *info = SkEncodedInfo::Make(features.width, features.height, color, alph a, 8);
scroggo 2016/03/23 14:48:50 Similarly, is 8 bits per component meaningful here
msarett 2016/03/24 16:20:44 Acknowledged.
70 SkToBool(features.has_alpha) ? kUnpremul_SkAlp haType
71 : kOpaque_SkAlphaT ype);
72 } 70 }
73 return true; 71 return true;
74 } 72 }
75 73
76 SkCodec* SkWebpCodec::NewFromStream(SkStream* stream) { 74 SkCodec* SkWebpCodec::NewFromStream(SkStream* stream) {
77 SkAutoTDelete<SkStream> streamDeleter(stream); 75 SkAutoTDelete<SkStream> streamDeleter(stream);
78 SkImageInfo info; 76 SkEncodedInfo info;
79 if (webp_parse_header(stream, &info)) { 77 if (webp_parse_header(stream, &info)) {
80 return new SkWebpCodec(info, streamDeleter.release()); 78 return new SkWebpCodec(info, streamDeleter.release());
81 } 79 }
82 return nullptr; 80 return nullptr;
83 } 81 }
84 82
85 // This version is slightly different from SkCodecPriv's version of conversion_p ossible. It 83 // This version is slightly different from SkCodecPriv's version of conversion_p ossible. It
86 // supports both byte orders for 8888. 84 // supports both byte orders for 8888.
87 static bool webp_conversion_possible(const SkImageInfo& dst, const SkImageInfo& src) { 85 static bool webp_conversion_possible(const SkImageInfo& dst, const SkImageInfo& src) {
88 if (dst.profileType() != src.profileType()) { 86 if (dst.profileType() != src.profileType()) {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 return kSuccess; 242 return kSuccess;
245 case VP8_STATUS_SUSPENDED: 243 case VP8_STATUS_SUSPENDED:
246 // Break out of the switch statement. Continue the loop. 244 // Break out of the switch statement. Continue the loop.
247 break; 245 break;
248 default: 246 default:
249 return kInvalidInput; 247 return kInvalidInput;
250 } 248 }
251 } 249 }
252 } 250 }
253 251
254 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream) 252 SkWebpCodec::SkWebpCodec(const SkEncodedInfo& info, SkStream* stream)
255 : INHERITED(info, stream) {} 253 : INHERITED(info, stream) {}
OLDNEW
« src/codec/SkPngCodec.cpp ('K') | « src/codec/SkWebpCodec.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698