| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Apple Computer, Inc. | 2 * Copyright (C) 2006 Apple Computer, Inc. |
| 3 * | 3 * |
| 4 * Portions are Copyright (C) 2001-6 mozilla.org | 4 * Portions are Copyright (C) 2001-6 mozilla.org |
| 5 * | 5 * |
| 6 * Other contributors: | 6 * Other contributors: |
| 7 * Stuart Parmenter <stuart@mozilla.com> | 7 * Stuart Parmenter <stuart@mozilla.com> |
| 8 * | 8 * |
| 9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Lesser General Public | 10 * modify it under the terms of the GNU Lesser General Public |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 } | 355 } |
| 356 | 356 |
| 357 m_nextReadPosition += bytes; | 357 m_nextReadPosition += bytes; |
| 358 m_info.src->bytes_in_buffer = bytes; | 358 m_info.src->bytes_in_buffer = bytes; |
| 359 const JOCTET* nextByte = reinterpret_cast_ptr<const JOCTET*>(segment); | 359 const JOCTET* nextByte = reinterpret_cast_ptr<const JOCTET*>(segment); |
| 360 m_info.src->next_input_byte = nextByte; | 360 m_info.src->next_input_byte = nextByte; |
| 361 m_lastSetByte = nextByte; | 361 m_lastSetByte = nextByte; |
| 362 return true; | 362 return true; |
| 363 } | 363 } |
| 364 | 364 |
| 365 void setData(SegmentReader* data) | 365 void setData(SharedBuffer* data) |
| 366 { | 366 { |
| 367 if (m_data.get() == data) | 367 if (m_data.get() == data) |
| 368 return; | 368 return; |
| 369 | 369 |
| 370 m_data = data; | 370 m_data = data; |
| 371 | 371 |
| 372 // If a restart is needed, the next call to fillBuffer will read from th
e new SegmentReader. | 372 // If a restart is needed, the next call to fillBuffer will read from th
e new SharedBuffer. |
| 373 if (m_needsRestart) | 373 if (m_needsRestart) |
| 374 return; | 374 return; |
| 375 | 375 |
| 376 // Otherwise, empty the buffer, and leave the position the same, so fill
Buffer continues | 376 // Otherwise, empty the buffer, and leave the position the same, so fill
Buffer continues |
| 377 // reading from the same position in the new SegmentReader. | 377 // reading from the same position in the new SharedBuffer. |
| 378 m_nextReadPosition -= m_info.src->bytes_in_buffer; | 378 m_nextReadPosition -= m_info.src->bytes_in_buffer; |
| 379 clearBuffer(); | 379 clearBuffer(); |
| 380 } | 380 } |
| 381 | 381 |
| 382 bool decode(bool onlySize) | 382 bool decode(bool onlySize) |
| 383 { | 383 { |
| 384 // We need to do the setjmp here. Otherwise bad things will happen | 384 // We need to do the setjmp here. Otherwise bad things will happen |
| 385 if (setjmp(m_err.setjmp_buffer)) | 385 if (setjmp(m_err.setjmp_buffer)) |
| 386 return m_decoder->setFailed(); | 386 return m_decoder->setFailed(); |
| 387 | 387 |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 } | 631 } |
| 632 | 632 |
| 633 void clearBuffer() | 633 void clearBuffer() |
| 634 { | 634 { |
| 635 // Let libjpeg know that the buffer needs to be refilled. | 635 // Let libjpeg know that the buffer needs to be refilled. |
| 636 m_info.src->bytes_in_buffer = 0; | 636 m_info.src->bytes_in_buffer = 0; |
| 637 m_info.src->next_input_byte = nullptr; | 637 m_info.src->next_input_byte = nullptr; |
| 638 m_lastSetByte = nullptr; | 638 m_lastSetByte = nullptr; |
| 639 } | 639 } |
| 640 | 640 |
| 641 RefPtr<SegmentReader> m_data; | 641 RefPtr<SharedBuffer> m_data; |
| 642 JPEGImageDecoder* m_decoder; | 642 JPEGImageDecoder* m_decoder; |
| 643 | 643 |
| 644 // Input reading: True if we need to back up to m_restartPosition. | 644 // Input reading: True if we need to back up to m_restartPosition. |
| 645 bool m_needsRestart; | 645 bool m_needsRestart; |
| 646 // If libjpeg needed to restart, this is the position to restart from. | 646 // If libjpeg needed to restart, this is the position to restart from. |
| 647 size_t m_restartPosition; | 647 size_t m_restartPosition; |
| 648 // This is the position where we will read from, unless there is a restart. | 648 // This is the position where we will read from, unless there is a restart. |
| 649 size_t m_nextReadPosition; | 649 size_t m_nextReadPosition; |
| 650 // This is how we know to update the restart position. It is the last value | 650 // This is how we know to update the restart position. It is the last value |
| 651 // we set to next_input_byte. libjpeg will update next_input_byte when it | 651 // we set to next_input_byte. libjpeg will update next_input_byte when it |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 if (!ImageDecoder::setSize(width, height)) | 717 if (!ImageDecoder::setSize(width, height)) |
| 718 return false; | 718 return false; |
| 719 | 719 |
| 720 if (!desiredScaleNumerator()) | 720 if (!desiredScaleNumerator()) |
| 721 return setFailed(); | 721 return setFailed(); |
| 722 | 722 |
| 723 setDecodedSize(width, height); | 723 setDecodedSize(width, height); |
| 724 return true; | 724 return true; |
| 725 } | 725 } |
| 726 | 726 |
| 727 void JPEGImageDecoder::onSetData(SegmentReader* data) | 727 void JPEGImageDecoder::onSetData(SharedBuffer* data) |
| 728 { | 728 { |
| 729 if (m_reader) | 729 if (m_reader) |
| 730 m_reader->setData(data); | 730 m_reader->setData(data); |
| 731 } | 731 } |
| 732 | 732 |
| 733 void JPEGImageDecoder::setDecodedSize(unsigned width, unsigned height) | 733 void JPEGImageDecoder::setDecodedSize(unsigned width, unsigned height) |
| 734 { | 734 { |
| 735 m_decodedSize = IntSize(width, height); | 735 m_decodedSize = IntSize(width, height); |
| 736 } | 736 } |
| 737 | 737 |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 // has failed. | 989 // has failed. |
| 990 if (!m_reader->decode(onlySize) && isAllDataReceived()) | 990 if (!m_reader->decode(onlySize) && isAllDataReceived()) |
| 991 setFailed(); | 991 setFailed(); |
| 992 | 992 |
| 993 // If decoding is done or failed, we don't need the JPEGImageReader anymore. | 993 // If decoding is done or failed, we don't need the JPEGImageReader anymore. |
| 994 if (isComplete(this, onlySize) || failed()) | 994 if (isComplete(this, onlySize) || failed()) |
| 995 m_reader.clear(); | 995 m_reader.clear(); |
| 996 } | 996 } |
| 997 | 997 |
| 998 } // namespace blink | 998 } // namespace blink |
| OLD | NEW |