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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
302 class JPEGImageReader { | 317 class JPEGImageReader { |
303 WTF_MAKE_FAST_ALLOCATED(JPEGImageReader); | 318 WTF_MAKE_FAST_ALLOCATED(JPEGImageReader); |
304 public: | 319 public: |
305 JPEGImageReader(JPEGImageDecoder* decoder) | 320 JPEGImageReader(JPEGImageDecoder* decoder) |
306 : m_decoder(decoder) | 321 : m_decoder(decoder) |
307 , m_bufferLength(0) | 322 , m_bufferLength(0) |
308 , m_bytesToSkip(0) | 323 , m_bytesToSkip(0) |
309 , m_state(JPEG_HEADER) | 324 , m_state(JPEG_HEADER) |
310 , m_samples(0) | 325 , m_samples(0) |
311 #if USE(QCMSLIB) | 326 #if USE(QCMSLIB) |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 if (m_bytesToSkip) | 404 if (m_bytesToSkip) |
390 skipBytes(m_bytesToSkip); | 405 skipBytes(m_bytesToSkip); |
391 | 406 |
392 m_bufferLength = data.size(); | 407 m_bufferLength = data.size(); |
393 | 408 |
394 // We need to do the setjmp here. Otherwise bad things will happen | 409 // We need to do the setjmp here. Otherwise bad things will happen |
395 if (setjmp(m_err.setjmp_buffer)) | 410 if (setjmp(m_err.setjmp_buffer)) |
396 return m_decoder->setFailed(); | 411 return m_decoder->setFailed(); |
397 | 412 |
398 J_COLOR_SPACE overrideColorSpace = JCS_UNKNOWN; | 413 J_COLOR_SPACE overrideColorSpace = JCS_UNKNOWN; |
| 414 |
399 switch (m_state) { | 415 switch (m_state) { |
400 case JPEG_HEADER: | 416 case JPEG_HEADER: |
401 // Read file parameters with jpeg_read_header(). | 417 // Read file parameters with jpeg_read_header(). |
402 if (jpeg_read_header(&m_info, true) == JPEG_SUSPENDED) | 418 if (jpeg_read_header(&m_info, true) == JPEG_SUSPENDED) |
403 return false; // I/O suspension. | 419 return false; // I/O suspension. |
404 | 420 |
405 switch (m_info.jpeg_color_space) { | 421 switch (m_info.jpeg_color_space) { |
406 case JCS_YCbCr: | 422 case JCS_YCbCr: |
407 // libjpeg can convert YCbCr image pixels to RGB. | 423 // libjpeg can convert YCbCr image pixels to RGB. |
408 m_info.out_color_space = rgbOutputColorSpace(); | 424 m_info.out_color_space = rgbOutputColorSpace(); |
(...skipping 16 matching lines...) Expand all Loading... |
425 case JCS_CMYK: | 441 case JCS_CMYK: |
426 case JCS_YCCK: | 442 case JCS_YCCK: |
427 // libjpeg can convert YCCK to CMYK, but neither to RGB, so we | 443 // libjpeg can convert YCCK to CMYK, but neither to RGB, so we |
428 // manually convert CMKY to RGB. | 444 // manually convert CMKY to RGB. |
429 m_info.out_color_space = JCS_CMYK; | 445 m_info.out_color_space = JCS_CMYK; |
430 break; | 446 break; |
431 default: | 447 default: |
432 return m_decoder->setFailed(); | 448 return m_decoder->setFailed(); |
433 } | 449 } |
434 | 450 |
| 451 if (!validateSubsampling(&m_info)) |
| 452 return m_decoder->setFailed(); |
| 453 |
435 m_state = JPEG_START_DECOMPRESS; | 454 m_state = JPEG_START_DECOMPRESS; |
436 | 455 |
437 // We can fill in the size now that the header is available. | 456 // We can fill in the size now that the header is available. |
438 if (!m_decoder->setSize(m_info.image_width, m_info.image_height)) | 457 if (!m_decoder->setSize(m_info.image_width, m_info.image_height)) |
439 return false; | 458 return false; |
440 | 459 |
441 // Calculate and set decoded size. | 460 // Calculate and set decoded size. |
442 m_info.scale_num = m_decoder->desiredScaleNumerator(); | 461 m_info.scale_num = m_decoder->desiredScaleNumerator(); |
443 m_info.scale_denom = scaleDenominator; | 462 m_info.scale_denom = scaleDenominator; |
444 // Scaling caused by running low on memory isn't supported by YUV de
coding since | 463 // 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 Loading... |
1002 // has failed. | 1021 // has failed. |
1003 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) | 1022 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) |
1004 setFailed(); | 1023 setFailed(); |
1005 // If we're done decoding the image, we don't need the JPEGImageReader | 1024 // If we're done decoding the image, we don't need the JPEGImageReader |
1006 // anymore. (If we failed, |m_reader| has already been cleared.) | 1025 // anymore. (If we failed, |m_reader| has already been cleared.) |
1007 else if ((!m_frameBufferCache.isEmpty() && (m_frameBufferCache[0].status() =
= ImageFrame::FrameComplete)) || (hasImagePlanes() && !onlySize)) | 1026 else if ((!m_frameBufferCache.isEmpty() && (m_frameBufferCache[0].status() =
= ImageFrame::FrameComplete)) || (hasImagePlanes() && !onlySize)) |
1008 m_reader.clear(); | 1027 m_reader.clear(); |
1009 } | 1028 } |
1010 | 1029 |
1011 } | 1030 } |
OLD | NEW |