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

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

Issue 1040453002: Add SkPngChunkReader. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update SkImageDecoder_empty Created 5 years, 1 month 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.cpp ('k') | src/codec/SkCodec_libpng.cpp » ('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 "SkColorTable.h" 9 #include "SkColorTable.h"
10 #include "SkPngChunkReader.h"
10 #include "SkEncodedFormat.h" 11 #include "SkEncodedFormat.h"
11 #include "SkImageInfo.h" 12 #include "SkImageInfo.h"
12 #include "SkRefCnt.h" 13 #include "SkRefCnt.h"
13 #include "SkSwizzler.h" 14 #include "SkSwizzler.h"
14 15
15 #include "png.h" 16 #include "png.h"
16 17
17 class SkStream; 18 class SkStream;
18 19
19 class SkPngCodec : public SkCodec { 20 class SkPngCodec : public SkCodec {
20 public: 21 public:
21 static bool IsPng(SkStream*); 22 static bool IsPng(SkStream*);
22 23
23 // Assume IsPng was called and returned true. 24 // Assume IsPng was called and returned true.
24 static SkCodec* NewFromStream(SkStream*); 25 static SkCodec* NewFromStream(SkStream*, SkPngChunkReader* = NULL);
25 26
26 virtual ~SkPngCodec(); 27 virtual ~SkPngCodec();
27 28
28 protected: 29 protected:
29 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo lor*, int*, int*) 30 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo lor*, int*, int*)
30 override; 31 override;
31 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF ormat; } 32 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF ormat; }
32 bool onRewind() override; 33 bool onRewind() override;
33 uint32_t onGetFillValue(SkColorType colorType, SkAlphaType alphaType) const override; 34 uint32_t onGetFillValue(SkColorType colorType, SkAlphaType alphaType) const override;
34 bool onReallyHasAlpha() const final; 35 bool onReallyHasAlpha() const final;
35 36
36 // Helper to set up swizzler and color table. Also calls png_read_update_inf o. 37 // Helper to set up swizzler and color table. Also calls png_read_update_inf o.
37 Result initializeSwizzler(const SkImageInfo& requestedInfo, const Options&, 38 Result initializeSwizzler(const SkImageInfo& requestedInfo, const Options&,
38 SkPMColor*, int* ctableCount); 39 SkPMColor*, int* ctableCount);
39 SkSampler* getSampler(bool createIfNecessary) override { 40 SkSampler* getSampler(bool createIfNecessary) override {
40 SkASSERT(fSwizzler); 41 SkASSERT(fSwizzler);
41 return fSwizzler; 42 return fSwizzler;
42 } 43 }
43 44
44 SkPngCodec(const SkImageInfo&, SkStream*, png_structp, png_infop, int, int); 45 SkPngCodec(const SkImageInfo&, SkStream*, SkPngChunkReader*, png_structp, pn g_infop, int, int);
45 46
46 png_structp png_ptr() { return fPng_ptr; } 47 png_structp png_ptr() { return fPng_ptr; }
47 SkSwizzler* swizzler() { return fSwizzler; } 48 SkSwizzler* swizzler() { return fSwizzler; }
48 SkSwizzler::SrcConfig srcConfig() const { return fSrcConfig; } 49 SkSwizzler::SrcConfig srcConfig() const { return fSrcConfig; }
49 int numberPasses() const { return fNumberPasses; } 50 int numberPasses() const { return fNumberPasses; }
50 51
51 enum AlphaState { 52 enum AlphaState {
52 // This class has done no decoding, or threw away its knowledge (in 53 // This class has done no decoding, or threw away its knowledge (in
53 // scanline decodes). 54 // scanline decodes).
54 kUnknown_AlphaState, 55 kUnknown_AlphaState,
55 // This class found the image (possibly partial, in the case of a 56 // This class found the image (possibly partial, in the case of a
56 // scanline decode) to be opaque. 57 // scanline decode) to be opaque.
57 kOpaque_AlphaState, 58 kOpaque_AlphaState,
58 // Ths class found the image to have alpha. 59 // Ths class found the image to have alpha.
59 kHasAlpha_AlphaState, 60 kHasAlpha_AlphaState,
60 }; 61 };
61 62
62 virtual AlphaState alphaInScanlineDecode() const = 0; 63 virtual AlphaState alphaInScanlineDecode() const = 0;
63 64
64 private: 65 private:
65 png_structp fPng_ptr; 66 SkAutoTUnref<SkPngChunkReader> fPngChunkReader;
66 png_infop fInfo_ptr; 67 png_structp fPng_ptr;
68 png_infop fInfo_ptr;
67 69
68 // These are stored here so they can be used both by normal decoding and sca nline decoding. 70 // These are stored here so they can be used both by normal decoding and sca nline decoding.
69 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul. 71 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul.
70 SkAutoTDelete<SkSwizzler> fSwizzler; 72 SkAutoTDelete<SkSwizzler> fSwizzler;
71 73
72 SkSwizzler::SrcConfig fSrcConfig; 74 SkSwizzler::SrcConfig fSrcConfig;
73 const int fNumberPasses; 75 const int fNumberPasses;
74 int fBitDepth; 76 int fBitDepth;
75 AlphaState fAlphaState; 77 AlphaState fAlphaState;
76 78
77 bool decodePalette(bool premultiply, int* ctableCount); 79 bool decodePalette(bool premultiply, int* ctableCount);
78 void destroyReadStruct(); 80 void destroyReadStruct();
79 81
80 typedef SkCodec INHERITED; 82 typedef SkCodec INHERITED;
81 }; 83 };
OLDNEW
« no previous file with comments | « src/codec/SkCodec.cpp ('k') | src/codec/SkCodec_libpng.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698