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

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

Issue 1472123002: Make SkCodec support peek() and read() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Make IsWbmp call read_header 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
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"
11 #include "SkColorTable.h" 11 #include "SkColorTable.h"
12 #include "SkData.h"
12 #include "SkStream.h" 13 #include "SkStream.h"
13 #include "SkCodec_wbmp.h" 14 #include "SkCodec_wbmp.h"
14 15
15 // Each bit represents a pixel, so width is actually a number of bits. 16 // Each bit represents a pixel, so width is actually a number of bits.
16 // A row will always be stored in bytes, so we round width up to the 17 // A row will always be stored in bytes, so we round width up to the
17 // nearest multiple of 8 to get the number of bits actually in the row. 18 // nearest multiple of 8 to get the number of bits actually in the row.
18 // We then divide by 8 to convert to bytes. 19 // We then divide by 8 to convert to bytes.
19 static inline size_t get_src_row_bytes(int width) { 20 static inline size_t get_src_row_bytes(int width) {
20 return SkAlign8(width) >> 3; 21 return SkAlign8(width) >> 3;
21 } 22 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 uint8_t data; 59 uint8_t data;
59 if (!read_byte(stream, &data) || data != 0) { // unknown type 60 if (!read_byte(stream, &data) || data != 0) { // unknown type
60 return false; 61 return false;
61 } 62 }
62 if (!read_byte(stream, &data) || (data & 0x9F)) { // skip fixed header 63 if (!read_byte(stream, &data) || (data & 0x9F)) { // skip fixed header
63 return false; 64 return false;
64 } 65 }
65 } 66 }
66 67
67 uint64_t width, height; 68 uint64_t width, height;
68 if (!read_mbf(stream, &width) || width > 0xFFFF || !width) { 69 if (!read_mbf(stream, &width) || width > 0xFFFF || !width) {
msarett 2015/11/30 14:08:11 read_header is called by IsWbmp and NewFromStream.
scroggo 2015/11/30 20:02:30 Yeah, I considered something like that. You're cor
69 return false; 70 return false;
70 } 71 }
71 if (!read_mbf(stream, &height) || height > 0xFFFF || !height) { 72 if (!read_mbf(stream, &height) || height > 0xFFFF || !height) {
72 return false; 73 return false;
73 } 74 }
74 if (size) { 75 if (size) {
75 *size = SkISize::Make(SkToS32(width), SkToS32(height)); 76 *size = SkISize::Make(SkToS32(width), SkToS32(height));
76 } 77 }
77 return true; 78 return true;
78 } 79 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 if (!this->readRow(src.get())) { 145 if (!this->readRow(src.get())) {
145 *rowsDecoded = y; 146 *rowsDecoded = y;
146 return kIncompleteInput; 147 return kIncompleteInput;
147 } 148 }
148 swizzler->swizzle(dstRow, src.get()); 149 swizzler->swizzle(dstRow, src.get());
149 dstRow = SkTAddOffset<void>(dstRow, rowBytes); 150 dstRow = SkTAddOffset<void>(dstRow, rowBytes);
150 } 151 }
151 return kSuccess; 152 return kSuccess;
152 } 153 }
153 154
154 bool SkWbmpCodec::IsWbmp(SkStream* stream) { 155 bool SkWbmpCodec::IsWbmp(const char* buffer, size_t bytesRead) {
155 return read_header(stream, nullptr); 156 SkAutoTUnref<SkData> data(SkData::NewWithoutCopy(buffer, bytesRead));
157 SkMemoryStream stream(data);
158 return read_header(&stream, nullptr);
156 } 159 }
157 160
158 SkCodec* SkWbmpCodec::NewFromStream(SkStream* stream) { 161 SkCodec* SkWbmpCodec::NewFromStream(SkStream* stream) {
159 SkAutoTDelete<SkStream> streamDeleter(stream); 162 SkAutoTDelete<SkStream> streamDeleter(stream);
160 SkISize size; 163 SkISize size;
161 if (!read_header(stream, &size)) { 164 if (!read_header(stream, &size)) {
162 return nullptr; 165 return nullptr;
163 } 166 }
164 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), 167 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(),
165 kGray_8_SkColorType, kOpaque_SkAlphaType); 168 kGray_8_SkColorType, kOpaque_SkAlphaType);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 // Initialize the swizzler 203 // Initialize the swizzler
201 fSwizzler.reset(this->initializeSwizzler(dstInfo, get_color_ptr(fColorTable. get()), options)); 204 fSwizzler.reset(this->initializeSwizzler(dstInfo, get_color_ptr(fColorTable. get()), options));
202 if (nullptr == fSwizzler.get()) { 205 if (nullptr == fSwizzler.get()) {
203 return kInvalidConversion; 206 return kInvalidConversion;
204 } 207 }
205 208
206 fSrcBuffer.reset(fSrcRowBytes); 209 fSrcBuffer.reset(fSrcRowBytes);
207 210
208 return kSuccess; 211 return kSuccess;
209 } 212 }
OLDNEW
« src/codec/SkCodec.cpp ('K') | « src/codec/SkCodec_wbmp.h ('k') | src/codec/SkJpegCodec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698