Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkJpegDecoderMgr.h" | 8 #include "SkJpegDecoderMgr.h" |
| 9 #include "SkJpegUtility_codec.h" | 9 #include "SkJpegUtility_codec.h" |
| 10 | 10 |
| 11 /* | 11 /* |
| 12 * Print information, warning, and error messages | 12 * Print information, warning, and error messages |
| 13 */ | 13 */ |
| 14 static void print_message(const j_common_ptr info, const char caller[]) { | 14 static void print_message(const j_common_ptr info, const char caller[]) { |
| 15 char buffer[JMSG_LENGTH_MAX]; | 15 char buffer[JMSG_LENGTH_MAX]; |
| 16 info->err->format_message(info, buffer); | 16 info->err->format_message(info, buffer); |
| 17 SkCodecPrintf("libjpeg error %d <%s> from %s\n", info->err->msg_code, buffer , caller); | 17 SkCodecPrintf("libjpeg error %d <%s> from %s\n", info->err->msg_code, buffer , caller); |
| 18 } | 18 } |
| 19 | 19 |
| 20 /* | 20 /* |
| 21 * Reporting functions for libjpeg | 21 * Reporting function for error and warning messages. |
| 22 */ | 22 */ |
| 23 static void emit_message(j_common_ptr info, int) { | |
|
msarett
2015/11/10 15:26:35
The default implementation of emit_message is much
| |
| 24 print_message(info, "emit_message"); | |
| 25 } | |
| 26 static void output_message(j_common_ptr info) { | 23 static void output_message(j_common_ptr info) { |
|
msarett
2015/11/10 15:26:35
By overriding output_message, we can use SkCodecPr
| |
| 27 print_message(info, "output_message"); | 24 print_message(info, "output_message"); |
| 28 } | 25 } |
| 29 | 26 |
| 30 bool JpegDecoderMgr::returnFalse(const char caller[]) { | 27 bool JpegDecoderMgr::returnFalse(const char caller[]) { |
| 31 print_message((j_common_ptr) &fDInfo, caller); | 28 print_message((j_common_ptr) &fDInfo, caller); |
| 32 return false; | 29 return false; |
| 33 } | 30 } |
| 34 | 31 |
| 35 SkCodec::Result JpegDecoderMgr::returnFailure(const char caller[], SkCodec::Resu lt result) { | 32 SkCodec::Result JpegDecoderMgr::returnFailure(const char caller[], SkCodec::Resu lt result) { |
| 36 print_message((j_common_ptr) &fDInfo, caller); | 33 print_message((j_common_ptr) &fDInfo, caller); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 52 { | 49 { |
| 53 // Error manager must be set before any calls to libjeg in order to handle f ailures | 50 // Error manager must be set before any calls to libjeg in order to handle f ailures |
| 54 fDInfo.err = jpeg_std_error(&fErrorMgr); | 51 fDInfo.err = jpeg_std_error(&fErrorMgr); |
| 55 fErrorMgr.error_exit = skjpeg_err_exit; | 52 fErrorMgr.error_exit = skjpeg_err_exit; |
| 56 } | 53 } |
| 57 | 54 |
| 58 void JpegDecoderMgr::init() { | 55 void JpegDecoderMgr::init() { |
| 59 jpeg_create_decompress(&fDInfo); | 56 jpeg_create_decompress(&fDInfo); |
| 60 fInit = true; | 57 fInit = true; |
| 61 fDInfo.src = &fSrcMgr; | 58 fDInfo.src = &fSrcMgr; |
| 62 fDInfo.err->emit_message = &emit_message; | |
| 63 fDInfo.err->output_message = &output_message; | 59 fDInfo.err->output_message = &output_message; |
| 64 } | 60 } |
| 65 | 61 |
| 66 JpegDecoderMgr::~JpegDecoderMgr() { | 62 JpegDecoderMgr::~JpegDecoderMgr() { |
| 67 if (fInit) { | 63 if (fInit) { |
| 68 jpeg_destroy_decompress(&fDInfo); | 64 jpeg_destroy_decompress(&fDInfo); |
| 69 } | 65 } |
| 70 } | 66 } |
| 71 | 67 |
| 72 jmp_buf& JpegDecoderMgr::getJmpBuf() { | 68 jmp_buf& JpegDecoderMgr::getJmpBuf() { |
| 73 return fErrorMgr.fJmpBuf; | 69 return fErrorMgr.fJmpBuf; |
| 74 } | 70 } |
| 75 | 71 |
| 76 jpeg_decompress_struct* JpegDecoderMgr::dinfo() { | 72 jpeg_decompress_struct* JpegDecoderMgr::dinfo() { |
| 77 return &fDInfo; | 73 return &fDInfo; |
| 78 } | 74 } |
| OLD | NEW |