Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp

Issue 1812273003: Eliminate copies of encoded image data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 } 387 }
388 388
389 m_nextReadPosition += bytes; 389 m_nextReadPosition += bytes;
390 m_info.src->bytes_in_buffer = bytes; 390 m_info.src->bytes_in_buffer = bytes;
391 const JOCTET* nextByte = reinterpret_cast_ptr<const JOCTET*>(segment); 391 const JOCTET* nextByte = reinterpret_cast_ptr<const JOCTET*>(segment);
392 m_info.src->next_input_byte = nextByte; 392 m_info.src->next_input_byte = nextByte;
393 m_lastSetByte = nextByte; 393 m_lastSetByte = nextByte;
394 return true; 394 return true;
395 } 395 }
396 396
397 void setData(SharedBuffer* data) 397 void setData(SegmentReader* data)
398 { 398 {
399 if (m_data.get() == data) 399 if (m_data.get() == data)
400 return; 400 return;
401 401
402 m_data = data; 402 m_data = data;
403 403
404 // If a restart is needed, the next call to fillBuffer will read from th e new SharedBuffer. 404 // If a restart is needed, the next call to fillBuffer will read from th e new SegmentReader.
405 if (m_needsRestart) 405 if (m_needsRestart)
406 return; 406 return;
407 407
408 // Otherwise, empty the buffer, and leave the position the same, so fill Buffer continues 408 // Otherwise, empty the buffer, and leave the position the same, so fill Buffer continues
409 // reading from the same position in the new SharedBuffer. 409 // reading from the same position in the new SegmentReader.
410 m_nextReadPosition -= m_info.src->bytes_in_buffer; 410 m_nextReadPosition -= m_info.src->bytes_in_buffer;
411 clearBuffer(); 411 clearBuffer();
412 } 412 }
413 413
414 bool decode(bool onlySize) 414 bool decode(bool onlySize)
415 { 415 {
416 // We need to do the setjmp here. Otherwise bad things will happen 416 // We need to do the setjmp here. Otherwise bad things will happen
417 if (setjmp(m_err.setjmp_buffer)) 417 if (setjmp(m_err.setjmp_buffer))
418 return m_decoder->setFailed(); 418 return m_decoder->setFailed();
419 419
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 } 693 }
694 694
695 void clearBuffer() 695 void clearBuffer()
696 { 696 {
697 // Let libjpeg know that the buffer needs to be refilled. 697 // Let libjpeg know that the buffer needs to be refilled.
698 m_info.src->bytes_in_buffer = 0; 698 m_info.src->bytes_in_buffer = 0;
699 m_info.src->next_input_byte = nullptr; 699 m_info.src->next_input_byte = nullptr;
700 m_lastSetByte = nullptr; 700 m_lastSetByte = nullptr;
701 } 701 }
702 702
703 RefPtr<SharedBuffer> m_data; 703 RefPtr<SegmentReader> m_data;
704 JPEGImageDecoder* m_decoder; 704 JPEGImageDecoder* m_decoder;
705 705
706 // Input reading: True if we need to back up to m_restartPosition. 706 // Input reading: True if we need to back up to m_restartPosition.
707 bool m_needsRestart; 707 bool m_needsRestart;
708 // If libjpeg needed to restart, this is the position to restart from. 708 // If libjpeg needed to restart, this is the position to restart from.
709 unsigned m_restartPosition; 709 unsigned m_restartPosition;
710 // This is the position where we will read from, unless there is a restart. 710 // This is the position where we will read from, unless there is a restart.
711 unsigned m_nextReadPosition; 711 unsigned m_nextReadPosition;
712 // This is how we know to update the restart position. It is the last value 712 // This is how we know to update the restart position. It is the last value
713 // we set to next_input_byte. libjpeg will update next_input_byte when it 713 // we set to next_input_byte. libjpeg will update next_input_byte when it
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 if (!ImageDecoder::setSize(width, height)) 784 if (!ImageDecoder::setSize(width, height))
785 return false; 785 return false;
786 786
787 if (!desiredScaleNumerator()) 787 if (!desiredScaleNumerator())
788 return setFailed(); 788 return setFailed();
789 789
790 setDecodedSize(width, height); 790 setDecodedSize(width, height);
791 return true; 791 return true;
792 } 792 }
793 793
794 void JPEGImageDecoder::onSetData(SharedBuffer* data) 794 void JPEGImageDecoder::onSetData(SegmentReader* data)
795 { 795 {
796 if (m_reader) 796 if (m_reader)
797 m_reader->setData(data); 797 m_reader->setData(data);
798 } 798 }
799 799
800 void JPEGImageDecoder::setDecodedSize(unsigned width, unsigned height) 800 void JPEGImageDecoder::setDecodedSize(unsigned width, unsigned height)
801 { 801 {
802 m_decodedSize = IntSize(width, height); 802 m_decodedSize = IntSize(width, height);
803 } 803 }
804 804
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 // has failed. 1070 // has failed.
1071 if (!m_reader->decode(onlySize) && isAllDataReceived()) 1071 if (!m_reader->decode(onlySize) && isAllDataReceived())
1072 setFailed(); 1072 setFailed();
1073 1073
1074 // If decoding is done or failed, we don't need the JPEGImageReader anymore. 1074 // If decoding is done or failed, we don't need the JPEGImageReader anymore.
1075 if (isComplete(this, onlySize) || failed()) 1075 if (isComplete(this, onlySize) || failed())
1076 m_reader.clear(); 1076 m_reader.clear();
1077 } 1077 }
1078 1078
1079 } 1079 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698