Matt Sarett | 5df93de | 2017-03-22 21:52:47 +0000 | [diff] [blame] | 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 "SkStream.h" |
Chris Dalton | 3e79459 | 2017-12-01 13:11:09 -0700 | [diff] [blame] | 13 | #include "SkTArray.h" |
Matt Sarett | 5df93de | 2017-03-22 21:52:47 +0000 | [diff] [blame] | 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 | static constexpr uint32_t kICCMarker = JPEG_APP0 + 2; |
| 25 | static constexpr uint32_t kICCMarkerHeaderSize = 14; |
| 26 | static constexpr uint8_t kICCSig[] = { |
| 27 | 'I', 'C', 'C', '_', 'P', 'R', 'O', 'F', 'I', 'L', 'E', '\0', |
| 28 | }; |
| 29 | |
| 30 | /* |
| 31 | * Error handling struct |
| 32 | */ |
| 33 | struct skjpeg_error_mgr : jpeg_error_mgr { |
Chris Dalton | 3e79459 | 2017-12-01 13:11:09 -0700 | [diff] [blame] | 34 | class AutoPushJmpBuf { |
| 35 | public: |
| 36 | AutoPushJmpBuf(skjpeg_error_mgr* mgr) : fMgr(mgr) { |
| 37 | fMgr->fJmpBufStack.push_back(&fJmpBuf); |
| 38 | } |
| 39 | ~AutoPushJmpBuf() { |
| 40 | SkASSERT(fMgr->fJmpBufStack.back() == &fJmpBuf); |
| 41 | fMgr->fJmpBufStack.pop_back(); |
| 42 | } |
| 43 | operator jmp_buf&() { return fJmpBuf; } |
| 44 | |
| 45 | private: |
| 46 | skjpeg_error_mgr* const fMgr; |
| 47 | jmp_buf fJmpBuf; |
| 48 | }; |
| 49 | |
| 50 | SkSTArray<4, jmp_buf*> fJmpBufStack; |
Matt Sarett | 5df93de | 2017-03-22 21:52:47 +0000 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | #endif |