blob: e9dd9778ee13193c74650941fdeefc2e2b8f6958 [file] [log] [blame]
reed@android.com6f598152010-01-21 15:34:19 +00001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SkJpegUtility_DEFINED
18#define SkJpegUtility_DEFINED
19
20#include "SkImageDecoder.h"
21#include "SkStream.h"
22
23extern "C" {
24 #include "jpeglib.h"
25 #include "jerror.h"
26}
27
28#include <setjmp.h>
29
30/* Our error-handling struct.
31 *
32*/
33struct skjpeg_error_mgr : jpeg_error_mgr {
34 jmp_buf fJmpBuf;
35};
36
37
38void skjpeg_error_exit(j_common_ptr cinfo);
39
40///////////////////////////////////////////////////////////////////////////
41/* Our source struct for directing jpeg to our stream object.
42*/
43struct skjpeg_source_mgr : jpeg_source_mgr {
djsollen@google.com57f49692011-02-23 20:46:31 +000044 skjpeg_source_mgr(SkStream* stream, SkImageDecoder* decoder, bool ownStream);
45 ~skjpeg_source_mgr();
reed@android.com6f598152010-01-21 15:34:19 +000046
47 SkStream* fStream;
djsollen@google.com57f49692011-02-23 20:46:31 +000048 void* fMemoryBase;
reed@android.com6f598152010-01-21 15:34:19 +000049 size_t fMemoryBaseSize;
djsollen@google.com57f49692011-02-23 20:46:31 +000050 bool fUnrefStream;
reed@android.com6f598152010-01-21 15:34:19 +000051 SkImageDecoder* fDecoder;
52 enum {
53 kBufferSize = 1024
54 };
55 char fBuffer[kBufferSize];
56};
57
58/////////////////////////////////////////////////////////////////////////////
59/* Our destination struct for directing decompressed pixels to our stream
60 * object.
61 */
62struct skjpeg_destination_mgr : jpeg_destination_mgr {
63 skjpeg_destination_mgr(SkWStream* stream);
64
65 SkWStream* fStream;
66
67 enum {
68 kBufferSize = 1024
69 };
70 uint8_t fBuffer[kBufferSize];
71};
72
73#endif