| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Apple Computer, Inc. | 2 * Copyright (C) 2006 Apple Computer, Inc. |
| 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
| 4 * | 4 * |
| 5 * Portions are Copyright (C) 2001 mozilla.org | 5 * Portions are Copyright (C) 2001 mozilla.org |
| 6 * | 6 * |
| 7 * Other contributors: | 7 * Other contributors: |
| 8 * Stuart Parmenter <stuart@mozilla.com> | 8 * Stuart Parmenter <stuart@mozilla.com> |
| 9 * | 9 * |
| 10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 80 } |
| 81 | 81 |
| 82 } // anonymous | 82 } // anonymous |
| 83 | 83 |
| 84 namespace blink { | 84 namespace blink { |
| 85 | 85 |
| 86 class PNGImageReader final { | 86 class PNGImageReader final { |
| 87 USING_FAST_MALLOC(PNGImageReader); | 87 USING_FAST_MALLOC(PNGImageReader); |
| 88 WTF_MAKE_NONCOPYABLE(PNGImageReader); | 88 WTF_MAKE_NONCOPYABLE(PNGImageReader); |
| 89 public: | 89 public: |
| 90 PNGImageReader(PNGImageDecoder* decoder, unsigned readOffset) | 90 PNGImageReader(PNGImageDecoder* decoder, size_t readOffset) |
| 91 : m_decoder(decoder) | 91 : m_decoder(decoder) |
| 92 , m_readOffset(readOffset) | 92 , m_readOffset(readOffset) |
| 93 , m_currentBufferSize(0) | 93 , m_currentBufferSize(0) |
| 94 , m_decodingSizeOnly(false) | 94 , m_decodingSizeOnly(false) |
| 95 , m_hasAlpha(false) | 95 , m_hasAlpha(false) |
| 96 #if USE(QCMSLIB) | 96 #if USE(QCMSLIB) |
| 97 , m_transform(0) | 97 , m_transform(0) |
| 98 , m_rowBuffer() | 98 , m_rowBuffer() |
| 99 #endif | 99 #endif |
| 100 { | 100 { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 116 | 116 |
| 117 bool decode(const SharedBuffer& data, bool sizeOnly) | 117 bool decode(const SharedBuffer& data, bool sizeOnly) |
| 118 { | 118 { |
| 119 m_decodingSizeOnly = sizeOnly; | 119 m_decodingSizeOnly = sizeOnly; |
| 120 | 120 |
| 121 // We need to do the setjmp here. Otherwise bad things will happen. | 121 // We need to do the setjmp here. Otherwise bad things will happen. |
| 122 if (setjmp(JMPBUF(m_png))) | 122 if (setjmp(JMPBUF(m_png))) |
| 123 return m_decoder->setFailed(); | 123 return m_decoder->setFailed(); |
| 124 | 124 |
| 125 const char* segment; | 125 const char* segment; |
| 126 while (unsigned segmentLength = data.getSomeData(segment, m_readOffset))
{ | 126 while (size_t segmentLength = data.getSomeData(segment, m_readOffset)) { |
| 127 m_readOffset += segmentLength; | 127 m_readOffset += segmentLength; |
| 128 m_currentBufferSize = m_readOffset; | 128 m_currentBufferSize = m_readOffset; |
| 129 png_process_data(m_png, m_info, reinterpret_cast<png_bytep>(const_ca
st<char*>(segment)), segmentLength); | 129 png_process_data(m_png, m_info, reinterpret_cast<png_bytep>(const_ca
st<char*>(segment)), segmentLength); |
| 130 if (sizeOnly ? m_decoder->isDecodedSizeAvailable() : m_decoder->fram
eIsCompleteAtIndex(0)) | 130 if (sizeOnly ? m_decoder->isDecodedSizeAvailable() : m_decoder->fram
eIsCompleteAtIndex(0)) |
| 131 return true; | 131 return true; |
| 132 } | 132 } |
| 133 | 133 |
| 134 return false; | 134 return false; |
| 135 } | 135 } |
| 136 | 136 |
| 137 png_structp pngPtr() const { return m_png; } | 137 png_structp pngPtr() const { return m_png; } |
| 138 png_infop infoPtr() const { return m_info; } | 138 png_infop infoPtr() const { return m_info; } |
| 139 | 139 |
| 140 void setReadOffset(unsigned offset) { m_readOffset = offset; } | 140 void setReadOffset(size_t offset) { m_readOffset = offset; } |
| 141 unsigned currentBufferSize() const { return m_currentBufferSize; } | 141 size_t currentBufferSize() const { return m_currentBufferSize; } |
| 142 bool decodingSizeOnly() const { return m_decodingSizeOnly; } | 142 bool decodingSizeOnly() const { return m_decodingSizeOnly; } |
| 143 void setHasAlpha(bool hasAlpha) { m_hasAlpha = hasAlpha; } | 143 void setHasAlpha(bool hasAlpha) { m_hasAlpha = hasAlpha; } |
| 144 bool hasAlpha() const { return m_hasAlpha; } | 144 bool hasAlpha() const { return m_hasAlpha; } |
| 145 | 145 |
| 146 png_bytep interlaceBuffer() const { return m_interlaceBuffer.get(); } | 146 png_bytep interlaceBuffer() const { return m_interlaceBuffer.get(); } |
| 147 void createInterlaceBuffer(int size) { m_interlaceBuffer = adoptArrayPtr(new
png_byte[size]); } | 147 void createInterlaceBuffer(int size) { m_interlaceBuffer = adoptArrayPtr(new
png_byte[size]); } |
| 148 #if USE(QCMSLIB) | 148 #if USE(QCMSLIB) |
| 149 png_bytep rowBuffer() const { return m_rowBuffer.get(); } | 149 png_bytep rowBuffer() const { return m_rowBuffer.get(); } |
| 150 void createRowBuffer(int size) { m_rowBuffer = adoptArrayPtr(new png_byte[si
ze]); } | 150 void createRowBuffer(int size) { m_rowBuffer = adoptArrayPtr(new png_byte[si
ze]); } |
| 151 qcms_transform* colorTransform() const { return m_transform; } | 151 qcms_transform* colorTransform() const { return m_transform; } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 m_transform = qcms_transform_create(inputProfile, dataFormat, deviceProf
ile, dataFormat, QCMS_INTENT_PERCEPTUAL); | 187 m_transform = qcms_transform_create(inputProfile, dataFormat, deviceProf
ile, dataFormat, QCMS_INTENT_PERCEPTUAL); |
| 188 | 188 |
| 189 qcms_profile_release(inputProfile); | 189 qcms_profile_release(inputProfile); |
| 190 } | 190 } |
| 191 #endif | 191 #endif |
| 192 | 192 |
| 193 private: | 193 private: |
| 194 png_structp m_png; | 194 png_structp m_png; |
| 195 png_infop m_info; | 195 png_infop m_info; |
| 196 PNGImageDecoder* m_decoder; | 196 PNGImageDecoder* m_decoder; |
| 197 unsigned m_readOffset; | 197 size_t m_readOffset; |
| 198 unsigned m_currentBufferSize; | 198 size_t m_currentBufferSize; |
| 199 bool m_decodingSizeOnly; | 199 bool m_decodingSizeOnly; |
| 200 bool m_hasAlpha; | 200 bool m_hasAlpha; |
| 201 OwnPtr<png_byte[]> m_interlaceBuffer; | 201 OwnPtr<png_byte[]> m_interlaceBuffer; |
| 202 #if USE(QCMSLIB) | 202 #if USE(QCMSLIB) |
| 203 qcms_transform* m_transform; | 203 qcms_transform* m_transform; |
| 204 OwnPtr<png_byte[]> m_rowBuffer; | 204 OwnPtr<png_byte[]> m_rowBuffer; |
| 205 #endif | 205 #endif |
| 206 }; | 206 }; |
| 207 | 207 |
| 208 PNGImageDecoder::PNGImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOp
tion colorOptions, size_t maxDecodedBytes, unsigned offset) | 208 PNGImageDecoder::PNGImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOp
tion colorOptions, size_t maxDecodedBytes, size_t offset) |
| 209 : ImageDecoder(alphaOption, colorOptions, maxDecodedBytes) | 209 : ImageDecoder(alphaOption, colorOptions, maxDecodedBytes) |
| 210 , m_hasColorProfile(false) | 210 , m_hasColorProfile(false) |
| 211 , m_offset(offset) | 211 , m_offset(offset) |
| 212 { | 212 { |
| 213 } | 213 } |
| 214 | 214 |
| 215 PNGImageDecoder::~PNGImageDecoder() | 215 PNGImageDecoder::~PNGImageDecoder() |
| 216 { | 216 { |
| 217 } | 217 } |
| 218 | 218 |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 // has failed. | 503 // has failed. |
| 504 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) | 504 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) |
| 505 setFailed(); | 505 setFailed(); |
| 506 | 506 |
| 507 // If decoding is done or failed, we don't need the PNGImageReader anymore. | 507 // If decoding is done or failed, we don't need the PNGImageReader anymore. |
| 508 if (isComplete(this) || failed()) | 508 if (isComplete(this) || failed()) |
| 509 m_reader.clear(); | 509 m_reader.clear(); |
| 510 } | 510 } |
| 511 | 511 |
| 512 } // namespace blink | 512 } // namespace blink |
| OLD | NEW |