Chromium Code Reviews| Index: Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp |
| diff --git a/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp b/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp |
| index cfa029567b0d29266eea09b72f5d271018fd003d..47ea1df071cd9ded4689ab3eb42fd520612f02cc 100644 |
| --- a/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp |
| +++ b/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp |
| @@ -252,11 +252,12 @@ static void readColorProfile(jpeg_decompress_struct* info, ColorProfile& colorPr |
| } |
| #endif |
| -static IntSize computeUVSize(const jpeg_decompress_struct* info) |
| +static IntSize computeYUVSize(const jpeg_decompress_struct* info, int component, bool memoryAllocation) |
| { |
| - int h = info->cur_comp_info[0]->h_samp_factor; |
| - int v = info->cur_comp_info[0]->v_samp_factor; |
| - return IntSize((info->output_width + h - 1) / h, (info->output_height + v - 1) / v); |
| + if (memoryAllocation) { |
| + return IntSize(info->cur_comp_info[component]->width_in_blocks * DCTSIZE, info->cur_comp_info[component]->height_in_blocks * DCTSIZE); |
| + } |
| + return IntSize(info->cur_comp_info[component]->downsampled_width, info->cur_comp_info[component]->downsampled_height); |
| } |
| static yuv_subsampling yuvSubsampling(const jpeg_decompress_struct& info) |
| @@ -475,6 +476,7 @@ public: |
| if (overrideColorSpace == JCS_YCbCr) { |
| m_info.out_color_space = JCS_YCbCr; |
| m_info.raw_data_out = TRUE; |
| + m_uvSize = computeYUVSize(&m_info, 1, true); // U size and V size have to be the same if we got here |
|
sugoi1
2014/09/05 20:14:57
This is unfortunate, but I have to cache this valu
Noel Gordon
2014/09/08 16:13:32
"// U size and V size have to be the same if we go
sugoi1
2014/09/09 15:08:15
If we have reached this point in the code, it mean
|
| } |
| // Don't allocate a giant and superfluous memory buffer when the |
| @@ -596,6 +598,7 @@ public: |
| jpeg_decompress_struct* info() { return &m_info; } |
| JSAMPARRAY samples() const { return m_samples; } |
| JPEGImageDecoder* decoder() { return m_decoder; } |
| + IntSize uvSize() const { return m_uvSize; } |
| #if USE(QCMSLIB) |
| qcms_transform* colorTransform() const { return m_transform; } |
| @@ -638,6 +641,8 @@ private: |
| JSAMPARRAY m_samples; |
| + IntSize m_uvSize; |
| + |
| #if USE(QCMSLIB) |
| qcms_transform* m_transform; |
| #endif |
| @@ -712,12 +717,12 @@ void JPEGImageDecoder::setDecodedSize(unsigned width, unsigned height) |
| m_decodedSize = IntSize(width, height); |
| } |
| -IntSize JPEGImageDecoder::decodedYUVSize(int component) const |
| +IntSize JPEGImageDecoder::decodedYUVSize(int component, bool memoryAllocation) const |
| { |
| - if (((component == 1) || (component == 2)) && m_reader.get()) { // Asking for U or V |
| + if (((component >= 0) && (component <= 2)) && m_reader.get()) { |
|
Noel Gordon
2014/09/08 16:13:33
nit: m_reader.get() -> m_reader
sugoi1
2014/09/09 15:08:15
Done.
|
| const jpeg_decompress_struct* info = m_reader->info(); |
| if (info && (info->out_color_space == JCS_YCbCr)) { |
|
Noel Gordon
2014/09/08 16:13:32
nit: info() is never null
sugoi1
2014/09/09 15:08:15
Done.
|
| - return computeUVSize(info); |
| + return computeYUVSize(info, component, memoryAllocation); |
| } |
| } |
| @@ -855,7 +860,7 @@ static bool outputRawData(JPEGImageReader* reader, ImagePlanes* imagePlanes) |
| int yHeight = info->output_height; |
| int yMaxH = yHeight - 1; |
| int v = info->cur_comp_info[0]->v_samp_factor; |
| - IntSize uvSize = computeUVSize(info); |
| + IntSize uvSize = reader->uvSize(); |
| int uvMaxH = uvSize.height() - 1; |
| JSAMPROW outputY = static_cast<JSAMPROW>(imagePlanes->plane(0)); |
| JSAMPROW outputU = static_cast<JSAMPROW>(imagePlanes->plane(1)); |