Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkJpegPriv.h
Go to the documentation of this file.
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
15
16#include <setjmp.h>
17// stdio is needed for jpeglib
18#include <stdio.h>
19
20extern "C" {
21 #include "jpeglib.h" // NO_G3_REWRITE
22 #include "jerror.h" // NO_G3_REWRITE
23}
24
25/*
26 * Error handling struct
27 */
28struct skjpeg_error_mgr : jpeg_error_mgr {
30 public:
31 AutoPushJmpBuf(skjpeg_error_mgr* mgr) : fMgr(mgr) { fMgr->push(&fJmpBuf); }
32 ~AutoPushJmpBuf() { fMgr->pop(&fJmpBuf); }
33 operator jmp_buf&() { return fJmpBuf; }
34
35 private:
36 skjpeg_error_mgr* const fMgr;
37 jmp_buf fJmpBuf;
38 };
39
40 void push(jmp_buf* j) {
41 SkASSERT(fStack[3] == nullptr); // if we assert here, the stack has overflowed
42 fStack[3] = fStack[2];
43 fStack[2] = fStack[1];
44 fStack[1] = fStack[0];
45 fStack[0] = j;
46 }
47
48 void pop(jmp_buf* j) {
49 SkASSERT(fStack[0] == j); // if we assert here, the pushes and pops were unbalanced
50 fStack[0] = fStack[1];
51 fStack[1] = fStack[2];
52 fStack[2] = fStack[3];
53 fStack[3] = nullptr;
54 }
55
56 jmp_buf* fStack[4] = {};
57};
58
59#endif
#define SkASSERT(cond)
Definition SkAssert.h:116
AutoPushJmpBuf(skjpeg_error_mgr *mgr)
Definition SkJpegPriv.h:31
void push(jmp_buf *j)
Definition SkJpegPriv.h:40
void pop(jmp_buf *j)
Definition SkJpegPriv.h:48
jmp_buf * fStack[4]
Definition SkJpegPriv.h:56