unplugged-system/external/skia/include/mtk/SkJpegUtility_MTK.h

77 lines
1.9 KiB
C++

/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkJpegUtility_MTK_DEFINED
#define SkJpegUtility_MTK_DEFINED
#include "include/mtk/SkImageDecoder.h"
#include "include/private/base/SkTArray.h"
#include <cstdint>
#include <setjmp.h>
extern "C" {
// We need to include stdio.h before jpeg because jpeg does not include it, but uses FILE
// See https://github.com/libjpeg-turbo/libjpeg-turbo/issues/17
#include <stdio.h> // IWYU pragma: keep
#include "jpeglib_alpha.h"
}
class SkStream;
/*
* MTK error-handling struct
*/
struct skjpeg_error_mgr_MTK : jpeg_error_mgr_ALPHA {
class AutoPushJmpBuf {
public:
AutoPushJmpBuf(skjpeg_error_mgr_MTK* mgr) : fMgr(mgr) {
fMgr->fJmpBufStack.push_back(&fJmpBuf);
}
~AutoPushJmpBuf() {
SkASSERT(fMgr->fJmpBufStack.back() == &fJmpBuf);
fMgr->fJmpBufStack.pop_back();
}
operator jmp_buf&() { return fJmpBuf; }
private:
skjpeg_error_mgr_MTK* const fMgr;
jmp_buf fJmpBuf;
};
SkSTArray<4, jmp_buf*> fJmpBufStack;
};
/*
* Error handling function
*/
void skjpeg_err_exit_MTK(j_common_ptr_ALPHA cinfo);
/*
* Source handling struct for that allows libjpeg to use our stream object
*/
struct skjpeg_source_mgr_MTK : jpeg_source_mgr_ALPHA {
skjpeg_source_mgr_MTK(SkStream* stream, SkImageDecoder* decoder);
skjpeg_source_mgr_MTK(SkStream* stream);
SkStream* fStream; // unowned
// Unowned pointer to the decoder, used to check if the decoding process
// has been cancelled.
SkImageDecoder* fDecoder;
enum {
// TODO (msarett): Experiment with different buffer sizes.
// This size was chosen because it matches SkImageDecoder.
kBufferSize = 1024
};
char fBuffer[kBufferSize];
};
#endif