Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: src/codec/SkJpegDecoderMgr.cpp

Issue 1076923002: SkJpegCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@gif-real
Patch Set: Introduction of DecoderMgr Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 #include "SkJpegDecoderMgr.h"
9 #include "SkJpegUtility.h"
10
11 /*
12 * Print information, warning, and error messages
13 */
14 static void print_message(const j_common_ptr info, const char caller[]) {
15 char buffer[JMSG_LENGTH_MAX];
16 info->err->format_message(info, buffer);
17 SkCodecPrintf("libjpeg error %d <%s> from %s\n", info->err->msg_code, buffer , caller);
18 }
19
20 /*
21 * Reporting functions for libjpeg
22 */
23 static void emit_message(j_common_ptr info, int) {
24 print_message(info, "emit_message");
25 }
26 static void output_message(j_common_ptr info) {
27 print_message(info, "output_message");
28 }
29
30 /*
31 * Choose the size of the memory buffer on Android
32 */
33 static void overwrite_mem_buffer_size(jpeg_decompress_struct* fDInfo) {
34 #ifdef SK_BUILD_FOR_ANDROID
35
36 // Use 30 MB for devices with a large amount of system memory and 5MB otherwise
37 // TODO: (msarett) This matches SkImageDecoder. Why were these values chosen?
38 #ifdef ANDROID_LARGE_MEMORY_DEVICE
39 fDInfo.mem->max_memory_to_use = 30 * 1024 * 1024;
40 #else
41 fDInfo.mem->max_memory_to_use = 5 * 1024 * 1024;
42 #endif
43
44 #endif // SK_BUILD_FOR_ANDROID
45 }
46
47 bool JpegDecoderMgr::returnFalse(const char caller[]) {
48 print_message((j_common_ptr) &fDInfo, caller);
49 return false;
50 }
51
52 SkCodec::Result JpegDecoderMgr::returnFailure(const char caller[], SkCodec::Resu lt result) {
53 print_message((j_common_ptr) &fDInfo, caller);
54 return result;
55 }
56
57 SkColorType JpegDecoderMgr::getColorType() {
58 switch (fDInfo.jpeg_color_space) {
59 case JCS_CMYK:
60 case JCS_YCCK:
61 // libjpeg cannot convert from CMYK or YCCK to RGB.
62 // Here, we ask libjpeg to give us CMYK samples back and
63 // we will later manually convert them to RGB.
64 fDInfo.out_color_space = JCS_CMYK;
65 return kN32_SkColorType;
66 case JCS_GRAYSCALE:
67 fDInfo.out_color_space = JCS_GRAYSCALE;
68 return kGray_8_SkColorType;
69 default:
70 #ifdef ANDROID_RGB
71 fDInfo.out_color_space = JCS_RGBA_8888;
72 #else
73 fDInfo.out_color_space = JCS_RGB;
74 #endif
75 return kN32_SkColorType;
76 }
77 }
78
79 JpegDecoderMgr::JpegDecoderMgr(SkStream* stream)
80 : fSrcMgr(stream)
81 {
82 // Error manager must be set before any calls to libjeg in order to handle f ailures
83 fDInfo.err = jpeg_std_error(&fErrorMgr);
84 fErrorMgr.error_exit = skjpeg_err_exit;
85 }
86
87 void JpegDecoderMgr::init() {
88 jpeg_create_decompress(&fDInfo);
89 fDInfo.src = &fSrcMgr;
90 overwrite_mem_buffer_size(&fDInfo);
91 fDInfo.err->emit_message = &emit_message;
92 fDInfo.err->output_message = &output_message;
93 }
94
95 JpegDecoderMgr::~JpegDecoderMgr() {
96 jpeg_destroy_decompress(&fDInfo);
scroggo 2015/04/15 00:31:06 Don't we only want to do this if init was called?
msarett 2015/04/15 12:43:11 Yes it is unnecessary otherwise! Fixed.
97 }
98
99 jpeg_decompress_struct* JpegDecoderMgr::dinfo() {
100 return &fDInfo;
101 }
102
103 skjpeg_error_mgr* JpegDecoderMgr::errorMgr() {
scroggo 2015/04/15 00:31:06 You appear to only use this to get the jump buffer
msarett 2015/04/15 12:43:12 I had exactly the same though. I wrote: jmp_buf
104 return &fErrorMgr;
105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698