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 "SkJpegDecoderMgr.h" | 8 #include "SkJpegDecoderMgr.h" |
9 #include "SkJpegUtility_codec.h" | 9 #include "SkJpegUtility_codec.h" |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 return false; | 32 return false; |
33 } | 33 } |
34 | 34 |
35 SkCodec::Result JpegDecoderMgr::returnFailure(const char caller[], SkCodec::Resu
lt result) { | 35 SkCodec::Result JpegDecoderMgr::returnFailure(const char caller[], SkCodec::Resu
lt result) { |
36 print_message((j_common_ptr) &fDInfo, caller); | 36 print_message((j_common_ptr) &fDInfo, caller); |
37 return result; | 37 return result; |
38 } | 38 } |
39 | 39 |
40 SkColorType JpegDecoderMgr::getColorType() { | 40 SkColorType JpegDecoderMgr::getColorType() { |
41 switch (fDInfo.jpeg_color_space) { | 41 switch (fDInfo.jpeg_color_space) { |
| 42 case JCS_CMYK: |
| 43 case JCS_YCCK: |
| 44 // libjpeg cannot convert from CMYK or YCCK to RGB. |
| 45 // Here, we ask libjpeg to give us CMYK samples back and |
| 46 // we will later manually convert them to RGB. |
| 47 fDInfo.out_color_space = JCS_CMYK; |
| 48 return kN32_SkColorType; |
42 case JCS_GRAYSCALE: | 49 case JCS_GRAYSCALE: |
| 50 fDInfo.out_color_space = JCS_GRAYSCALE; |
43 return kGray_8_SkColorType; | 51 return kGray_8_SkColorType; |
44 default: | 52 default: |
| 53 #ifdef ANDROID_RGB |
| 54 fDInfo.out_color_space = JCS_RGBA_8888; |
| 55 #else |
| 56 fDInfo.out_color_space = JCS_RGB; |
| 57 #endif |
45 return kN32_SkColorType; | 58 return kN32_SkColorType; |
46 } | 59 } |
47 } | 60 } |
48 | 61 |
49 JpegDecoderMgr::JpegDecoderMgr(SkStream* stream) | 62 JpegDecoderMgr::JpegDecoderMgr(SkStream* stream) |
50 : fSrcMgr(stream) | 63 : fSrcMgr(stream) |
51 , fInit(false) | 64 , fInit(false) |
52 { | 65 { |
53 // Error manager must be set before any calls to libjeg in order to handle f
ailures | 66 // Error manager must be set before any calls to libjeg in order to handle f
ailures |
54 fDInfo.err = turbo_jpeg_std_error(&fErrorMgr); | 67 fDInfo.err = jpeg_std_error(&fErrorMgr); |
55 fErrorMgr.error_exit = skjpeg_err_exit; | 68 fErrorMgr.error_exit = skjpeg_err_exit; |
56 } | 69 } |
57 | 70 |
58 void JpegDecoderMgr::init() { | 71 void JpegDecoderMgr::init() { |
59 jpeg_create_decompress(&fDInfo); | 72 jpeg_create_decompress(&fDInfo); |
60 fInit = true; | 73 fInit = true; |
61 fDInfo.src = &fSrcMgr; | 74 fDInfo.src = &fSrcMgr; |
62 fDInfo.err->emit_message = &emit_message; | 75 fDInfo.err->emit_message = &emit_message; |
63 fDInfo.err->output_message = &output_message; | 76 fDInfo.err->output_message = &output_message; |
64 } | 77 } |
65 | 78 |
66 JpegDecoderMgr::~JpegDecoderMgr() { | 79 JpegDecoderMgr::~JpegDecoderMgr() { |
67 if (fInit) { | 80 if (fInit) { |
68 jpeg_destroy_decompress(&fDInfo); | 81 jpeg_destroy_decompress(&fDInfo); |
69 } | 82 } |
70 } | 83 } |
71 | 84 |
72 jmp_buf& JpegDecoderMgr::getJmpBuf() { | 85 jmp_buf& JpegDecoderMgr::getJmpBuf() { |
73 return fErrorMgr.fJmpBuf; | 86 return fErrorMgr.fJmpBuf; |
74 } | 87 } |
75 | 88 |
76 jpeg_decompress_struct* JpegDecoderMgr::dinfo() { | 89 jpeg_decompress_struct* JpegDecoderMgr::dinfo() { |
77 return &fDInfo; | 90 return &fDInfo; |
78 } | 91 } |
OLD | NEW |