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" |
msarett | e16b04a | 2015-04-15 07:32:19 -0700 | [diff] [blame] | 13 | #include <stdio.h> |
msarett | c1d0312 | 2016-03-25 08:58:55 -0700 | [diff] [blame] | 14 | #include "SkJpegUtility.h" |
msarett | e16b04a | 2015-04-15 07:32:19 -0700 | [diff] [blame] | 15 | |
| 16 | extern "C" { |
msarett | e16b04a | 2015-04-15 07:32:19 -0700 | [diff] [blame] | 17 | #include "jpeglib.h" |
| 18 | } |
| 19 | |
| 20 | class JpegDecoderMgr : SkNoncopyable { |
| 21 | public: |
| 22 | |
| 23 | /* |
| 24 | * Print a useful error message and return false |
| 25 | */ |
| 26 | bool returnFalse(const char caller[]); |
| 27 | |
| 28 | /* |
| 29 | * Print a useful error message and return a decode failure |
| 30 | */ |
| 31 | SkCodec::Result returnFailure(const char caller[], SkCodec::Result result); |
| 32 | |
| 33 | /* |
| 34 | * Create the decode manager |
| 35 | * Does not take ownership of stream |
| 36 | */ |
| 37 | JpegDecoderMgr(SkStream* stream); |
| 38 | |
| 39 | /* |
| 40 | * Initialize decompress struct |
| 41 | * Initialize the source manager |
| 42 | */ |
| 43 | void init(); |
| 44 | |
| 45 | /* |
msarett | ac6c750 | 2016-04-25 09:30:24 -0700 | [diff] [blame] | 46 | * Returns true if it successfully sets outColor to the encoded color, |
| 47 | * and false otherwise. |
msarett | e16b04a | 2015-04-15 07:32:19 -0700 | [diff] [blame] | 48 | */ |
msarett | ac6c750 | 2016-04-25 09:30:24 -0700 | [diff] [blame] | 49 | bool getEncodedColor(SkEncodedInfo::Color* outColor); |
msarett | e16b04a | 2015-04-15 07:32:19 -0700 | [diff] [blame] | 50 | |
| 51 | /* |
| 52 | * Free memory used by the decode manager |
| 53 | */ |
| 54 | ~JpegDecoderMgr(); |
| 55 | |
| 56 | /* |
| 57 | * Get the jump buffer in order to set an error return point |
| 58 | */ |
| 59 | jmp_buf& getJmpBuf(); |
| 60 | |
| 61 | /* |
| 62 | * Get function for the decompress info struct |
| 63 | */ |
| 64 | jpeg_decompress_struct* dinfo(); |
| 65 | |
| 66 | private: |
| 67 | |
| 68 | jpeg_decompress_struct fDInfo; |
| 69 | skjpeg_source_mgr fSrcMgr; |
| 70 | skjpeg_error_mgr fErrorMgr; |
Matt Sarett | dbdf6d2 | 2016-11-08 15:26:56 -0500 | [diff] [blame] | 71 | jpeg_progress_mgr fProgressMgr; |
msarett | e16b04a | 2015-04-15 07:32:19 -0700 | [diff] [blame] | 72 | bool fInit; |
| 73 | }; |
| 74 | |
| 75 | #endif |