Chromium Code Reviews| 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)(const GIFFrameContext&, GIFRow::con st_iterator rowBegin, size_t rowNumber, unsigned repeatCount, bool writeTranspar entPixels); |
|
scroggo_chromium
2016/01/06 21:50:41
Does this pointer need to be public?
Also, maybe
aleksandar.stojiljkovic
2016/01/18 13:58:50
Done.
All private, typedef, m_XXXXFunction found e
| |
| 63 inline bool haveDecodedRow(const GIFFrameContext& frameContext, GIFRow::cons t_iterator rowBegin, size_t rowNumber, unsigned repeatCount, bool writeTranspare ntPixels) | |
| 64 { | |
| 65 return (this->*phaveDecodedRow)(frameContext, rowBegin, rowNumber, repea tCount, 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(const GIFFrameContext&, GIFRow::const_iterator rowBeg in, size_t rowNumber, unsigned repeatCount, bool writeTransparentPixels); | |
|
scroggo_chromium
2016/01/06 21:50:41
Can these be private?
aleksandar.stojiljkovic
2016/01/18 13:58:50
Done.
| |
| 76 bool haveDecodedRowIndex8(const GIFFrameContext&, GIFRow::const_iterator row Begin, size_t rowNumber, unsigned repeatCount, bool writeTransparentPixels); | |
| 77 | |
| 64 // For testing. | 78 // For testing. |
| 65 bool parseCompleted() const; | 79 bool parseCompleted() const; |
| 66 | 80 |
| 81 // For supporting both N32 and Index8 output. | |
| 82 bool canDecodeTo(size_t index, ImageFrame::ColorType outputType) override; | |
| 83 | |
| 67 private: | 84 private: |
| 68 // ImageDecoder: | 85 // ImageDecoder: |
| 69 void clearFrameBuffer(size_t frameIndex) override; | 86 void clearFrameBuffer(size_t frameIndex) override; |
| 70 virtual void decodeSize() { parse(GIFSizeQuery); } | 87 virtual void decodeSize() { parse(GIFSizeQuery); } |
| 71 size_t decodeFrameCount() override; | 88 size_t decodeFrameCount() override; |
| 72 void initializeNewFrame(size_t) override; | 89 void initializeNewFrame(size_t) override; |
| 73 void decode(size_t) override; | 90 void decode(size_t) override; |
| 74 | 91 |
| 92 | |
| 75 // Parses as much as is needed to answer the query, ignoring bitmap | 93 // Parses as much as is needed to answer the query, ignoring bitmap |
| 76 // data. If parsing fails, sets the "decode failure" flag. | 94 // data. If parsing fails, sets the "decode failure" flag. |
| 77 void parse(GIFParseQuery); | 95 void parse(GIFParseQuery); |
| 78 | 96 |
| 79 // Called to initialize the frame buffer with the given index, based on | 97 bool initFrameBufferN32(size_t frameIndex); |
| 80 // the previous frame's disposal method. Returns true on success. On | 98 |
| 81 // failure, this will mark the image as failed. | 99 bool isIndex8Applicable(const GIFFrameContext&, size_t requiredPreviousFrame Index) const; |
| 82 bool initFrameBuffer(size_t frameIndex); | 100 void updateRequiredPreviousFrame(ImageFrame*, const GIFFrameContext&); |
| 101 unsigned char getBackgroundIndex(const GIFFrameContext&) const; | |
|
scroggo_chromium
2016/01/06 21:50:41
I think you defined this as an unsigned short in G
aleksandar.stojiljkovic
2016/01/18 13:58:50
Done. unsigned everywhere.
| |
| 102 SkColor getBackgroundColor(size_t frameIndex) const; | |
| 103 bool initFrameBufferFromPreviousN32(ImageFrame* const buffer, const ImageFra me& previousBuffer); | |
| 104 void setupHaveDecodedRowCallbacks(bool isIndex8); | |
| 83 | 105 |
| 84 bool m_currentBufferSawAlpha; | 106 bool m_currentBufferSawAlpha; |
| 85 mutable int m_repetitionCount; | 107 mutable int m_repetitionCount; |
| 86 OwnPtr<GIFImageReader> m_reader; | 108 OwnPtr<GIFImageReader> m_reader; |
| 109 | |
| 110 // Holds information about which decoding output was requested in constructo r. | |
|
scroggo_chromium
2016/01/06 21:50:41
If this always matches the constructor, I think it
aleksandar.stojiljkovic
2016/01/18 13:58:50
Done.
| |
| 111 // N32 color mode is used for testing only. | |
| 112 ImageFrame::ColorType m_colorMode; | |
| 113 | |
| 87 }; | 114 }; |
| 88 | 115 |
| 89 } // namespace blink | 116 } // namespace blink |
| 90 | 117 |
| 91 #endif | 118 #endif |
| OLD | NEW |