1 /* 2 * Copyright 2017 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 9 #ifndef SkJpegPriv_DEFINED 10 #define SkJpegPriv_DEFINED 11 12 #include "include/core/SkStream.h" 13 #include "include/private/base/SkTArray.h" 14 15 #include <setjmp.h> 16 // stdio is needed for jpeglib 17 #include <stdio.h> 18 19 extern "C" { 20 #include "jpeglib.h" 21 #include "jerror.h" 22 } 23 24 /* 25 * Error handling struct 26 */ 27 struct skjpeg_error_mgr : jpeg_error_mgr { 28 class AutoPushJmpBuf { 29 public: AutoPushJmpBufskjpeg_error_mgr30 AutoPushJmpBuf(skjpeg_error_mgr* mgr) : fMgr(mgr) { 31 fMgr->fJmpBufStack.push_back(&fJmpBuf); 32 } ~AutoPushJmpBufskjpeg_error_mgr33 ~AutoPushJmpBuf() { 34 SkASSERT(fMgr->fJmpBufStack.back() == &fJmpBuf); 35 fMgr->fJmpBufStack.pop_back(); 36 } 37 operator jmp_buf&() { return fJmpBuf; } 38 39 private: 40 skjpeg_error_mgr* const fMgr; 41 jmp_buf fJmpBuf; 42 }; 43 44 SkSTArray<4, jmp_buf*> fJmpBufStack; 45 }; 46 47 #endif 48