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

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: Rebase 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 | « src/codec/SkCodec_wbmp.h ('k') | src/codec/SkJpegCodec.h » ('j') | 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 "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 122 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 void* 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
« no previous file with comments | « 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