blob: f3834fe79b58f9a1b04f247f2faf38764ff81a59 [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 /*
Chris Dalton3e794592017-12-01 13:11:09 -070057 * Get the skjpeg_error_mgr in order to set an error return jmp_buf
msarette16b04a2015-04-15 07:32:19 -070058 */
Chris Dalton3e794592017-12-01 13:11:09 -070059 skjpeg_error_mgr* errorMgr() { return &fErrorMgr; }
msarette16b04a2015-04-15 07:32:19 -070060
61 /*
62 * Get function for the decompress info struct
63 */
Chris Dalton3e794592017-12-01 13:11:09 -070064 jpeg_decompress_struct* dinfo() { return &fDInfo; }
msarette16b04a2015-04-15 07:32:19 -070065
66private:
67
Matt Sarett15f4d022017-06-06 17:58:33 +000068 jpeg_decompress_struct fDInfo;
69 skjpeg_source_mgr fSrcMgr;
70 skjpeg_error_mgr fErrorMgr;
71 jpeg_progress_mgr fProgressMgr;
72 bool fInit;
msarette16b04a2015-04-15 07:32:19 -070073};
74
75#endif