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

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

Issue 1647703006: Track positions of dimensions in image files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated GIF dimensions UMA logic Created 4 years, 10 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 20 matching lines...) Expand all
31 * version of this file under the LGPL, indicate your decision by 31 * version of this file under the LGPL, indicate your decision by
32 * deletingthe provisions above and replace them with the notice and 32 * deletingthe provisions above and replace them with the notice and
33 * other provisions required by the MPL or the GPL, as the case may be. 33 * other provisions required by the MPL or the GPL, as the case may be.
34 * If you do not delete the provisions above, a recipient may use your 34 * If you do not delete the provisions above, a recipient may use your
35 * version of this file under any of the LGPL, the MPL or the GPL. 35 * version of this file under any of the LGPL, the MPL or the GPL.
36 */ 36 */
37 37
38 #include "platform/image-decoders/jpeg/JPEGImageDecoder.h" 38 #include "platform/image-decoders/jpeg/JPEGImageDecoder.h"
39 39
40 #include "platform/PlatformInstrumentation.h" 40 #include "platform/PlatformInstrumentation.h"
41 #include "public/platform/Platform.h"
42
43 #include <stdint.h>
41 44
42 extern "C" { 45 extern "C" {
43 #include <stdio.h> // jpeglib.h needs stdio FILE. 46 #include <stdio.h> // jpeglib.h needs stdio FILE.
44 #include "jpeglib.h" 47 #include "jpeglib.h"
45 #if USE(ICCJPEG) 48 #if USE(ICCJPEG)
46 #include "iccjpeg.h" 49 #include "iccjpeg.h"
47 #endif 50 #endif
48 #if USE(QCMSLIB) 51 #if USE(QCMSLIB)
49 #include "qcms.h" 52 #include "qcms.h"
50 #endif 53 #endif
(...skipping 18 matching lines...) Expand all
69 inline bool colorSpaceHasAlpha(J_COLOR_SPACE) { return false; } 72 inline bool colorSpaceHasAlpha(J_COLOR_SPACE) { return false; }
70 #endif 73 #endif
71 74
72 namespace { 75 namespace {
73 76
74 const int exifMarker = JPEG_APP0 + 1; 77 const int exifMarker = JPEG_APP0 + 1;
75 78
76 // JPEG only supports a denominator of 8. 79 // JPEG only supports a denominator of 8.
77 const unsigned scaleDenominator = 8; 80 const unsigned scaleDenominator = 8;
78 81
82
83 // Returns a 16-bit integer with big-endian representation from a byte array.
84 unsigned getUint16(const char* p)
85 {
86 return ((*((unsigned char*)p)) << 8) + *((unsigned char*)(p + 1));
87 }
88
89 // Returns the number of bytes that must be fetched before the image dimensions can be determined.
90 // Used for metrics only. Returns 0 if dimensions not found.
91 size_t getDimensionsOffset(const RefPtr<blink::SharedBuffer>& m_data)
92 {
93 const char* segment;
94 size_t pos = 0;
95 int height = 0, width = 0;
96 size_t length = m_data->getSomeData(segment, pos);
97 if (length < 2 || 0xFFD8 != getUint16(&segment[0]))
98 return 0;
99 pos += 2;
100 while ((length = m_data->getSomeData(segment, pos))) {
101 if (length < 2)
102 return 0;
103 int marker = getUint16(&segment[0]) & 0xfffc;
104 if (marker == 0xffc0)
105 break;
106 pos += 2 + getUint16(&segment[2]);
107 }
108 if (length < 8)
109 return 0;
110 // Height and width are two bytes each and are at bytes 5 and 7 of this segm ent, respectively.
111 return pos + 8;
112 }
113
79 } // namespace 114 } // namespace
80 115
81 namespace blink { 116 namespace blink {
82 117
83 struct decoder_error_mgr { 118 struct decoder_error_mgr {
84 DISALLOW_NEW(); 119 DISALLOW_NEW();
85 struct jpeg_error_mgr pub; // "public" fields for IJG library 120 struct jpeg_error_mgr pub; // "public" fields for IJG library
86 int num_corrupt_warnings; // Counts corrupt warning messages 121 int num_corrupt_warnings; // Counts corrupt warning messages
87 jmp_buf setjmp_buffer; // For handling catastropic errors 122 jmp_buf setjmp_buffer; // For handling catastropic errors
88 }; 123 };
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 // Calculate and set decoded size. 498 // Calculate and set decoded size.
464 m_info.scale_num = m_decoder->desiredScaleNumerator(); 499 m_info.scale_num = m_decoder->desiredScaleNumerator();
465 m_info.scale_denom = scaleDenominator; 500 m_info.scale_denom = scaleDenominator;
466 // Scaling caused by running low on memory isn't supported by YUV de coding since 501 // Scaling caused by running low on memory isn't supported by YUV de coding since
467 // YUV decoding is performed on full sized images. At this point, bu ffers and various 502 // YUV decoding is performed on full sized images. At this point, bu ffers and various
468 // image info structs have already been setup to the scaled size aft er reading the 503 // image info structs have already been setup to the scaled size aft er reading the
469 // image header using this decoder, so using the full size is no lon ger possible. 504 // image header using this decoder, so using the full size is no lon ger possible.
470 if (m_info.scale_num != m_info.scale_denom) 505 if (m_info.scale_num != m_info.scale_denom)
471 overrideColorSpace = JCS_UNKNOWN; 506 overrideColorSpace = JCS_UNKNOWN;
472 jpeg_calc_output_dimensions(&m_info); 507 jpeg_calc_output_dimensions(&m_info);
508 m_decoder->setSizeOffset(m_nextReadPosition);
473 m_decoder->setDecodedSize(m_info.output_width, m_info.output_height) ; 509 m_decoder->setDecodedSize(m_info.output_width, m_info.output_height) ;
474 510
475 m_decoder->setOrientation(readImageOrientation(info())); 511 m_decoder->setOrientation(readImageOrientation(info()));
476 512
477 #if USE(QCMSLIB) 513 #if USE(QCMSLIB)
478 // Allow color management of the decoded RGBA pixels if possible. 514 // Allow color management of the decoded RGBA pixels if possible.
479 if (!m_decoder->ignoresGammaAndColorProfile()) { 515 if (!m_decoder->ignoresGammaAndColorProfile()) {
480 ColorProfile colorProfile; 516 ColorProfile colorProfile;
481 readColorProfile(info(), colorProfile); 517 readColorProfile(info(), colorProfile);
482 createColorTransform(colorProfile, colorSpaceHasAlpha(m_info.out _color_space)); 518 createColorTransform(colorProfile, colorSpaceHasAlpha(m_info.out _color_space));
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 return reinterpret_cast_ptr<decoder_source_mgr*>(jd->src)->reader->fillBuffe r(); 800 return reinterpret_cast_ptr<decoder_source_mgr*>(jd->src)->reader->fillBuffe r();
765 } 801 }
766 802
767 void term_source(j_decompress_ptr jd) 803 void term_source(j_decompress_ptr jd)
768 { 804 {
769 reinterpret_cast_ptr<decoder_source_mgr*>(jd->src)->reader->decoder()->compl ete(); 805 reinterpret_cast_ptr<decoder_source_mgr*>(jd->src)->reader->decoder()->compl ete();
770 } 806 }
771 807
772 JPEGImageDecoder::JPEGImageDecoder(AlphaOption alphaOption, GammaAndColorProfile Option colorOptions, size_t maxDecodedBytes) 808 JPEGImageDecoder::JPEGImageDecoder(AlphaOption alphaOption, GammaAndColorProfile Option colorOptions, size_t maxDecodedBytes)
773 : ImageDecoder(alphaOption, colorOptions, maxDecodedBytes) 809 : ImageDecoder(alphaOption, colorOptions, maxDecodedBytes)
774 , m_hasColorProfile(false) 810 , m_sizeOffset(0), m_sizeOffsetOptimized(0), m_hasColorProfile(false)
775 { 811 {
776 } 812 }
777 813
778 JPEGImageDecoder::~JPEGImageDecoder() 814 JPEGImageDecoder::~JPEGImageDecoder()
779 { 815 {
780 } 816 }
781 817
782 bool JPEGImageDecoder::setSize(unsigned width, unsigned height) 818 bool JPEGImageDecoder::setSize(unsigned width, unsigned height)
783 { 819 {
784 if (!ImageDecoder::setSize(width, height)) 820 if (!ImageDecoder::setSize(width, height))
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 1099
1064 if (!m_reader) { 1100 if (!m_reader) {
1065 m_reader = adoptPtr(new JPEGImageReader(this)); 1101 m_reader = adoptPtr(new JPEGImageReader(this));
1066 m_reader->setData(m_data.get()); 1102 m_reader->setData(m_data.get());
1067 } 1103 }
1068 1104
1069 // If we couldn't decode the image but have received all the data, decoding 1105 // If we couldn't decode the image but have received all the data, decoding
1070 // has failed. 1106 // has failed.
1071 if (!m_reader->decode(onlySize) && isAllDataReceived()) 1107 if (!m_reader->decode(onlySize) && isAllDataReceived())
1072 setFailed(); 1108 setFailed();
1109 // Decoding should happen only once.
1110 if (!onlySize && isComplete(this, onlySize)) {
1111 Platform::current()->histogramCustomCounts(
1112 "Blink.Images.SizeOffsetOptimized_JPEG", getDimensionsOffset(m_data) , 1, 1000000, 50);
1113 Platform::current()->histogramCustomCounts(
1114 "Blink.Images.SizeOffset_JPEG", m_sizeOffset, 1, 1000000, 50);
1115 }
1073 1116
1074 // If decoding is done or failed, we don't need the JPEGImageReader anymore. 1117 // If decoding is done or failed, we don't need the JPEGImageReader anymore.
1075 if (isComplete(this, onlySize) || failed()) 1118 if (isComplete(this, onlySize) || failed())
1076 m_reader.clear(); 1119 m_reader.clear();
1077 } 1120 }
1078 1121
1079 } // namespace blink 1122 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698