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 * Copyright (C) 2007-2009 Torch Mobile, Inc. | 9 * Copyright (C) 2007-2009 Torch Mobile, Inc. |
10 * | 10 * |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 ignoreProfile = true; | 245 ignoreProfile = true; |
246 | 246 |
247 ASSERT(colorProfile.isEmpty()); | 247 ASSERT(colorProfile.isEmpty()); |
248 if (!ignoreProfile) | 248 if (!ignoreProfile) |
249 colorProfile.append(profileData, profileLength); | 249 colorProfile.append(profileData, profileLength); |
250 free(profile); | 250 free(profile); |
251 #endif | 251 #endif |
252 } | 252 } |
253 #endif | 253 #endif |
254 | 254 |
255 static IntSize computeUVSize(const jpeg_decompress_struct* info) | 255 static IntSize computeYUVSize(const jpeg_decompress_struct* info, int component, ImageDecoder::SizeType sizeType) |
256 { | 256 { |
257 int h = info->cur_comp_info[0]->h_samp_factor; | 257 if (sizeType == ImageDecoder::SizeForMemoryAllocation) { |
258 int v = info->cur_comp_info[0]->v_samp_factor; | 258 return IntSize(info->cur_comp_info[component]->width_in_blocks * DCTSIZE , info->cur_comp_info[component]->height_in_blocks * DCTSIZE); |
259 return IntSize((info->output_width + h - 1) / h, (info->output_height + v - 1) / v); | 259 } |
260 return IntSize(info->cur_comp_info[component]->downsampled_width, info->cur_ comp_info[component]->downsampled_height); | |
260 } | 261 } |
261 | 262 |
262 static yuv_subsampling yuvSubsampling(const jpeg_decompress_struct& info) | 263 static yuv_subsampling yuvSubsampling(const jpeg_decompress_struct& info) |
263 { | 264 { |
264 if ((DCTSIZE == 8) | 265 if ((DCTSIZE == 8) |
265 && (info.num_components == 3) | 266 && (info.num_components == 3) |
266 && (info.comps_in_scan >= info.num_components) | 267 && (info.comps_in_scan >= info.num_components) |
267 && (info.scale_denom <= 8) | 268 && (info.scale_denom <= 8) |
268 && (info.cur_comp_info[0]) | 269 && (info.cur_comp_info[0]) |
269 && (info.cur_comp_info[1]) | 270 && (info.cur_comp_info[1]) |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 if (m_info.out_color_space == JCS_EXT_BGRA) | 469 if (m_info.out_color_space == JCS_EXT_BGRA) |
469 m_info.out_color_space = JCS_EXT_RGBA; | 470 m_info.out_color_space = JCS_EXT_RGBA; |
470 #endif | 471 #endif |
471 } | 472 } |
472 m_decoder->setHasColorProfile(!!m_transform); | 473 m_decoder->setHasColorProfile(!!m_transform); |
473 } | 474 } |
474 #endif | 475 #endif |
475 if (overrideColorSpace == JCS_YCbCr) { | 476 if (overrideColorSpace == JCS_YCbCr) { |
476 m_info.out_color_space = JCS_YCbCr; | 477 m_info.out_color_space = JCS_YCbCr; |
477 m_info.raw_data_out = TRUE; | 478 m_info.raw_data_out = TRUE; |
479 m_uvSize = computeYUVSize(&m_info, 1, ImageDecoder::SizeForMemor yAllocation); // U size and V size have to be the same if we got here | |
478 } | 480 } |
479 | 481 |
480 // Don't allocate a giant and superfluous memory buffer when the | 482 // Don't allocate a giant and superfluous memory buffer when the |
481 // image is a sequential JPEG. | 483 // image is a sequential JPEG. |
482 m_info.buffered_image = jpeg_has_multiple_scans(&m_info); | 484 m_info.buffered_image = jpeg_has_multiple_scans(&m_info); |
483 | 485 |
484 if (onlySize) { | 486 if (onlySize) { |
485 // We can stop here. Reduce our buffer length and available data . | 487 // We can stop here. Reduce our buffer length and available data . |
486 m_bufferLength -= m_info.src->bytes_in_buffer; | 488 m_bufferLength -= m_info.src->bytes_in_buffer; |
487 m_info.src->bytes_in_buffer = 0; | 489 m_info.src->bytes_in_buffer = 0; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
589 // We can get here if the constructor failed. | 591 // We can get here if the constructor failed. |
590 return m_decoder->setFailed(); | 592 return m_decoder->setFailed(); |
591 } | 593 } |
592 | 594 |
593 return true; | 595 return true; |
594 } | 596 } |
595 | 597 |
596 jpeg_decompress_struct* info() { return &m_info; } | 598 jpeg_decompress_struct* info() { return &m_info; } |
597 JSAMPARRAY samples() const { return m_samples; } | 599 JSAMPARRAY samples() const { return m_samples; } |
598 JPEGImageDecoder* decoder() { return m_decoder; } | 600 JPEGImageDecoder* decoder() { return m_decoder; } |
601 IntSize uvSize() const { return m_uvSize; } | |
599 #if USE(QCMSLIB) | 602 #if USE(QCMSLIB) |
600 qcms_transform* colorTransform() const { return m_transform; } | 603 qcms_transform* colorTransform() const { return m_transform; } |
601 | 604 |
602 void clearColorTransform() | 605 void clearColorTransform() |
603 { | 606 { |
604 if (m_transform) | 607 if (m_transform) |
605 qcms_transform_release(m_transform); | 608 qcms_transform_release(m_transform); |
606 m_transform = 0; | 609 m_transform = 0; |
607 } | 610 } |
608 | 611 |
(...skipping 22 matching lines...) Expand all Loading... | |
631 JPEGImageDecoder* m_decoder; | 634 JPEGImageDecoder* m_decoder; |
632 unsigned m_bufferLength; | 635 unsigned m_bufferLength; |
633 int m_bytesToSkip; | 636 int m_bytesToSkip; |
634 | 637 |
635 jpeg_decompress_struct m_info; | 638 jpeg_decompress_struct m_info; |
636 decoder_error_mgr m_err; | 639 decoder_error_mgr m_err; |
637 jstate m_state; | 640 jstate m_state; |
638 | 641 |
639 JSAMPARRAY m_samples; | 642 JSAMPARRAY m_samples; |
640 | 643 |
644 IntSize m_uvSize; | |
645 | |
641 #if USE(QCMSLIB) | 646 #if USE(QCMSLIB) |
642 qcms_transform* m_transform; | 647 qcms_transform* m_transform; |
643 #endif | 648 #endif |
644 }; | 649 }; |
645 | 650 |
646 // Override the standard error method in the IJG JPEG decoder code. | 651 // Override the standard error method in the IJG JPEG decoder code. |
647 void error_exit(j_common_ptr cinfo) | 652 void error_exit(j_common_ptr cinfo) |
648 { | 653 { |
649 // Return control to the setjmp point. | 654 // Return control to the setjmp point. |
650 decoder_error_mgr *err = reinterpret_cast_ptr<decoder_error_mgr *>(cinfo->er r); | 655 decoder_error_mgr *err = reinterpret_cast_ptr<decoder_error_mgr *>(cinfo->er r); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
705 | 710 |
706 setDecodedSize(width, height); | 711 setDecodedSize(width, height); |
707 return true; | 712 return true; |
708 } | 713 } |
709 | 714 |
710 void JPEGImageDecoder::setDecodedSize(unsigned width, unsigned height) | 715 void JPEGImageDecoder::setDecodedSize(unsigned width, unsigned height) |
711 { | 716 { |
712 m_decodedSize = IntSize(width, height); | 717 m_decodedSize = IntSize(width, height); |
713 } | 718 } |
714 | 719 |
715 IntSize JPEGImageDecoder::decodedYUVSize(int component) const | 720 IntSize JPEGImageDecoder::decodedYUVSize(int component, ImageDecoder::SizeType s izeType) const |
716 { | 721 { |
717 if (((component == 1) || (component == 2)) && m_reader.get()) { // Asking fo r U or V | 722 if (((component >= 0) && (component <= 2)) && m_reader) { |
Stephen White
2014/09/09 15:33:51
Nit: spurious parens (now that these are all &&'s)
| |
718 const jpeg_decompress_struct* info = m_reader->info(); | 723 const jpeg_decompress_struct* info = m_reader->info(); |
719 if (info && (info->out_color_space == JCS_YCbCr)) { | 724 if (info->out_color_space == JCS_YCbCr) { |
720 return computeUVSize(info); | 725 return computeYUVSize(info, component, sizeType); |
721 } | 726 } |
722 } | 727 } |
723 | 728 |
724 return m_decodedSize; | 729 return m_decodedSize; |
725 } | 730 } |
726 | 731 |
727 unsigned JPEGImageDecoder::desiredScaleNumerator() const | 732 unsigned JPEGImageDecoder::desiredScaleNumerator() const |
728 { | 733 { |
729 size_t originalBytes = size().width() * size().height() * 4; | 734 size_t originalBytes = size().width() * size().height() * 4; |
730 if (originalBytes <= m_maxDecodedBytes) { | 735 if (originalBytes <= m_maxDecodedBytes) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
848 jpeg_decompress_struct* info = reader->info(); | 853 jpeg_decompress_struct* info = reader->info(); |
849 JSAMPARRAY bufferraw[3]; | 854 JSAMPARRAY bufferraw[3]; |
850 JSAMPROW bufferraw2[32]; | 855 JSAMPROW bufferraw2[32]; |
851 bufferraw[0] = &bufferraw2[0]; // Y channel rows (8 or 16) | 856 bufferraw[0] = &bufferraw2[0]; // Y channel rows (8 or 16) |
852 bufferraw[1] = &bufferraw2[16]; // U channel rows (8) | 857 bufferraw[1] = &bufferraw2[16]; // U channel rows (8) |
853 bufferraw[2] = &bufferraw2[24]; // V channel rows (8) | 858 bufferraw[2] = &bufferraw2[24]; // V channel rows (8) |
854 int yWidth = info->output_width; | 859 int yWidth = info->output_width; |
855 int yHeight = info->output_height; | 860 int yHeight = info->output_height; |
856 int yMaxH = yHeight - 1; | 861 int yMaxH = yHeight - 1; |
857 int v = info->cur_comp_info[0]->v_samp_factor; | 862 int v = info->cur_comp_info[0]->v_samp_factor; |
858 IntSize uvSize = computeUVSize(info); | 863 IntSize uvSize = reader->uvSize(); |
859 int uvMaxH = uvSize.height() - 1; | 864 int uvMaxH = uvSize.height() - 1; |
860 JSAMPROW outputY = static_cast<JSAMPROW>(imagePlanes->plane(0)); | 865 JSAMPROW outputY = static_cast<JSAMPROW>(imagePlanes->plane(0)); |
861 JSAMPROW outputU = static_cast<JSAMPROW>(imagePlanes->plane(1)); | 866 JSAMPROW outputU = static_cast<JSAMPROW>(imagePlanes->plane(1)); |
862 JSAMPROW outputV = static_cast<JSAMPROW>(imagePlanes->plane(2)); | 867 JSAMPROW outputV = static_cast<JSAMPROW>(imagePlanes->plane(2)); |
863 size_t rowBytesY = imagePlanes->rowBytes(0); | 868 size_t rowBytesY = imagePlanes->rowBytes(0); |
864 size_t rowBytesU = imagePlanes->rowBytes(1); | 869 size_t rowBytesU = imagePlanes->rowBytes(1); |
865 size_t rowBytesV = imagePlanes->rowBytes(2); | 870 size_t rowBytesV = imagePlanes->rowBytes(2); |
866 | 871 |
867 int yScanlinesToRead = DCTSIZE * v; | 872 int yScanlinesToRead = DCTSIZE * v; |
868 JSAMPROW yLastRow = *samples; | 873 JSAMPROW yLastRow = *samples; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1001 // has failed. | 1006 // has failed. |
1002 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) | 1007 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) |
1003 setFailed(); | 1008 setFailed(); |
1004 // If we're done decoding the image, we don't need the JPEGImageReader | 1009 // If we're done decoding the image, we don't need the JPEGImageReader |
1005 // anymore. (If we failed, |m_reader| has already been cleared.) | 1010 // anymore. (If we failed, |m_reader| has already been cleared.) |
1006 else if ((!m_frameBufferCache.isEmpty() && (m_frameBufferCache[0].status() = = ImageFrame::FrameComplete)) || (hasImagePlanes() && !onlySize)) | 1011 else if ((!m_frameBufferCache.isEmpty() && (m_frameBufferCache[0].status() = = ImageFrame::FrameComplete)) || (hasImagePlanes() && !onlySize)) |
1007 m_reader.clear(); | 1012 m_reader.clear(); |
1008 } | 1013 } |
1009 | 1014 |
1010 } | 1015 } |
OLD | NEW |