| 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 "include/codec/SkCodec.h" |
| 12 |
#include "include/private/SkEncodedInfo.h" |
| 13 |
#include "include/private/base/SkNoncopyable.h" |
| 14 |
#include "src/codec/SkJpegPriv.h" |
| 15 |
#include "src/codec/SkJpegSourceMgr.h" |
| 16 |
|
| 17 |
extern "C" { |
| 18 |
#include "jpeglib.h" // NO_G3_REWRITE |
| 19 |
} |
| 20 |
|
| 21 |
#include <memory> |
| 22 |
|
| 23 |
class SkStream; |
| 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 |
explicit JpegDecoderMgr(SkStream* stream); |
| 43 |
|
| 44 |
/* |
| 45 |
* Initialize decompress struct |
| 46 |
* Initialize the source manager |
| 47 |
*/ |
| 48 |
void init(); |
| 49 |
|
| 50 |
/* |
| 51 |
* Returns true if it successfully sets outColor to the encoded color, |
| 52 |
* and false otherwise. |
| 53 |
*/ |
| 54 |
bool getEncodedColor(SkEncodedInfo::Color* outColor); |
| 55 |
|
| 56 |
/* |
| 57 |
* Free memory used by the decode manager |
| 58 |
*/ |
| 59 |
~JpegDecoderMgr(); |
| 60 |
|
| 61 |
/* |
| 62 |
* Get the skjpeg_error_mgr in order to set an error return jmp_buf |
| 63 |
*/ |
| 64 |
skjpeg_error_mgr* errorMgr() { return &fErrorMgr; } |
| 65 |
|
| 66 |
/* |
| 67 |
* Get function for the decompress info struct |
| 68 |
*/ |
| 69 |
jpeg_decompress_struct* dinfo() { return &fDInfo; } |
| 70 |
|
| 71 |
// Get the source manager. |
| 72 |
SkJpegSourceMgr* getSourceMgr(); |
| 73 |
|
| 74 |
private: |
| 75 |
// Wrapper that calls into the full SkJpegSourceMgr interface. |
| 76 |
struct SourceMgr : jpeg_source_mgr { |
| 77 |
static void InitSource(j_decompress_ptr dinfo); |
| 78 |
static void SkipInputData(j_decompress_ptr dinfo, long num_bytes_long); |
| 79 |
static boolean FillInputBuffer(j_decompress_ptr dinfo); |
| 80 |
static void TermSource(j_decompress_ptr dinfo); |
| 81 |
|
| 82 |
explicit SourceMgr(std::unique_ptr<SkJpegSourceMgr> mgr); |
| 83 |
std::unique_ptr<SkJpegSourceMgr> fSourceMgr; |
| 84 |
}; |
| 85 |
|
| 86 |
jpeg_decompress_struct fDInfo; |
| 87 |
SourceMgr fSrcMgr; |
| 88 |
skjpeg_error_mgr fErrorMgr; |
| 89 |
jpeg_progress_mgr fProgressMgr; |
| 90 |
bool fInit; |
| 91 |
}; |
| 92 |
|
| 93 |
#endif |