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

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

Issue 1473673005: Support wbmp that are supported by SkImageDecoder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 | tests/CodexTest.cpp » ('j') | tests/CodexTest.cpp » ('J')
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 "SkCodec.h" 8 #include "SkCodec.h"
9 #include "SkCodecPriv.h" 9 #include "SkCodecPriv.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 11 matching lines...) Expand all
22 22
23 static inline void setup_color_table(SkColorType colorType, 23 static inline void setup_color_table(SkColorType colorType,
24 SkPMColor* colorPtr, int* colorCount) { 24 SkPMColor* colorPtr, int* colorCount) {
25 if (kIndex_8_SkColorType == colorType) { 25 if (kIndex_8_SkColorType == colorType) {
26 colorPtr[0] = SK_ColorBLACK; 26 colorPtr[0] = SK_ColorBLACK;
27 colorPtr[1] = SK_ColorWHITE; 27 colorPtr[1] = SK_ColorWHITE;
28 *colorCount = 2; 28 *colorCount = 2;
29 } 29 }
30 } 30 }
31 31
32 static bool read_byte(SkStream* stream, uint8_t* data)
33 {
34 return stream->read(data, 1) == 1;
35 }
36
32 // http://en.wikipedia.org/wiki/Variable-length_quantity 37 // http://en.wikipedia.org/wiki/Variable-length_quantity
33 static bool read_mbf(SkStream* stream, uint64_t* value) { 38 static bool read_mbf(SkStream* stream, uint64_t* value) {
34 uint64_t n = 0; 39 uint64_t n = 0;
35 uint8_t data; 40 uint8_t data;
36 const uint64_t kLimit = 0xFE00000000000000; 41 const uint64_t kLimit = 0xFE00000000000000;
37 SkASSERT(kLimit == ~((~static_cast<uint64_t>(0)) >> 7)); 42 SkASSERT(kLimit == ~((~static_cast<uint64_t>(0)) >> 7));
38 do { 43 do {
39 if (n & kLimit) { // Will overflow on shift by 7. 44 if (n & kLimit) { // Will overflow on shift by 7.
40 return false; 45 return false;
41 } 46 }
42 if (stream->read(&data, 1) != 1) { 47 if (stream->read(&data, 1) != 1) {
43 return false; 48 return false;
44 } 49 }
45 n = (n << 7) | (data & 0x7F); 50 n = (n << 7) | (data & 0x7F);
46 } while (data & 0x80); 51 } while (data & 0x80);
47 *value = n; 52 *value = n;
48 return true; 53 return true;
49 } 54 }
50 55
51 static bool read_header(SkStream* stream, SkISize* size) { 56 static bool read_header(SkStream* stream, SkISize* size) {
57 {
58 uint8_t data;
59 if (!read_byte(stream, &data) || data != 0) { // unknown type
60 return false;
61 }
62 if (!read_byte(stream, &data) || (data & 0x9F)) { // skip fixed header
63 return false;
64 }
65 }
66
52 uint64_t width, height; 67 uint64_t width, height;
53 uint16_t data;
54 if (stream->read(&data, 2) != 2 || data != 0) {
55 return false;
56 }
57 if (!read_mbf(stream, &width) || width > 0xFFFF || !width) { 68 if (!read_mbf(stream, &width) || width > 0xFFFF || !width) {
58 return false; 69 return false;
59 } 70 }
60 if (!read_mbf(stream, &height) || height > 0xFFFF || !height) { 71 if (!read_mbf(stream, &height) || height > 0xFFFF || !height) {
61 return false; 72 return false;
62 } 73 }
63 if (size) { 74 if (size) {
64 *size = SkISize::Make(SkToS32(width), SkToS32(height)); 75 *size = SkISize::Make(SkToS32(width), SkToS32(height));
65 } 76 }
66 return true; 77 return true;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 // Initialize the swizzler 200 // Initialize the swizzler
190 fSwizzler.reset(this->initializeSwizzler(dstInfo, get_color_ptr(fColorTable. get()), options)); 201 fSwizzler.reset(this->initializeSwizzler(dstInfo, get_color_ptr(fColorTable. get()), options));
191 if (nullptr == fSwizzler.get()) { 202 if (nullptr == fSwizzler.get()) {
192 return kInvalidConversion; 203 return kInvalidConversion;
193 } 204 }
194 205
195 fSrcBuffer.reset(fSrcRowBytes); 206 fSrcBuffer.reset(fSrcRowBytes);
196 207
197 return kSuccess; 208 return kSuccess;
198 } 209 }
OLDNEW
« no previous file with comments | « no previous file | tests/CodexTest.cpp » ('j') | tests/CodexTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698