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

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoder.h

Issue 2386453003: WIP: Implement APNG (Closed)
Patch Set: Change behavior on failure during decoding or parsing. Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 25 matching lines...) Expand all
36 class PLATFORM_EXPORT PNGImageDecoder final : public ImageDecoder { 36 class PLATFORM_EXPORT PNGImageDecoder final : public ImageDecoder {
37 WTF_MAKE_NONCOPYABLE(PNGImageDecoder); 37 WTF_MAKE_NONCOPYABLE(PNGImageDecoder);
38 38
39 public: 39 public:
40 PNGImageDecoder(AlphaOption, 40 PNGImageDecoder(AlphaOption,
41 ColorSpaceOption, 41 ColorSpaceOption,
42 size_t maxDecodedBytes, 42 size_t maxDecodedBytes,
43 size_t offset = 0); 43 size_t offset = 0);
44 ~PNGImageDecoder() override; 44 ~PNGImageDecoder() override;
45 45
46 enum class PNGParseQuery { PNGSizeQuery, PNGMetaDataQuery };
47
46 // ImageDecoder: 48 // ImageDecoder:
47 String filenameExtension() const override { return "png"; } 49 String filenameExtension() const override { return "png"; }
50 int repetitionCount() const override;
51 bool frameIsCompleteAtIndex(size_t) const override;
52 float frameDurationAtIndex(size_t) const override;
53 size_t clearCacheExceptFrame(size_t) override;
54 // Failures are handled differently, based on the image and state of the
55 // decoder:
56 //
57 // 1) When a non-animated PNG, or the first frame of an animated PNG, can't
scroggo_chromium 2016/11/29 16:30:52 nit: these commas are unnecessary
joostouwerling 2016/12/02 16:08:42 Done.
58 // be decoded or parsed, set the decoder to the failed state, because there
59 // are no frames we can show to the client. Also set the state to failed if
scroggo_chromium 2016/11/29 16:30:52 For a partial first frame (or partial only frame,
joostouwerling 2016/12/02 16:08:42 Yes, the current behavior is that any failure inva
60 // a parse error occurs before any frames were received.
61 // 2) When a decoding failure occurs for non-first frames, we still want to
62 // show earlier frames. This means the frame count needs to be adjusted.
63 // 3) When a parsing failure occurs, the frame count is adjusted to the number
64 // of successfully parsed frames, since we can still show those.
65 //
66 // In cases 2 and 3, we have to prevent parse() from adjusting the frame
67 // count to pre-failure values by setting |m_failedWithCorrectFrames| to true.
68 bool setFailed() override;
48 69
49 // Callbacks from libpng 70 // Callbacks from libpng
50 void headerAvailable(); 71 void headerAvailable();
51 void rowAvailable(unsigned char* row, unsigned rowIndex, int); 72 void rowAvailable(unsigned char* row, unsigned rowIndex, int);
52 void complete(); 73 void complete();
53 74
75 // Additional methods used for APNG
76 void setRepetitionCount(size_t);
77
54 private: 78 private:
55 // ImageDecoder: 79 // ImageDecoder:
56 void decodeSize() override { decode(true); } 80 void decodeSize() override { parse(PNGParseQuery::PNGSizeQuery); }
57 void decode(size_t) override { decode(false); } 81 void decode(size_t) override;
82 size_t decodeFrameCount() override;
83 void initializeNewFrame(size_t) override;
84 void clearFrameBuffer(size_t) override;
58 85
59 // Decodes the image. If |onlySize| is true, stops decoding after 86 bool initFrameBuffer(size_t);
60 // calculating the image size. If decoding fails but there is no more 87 void parse(PNGParseQuery);
61 // data coming, sets the "decode failure" flag. 88 // Used by clearCacheExceptFrame if two frames need to be kept in cache.
62 void decode(bool onlySize); 89 size_t clearCacheExceptTwoFrames(size_t, size_t);
63 90
64 std::unique_ptr<PNGImageReader> m_reader; 91 std::unique_ptr<PNGImageReader> m_reader;
65 const unsigned m_offset; 92 const unsigned m_offset;
93 size_t m_frameCount;
94 size_t m_currentFrame;
95 // m_repetitionCount is set to cAnimationLoopOnce by default, so the
96 // DeferredImageDecoder takes into account that this may be an animated
97 // image, but we don't know for sure yet.
98 int m_repetitionCount;
99 // This flag is set to true if the color space has been set. This is used to
100 // prevent setting the color space in each frame, which is unnecessary since
101 // frames don't have their own color space.
102 bool m_colorSpaceSet;
103 bool m_hasAlphaChannel;
104 bool m_currentBufferSawAlpha;
105
106 // This flag is set to true while PNGImageReader is parsing. This is used by
107 // setFailed() to determine how to handle a failure.
108 bool m_isParsing;
109 // This flag is set to true when a failure has occured, but there are earlier
110 // frames that can still be shown. In that case, the frame count is lowered.
111 // This flag prevents from calling parse() again, which could change the frame
112 // count back to the pre-failure value.
113 bool m_failedWithCorrectFrames;
66 }; 114 };
67 115
68 } // namespace blink 116 } // namespace blink
69 117
70 #endif 118 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698