OLD | NEW |
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 Loading... |
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 // Get the encoded color type | 214 // Recommend the color type to decode to |
215 SkEncodedInfo::Color color = decoderMgr->getEncodedColor(); | 215 const SkColorType colorType = decoderMgr->getColorType(); |
216 if (SkEncodedInfo::kUnknown_Color == color) { | |
217 return false; | |
218 } | |
219 | 216 |
220 // Create image info object and the codec | 217 // Create image info object and the codec |
221 SkEncodedInfo info = SkEncodedInfo::Make(color, SkEncodedInfo::kOpaque_A
lpha, 8); | 218 const SkImageInfo& imageInfo = SkImageInfo::Make(decoderMgr->dinfo()->im
age_width, |
| 219 decoderMgr->dinfo()->image_height, colorType, kOpaque_SkAlphaTyp
e); |
222 | 220 |
223 Origin orientation = get_exif_orientation(decoderMgr->dinfo()); | 221 Origin orientation = get_exif_orientation(decoderMgr->dinfo()); |
224 sk_sp<SkColorSpace> colorSpace = get_icc_profile(decoderMgr->dinfo()); | 222 sk_sp<SkColorSpace> colorSpace = get_icc_profile(decoderMgr->dinfo()); |
225 | 223 |
226 *codecOut = new SkJpegCodec(decoderMgr->dinfo()->image_width, | 224 *codecOut = new SkJpegCodec(imageInfo, stream, decoderMgr.release(), col
orSpace, |
227 decoderMgr->dinfo()->image_height, info, stream, decoderMgr.rele
ase(), colorSpace, | |
228 orientation); | 225 orientation); |
229 } else { | 226 } else { |
230 SkASSERT(nullptr != decoderMgrOut); | 227 SkASSERT(nullptr != decoderMgrOut); |
231 *decoderMgrOut = decoderMgr.release(); | 228 *decoderMgrOut = decoderMgr.release(); |
232 } | 229 } |
233 return true; | 230 return true; |
234 } | 231 } |
235 | 232 |
236 SkCodec* SkJpegCodec::NewFromStream(SkStream* stream) { | 233 SkCodec* SkJpegCodec::NewFromStream(SkStream* stream) { |
237 SkAutoTDelete<SkStream> streamDeleter(stream); | 234 SkAutoTDelete<SkStream> streamDeleter(stream); |
238 SkCodec* codec = nullptr; | 235 SkCodec* codec = nullptr; |
239 if (ReadHeader(stream, &codec, nullptr)) { | 236 if (ReadHeader(stream, &codec, nullptr)) { |
240 // Codec has taken ownership of the stream, we do not need to delete it | 237 // Codec has taken ownership of the stream, we do not need to delete it |
241 SkASSERT(codec); | 238 SkASSERT(codec); |
242 streamDeleter.release(); | 239 streamDeleter.release(); |
243 return codec; | 240 return codec; |
244 } | 241 } |
245 return nullptr; | 242 return nullptr; |
246 } | 243 } |
247 | 244 |
248 SkJpegCodec::SkJpegCodec(int width, int height, const SkEncodedInfo& info, SkStr
eam* stream, | 245 SkJpegCodec::SkJpegCodec(const SkImageInfo& srcInfo, SkStream* stream, |
249 JpegDecoderMgr* decoderMgr, sk_sp<SkColorSpace> colorSpace, Origin origi
n) | 246 JpegDecoderMgr* decoderMgr, sk_sp<SkColorSpace> colorSpace, Origin origi
n) |
250 : INHERITED(width, height, info, stream, colorSpace, origin) | 247 : INHERITED(srcInfo, stream, colorSpace, origin) |
251 , fDecoderMgr(decoderMgr) | 248 , fDecoderMgr(decoderMgr) |
252 , fReadyState(decoderMgr->dinfo()->global_state) | 249 , fReadyState(decoderMgr->dinfo()->global_state) |
253 , fSwizzlerSubset(SkIRect::MakeEmpty()) | 250 , fSwizzlerSubset(SkIRect::MakeEmpty()) |
254 {} | 251 {} |
255 | 252 |
256 /* | 253 /* |
257 * Return the row bytes of a particular image type and width | 254 * Return the row bytes of a particular image type and width |
258 */ | 255 */ |
259 static size_t get_row_bytes(const j_decompress_ptr dinfo) { | 256 static size_t get_row_bytes(const j_decompress_ptr dinfo) { |
260 #ifdef TURBO_HAS_565 | 257 #ifdef TURBO_HAS_565 |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 | 889 |
893 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); | 890 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); |
894 if (linesRead < remainingRows) { | 891 if (linesRead < remainingRows) { |
895 // FIXME: Handle incomplete YUV decodes without signalling an error. | 892 // FIXME: Handle incomplete YUV decodes without signalling an error. |
896 return kInvalidInput; | 893 return kInvalidInput; |
897 } | 894 } |
898 } | 895 } |
899 | 896 |
900 return kSuccess; | 897 return kSuccess; |
901 } | 898 } |
OLD | NEW |