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/SkTArray.h"
14
15#include <setjmp.h>
16// stdio is needed for jpeglib
17#include <stdio.h>
18
19extern "C" {
20 #include "jpeglib.h"
21 #include "jerror.h"
22}
23
24static constexpr uint32_t kICCMarker = JPEG_APP0 + 2;
25static constexpr uint32_t kICCMarkerHeaderSize = 14;
26static constexpr uint8_t kICCSig[] = {
27 'I', 'C', 'C', '_', 'P', 'R', 'O', 'F', 'I', 'L', 'E', '\0',
28};
29
30/*
31 * Error handling struct
32 */
33struct skjpeg_error_mgr : jpeg_error_mgr {
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;
51};
52
53#endif
54