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; |
| 37 typedef Vector<blink::ImageFrame::PixelData> GIFColorTable; | |
| 36 | 38 |
| 37 namespace blink { | 39 namespace blink { |
| 38 | 40 |
| 39 // This class decodes the GIF image format. | 41 // This class decodes the GIF image format. |
| 40 class PLATFORM_EXPORT GIFImageDecoder final : public ImageDecoder { | 42 class PLATFORM_EXPORT GIFImageDecoder final : public ImageDecoder { |
| 41 WTF_MAKE_NONCOPYABLE(GIFImageDecoder); | 43 WTF_MAKE_NONCOPYABLE(GIFImageDecoder); |
| 42 public: | 44 public: |
| 43 GIFImageDecoder(AlphaOption, GammaAndColorProfileOption, size_t maxDecodedBy tes); | 45 GIFImageDecoder(AlphaOption, GammaAndColorProfileOption, size_t maxDecodedBy tes, ImageFrame::ColorType decodeTo = ImageFrame::Index8); |
|
scroggo_chromium
2016/04/29 19:48:15
Since this is always Index8 except for testing, wh
| |
| 44 ~GIFImageDecoder() override; | 46 ~GIFImageDecoder() override; |
| 45 | 47 |
| 46 enum GIFParseQuery { GIFSizeQuery, GIFFrameCountQuery }; | 48 enum GIFParseQuery { GIFSizeQuery, GIFFrameCountQuery }; |
| 47 | 49 |
| 48 // ImageDecoder: | 50 // ImageDecoder: |
| 49 String filenameExtension() const override { return "gif"; } | 51 String filenameExtension() const override { return "gif"; } |
| 50 void onSetData(SharedBuffer* data) override; | 52 void onSetData(SharedBuffer* data) override; |
| 51 int repetitionCount() const override; | 53 int repetitionCount() const override; |
| 52 bool frameIsCompleteAtIndex(size_t) const override; | 54 bool frameIsCompleteAtIndex(size_t) const override; |
| 53 float frameDurationAtIndex(size_t) const override; | 55 float frameDurationAtIndex(size_t) const override; |
| 54 size_t clearCacheExceptFrame(size_t) override; | 56 size_t clearCacheExceptFrame(size_t) override; |
| 55 // CAUTION: setFailed() deletes |m_reader|. Be careful to avoid | 57 // CAUTION: setFailed() deletes |m_reader|. Be careful to avoid |
| 56 // accessing deleted memory, especially when calling this from inside | 58 // accessing deleted memory, especially when calling this from inside |
| 57 // GIFImageReader! | 59 // GIFImageReader! |
| 58 bool setFailed() override; | 60 bool setFailed() override; |
| 59 | 61 |
| 60 // Callbacks from the GIF reader. | 62 // 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); | 63 void haveDecodedRow(const GIFFrameContext&, GIFRow::const_iterator rowBegin, size_t rowNumber, unsigned repeatCount, bool writeTransparentPixels); |
| 62 bool frameComplete(size_t frameIndex); | 64 bool frameComplete(size_t frameIndex); |
| 63 | 65 |
| 66 // Called to initialize the frame buffer with the given index, based on | |
| 67 // the previous frame's disposal method. Returns true on success. On | |
| 68 // failure, this will mark the image as failed. | |
| 69 bool initFrameBuffer(size_t frameIndex); | |
| 70 | |
| 64 // For testing. | 71 // For testing. |
| 65 bool parseCompleted() const; | 72 bool parseCompleted() const; |
| 66 | 73 |
| 74 // For supporting both N32 and Index8 output. | |
| 75 bool canDecodeTo(size_t index, ImageFrame::ColorType outputType) override; | |
| 76 | |
| 67 private: | 77 private: |
| 68 // ImageDecoder: | 78 // ImageDecoder: |
| 69 void clearFrameBuffer(size_t frameIndex) override; | 79 void clearFrameBuffer(size_t frameIndex) override; |
| 70 virtual void decodeSize() { parse(GIFSizeQuery); } | 80 virtual void decodeSize() { parse(GIFSizeQuery); } |
| 71 size_t decodeFrameCount() override; | 81 size_t decodeFrameCount() override; |
| 72 void initializeNewFrame(size_t) override; | 82 void initializeNewFrame(size_t) override; |
| 73 void decode(size_t) override; | 83 void decode(size_t) override; |
| 74 | 84 |
| 85 | |
|
scroggo_chromium
2016/04/29 19:48:15
nit: Please remove this extra line.
| |
| 75 // Parses as much as is needed to answer the query, ignoring bitmap | 86 // Parses as much as is needed to answer the query, ignoring bitmap |
| 76 // data. If parsing fails, sets the "decode failure" flag. | 87 // data. If parsing fails, sets the "decode failure" flag. |
| 77 void parse(GIFParseQuery); | 88 void parse(GIFParseQuery); |
| 78 | 89 |
| 79 // Called to initialize the frame buffer with the given index, based on | 90 bool initFrameBufferN32(size_t frameIndex); |
| 80 // the previous frame's disposal method. Returns true on success. On | 91 |
| 81 // failure, this will mark the image as failed. | 92 bool isIndex8Applicable(const GIFFrameContext&, size_t requiredPreviousFrame Index) const; |
| 82 bool initFrameBuffer(size_t frameIndex); | 93 void updateRequiredPreviousFrame(ImageFrame*, const GIFFrameContext&); |
| 94 unsigned getBackgroundIndex(const GIFFrameContext&) const; | |
| 95 SkColor getBackgroundColor(size_t frameIndex) const; | |
| 96 bool initFrameBufferFromPrevious(ImageFrame* buffer, const ImageFrame& previ ousBuffer, ImageFrame::ColorType, size_t transparentIndex = 0xFF); | |
| 97 void setupHaveDecodedRowCallbacks(bool isIndex8); | |
| 98 | |
| 99 // Callback implementations for different output. | |
| 100 void writeRowN32(const GIFFrameContext&, ImageFrame&, const GIFColorTable&, GIFRow::const_iterator, GIFRow::const_iterator, int, int, bool); | |
| 101 void writeRowIndex8(const GIFFrameContext&, ImageFrame&, const GIFColorTable &, GIFRow::const_iterator, GIFRow::const_iterator, int, int, bool); | |
| 102 | |
| 103 typedef void (GIFImageDecoder::*WriteRowFunction)(const GIFFrameContext&, Im ageFrame&, const GIFColorTable&, GIFRow::const_iterator, GIFRow::const_iterator, int, int, bool); | |
|
scroggo_chromium
2016/04/29 19:48:15
Please add parameter names where they are not obvi
| |
| 104 typedef void (*CopyRowNTimesFunction)(ImageFrame&, int, int, int, int); | |
| 105 | |
| 106 WriteRowFunction m_writeRowFunction; | |
| 107 CopyRowNTimesFunction m_copyRowNTimesFunction; | |
| 83 | 108 |
| 84 bool m_currentBufferSawAlpha; | 109 bool m_currentBufferSawAlpha; |
| 85 mutable int m_repetitionCount; | 110 mutable int m_repetitionCount; |
| 86 OwnPtr<GIFImageReader> m_reader; | 111 OwnPtr<GIFImageReader> m_reader; |
| 112 | |
| 113 // Important for testing only - it is always Index8 mode except in some test s | |
| 114 // where we also use N32 mode to compare with Index8. | |
| 115 ImageFrame::ColorType m_requestedColorMode; | |
|
scroggo_chromium
2016/04/29 19:48:15
Could be const?
| |
| 87 }; | 116 }; |
| 88 | 117 |
| 89 } // namespace blink | 118 } // namespace blink |
| 90 | 119 |
| 91 #endif | 120 #endif |
| OLD | NEW |