File indexing completed on 2024-05-05 08:25:40
0001 // vim: set tabstop=4 shiftwidth=4 expandtab 0002 /* 0003 Gwenview: an image viewer 0004 Copyright 2007 Aurélien Gâteau <agateau@kde.org> 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License 0008 as published by the Free Software Foundation; either version 2 0009 of the License, or (at your option) any later version. 0010 0011 This program is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 GNU General Public License for more details. 0015 0016 You should have received a copy of the GNU General Public License 0017 along with this program; if not, write to the Free Software 0018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0019 0020 */ 0021 #ifndef JPEGERRORMANAGER_H 0022 #define JPEGERRORMANAGER_H 0023 0024 #include <csetjmp> 0025 0026 extern "C" { 0027 #define XMD_H 0028 #include <jpeglib.h> 0029 #undef const 0030 } 0031 0032 namespace Gwenview 0033 { 0034 /** 0035 * A simple error manager which overrides jpeg_error_mgr.error_exit to avoid 0036 * calls to exit(). It uses setjmp, which I don't like, but I don't fill like 0037 * introducing exceptions to the code base for now. 0038 * 0039 * In order to use it, give an instance of it to jpeg_decompress_struct.err, 0040 * then call setjmp(errorManager.jmp_buffer) 0041 */ 0042 struct JPEGErrorManager : public jpeg_error_mgr { 0043 JPEGErrorManager() 0044 : jpeg_error_mgr() 0045 { 0046 jpeg_std_error(this); 0047 error_exit = errorExitCallBack; 0048 } 0049 0050 jmp_buf jmp_buffer; 0051 0052 static void errorExitCallBack(j_common_ptr cinfo) 0053 { 0054 auto *myerr = static_cast<JPEGErrorManager *>(cinfo->err); 0055 char buffer[JMSG_LENGTH_MAX]; 0056 (*cinfo->err->format_message)(cinfo, buffer); 0057 qCWarning(GWENVIEW_LIB_LOG) << buffer; 0058 longjmp(myerr->jmp_buffer, 1); 0059 } 0060 }; 0061 0062 } // namespace 0063 0064 #endif /* JPEGERRORMANAGER_H */