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

Side by Side Diff: src/codec/SkPngCodec.h

Issue 1997703003: Make SkPngCodec decode progressively. (Closed) Base URL: https://skia.googlesource.com/skia.git@foil
Patch Set: Respond to comments Created 4 years, 7 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
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 "SkColorTable.h" 9 #include "SkColorTable.h"
10 #include "SkPngChunkReader.h" 10 #include "SkPngChunkReader.h"
11 #include "SkEncodedFormat.h" 11 #include "SkEncodedFormat.h"
12 #include "SkImageInfo.h" 12 #include "SkImageInfo.h"
13 #include "SkRefCnt.h" 13 #include "SkRefCnt.h"
14 #include "SkSwizzler.h" 14 #include "SkSwizzler.h"
15 15
16 #include "png.h" 16 #include "png.h"
17 17
18 class SkStream; 18 class SkStream;
19 19
20 class SkPngCodec : public SkCodec { 20 class SkPngCodec : public SkCodec {
21 public: 21 public:
22 static bool IsPng(const char*, size_t); 22 static bool IsPng(const char*, size_t);
23 23
24 // Assume IsPng was called and returned true. 24 // Assume IsPng was called and returned true.
25 static SkCodec* NewFromStream(SkStream*, SkPngChunkReader* = NULL); 25 static SkCodec* NewFromStream(SkStream*, SkPngChunkReader* = NULL);
26 26
27 virtual ~SkPngCodec(); 27 virtual ~SkPngCodec();
28 28
29 protected: 29 protected:
30 SkPngCodec(int width, int height, const SkEncodedInfo&, SkStream*, SkPngChun kReader*,
31 png_structp, png_infop, int bitDepth, sk_sp<SkColorSpace>);
32
30 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo lor*, int*, int*) 33 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo lor*, int*, int*)
31 override; 34 override;
32 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF ormat; } 35 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF ormat; }
33 bool onRewind() override; 36 bool onRewind() override;
34 uint32_t onGetFillValue(SkColorType) const override; 37 uint32_t onGetFillValue(SkColorType) const override;
35 38
36 // Helper to set up swizzler and color table. Also calls png_read_update_inf o. 39 // Helper to set up swizzler and color table. Also calls png_read_update_inf o.
37 Result initializeSwizzler(const SkImageInfo& requestedInfo, const Options&, 40 bool initializeSwizzler(const SkImageInfo& requestedInfo, const Options&,
38 SkPMColor*, int* ctableCount); 41 SkPMColor*, int* ctableCount);
39 SkSampler* getSampler(bool createIfNecessary) override { 42 SkSampler* getSampler(bool createIfNecessary) override {
40 SkASSERT(fSwizzler); 43 SkASSERT(fSwizzler);
41 return fSwizzler; 44 return fSwizzler;
42 } 45 }
43 46
44 SkPngCodec(int width, int height, const SkEncodedInfo&, SkStream*, SkPngChun kReader*, 47 png_structp png_ptr() { return fPng_ptr; }
45 png_structp, png_infop, int, int, sk_sp<SkColorSpace>); 48 png_infop info_ptr() { return fInfo_ptr; }
49 SkSwizzler* swizzler() { return fSwizzler; }
46 50
47 png_structp png_ptr() { return fPng_ptr; } 51 /**
48 SkSwizzler* swizzler() { return fSwizzler; } 52 * Pass available input to libpng to process it.
49 int numberPasses() const { return fNumberPasses; } 53 *
54 * libpng will call any relevant callbacks installed. This will continue de coding
55 * until it reaches the end of the file, or until a callback tells libpng t o stop.
56 */
57 void processData();
58
59 Result onStartIncrementalDecode(const SkImageInfo& dstInfo, const SkCodec::O ptions&,
60 SkPMColor* ctable, int* ctableCount) override;
61 Result onIncrementalDecode(std::function<void*(int)> callback, int*) overrid e;
50 62
51 private: 63 private:
52 SkAutoTUnref<SkPngChunkReader> fPngChunkReader; 64 SkAutoTUnref<SkPngChunkReader> fPngChunkReader;
53 png_structp fPng_ptr; 65 png_structp fPng_ptr;
54 png_infop fInfo_ptr; 66 png_infop fInfo_ptr;
55 67
56 // These are stored here so they can be used both by normal decoding and sca nline decoding.
57 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul. 68 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul.
58 SkAutoTDelete<SkSwizzler> fSwizzler; 69 SkAutoTDelete<SkSwizzler> fSwizzler;
59 70
60 const int fNumberPasses; 71 const int fBitDepth;
61 int fBitDepth;
62 72
63 bool createColorTable(SkColorType dstColorType, bool premultiply, int* ctabl eCount); 73 bool createColorTable(SkColorType dstColorType, bool premultiply, int* ctabl eCount);
64 void destroyReadStruct(); 74 void destroyReadStruct();
65 75
76 virtual Result decodeAllRows(void* dst, size_t rowBytes, int* rowsDecoded) = 0;
77 virtual void setRange(int firstRow, int lastRow) = 0;
78 virtual Result decode(std::function<void*(int)> callback, int* rowsDecoded) = 0;
79
66 typedef SkCodec INHERITED; 80 typedef SkCodec INHERITED;
67 }; 81 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698