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

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

Issue 2184543003: Perform color correction on png decodes (Closed) Base URL: https://skia.googlesource.com/skia.git@colorjpegs
Patch Set: Rebase on Sk4u Created 4 years, 4 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 "SkColorSpaceXform.h"
9 #include "SkColorTable.h" 10 #include "SkColorTable.h"
10 #include "SkPngChunkReader.h" 11 #include "SkPngChunkReader.h"
11 #include "SkEncodedFormat.h" 12 #include "SkEncodedFormat.h"
12 #include "SkImageInfo.h" 13 #include "SkImageInfo.h"
13 #include "SkRefCnt.h" 14 #include "SkRefCnt.h"
14 #include "SkSwizzler.h" 15 #include "SkSwizzler.h"
15 16
16 #include "png.h" 17 #include "png.h"
17 18
18 class SkStream; 19 class SkStream;
19 20
20 class SkPngCodec : public SkCodec { 21 class SkPngCodec : public SkCodec {
21 public: 22 public:
22 static bool IsPng(const char*, size_t); 23 static bool IsPng(const char*, size_t);
23 24
24 // Assume IsPng was called and returned true. 25 // Assume IsPng was called and returned true.
25 static SkCodec* NewFromStream(SkStream*, SkPngChunkReader* = NULL); 26 static SkCodec* NewFromStream(SkStream*, SkPngChunkReader* = NULL);
26 27
27 virtual ~SkPngCodec(); 28 virtual ~SkPngCodec();
28 29
29 protected: 30 protected:
30 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo lor*, int*, int*) 31 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo lor*, int*, int*)
31 override; 32 override;
32 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF ormat; } 33 SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedF ormat; }
33 bool onRewind() override; 34 bool onRewind() override;
34 uint32_t onGetFillValue(SkColorType) const override; 35 uint32_t onGetFillValue(SkColorType) const override;
35 36
36 // Helper to set up swizzler and color table. Also calls png_read_update_inf o. 37 // Helper to set up swizzler, color xforms, and color table. Also calls png_ read_update_info.
37 Result initializeSwizzler(const SkImageInfo& requestedInfo, const Options&, 38 bool initializeXforms(const SkImageInfo& requestedInfo, const Options&, SkPM Color* colorPtr,
38 SkPMColor*, int* ctableCount); 39 int* colorCount);
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 }
44 void allocateStorage(const SkImageInfo& dstInfo);
45
46 virtual int readRows(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, int count,
47 int startRow) = 0;
43 48
44 SkPngCodec(int width, int height, const SkEncodedInfo&, SkStream*, SkPngChun kReader*, 49 SkPngCodec(int width, int height, const SkEncodedInfo&, SkStream*, SkPngChun kReader*,
45 png_structp, png_infop, int, int, sk_sp<SkColorSpace>); 50 png_structp, png_infop, int, int, sk_sp<SkColorSpace>);
46 51
47 png_structp png_ptr() { return fPng_ptr; } 52 protected:
mtklein 2016/07/29 18:48:56 You're already protected here.
msarett 2016/07/29 20:07:51 Of course, got it.
48 SkSwizzler* swizzler() { return fSwizzler; } 53 SkAutoTUnref<SkPngChunkReader> fPngChunkReader;
49 int numberPasses() const { return fNumberPasses; } 54 png_structp fPng_ptr;
55 png_infop fInfo_ptr;
56
57 // These are stored here so they can be used both by normal decoding and sca nline decoding.
58 SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul.
59 SkAutoTDelete<SkSwizzler> fSwizzler;
60 std::unique_ptr<SkColorSpaceXform> fColorXform;
61 SkAutoTMalloc<uint8_t> fStorage;
62 uint8_t* fSwizzlerSrcRow;
63 uint32_t* fColorXformSrcRow;
64 size_t fSrcRowBytes;
65
66 const int fNumberPasses;
67 int fBitDepth;
mtklein 2016/07/29 18:48:56 I usually find that when data is protected as oppo
msarett 2016/07/29 20:07:50 I think you make a good point... I did my best to
50 68
51 private: 69 private:
52 SkAutoTUnref<SkPngChunkReader> fPngChunkReader;
53 png_structp fPng_ptr;
54 png_infop fInfo_ptr;
55
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.
58 SkAutoTDelete<SkSwizzler> fSwizzler;
59
60 const int fNumberPasses;
61 int fBitDepth;
62
63 bool createColorTable(SkColorType dstColorType, bool premultiply, int* ctabl eCount); 70 bool createColorTable(SkColorType dstColorType, bool premultiply, int* ctabl eCount);
64 void destroyReadStruct(); 71 void destroyReadStruct();
65 72
66 typedef SkCodec INHERITED; 73 typedef SkCodec INHERITED;
67 }; 74 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698