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

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

Issue 2277903002: SkPngCodec: voidp instead of forward-declares for png.h types. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 3 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
« no previous file with comments | « no previous file | src/codec/SkPngCodec.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 "SkColorSpaceXform.h" 9 #include "SkColorSpaceXform.h"
10 #include "SkColorTable.h" 10 #include "SkColorTable.h"
11 #include "SkPngChunkReader.h" 11 #include "SkPngChunkReader.h"
12 #include "SkEncodedFormat.h" 12 #include "SkEncodedFormat.h"
13 #include "SkImageInfo.h" 13 #include "SkImageInfo.h"
14 #include "SkRefCnt.h" 14 #include "SkRefCnt.h"
15 #include "SkSwizzler.h" 15 #include "SkSwizzler.h"
16 16
17 // Instead of including png.h here, forward declare the few types we refer to.
18 struct png_struct_def;
19 struct png_info_def;
20 typedef png_struct_def png_struct;
21 typedef png_info_def png_info;
22
23 class SkStream; 17 class SkStream;
24 18
25 class SkPngCodec : public SkCodec { 19 class SkPngCodec : public SkCodec {
26 public: 20 public:
27 static bool IsPng(const char*, size_t); 21 static bool IsPng(const char*, size_t);
28 22
29 // Assume IsPng was called and returned true. 23 // Assume IsPng was called and returned true.
30 static SkCodec* NewFromStream(SkStream*, SkPngChunkReader* = NULL); 24 static SkCodec* NewFromStream(SkStream*, SkPngChunkReader* = NULL);
31 25
32 virtual ~SkPngCodec(); 26 virtual ~SkPngCodec();
33 27
34 protected: 28 protected:
29 // We hold the png_ptr and info_ptr as voidp to avoid having to include png. h
30 // or forward declare their types here. voidp auto-casts to the real pointe r types.
31 struct voidp {
32 voidp(void* ptr) : fPtr(ptr) {}
33
34 template <typename T>
35 operator T*() const { return (T*)fPtr; }
36
37 explicit operator bool() const { return fPtr != nullptr; }
38
39 void* fPtr;
40 };
41
35 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo lor*, int*, int*) 42 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo lor*, int*, int*)
36 override; 43 override;
37 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF ormat; } 44 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF ormat; }
38 bool onRewind() override; 45 bool onRewind() override;
39 uint32_t onGetFillValue(SkColorType) const override; 46 uint32_t onGetFillValue(SkColorType) const override;
40 47
41 // Helper to set up swizzler, color xforms, and color table. Also calls png_ read_update_info. 48 // Helper to set up swizzler, color xforms, and color table. Also calls png_ read_update_info.
42 bool initializeXforms(const SkImageInfo& requestedInfo, const Options&, SkPM Color* colorPtr, 49 bool initializeXforms(const SkImageInfo& requestedInfo, const Options&, SkPM Color* colorPtr,
43 int* colorCount); 50 int* colorCount);
44 SkSampler* getSampler(bool createIfNecessary) override { 51 SkSampler* getSampler(bool createIfNecessary) override {
45 SkASSERT(fSwizzler); 52 SkASSERT(fSwizzler);
46 return fSwizzler; 53 return fSwizzler;
47 } 54 }
48 void allocateStorage(); 55 void allocateStorage();
49 56
50 virtual int readRows(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, int count, 57 virtual int readRows(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, int count,
51 int startRow) = 0; 58 int startRow) = 0;
52 59
53 SkPngCodec(const SkEncodedInfo&, const SkImageInfo&, SkStream*, SkPngChunkRe ader*, 60 SkPngCodec(const SkEncodedInfo&, const SkImageInfo&, SkStream*, SkPngChunkRe ader*,
54 png_struct*, png_info*, int, int); 61 void* png_ptr, void* info_ptr, int, int);
55 62
56 SkAutoTUnref<SkPngChunkReader> fPngChunkReader; 63 SkAutoTUnref<SkPngChunkReader> fPngChunkReader;
57 png_struct* fPng_ptr; 64 voidp fPng_ptr;
58 png_info* fInfo_ptr; 65 voidp fInfo_ptr;
59 66
60 // These are stored here so they can be used both by normal decoding and sca nline decoding. 67 // These are stored here so they can be used both by normal decoding and sca nline decoding.
61 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul. 68 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul.
62 SkAutoTDelete<SkSwizzler> fSwizzler; 69 SkAutoTDelete<SkSwizzler> fSwizzler;
63 std::unique_ptr<SkColorSpaceXform> fColorXform; 70 std::unique_ptr<SkColorSpaceXform> fColorXform;
64 SkAutoTMalloc<uint8_t> fStorage; 71 SkAutoTMalloc<uint8_t> fStorage;
65 uint8_t* fSwizzlerSrcRow; 72 uint8_t* fSwizzlerSrcRow;
66 uint32_t* fColorXformSrcRow; 73 uint32_t* fColorXformSrcRow;
67 size_t fSrcRowBytes; 74 size_t fSrcRowBytes;
68 75
69 const int fNumberPasses; 76 const int fNumberPasses;
70 int fBitDepth; 77 int fBitDepth;
71 78
72 private: 79 private:
73 bool createColorTable(const SkImageInfo& dstInfo, int* ctableCount); 80 bool createColorTable(const SkImageInfo& dstInfo, int* ctableCount);
74 void destroyReadStruct(); 81 void destroyReadStruct();
75 82
76 typedef SkCodec INHERITED; 83 typedef SkCodec INHERITED;
77 }; 84 };
OLDNEW
« no previous file with comments | « no previous file | src/codec/SkPngCodec.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698