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

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

Issue 480093003: Follow up on previous cl (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 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 | « Source/platform/image-decoders/ImageDecoder.cpp ('k') | 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 } 252 }
253 #endif 253 #endif
254 254
255 static IntSize computeUVSize(const jpeg_decompress_struct* info) 255 static IntSize computeUVSize(const jpeg_decompress_struct* info)
256 { 256 {
257 int h = info->cur_comp_info[0]->h_samp_factor; 257 int h = info->cur_comp_info[0]->h_samp_factor;
258 int v = info->cur_comp_info[0]->v_samp_factor; 258 int v = info->cur_comp_info[0]->v_samp_factor;
259 return IntSize((info->output_width + h - 1) / h, (info->output_height + v - 1) / v); 259 return IntSize((info->output_width + h - 1) / h, (info->output_height + v - 1) / v);
260 } 260 }
261 261
262 static yuv_subsampling getYUVSubsampling(const jpeg_decompress_struct& info) 262 static yuv_subsampling yuvSubsampling(const jpeg_decompress_struct& info)
263 { 263 {
264 if ((DCTSIZE == 8) 264 if ((DCTSIZE == 8)
265 && (info.num_components == 3) 265 && (info.num_components == 3)
266 && (info.scale_denom <= 8) 266 && (info.scale_denom <= 8)
267 && (info.cur_comp_info[1]->h_samp_factor == 1) 267 && (info.cur_comp_info[1]->h_samp_factor == 1)
268 && (info.cur_comp_info[1]->v_samp_factor == 1) 268 && (info.cur_comp_info[1]->v_samp_factor == 1)
269 && (info.cur_comp_info[2]->h_samp_factor == 1) 269 && (info.cur_comp_info[2]->h_samp_factor == 1)
270 && (info.cur_comp_info[2]->v_samp_factor == 1)) { 270 && (info.cur_comp_info[2]->v_samp_factor == 1)) {
271 int h = info.cur_comp_info[0]->h_samp_factor; 271 int h = info.cur_comp_info[0]->h_samp_factor;
272 int v = info.cur_comp_info[0]->v_samp_factor; 272 int v = info.cur_comp_info[0]->v_samp_factor;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 // If we still have bytes to skip, try to skip those now. 393 // If we still have bytes to skip, try to skip those now.
394 if (m_bytesToSkip) 394 if (m_bytesToSkip)
395 skipBytes(m_bytesToSkip); 395 skipBytes(m_bytesToSkip);
396 396
397 m_bufferLength = data.size(); 397 m_bufferLength = data.size();
398 398
399 // We need to do the setjmp here. Otherwise bad things will happen 399 // We need to do the setjmp here. Otherwise bad things will happen
400 if (setjmp(m_err.setjmp_buffer)) 400 if (setjmp(m_err.setjmp_buffer))
401 return m_decoder->setFailed(); 401 return m_decoder->setFailed();
402 402
403 J_COLOR_SPACE overrideColorSpace = JCS_UNKNOWN;
403 switch (m_state) { 404 switch (m_state) {
404 case JPEG_HEADER: 405 case JPEG_HEADER:
405 // Read file parameters with jpeg_read_header(). 406 // Read file parameters with jpeg_read_header().
406 if (jpeg_read_header(&m_info, true) == JPEG_SUSPENDED) 407 if (jpeg_read_header(&m_info, true) == JPEG_SUSPENDED)
407 return false; // I/O suspension. 408 return false; // I/O suspension.
408 409
409 switch (m_info.jpeg_color_space) { 410 switch (m_info.jpeg_color_space) {
410 case JCS_YCbCr: 411 case JCS_YCbCr:
411 // libjpeg can convert YCbCr image pixels to RGB. 412 // libjpeg can convert YCbCr image pixels to RGB.
412 m_info.out_color_space = rgbOutputColorSpace(); 413 m_info.out_color_space = rgbOutputColorSpace();
413 if (m_decoder->YUVDecoding() && (getYUVSubsampling(m_info) != YU V_UNKNOWN)) { 414 if (m_decoder->YUVDecoding() && (yuvSubsampling(m_info) != YUV_U NKNOWN)) {
414 m_info.out_color_space = JCS_YCbCr; 415 overrideColorSpace = JCS_YCbCr;
415 m_info.raw_data_out = TRUE;
416 } 416 }
417 break; 417 break;
418 case JCS_GRAYSCALE: 418 case JCS_GRAYSCALE:
419 case JCS_RGB: 419 case JCS_RGB:
420 // libjpeg can convert GRAYSCALE image pixels to RGB. 420 // libjpeg can convert GRAYSCALE image pixels to RGB.
421 m_info.out_color_space = rgbOutputColorSpace(); 421 m_info.out_color_space = rgbOutputColorSpace();
422 #if defined(TURBO_JPEG_RGB_SWIZZLE) 422 #if defined(TURBO_JPEG_RGB_SWIZZLE)
423 if (m_info.saw_JFIF_marker) 423 if (m_info.saw_JFIF_marker)
424 break; 424 break;
425 // FIXME: Swizzle decoding does not support Adobe transform=0 425 // FIXME: Swizzle decoding does not support Adobe transform=0
(...skipping 25 matching lines...) Expand all
451 m_decoder->setDecodedSize(m_info.output_width, m_info.output_height) ; 451 m_decoder->setDecodedSize(m_info.output_width, m_info.output_height) ;
452 452
453 m_decoder->setOrientation(readImageOrientation(info())); 453 m_decoder->setOrientation(readImageOrientation(info()));
454 454
455 #if USE(QCMSLIB) 455 #if USE(QCMSLIB)
456 // Allow color management of the decoded RGBA pixels if possible. 456 // Allow color management of the decoded RGBA pixels if possible.
457 if (!m_decoder->ignoresGammaAndColorProfile()) { 457 if (!m_decoder->ignoresGammaAndColorProfile()) {
458 ColorProfile colorProfile; 458 ColorProfile colorProfile;
459 readColorProfile(info(), colorProfile); 459 readColorProfile(info(), colorProfile);
460 createColorTransform(colorProfile, colorSpaceHasAlpha(m_info.out _color_space)); 460 createColorTransform(colorProfile, colorSpaceHasAlpha(m_info.out _color_space));
461 if (m_transform && m_info.out_color_space == JCS_YCbCr) { 461 overrideColorSpace = JCS_UNKNOWN;
462 m_info.out_color_space = rgbOutputColorSpace();
463 m_info.raw_data_out = FALSE;
464 }
465 #if defined(TURBO_JPEG_RGB_SWIZZLE) 462 #if defined(TURBO_JPEG_RGB_SWIZZLE)
466 // Input RGBA data to qcms. Note: restored to BGRA on output. 463 // Input RGBA data to qcms. Note: restored to BGRA on output.
467 if (m_transform && m_info.out_color_space == JCS_EXT_BGRA) 464 if (m_transform && m_info.out_color_space == JCS_EXT_BGRA)
468 m_info.out_color_space = JCS_EXT_RGBA; 465 m_info.out_color_space = JCS_EXT_RGBA;
469 #endif 466 #endif
470 m_decoder->setHasColorProfile(!!m_transform); 467 m_decoder->setHasColorProfile(!!m_transform);
471 } 468 }
472 #endif 469 #endif
470 if (overrideColorSpace != JCS_UNKNOWN) {
Noel Gordon 2014/08/20 16:24:15 Is this if statement needed?
471 if (overrideColorSpace == JCS_YCbCr) {
472 m_info.out_color_space = JCS_YCbCr;
473 m_info.raw_data_out = TRUE;
474 }
475 }
476
473 // Don't allocate a giant and superfluous memory buffer when the 477 // Don't allocate a giant and superfluous memory buffer when the
474 // image is a sequential JPEG. 478 // image is a sequential JPEG.
475 m_info.buffered_image = jpeg_has_multiple_scans(&m_info); 479 m_info.buffered_image = jpeg_has_multiple_scans(&m_info);
476 480
477 if (onlySize) { 481 if (onlySize) {
478 // We can stop here. Reduce our buffer length and available data . 482 // We can stop here. Reduce our buffer length and available data .
479 m_bufferLength -= m_info.src->bytes_in_buffer; 483 m_bufferLength -= m_info.src->bytes_in_buffer;
480 m_info.src->bytes_in_buffer = 0; 484 m_info.src->bytes_in_buffer = 0;
481 return true; 485 return true;
482 } 486 }
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 // has failed. 989 // has failed.
986 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) 990 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived())
987 setFailed(); 991 setFailed();
988 // If we're done decoding the image, we don't need the JPEGImageReader 992 // If we're done decoding the image, we don't need the JPEGImageReader
989 // anymore. (If we failed, |m_reader| has already been cleared.) 993 // anymore. (If we failed, |m_reader| has already been cleared.)
990 else if (!m_frameBufferCache.isEmpty() && (m_frameBufferCache[0].status() == ImageFrame::FrameComplete)) 994 else if (!m_frameBufferCache.isEmpty() && (m_frameBufferCache[0].status() == ImageFrame::FrameComplete))
991 m_reader.clear(); 995 m_reader.clear();
992 } 996 }
993 997
994 } 998 }
OLDNEW
« no previous file with comments | « Source/platform/image-decoders/ImageDecoder.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698