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

Side by Side Diff: Source/platform/graphics/ImageFrameGenerator.cpp

Issue 544323002: Non DCTSIZE multiple width support for JPEG YUV decoding (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Tidying up the code Created 6 years, 3 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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 dst->lockPixels(); 62 dst->lockPixels();
63 return true; 63 return true;
64 } 64 }
65 65
66 private: 66 private:
67 SkImageInfo m_info; 67 SkImageInfo m_info;
68 void* m_pixels; 68 void* m_pixels;
69 size_t m_rowBytes; 69 size_t m_rowBytes;
70 }; 70 };
71 71
72 static bool updateYUVComponentSizes(const ImageDecoder* decoder, SkISize compone ntSizes[3], ImageDecoder::SizeType sizeType)
73 {
74 // canDecodeToYUV() has to be called AFTER isSizeAvailable(),
75 // otherwise the output color space may not be set in the decoder.
76 if (!decoder->isSizeAvailable() || !decoder->canDecodeToYUV())
77 return false;
78
79 IntSize size = decoder->decodedYUVSize(0, sizeType);
80 componentSizes[0].set(size.width(), size.height());
81 size = decoder->decodedYUVSize(1, sizeType);
82 componentSizes[1].set(size.width(), size.height());
83 size = decoder->decodedYUVSize(2, sizeType);
84 componentSizes[2].set(size.width(), size.height());
85 return true;
86 }
87
72 ImageFrameGenerator::ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<Sha redBuffer> data, bool allDataReceived, bool isMultiFrame) 88 ImageFrameGenerator::ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<Sha redBuffer> data, bool allDataReceived, bool isMultiFrame)
73 : m_fullSize(fullSize) 89 : m_fullSize(fullSize)
74 , m_isMultiFrame(isMultiFrame) 90 , m_isMultiFrame(isMultiFrame)
75 , m_decodeFailedAndEmpty(false) 91 , m_decodeFailedAndEmpty(false)
76 , m_decodeCount(0) 92 , m_decodeCount(0)
77 { 93 {
78 setData(data.get(), allDataReceived); 94 setData(data.get(), allDataReceived);
79 } 95 }
80 96
81 ImageFrameGenerator::~ImageFrameGenerator() 97 ImageFrameGenerator::~ImageFrameGenerator()
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 ASSERT(bitmap.height() == scaledSize.height()); 142 ASSERT(bitmap.height() == scaledSize.height());
127 143
128 bool result = true; 144 bool result = true;
129 // Check to see if decoder has written directly to the memory provided 145 // Check to see if decoder has written directly to the memory provided
130 // by Skia. If not make a copy. 146 // by Skia. If not make a copy.
131 if (bitmap.getPixels() != pixels) 147 if (bitmap.getPixels() != pixels)
132 result = bitmap.copyPixelsTo(pixels, rowBytes * info.fHeight, rowBytes); 148 result = bitmap.copyPixelsTo(pixels, rowBytes * info.fHeight, rowBytes);
133 return result; 149 return result;
134 } 150 }
135 151
136 bool ImageFrameGenerator::decodeToYUV(void* planes[3], size_t rowBytes[3]) 152 bool ImageFrameGenerator::decodeToYUV(SkISize componentSizes[3], void* planes[3] , size_t rowBytes[3])
137 { 153 {
138 // This method is called to populate a discardable memory owned by Skia. 154 // This method is called to populate a discardable memory owned by Skia.
139 155
140 // Prevents concurrent decode or scale operations on the same image data. 156 // Prevents concurrent decode or scale operations on the same image data.
141 MutexLocker lock(m_decodeMutex); 157 MutexLocker lock(m_decodeMutex);
142 158
143 if (m_decodeFailedAndEmpty) 159 if (m_decodeFailedAndEmpty)
144 return false; 160 return false;
145 161
146 TRACE_EVENT2("blink", "ImageFrameGenerator::decodeToYUV", "generator", this, "decodeCount", static_cast<int>(m_decodeCount)); 162 TRACE_EVENT2("blink", "ImageFrameGenerator::decodeToYUV", "generator", this, "decodeCount", static_cast<int>(m_decodeCount));
(...skipping 11 matching lines...) Expand all
158 ASSERT(allDataReceived); 174 ASSERT(allDataReceived);
159 175
160 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, ImageSource::Alph aPremultiplied, ImageSource::GammaAndColorProfileApplied); 176 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, ImageSource::Alph aPremultiplied, ImageSource::GammaAndColorProfileApplied);
161 if (!decoder) 177 if (!decoder)
162 return false; 178 return false;
163 179
164 decoder->setData(data, allDataReceived); 180 decoder->setData(data, allDataReceived);
165 181
166 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes(planes, rowBytes) ); 182 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes(planes, rowBytes) );
167 decoder->setImagePlanes(imagePlanes.release()); 183 decoder->setImagePlanes(imagePlanes.release());
184
185 bool sizeUpdated = updateYUVComponentSizes(decoder.get(), componentSizes, Im ageDecoder::ActualSize);
186 RELEASE_ASSERT(sizeUpdated);
187
168 bool yuvDecoded = decoder->decodeToYUV(); 188 bool yuvDecoded = decoder->decodeToYUV();
169 if (yuvDecoded) 189 if (yuvDecoded)
170 setHasAlpha(0, false); // YUV is always opaque 190 setHasAlpha(0, false); // YUV is always opaque
171 return yuvDecoded; 191 return yuvDecoded;
172 } 192 }
173 193
174 SkBitmap ImageFrameGenerator::tryToResumeDecode(const SkISize& scaledSize, size_ t index) 194 SkBitmap ImageFrameGenerator::tryToResumeDecode(const SkISize& scaledSize, size_ t index)
175 { 195 {
176 TRACE_EVENT1("blink", "ImageFrameGenerator::tryToResumeDecodeAndScale", "ind ex", static_cast<int>(index)); 196 TRACE_EVENT1("blink", "ImageFrameGenerator::tryToResumeDecodeAndScale", "ind ex", static_cast<int>(index));
177 197
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 327
308 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, ImageSource::Alph aPremultiplied, ImageSource::GammaAndColorProfileApplied); 328 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, ImageSource::Alph aPremultiplied, ImageSource::GammaAndColorProfileApplied);
309 if (!decoder) 329 if (!decoder)
310 return false; 330 return false;
311 331
312 // Setting a dummy ImagePlanes object signals to the decoder that we want to do YUV decoding. 332 // Setting a dummy ImagePlanes object signals to the decoder that we want to do YUV decoding.
313 decoder->setData(data, allDataReceived); 333 decoder->setData(data, allDataReceived);
314 OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes); 334 OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes);
315 decoder->setImagePlanes(dummyImagePlanes.release()); 335 decoder->setImagePlanes(dummyImagePlanes.release());
316 336
317 // canDecodeToYUV() has to be called AFTER isSizeAvailable(), 337 return updateYUVComponentSizes(decoder.get(), componentSizes, ImageDecoder:: SizeForMemoryAllocation);
318 // otherwise the output color space may not be set in the decoder.
319 if (!decoder->isSizeAvailable() || !decoder->canDecodeToYUV())
320 return false;
321
322 IntSize size = decoder->decodedYUVSize(0);
323 componentSizes[0].set(size.width(), size.height());
324 size = decoder->decodedYUVSize(1);
325 componentSizes[1].set(size.width(), size.height());
326 size = decoder->decodedYUVSize(2);
327 componentSizes[2].set(size.width(), size.height());
328 return true;
329 } 338 }
330 339
331 } // namespace blink 340 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/graphics/ImageFrameGenerator.h ('k') | Source/platform/image-decoders/ImageDecoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698