OLD | NEW |
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 13 matching lines...) Expand all Loading... |
24 */ | 24 */ |
25 | 25 |
26 #ifndef GIFImageDecoder_h | 26 #ifndef GIFImageDecoder_h |
27 #define GIFImageDecoder_h | 27 #define GIFImageDecoder_h |
28 | 28 |
29 #include "platform/image-decoders/ImageDecoder.h" | 29 #include "platform/image-decoders/ImageDecoder.h" |
30 #include "wtf/Noncopyable.h" | 30 #include "wtf/Noncopyable.h" |
31 #include "wtf/OwnPtr.h" | 31 #include "wtf/OwnPtr.h" |
32 | 32 |
33 class GIFImageReader; | 33 class GIFImageReader; |
| 34 struct GIFFrameContext; |
34 | 35 |
35 typedef Vector<unsigned char> GIFRow; | 36 typedef Vector<unsigned char> GIFRow; |
36 | 37 |
37 namespace blink { | 38 namespace blink { |
38 | 39 |
39 // This class decodes the GIF image format. | 40 // This class decodes the GIF image format. |
40 class PLATFORM_EXPORT GIFImageDecoder final : public ImageDecoder { | 41 class PLATFORM_EXPORT GIFImageDecoder final : public ImageDecoder { |
41 WTF_MAKE_NONCOPYABLE(GIFImageDecoder); | 42 WTF_MAKE_NONCOPYABLE(GIFImageDecoder); |
42 public: | 43 public: |
43 GIFImageDecoder(AlphaOption, GammaAndColorProfileOption, size_t maxDecodedBy
tes); | 44 GIFImageDecoder(AlphaOption, GammaAndColorProfileOption, size_t maxDecodedBy
tes, ImageFrame::ColorType decodeTo = ImageFrame::Index8); |
44 ~GIFImageDecoder() override; | 45 ~GIFImageDecoder() override; |
45 | 46 |
46 enum GIFParseQuery { GIFSizeQuery, GIFFrameCountQuery }; | 47 enum GIFParseQuery { GIFSizeQuery, GIFFrameCountQuery }; |
47 | 48 |
48 // ImageDecoder: | 49 // ImageDecoder: |
49 String filenameExtension() const override { return "gif"; } | 50 String filenameExtension() const override { return "gif"; } |
50 void onSetData(SharedBuffer* data) override; | 51 void onSetData(SharedBuffer* data) override; |
51 int repetitionCount() const override; | 52 int repetitionCount() const override; |
52 bool frameIsCompleteAtIndex(size_t) const override; | 53 bool frameIsCompleteAtIndex(size_t) const override; |
53 float frameDurationAtIndex(size_t) const override; | 54 float frameDurationAtIndex(size_t) const override; |
54 size_t clearCacheExceptFrame(size_t) override; | 55 size_t clearCacheExceptFrame(size_t) override; |
55 // CAUTION: setFailed() deletes |m_reader|. Be careful to avoid | 56 // CAUTION: setFailed() deletes |m_reader|. Be careful to avoid |
56 // accessing deleted memory, especially when calling this from inside | 57 // accessing deleted memory, especially when calling this from inside |
57 // GIFImageReader! | 58 // GIFImageReader! |
58 bool setFailed() override; | 59 bool setFailed() override; |
59 | 60 |
60 // Callbacks from the GIF reader. | 61 // Callbacks from the GIF reader. |
61 bool haveDecodedRow(size_t frameIndex, GIFRow::const_iterator rowBegin, size
_t width, size_t rowNumber, unsigned repeatCount, bool writeTransparentPixels); | 62 bool (GIFImageDecoder::*phaveDecodedRow)(size_t frameIndex, GIFRow::const_it
erator rowBegin, size_t width, size_t rowNumber, unsigned repeatCount, bool writ
eTransparentPixels); |
| 63 inline bool haveDecodedRow(size_t frameIndex, GIFRow::const_iterator rowBegi
n, size_t width, size_t rowNumber, unsigned repeatCount, bool writeTransparentPi
xels) |
| 64 { |
| 65 return (this->*phaveDecodedRow)(frameIndex, rowBegin, width, rowNumber,
repeatCount, writeTransparentPixels); |
| 66 } |
62 bool frameComplete(size_t frameIndex); | 67 bool frameComplete(size_t frameIndex); |
63 | 68 |
| 69 // Called to initialize the frame buffer with the given index, based on |
| 70 // the previous frame's disposal method. Returns true on success. On |
| 71 // failure, this will mark the image as failed. |
| 72 bool initFrameBuffer(size_t frameIndex); |
| 73 |
| 74 // Callback implementations for different output. |
| 75 bool haveDecodedRowN32(size_t frameIndex, GIFRow::const_iterator rowBegin, s
ize_t width, size_t rowNumber, unsigned repeatCount, bool writeTransparentPixels
); |
| 76 bool haveDecodedRowIndex8(size_t frameIndex, GIFRow::const_iterator rowBegin
, size_t width, size_t rowNumber, unsigned repeatCount, bool writeTransparentPix
els); |
| 77 |
| 78 // Callback when reader detects state requiring RGBA decoding. |
| 79 void setForceN32Decoding(bool); |
| 80 |
64 // For testing. | 81 // For testing. |
65 bool parseCompleted() const; | 82 bool parseCompleted() const; |
66 | 83 |
| 84 // For supporting both N32 and Index8 output. |
| 85 bool canDecodeTo(size_t index, ImageFrame::ColorType outputType) override; |
| 86 |
67 private: | 87 private: |
68 // ImageDecoder: | 88 // ImageDecoder: |
69 void clearFrameBuffer(size_t frameIndex) override; | 89 void clearFrameBuffer(size_t frameIndex) override; |
70 virtual void decodeSize() { parse(GIFSizeQuery); } | 90 virtual void decodeSize() { parse(GIFSizeQuery); } |
71 size_t decodeFrameCount() override; | 91 size_t decodeFrameCount() override; |
72 void initializeNewFrame(size_t) override; | 92 void initializeNewFrame(size_t) override; |
73 void decode(size_t) override; | 93 void decode(size_t) override; |
74 | 94 |
| 95 |
75 // Parses as much as is needed to answer the query, ignoring bitmap | 96 // Parses as much as is needed to answer the query, ignoring bitmap |
76 // data. If parsing fails, sets the "decode failure" flag. | 97 // data. If parsing fails, sets the "decode failure" flag. |
77 void parse(GIFParseQuery); | 98 void parse(GIFParseQuery); |
78 | 99 |
79 // Called to initialize the frame buffer with the given index, based on | 100 bool initFrameBufferN32(size_t frameIndex); |
80 // the previous frame's disposal method. Returns true on success. On | 101 |
81 // failure, this will mark the image as failed. | 102 void updateRequiredPreviousFrame(ImageFrame*, const GIFFrameContext&); |
82 bool initFrameBuffer(size_t frameIndex); | |
83 | 103 |
84 bool m_currentBufferSawAlpha; | 104 bool m_currentBufferSawAlpha; |
85 mutable int m_repetitionCount; | 105 mutable int m_repetitionCount; |
86 OwnPtr<GIFImageReader> m_reader; | 106 OwnPtr<GIFImageReader> m_reader; |
| 107 |
| 108 // Holds information about which decoding output was requested in constructo
r. |
| 109 // N32 color mode is used for testing only. |
| 110 ImageFrame::ColorType m_colorMode; |
| 111 |
| 112 // Used in Index8 decoding mode, some of the frames need to get decoded to N
32. |
| 113 // This flag is reset when situation allows going back to Index8 decoding in
initFrameBuffer. |
| 114 bool m_forceN32Decoding; |
87 }; | 115 }; |
88 | 116 |
89 } // namespace blink | 117 } // namespace blink |
90 | 118 |
91 #endif | 119 #endif |
OLD | NEW |