blob: 272c5b4b1ce7927df2295e5e838250d2f9cb0c29 [file] [log] [blame]
msarette16b04a2015-04-15 07:32:19 -07001/*
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"
msarette16b04a2015-04-15 07:32:19 -070013#include <stdio.h>
msarettc1d03122016-03-25 08:58:55 -070014#include "SkJpegUtility.h"
msarette16b04a2015-04-15 07:32:19 -070015
16extern "C" {
msarette16b04a2015-04-15 07:32:19 -070017 #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 /*
msarettac6c7502016-04-25 09:30:24 -070046 * Returns true if it successfully sets outColor to the encoded color,
47 * and false otherwise.
msarette16b04a2015-04-15 07:32:19 -070048 */
msarettac6c7502016-04-25 09:30:24 -070049 bool getEncodedColor(SkEncodedInfo::Color* outColor);
msarette16b04a2015-04-15 07:32:19 -070050
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
66private:
67
68 jpeg_decompress_struct fDInfo;
69 skjpeg_source_mgr fSrcMgr;
70 skjpeg_error_mgr fErrorMgr;
Matt Sarettdbdf6d22016-11-08 15:26:56 -050071 jpeg_progress_mgr fProgressMgr;
msarette16b04a2015-04-15 07:32:19 -070072 bool fInit;
73};
74
75#endif