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

Side by Side Diff: src/codec/SkJpegCodec.cpp

Issue 1820073002: Add SkEncodedInfo to report properties of encoded image data (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Response to comments Created 4 years, 9 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 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCodec.h" 8 #include "SkCodec.h"
9 #include "SkMSAN.h" 9 #include "SkMSAN.h"
10 #include "SkJpegCodec.h" 10 #include "SkJpegCodec.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 jpeg_save_markers(decoderMgr->dinfo(), kExifMarker, 0xFFFF); 204 jpeg_save_markers(decoderMgr->dinfo(), kExifMarker, 0xFFFF);
205 jpeg_save_markers(decoderMgr->dinfo(), kICCMarker, 0xFFFF); 205 jpeg_save_markers(decoderMgr->dinfo(), kICCMarker, 0xFFFF);
206 } 206 }
207 207
208 // Read the jpeg header 208 // Read the jpeg header
209 if (JPEG_HEADER_OK != jpeg_read_header(decoderMgr->dinfo(), true)) { 209 if (JPEG_HEADER_OK != jpeg_read_header(decoderMgr->dinfo(), true)) {
210 return decoderMgr->returnFalse("read_header"); 210 return decoderMgr->returnFalse("read_header");
211 } 211 }
212 212
213 if (codecOut) { 213 if (codecOut) {
214 // Recommend the color type to decode to 214 // Get the encoded color type
215 const SkColorType colorType = decoderMgr->getColorType(); 215 SkEncodedInfo::Color color;
216 if (!decoderMgr->getEncodedColor(&color)) {
scroggo 2016/03/24 20:51:03 Alternatively, this could return kUnknown on failu
msarett 2016/03/24 22:42:07 You're right, I like that better.
217 return false;
218 }
216 219
217 // Create image info object and the codec 220 // Create image info object and the codec
218 const SkImageInfo& imageInfo = SkImageInfo::Make(decoderMgr->dinfo()->im age_width, 221 SkEncodedInfo info = SkEncodedInfo::Make(decoderMgr->dinfo()->image_widt h,
219 decoderMgr->dinfo()->image_height, colorType, kOpaque_SkAlphaTyp e); 222 decoderMgr->dinfo()->image_height, color, SkEncodedInfo::kOpaque _Alpha, 8);
220 223
221 Origin orientation = get_exif_orientation(decoderMgr->dinfo()); 224 Origin orientation = get_exif_orientation(decoderMgr->dinfo());
222 sk_sp<SkColorSpace> colorSpace = get_icc_profile(decoderMgr->dinfo()); 225 sk_sp<SkColorSpace> colorSpace = get_icc_profile(decoderMgr->dinfo());
223 226
224 *codecOut = new SkJpegCodec(imageInfo, stream, decoderMgr.release(), col orSpace, 227 *codecOut = new SkJpegCodec(info, stream, decoderMgr.release(), colorSpa ce,
225 orientation); 228 orientation);
226 } else { 229 } else {
227 SkASSERT(nullptr != decoderMgrOut); 230 SkASSERT(nullptr != decoderMgrOut);
228 *decoderMgrOut = decoderMgr.release(); 231 *decoderMgrOut = decoderMgr.release();
229 } 232 }
230 return true; 233 return true;
231 } 234 }
232 235
233 SkCodec* SkJpegCodec::NewFromStream(SkStream* stream) { 236 SkCodec* SkJpegCodec::NewFromStream(SkStream* stream) {
234 SkAutoTDelete<SkStream> streamDeleter(stream); 237 SkAutoTDelete<SkStream> streamDeleter(stream);
235 SkCodec* codec = nullptr; 238 SkCodec* codec = nullptr;
236 if (ReadHeader(stream, &codec, nullptr)) { 239 if (ReadHeader(stream, &codec, nullptr)) {
237 // Codec has taken ownership of the stream, we do not need to delete it 240 // Codec has taken ownership of the stream, we do not need to delete it
238 SkASSERT(codec); 241 SkASSERT(codec);
239 streamDeleter.release(); 242 streamDeleter.release();
240 return codec; 243 return codec;
241 } 244 }
242 return nullptr; 245 return nullptr;
243 } 246 }
244 247
245 SkJpegCodec::SkJpegCodec(const SkImageInfo& srcInfo, SkStream* stream, 248 SkJpegCodec::SkJpegCodec(const SkEncodedInfo& info, SkStream* stream,
246 JpegDecoderMgr* decoderMgr, sk_sp<SkColorSpace> colorSpace, Origin origi n) 249 JpegDecoderMgr* decoderMgr, sk_sp<SkColorSpace> colorSpace, Origin origi n)
247 : INHERITED(srcInfo, stream, colorSpace, origin) 250 : INHERITED(info, stream, colorSpace, origin)
248 , fDecoderMgr(decoderMgr) 251 , fDecoderMgr(decoderMgr)
249 , fReadyState(decoderMgr->dinfo()->global_state) 252 , fReadyState(decoderMgr->dinfo()->global_state)
250 , fSwizzlerSubset(SkIRect::MakeEmpty()) 253 , fSwizzlerSubset(SkIRect::MakeEmpty())
251 {} 254 {}
252 255
253 /* 256 /*
254 * Return the row bytes of a particular image type and width 257 * Return the row bytes of a particular image type and width
255 */ 258 */
256 static size_t get_row_bytes(const j_decompress_ptr dinfo) { 259 static size_t get_row_bytes(const j_decompress_ptr dinfo) {
257 #ifdef TURBO_HAS_565 260 #ifdef TURBO_HAS_565
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 899
897 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); 900 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock);
898 if (linesRead < remainingRows) { 901 if (linesRead < remainingRows) {
899 // FIXME: Handle incomplete YUV decodes without signalling an error. 902 // FIXME: Handle incomplete YUV decodes without signalling an error.
900 return kInvalidInput; 903 return kInvalidInput;
901 } 904 }
902 } 905 }
903 906
904 return kSuccess; 907 return kSuccess;
905 } 908 }
OLDNEW
« no previous file with comments | « src/codec/SkJpegCodec.h ('k') | src/codec/SkJpegDecoderMgr.h » ('j') | src/codec/SkWebpCodec.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698