msarett | e16b04a | 2015-04-15 07:32:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkJpegDecoderMgr_DEFINED |
| 9 | #define SkJpegDecoderMgr_DEFINED |
| 10 | |
| 11 | #include "SkCodec.h" |
| 12 | #include "SkCodecPriv.h" |
mtklein | 525e90a | 2015-06-18 09:58:57 -0700 | [diff] [blame] | 13 | #include "SkJpegUtility_codec.h" |
msarett | e16b04a | 2015-04-15 07:32:19 -0700 | [diff] [blame] | 14 | #include "SkSwizzler.h" |
| 15 | #include "SkTemplates.h" |
| 16 | |
| 17 | // stdio is needed for jpeglib |
| 18 | #include <stdio.h> |
| 19 | |
| 20 | extern "C" { |
msarett | 40141b5 | 2015-07-01 14:41:02 -0700 | [diff] [blame] | 21 | #include "jpeglibmangler.h" |
msarett | e16b04a | 2015-04-15 07:32:19 -0700 | [diff] [blame] | 22 | #include "jpeglib.h" |
| 23 | } |
| 24 | |
| 25 | class JpegDecoderMgr : SkNoncopyable { |
| 26 | public: |
| 27 | |
| 28 | /* |
| 29 | * Print a useful error message and return false |
| 30 | */ |
| 31 | bool returnFalse(const char caller[]); |
| 32 | |
| 33 | /* |
| 34 | * Print a useful error message and return a decode failure |
| 35 | */ |
| 36 | SkCodec::Result returnFailure(const char caller[], SkCodec::Result result); |
| 37 | |
| 38 | /* |
| 39 | * Create the decode manager |
| 40 | * Does not take ownership of stream |
| 41 | */ |
| 42 | JpegDecoderMgr(SkStream* stream); |
| 43 | |
| 44 | /* |
| 45 | * Initialize decompress struct |
| 46 | * Initialize the source manager |
| 47 | */ |
| 48 | void init(); |
| 49 | |
| 50 | /* |
| 51 | * Recommend a color type based on the encoded format |
| 52 | */ |
| 53 | SkColorType getColorType(); |
| 54 | |
| 55 | /* |
| 56 | * Free memory used by the decode manager |
| 57 | */ |
| 58 | ~JpegDecoderMgr(); |
| 59 | |
| 60 | /* |
| 61 | * Get the jump buffer in order to set an error return point |
| 62 | */ |
| 63 | jmp_buf& getJmpBuf(); |
| 64 | |
| 65 | /* |
| 66 | * Get function for the decompress info struct |
| 67 | */ |
| 68 | jpeg_decompress_struct* dinfo(); |
| 69 | |
| 70 | private: |
| 71 | |
| 72 | jpeg_decompress_struct fDInfo; |
| 73 | skjpeg_source_mgr fSrcMgr; |
| 74 | skjpeg_error_mgr fErrorMgr; |
| 75 | bool fInit; |
| 76 | }; |
| 77 | |
| 78 | #endif |