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 "src/codec/SkCodecPriv.h"
13#include <stdio.h>
14#include "src/codec/SkJpegUtility.h"
15
16extern "C" {
17 #include "jpeglib.h"
18}
19
20class JpegDecoderMgr : SkNoncopyable {
21public:
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 /*
46 * Returns true if it successfully sets outColor to the encoded color,
47 * and false otherwise.
48 */
49 bool getEncodedColor(SkEncodedInfo::Color* outColor);
50
51 /*
52 * Free memory used by the decode manager
53 */
54 ~JpegDecoderMgr();
55
56 /*
57 * Get the skjpeg_error_mgr in order to set an error return jmp_buf
58 */
59 skjpeg_error_mgr* errorMgr() { return &fErrorMgr; }
60
61 /*
62 * Get function for the decompress info struct
63 */
64 jpeg_decompress_struct* dinfo() { return &fDInfo; }
65
66private:
67
68 jpeg_decompress_struct fDInfo;
69 skjpeg_source_mgr fSrcMgr;
70 skjpeg_error_mgr fErrorMgr;
71 jpeg_progress_mgr fProgressMgr;
72 bool fInit;
73};
74
75#endif
76