OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions |
| 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. |
| 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ |
| 25 |
| 26 |
| 27 #include "platform/image-decoders/SegmentReader.h" |
| 28 #include "platform/image-decoders/png/PNGImageDecoder.h" |
| 29 #include "platform/PlatformExport.h" |
| 30 #include "png.h" |
| 31 #include "wtf/Allocator.h" |
| 32 #include "wtf/PtrUtil.h" |
| 33 |
| 34 #ifndef PNGImageReader_h |
| 35 #define PNGImageReader_h |
| 36 |
| 37 namespace blink { |
| 38 |
| 39 class FastSharedBufferReader; |
| 40 |
| 41 class PLATFORM_EXPORT PNGImageReader final { |
| 42 USING_FAST_MALLOC(PNGImageReader); |
| 43 WTF_MAKE_NONCOPYABLE(PNGImageReader); |
| 44 public: |
| 45 PNGImageReader(PNGImageDecoder*, size_t readOffset); |
| 46 ~PNGImageReader(); |
| 47 |
| 48 struct FrameInfo { |
| 49 size_t readOffset; |
| 50 size_t byteLength; |
| 51 size_t duration; |
| 52 IntRect frameRect; |
| 53 ImageFrame::DisposalMethod disposalMethod; |
| 54 ImageFrame::AlphaBlendSource alphaBlend; |
| 55 }; |
| 56 |
| 57 |
| 58 // This method tries to parse the data stream in the SegmentReader, up to |
| 59 // the point where the PNGParseQuery can be answered. |
| 60 // @return true when the query is fulfilled. |
| 61 // false when: |
| 62 // A) not enough data provided |
| 63 // B) the data processing by libpng fails. In this case, it also |
| 64 // calls setFailed() on m_decoder. |
| 65 bool parse(SegmentReader&, PNGImageDecoder::PNGParseQuery); |
| 66 |
| 67 bool decode(SegmentReader&, size_t); |
| 68 const FrameInfo& frameInfo(size_t) const; |
| 69 |
| 70 // This will return the number of frames that have been detected in the |
| 71 // stream so far. If an incomplete stream is provided, this number is not |
| 72 // final. However, all frame info for the frames up to this number is |
| 73 // available so it can be used by the client if it wants to. |
| 74 size_t frameCount() const; |
| 75 |
| 76 // This is a callback for libpng, when it encounters an unknown chunk. |
| 77 void parseAnimationChunk(const char* tag, const void* dataChunk, size_t leng
th); |
| 78 |
| 79 png_structp pngPtr() const { return m_png; } |
| 80 png_infop infoPtr() const { return m_info; } |
| 81 |
| 82 size_t getReadOffset() const { return m_readOffset; } |
| 83 void setReadOffset(size_t offset) { m_readOffset = offset; } |
| 84 void setHasAlpha(bool hasAlpha) { m_hasAlpha = hasAlpha; } |
| 85 bool hasAlpha() const { return m_hasAlpha; } |
| 86 |
| 87 png_bytep interlaceBuffer() const { return m_interlaceBuffer.get(); } |
| 88 void createInterlaceBuffer(int size) { m_interlaceBuffer = wrapArrayUnique(n
ew png_byte[size]); } |
| 89 #if USE(QCMSLIB) |
| 90 png_bytep rowBuffer() const { return m_rowBuffer.get(); } |
| 91 void createRowBuffer(int size) { m_rowBuffer = wrapArrayUnique(new png_byte[
size]); } |
| 92 #endif |
| 93 |
| 94 |
| 95 private: |
| 96 png_structp m_png; |
| 97 png_infop m_info; |
| 98 PNGImageDecoder* m_decoder; |
| 99 size_t m_readOffset; |
| 100 bool m_hasAlpha; |
| 101 // This flag is set to true when an fcTL chunk is encountered before the |
| 102 // IDAT chunk(s). In that case, the IDAT data is the first frame. |
| 103 bool m_idatIsPartOfAnimation; |
| 104 bool m_parsedSignature; |
| 105 std::unique_ptr<png_byte[]> m_interlaceBuffer; |
| 106 |
| 107 Vector<FrameInfo, 1> m_frameInfo; |
| 108 FrameInfo m_newFrame; |
| 109 |
| 110 bool processData(SegmentReader&, size_t offset, size_t length); |
| 111 bool parseSize(SegmentReader&); |
| 112 void parseFrameInfo(const png_byte* data); |
| 113 |
| 114 #if USE(QCMSLIB) |
| 115 std::unique_ptr<png_byte[]> m_rowBuffer; |
| 116 #endif |
| 117 }; |
| 118 |
| 119 }; |
| 120 |
| 121 #endif |
OLD | NEW |