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

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

Issue 1069083003: Revert of Add helper to validate JPEG decode subsampling factors (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 * Copyright (C) 2007-2009 Torch Mobile, Inc. 9 * Copyright (C) 2007-2009 Torch Mobile, Inc.
10 * 10 *
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 return YUV_410; 292 return YUV_410;
293 default: 293 default:
294 break; 294 break;
295 } 295 }
296 } 296 }
297 } 297 }
298 298
299 return YUV_UNKNOWN; 299 return YUV_UNKNOWN;
300 } 300 }
301 301
302 bool validateSubsampling(const jpeg_decompress_struct* cinfo)
303 {
304 ASSERT(cinfo->num_components);
305
306 jpeg_component_info* component = cinfo->comp_info;
307 for (int c = 0; c < cinfo->num_components; ++c, ++component) {
308 if (component->h_samp_factor == 3)
309 component->h_samp_factor = 1;
310 if (component->v_samp_factor == 3)
311 component->v_samp_factor = 1;
312 }
313
314 return true;
315 }
316
317 class JPEGImageReader { 302 class JPEGImageReader {
318 WTF_MAKE_FAST_ALLOCATED(JPEGImageReader); 303 WTF_MAKE_FAST_ALLOCATED(JPEGImageReader);
319 public: 304 public:
320 JPEGImageReader(JPEGImageDecoder* decoder) 305 JPEGImageReader(JPEGImageDecoder* decoder)
321 : m_decoder(decoder) 306 : m_decoder(decoder)
322 , m_bufferLength(0) 307 , m_bufferLength(0)
323 , m_bytesToSkip(0) 308 , m_bytesToSkip(0)
324 , m_state(JPEG_HEADER) 309 , m_state(JPEG_HEADER)
325 , m_samples(0) 310 , m_samples(0)
326 #if USE(QCMSLIB) 311 #if USE(QCMSLIB)
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 if (m_bytesToSkip) 389 if (m_bytesToSkip)
405 skipBytes(m_bytesToSkip); 390 skipBytes(m_bytesToSkip);
406 391
407 m_bufferLength = data.size(); 392 m_bufferLength = data.size();
408 393
409 // We need to do the setjmp here. Otherwise bad things will happen 394 // We need to do the setjmp here. Otherwise bad things will happen
410 if (setjmp(m_err.setjmp_buffer)) 395 if (setjmp(m_err.setjmp_buffer))
411 return m_decoder->setFailed(); 396 return m_decoder->setFailed();
412 397
413 J_COLOR_SPACE overrideColorSpace = JCS_UNKNOWN; 398 J_COLOR_SPACE overrideColorSpace = JCS_UNKNOWN;
414
415 switch (m_state) { 399 switch (m_state) {
416 case JPEG_HEADER: 400 case JPEG_HEADER:
417 // Read file parameters with jpeg_read_header(). 401 // Read file parameters with jpeg_read_header().
418 if (jpeg_read_header(&m_info, true) == JPEG_SUSPENDED) 402 if (jpeg_read_header(&m_info, true) == JPEG_SUSPENDED)
419 return false; // I/O suspension. 403 return false; // I/O suspension.
420 404
421 switch (m_info.jpeg_color_space) { 405 switch (m_info.jpeg_color_space) {
422 case JCS_YCbCr: 406 case JCS_YCbCr:
423 // libjpeg can convert YCbCr image pixels to RGB. 407 // libjpeg can convert YCbCr image pixels to RGB.
424 m_info.out_color_space = rgbOutputColorSpace(); 408 m_info.out_color_space = rgbOutputColorSpace();
(...skipping 16 matching lines...) Expand all
441 case JCS_CMYK: 425 case JCS_CMYK:
442 case JCS_YCCK: 426 case JCS_YCCK:
443 // libjpeg can convert YCCK to CMYK, but neither to RGB, so we 427 // libjpeg can convert YCCK to CMYK, but neither to RGB, so we
444 // manually convert CMKY to RGB. 428 // manually convert CMKY to RGB.
445 m_info.out_color_space = JCS_CMYK; 429 m_info.out_color_space = JCS_CMYK;
446 break; 430 break;
447 default: 431 default:
448 return m_decoder->setFailed(); 432 return m_decoder->setFailed();
449 } 433 }
450 434
451 if (!validateSubsampling(&m_info))
452 return m_decoder->setFailed();
453
454 m_state = JPEG_START_DECOMPRESS; 435 m_state = JPEG_START_DECOMPRESS;
455 436
456 // We can fill in the size now that the header is available. 437 // We can fill in the size now that the header is available.
457 if (!m_decoder->setSize(m_info.image_width, m_info.image_height)) 438 if (!m_decoder->setSize(m_info.image_width, m_info.image_height))
458 return false; 439 return false;
459 440
460 // Calculate and set decoded size. 441 // Calculate and set decoded size.
461 m_info.scale_num = m_decoder->desiredScaleNumerator(); 442 m_info.scale_num = m_decoder->desiredScaleNumerator();
462 m_info.scale_denom = scaleDenominator; 443 m_info.scale_denom = scaleDenominator;
463 // Scaling caused by running low on memory isn't supported by YUV de coding since 444 // Scaling caused by running low on memory isn't supported by YUV de coding since
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 // has failed. 1002 // has failed.
1022 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) 1003 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived())
1023 setFailed(); 1004 setFailed();
1024 // If we're done decoding the image, we don't need the JPEGImageReader 1005 // If we're done decoding the image, we don't need the JPEGImageReader
1025 // anymore. (If we failed, |m_reader| has already been cleared.) 1006 // anymore. (If we failed, |m_reader| has already been cleared.)
1026 else if ((!m_frameBufferCache.isEmpty() && (m_frameBufferCache[0].status() = = ImageFrame::FrameComplete)) || (hasImagePlanes() && !onlySize)) 1007 else if ((!m_frameBufferCache.isEmpty() && (m_frameBufferCache[0].status() = = ImageFrame::FrameComplete)) || (hasImagePlanes() && !onlySize))
1027 m_reader.clear(); 1008 m_reader.clear();
1028 } 1009 }
1029 1010
1030 } 1011 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698