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 19 matching lines...) Expand all Loading... | |
30 bool JpegDecoderMgr::returnFalse(const char caller[]) { | 30 bool JpegDecoderMgr::returnFalse(const char caller[]) { |
31 print_message((j_common_ptr) &fDInfo, caller); | 31 print_message((j_common_ptr) &fDInfo, caller); |
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() { |
scroggo
2015/06/24 21:08:49
nit: Maybe this should be getRecommendedColorType?
| |
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; | |
49 case JCS_GRAYSCALE: | 42 case JCS_GRAYSCALE: |
50 fDInfo.out_color_space = JCS_GRAYSCALE; | |
51 return kGray_8_SkColorType; | 43 return kGray_8_SkColorType; |
52 default: | 44 default: |
53 #ifdef ANDROID_RGB | |
54 fDInfo.out_color_space = JCS_RGBA_8888; | |
55 #else | |
56 fDInfo.out_color_space = JCS_RGB; | |
57 #endif | |
58 return kN32_SkColorType; | 45 return kN32_SkColorType; |
59 } | 46 } |
60 } | 47 } |
61 | 48 |
62 JpegDecoderMgr::JpegDecoderMgr(SkStream* stream) | 49 JpegDecoderMgr::JpegDecoderMgr(SkStream* stream) |
63 : fSrcMgr(stream) | 50 : fSrcMgr(stream) |
64 , fInit(false) | 51 , fInit(false) |
65 { | 52 { |
66 // Error manager must be set before any calls to libjeg in order to handle f ailures | 53 // Error manager must be set before any calls to libjeg in order to handle f ailures |
67 fDInfo.err = jpeg_std_error(&fErrorMgr); | 54 fDInfo.err = turbo_jpeg_std_error(&fErrorMgr); |
68 fErrorMgr.error_exit = skjpeg_err_exit; | 55 fErrorMgr.error_exit = skjpeg_err_exit; |
69 } | 56 } |
70 | 57 |
71 void JpegDecoderMgr::init() { | 58 void JpegDecoderMgr::init() { |
72 jpeg_create_decompress(&fDInfo); | 59 jpeg_create_decompress(&fDInfo); |
73 fInit = true; | 60 fInit = true; |
74 fDInfo.src = &fSrcMgr; | 61 fDInfo.src = &fSrcMgr; |
75 fDInfo.err->emit_message = &emit_message; | 62 fDInfo.err->emit_message = &emit_message; |
76 fDInfo.err->output_message = &output_message; | 63 fDInfo.err->output_message = &output_message; |
77 } | 64 } |
78 | 65 |
79 JpegDecoderMgr::~JpegDecoderMgr() { | 66 JpegDecoderMgr::~JpegDecoderMgr() { |
80 if (fInit) { | 67 if (fInit) { |
81 jpeg_destroy_decompress(&fDInfo); | 68 jpeg_destroy_decompress(&fDInfo); |
82 } | 69 } |
83 } | 70 } |
84 | 71 |
85 jmp_buf& JpegDecoderMgr::getJmpBuf() { | 72 jmp_buf& JpegDecoderMgr::getJmpBuf() { |
86 return fErrorMgr.fJmpBuf; | 73 return fErrorMgr.fJmpBuf; |
87 } | 74 } |
88 | 75 |
89 jpeg_decompress_struct* JpegDecoderMgr::dinfo() { | 76 jpeg_decompress_struct* JpegDecoderMgr::dinfo() { |
90 return &fDInfo; | 77 return &fDInfo; |
91 } | 78 } |
OLD | NEW |