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

Side by Side Diff: src/codec/SkCodec_libpng.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_libpng.h ('k') | src/codec/SkCodec_wbmp.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_libpng.h" 8 #include "SkCodec_libpng.h"
9 #include "SkCodecPriv.h" 9 #include "SkCodecPriv.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 } 199 }
200 200
201 fColorTable.reset(new SkColorTable(colorStorage, colorCount)); 201 fColorTable.reset(new SkColorTable(colorStorage, colorCount));
202 return true; 202 return true;
203 } 203 }
204 204
205 /////////////////////////////////////////////////////////////////////////////// 205 ///////////////////////////////////////////////////////////////////////////////
206 // Creation 206 // Creation
207 /////////////////////////////////////////////////////////////////////////////// 207 ///////////////////////////////////////////////////////////////////////////////
208 208
209 #define PNG_BYTES_TO_CHECK 4 209 bool SkPngCodec::IsPng(const char* buf, size_t bytesRead) {
210 210 return !png_sig_cmp((png_bytep) buf, (png_size_t)0, bytesRead);
211 bool SkPngCodec::IsPng(SkStream* stream) {
212 char buf[PNG_BYTES_TO_CHECK];
213 if (stream->read(buf, PNG_BYTES_TO_CHECK) != PNG_BYTES_TO_CHECK) {
214 return false;
215 }
216 if (png_sig_cmp((png_bytep) buf, (png_size_t)0, PNG_BYTES_TO_CHECK)) {
217 return false;
218 }
219 return true;
220 } 211 }
221 212
222 // Reads the header and initializes the output fields, if not NULL. 213 // Reads the header and initializes the output fields, if not NULL.
223 // 214 //
224 // @param stream Input data. Will be read to get enough information to properly 215 // @param stream Input data. Will be read to get enough information to properly
225 // setup the codec. 216 // setup the codec.
226 // @param chunkReader SkPngChunkReader, for reading unknown chunks. May be NULL. 217 // @param chunkReader SkPngChunkReader, for reading unknown chunks. May be NULL.
227 // If not NULL, png_ptr will hold an *unowned* pointer to it. The caller is 218 // If not NULL, png_ptr will hold an *unowned* pointer to it. The caller is
228 // expected to continue to own it for the lifetime of the png_ptr. 219 // expected to continue to own it for the lifetime of the png_ptr.
229 // @param png_ptrp Optional output variable. If non-NULL, will be set to a new 220 // @param png_ptrp Optional output variable. If non-NULL, will be set to a new
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 } 857 }
867 858
868 if (1 == numberPasses) { 859 if (1 == numberPasses) {
869 return new SkPngScanlineDecoder(imageInfo, streamDeleter.detach(), chunk Reader, 860 return new SkPngScanlineDecoder(imageInfo, streamDeleter.detach(), chunk Reader,
870 png_ptr, info_ptr, bitDepth); 861 png_ptr, info_ptr, bitDepth);
871 } 862 }
872 863
873 return new SkPngInterlacedScanlineDecoder(imageInfo, streamDeleter.detach(), chunkReader, 864 return new SkPngInterlacedScanlineDecoder(imageInfo, streamDeleter.detach(), chunkReader,
874 png_ptr, info_ptr, bitDepth, numbe rPasses); 865 png_ptr, info_ptr, bitDepth, numbe rPasses);
875 } 866 }
OLDNEW
« no previous file with comments | « src/codec/SkCodec_libpng.h ('k') | src/codec/SkCodec_wbmp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698