blob: cc44f3c42117cd1b285ee5651180f47bd2b602df (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkJpegDecoderMgr.h"
#include "SkJpegUtility_codec.h"
/*
* Print information, warning, and error messages
*/
static void print_message(const j_common_ptr info, const char caller[]) {
char buffer[JMSG_LENGTH_MAX];
info->err->format_message(info, buffer);
SkCodecPrintf("libjpeg error %d <%s> from %s\n", info->err->msg_code, buffer, caller);
}
/*
* Reporting function for error and warning messages.
*/
static void output_message(j_common_ptr info) {
print_message(info, "output_message");
}
bool JpegDecoderMgr::returnFalse(const char caller[]) {
print_message((j_common_ptr) &fDInfo, caller);
return false;
}
SkCodec::Result JpegDecoderMgr::returnFailure(const char caller[], SkCodec::Result result) {
print_message((j_common_ptr) &fDInfo, caller);
return result;
}
SkColorType JpegDecoderMgr::getColorType() {
switch (fDInfo.jpeg_color_space) {
case JCS_GRAYSCALE:
return kGray_8_SkColorType;
default:
return kN32_SkColorType;
}
}
JpegDecoderMgr::JpegDecoderMgr(SkStream* stream)
: fSrcMgr(stream)
, fInit(false)
{
// Error manager must be set before any calls to libjeg in order to handle failures
fDInfo.err = jpeg_std_error(&fErrorMgr);
fErrorMgr.error_exit = skjpeg_err_exit;
}
void JpegDecoderMgr::init() {
jpeg_create_decompress(&fDInfo);
fInit = true;
fDInfo.src = &fSrcMgr;
fDInfo.err->output_message = &output_message;
}
JpegDecoderMgr::~JpegDecoderMgr() {
if (fInit) {
jpeg_destroy_decompress(&fDInfo);
}
}
jmp_buf& JpegDecoderMgr::getJmpBuf() {
return fErrorMgr.fJmpBuf;
}
jpeg_decompress_struct* JpegDecoderMgr::dinfo() {
return &fDInfo;
}
|