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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 class SegmentReader; | 45 class SegmentReader; |
46 | 46 |
47 class PLATFORM_EXPORT PNGImageReader final { | 47 class PLATFORM_EXPORT PNGImageReader final { |
48 USING_FAST_MALLOC(PNGImageReader); | 48 USING_FAST_MALLOC(PNGImageReader); |
49 WTF_MAKE_NONCOPYABLE(PNGImageReader); | 49 WTF_MAKE_NONCOPYABLE(PNGImageReader); |
50 | 50 |
51 public: | 51 public: |
52 PNGImageReader(PNGImageDecoder*, size_t offset); | 52 PNGImageReader(PNGImageDecoder*, size_t offset); |
53 ~PNGImageReader(); | 53 ~PNGImageReader(); |
54 | 54 |
55 bool decode(const SegmentReader&, bool sizeOnly); | 55 struct FrameInfo { |
| 56 size_t start; |
| 57 size_t finish; |
| 58 png_uint_32 width; |
| 59 png_uint_32 height; |
| 60 png_uint_32 xOffset; |
| 61 png_uint_32 yOffset; |
| 62 unsigned duration; |
| 63 unsigned dispose; |
| 64 unsigned blend; |
| 65 }; |
| 66 |
| 67 inline void processData(const SegmentReader& data, |
| 68 size_t index, |
| 69 size_t offset, |
| 70 size_t endOffset) { |
| 71 const char* segment; |
| 72 while (size_t segmentLength = data.getSomeData(segment, offset)) { |
| 73 if (endOffset && offset + segmentLength > endOffset) |
| 74 segmentLength = endOffset - offset; |
| 75 |
| 76 offset += segmentLength; |
| 77 png_process_data(m_png, m_info, |
| 78 reinterpret_cast<png_bytep>(const_cast<char*>(segment)), |
| 79 segmentLength); |
| 80 |
| 81 if (offset == endOffset) |
| 82 break; |
| 83 } |
| 84 if (!index) |
| 85 m_decodeOffset = offset; |
| 86 } |
| 87 |
| 88 bool parse(SegmentReader&); |
| 89 bool decode(SegmentReader&, size_t index); |
56 png_structp pngPtr() const { return m_png; } | 90 png_structp pngPtr() const { return m_png; } |
57 png_infop infoPtr() const { return m_info; } | 91 png_infop infoPtr() const { return m_info; } |
58 | 92 |
59 size_t getReadOffset() const { return m_readOffset; } | 93 int repetitionCount() const { return m_repetitionCount; } |
60 void setReadOffset(size_t offset) { m_readOffset = offset; } | 94 size_t imagesCount() const { |
61 size_t currentBufferSize() const { return m_currentBufferSize; } | 95 return m_frames.isEmpty() ? 1 : m_frames.size() - m_posterFrame; |
62 bool decodingSizeOnly() const { return m_decodingSizeOnly; } | 96 } |
| 97 const FrameInfo* frameInfo(size_t index) const { |
| 98 return m_frames.isEmpty() ? &m_currentFrame |
| 99 : &m_frames[index + m_posterFrame]; |
| 100 } |
63 void setHasAlpha(bool hasAlpha) { m_hasAlpha = hasAlpha; } | 101 void setHasAlpha(bool hasAlpha) { m_hasAlpha = hasAlpha; } |
64 bool hasAlpha() const { return m_hasAlpha; } | 102 bool hasAlpha() const { return m_hasAlpha; } |
65 | 103 |
66 png_bytep interlaceBuffer() const { return m_interlaceBuffer.get(); } | 104 png_bytep interlaceBuffer() const { return m_interlaceBuffer.get(); } |
67 void createInterlaceBuffer(int size) { | 105 void createInterlaceBuffer(int size) { |
68 m_interlaceBuffer = wrapArrayUnique(new png_byte[size]); | 106 m_interlaceBuffer = wrapArrayUnique(new png_byte[size]); |
69 } | 107 } |
70 | 108 |
71 private: | 109 private: |
72 png_structp m_png; | 110 png_structp m_png; |
73 png_infop m_info; | 111 png_infop m_info; |
74 PNGImageDecoder* m_decoder; | 112 PNGImageDecoder* m_decoder; |
75 size_t m_readOffset; | 113 size_t m_readOffset; |
76 size_t m_currentBufferSize; | 114 size_t m_parseOffset; |
77 bool m_decodingSizeOnly; | 115 size_t m_decodeOffset; |
| 116 size_t m_infoSize; |
| 117 bool m_isAnimated; |
| 118 bool m_isParsed; |
| 119 png_uint_32 m_width; |
| 120 png_uint_32 m_height; |
| 121 int m_repetitionCount; |
| 122 size_t m_posterFrame; |
| 123 size_t m_visibleFrames; |
| 124 FrameInfo m_currentFrame; |
| 125 Vector<FrameInfo> m_frames; |
78 bool m_hasAlpha; | 126 bool m_hasAlpha; |
79 std::unique_ptr<png_byte[]> m_interlaceBuffer; | 127 std::unique_ptr<png_byte[]> m_interlaceBuffer; |
80 }; | 128 }; |
81 | 129 |
82 } // namespace blink | 130 } // namespace blink |
83 | 131 |
84 #endif | 132 #endif |
OLD | NEW |