SkJpegUtility.h revision e3b95ce468c73af8247ba9582a7b84548b19f06a
1/* 2 * Copyright 2015 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 SkJpegUtility_codec_DEFINED 10#define SkJpegUtility_codec_DEFINED 11 12#include "SkStream.h" 13 14#include <setjmp.h> 15// stdio is needed for jpeglib 16#include <stdio.h> 17 18extern "C" { 19 #include "jpeglib.h" 20 #include "jerror.h" 21} 22 23static constexpr uint32_t kICCMarker = JPEG_APP0 + 2; 24static constexpr uint32_t kICCMarkerHeaderSize = 14; 25static constexpr uint8_t kICCSig[] = { 26 'I', 'C', 'C', '_', 'P', 'R', 'O', 'F', 'I', 'L', 'E', '\0', 27}; 28 29/* 30 * Error handling struct 31 */ 32struct skjpeg_error_mgr : jpeg_error_mgr { 33 jmp_buf fJmpBuf; 34}; 35 36/* 37 * Error handling function 38 */ 39void skjpeg_err_exit(j_common_ptr cinfo); 40 41/* 42 * Source handling struct for that allows libjpeg to use our stream object 43 */ 44struct skjpeg_source_mgr : jpeg_source_mgr { 45 skjpeg_source_mgr(SkStream* stream); 46 47 SkStream* fStream; // unowned 48 enum { 49 // TODO (msarett): Experiment with different buffer sizes. 50 // This size was chosen because it matches SkImageDecoder. 51 kBufferSize = 1024 52 }; 53 uint8_t fBuffer[kBufferSize]; 54}; 55 56#endif 57