1 /* Copyright (C) 2001-2006 Artifex Software, Inc. 2 All Rights Reserved. 3 4 This software is provided AS-IS with no warranty, either express or 5 implied. 6 7 This software is distributed under license and may not be copied, modified 8 or distributed except as expressly authorized under the terms of that 9 license. Refer to licensing information at http://www.artifex.com/ 10 or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134, 11 San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information. 12 */ 13 14 /* $Id: sdct.h 8022 2007-06-05 22:23:38Z giles $ */ 15 /* Definitions for DCT filters */ 16 /* Requires stream.h, strimpl.h, jpeg/jpeglib.h */ 17 18 #ifndef sdct_INCLUDED 19 # define sdct_INCLUDED 20 21 #include "setjmp_.h" /* for jmp_buf */ 22 23 /* ------ DCT filters ------ */ 24 25 /* 26 * We don't want to allocate JPEG's private data directly from 27 * the C heap, but we must allocate it as immovable; and to avoid 28 * garbage collection issues, we must keep GC-traceable pointers 29 * to every block allocated. 30 */ 31 typedef struct jpeg_block_s jpeg_block_t; 32 struct jpeg_block_s { 33 jpeg_block_t *next; 34 void *data; 35 }; 36 #define private_st_jpeg_block() /* in sjpegc.c */\ 37 gs_private_st_ptrs2(st_jpeg_block, jpeg_block_t, "jpeg_block_t",\ 38 jpeg_block_enum_ptrs, jpeg_block_reloc_ptrs, next, data) 39 40 /* 41 * Define the stream state. 42 * The jpeg_xxx_data structs are allocated in immovable memory 43 * to simplify use of the IJG library. 44 */ 45 #define jpeg_stream_data_common\ 46 /* We put a copy of the stream template here, because */\ 47 /* the minimum buffer sizes depend on the image parameters. */\ 48 stream_template template;\ 49 struct jpeg_error_mgr err;\ 50 gsfix_jmp_buf exit_jmpbuf;\ 51 gs_memory_t *memory; /* heap for library allocations */\ 52 jpeg_block_t *blocks; /* ptr to allocated data block list */\ 53 /* The following are documented in Adobe TN 5116. */\ 54 int Picky; /* 0 or 1 */\ 55 int Relax /* 0 or 1 */ 56 57 typedef struct jpeg_stream_data_s { 58 jpeg_stream_data_common; 59 } jpeg_stream_data; 60 61 /* Define initialization for the non-library part of the stream state. */ 62 #define jpeg_stream_data_common_init(pdata)\ 63 BEGIN\ 64 (pdata)->Picky = 0;\ 65 (pdata)->Relax = 0;\ 66 (pdata)->blocks = 0;\ 67 END 68 69 typedef struct jpeg_compress_data_s { 70 jpeg_stream_data_common; 71 /* cinfo must immediately follow the common fields */ 72 struct jpeg_compress_struct cinfo; 73 struct jpeg_destination_mgr destination; 74 byte finish_compress_buf[100]; 75 int fcb_size, fcb_pos; 76 } jpeg_compress_data; 77 78 extern_st(st_jpeg_compress_data); 79 #define public_st_jpeg_compress_data() /* in sdcte.c */\ 80 gs_public_st_ptrs1(st_jpeg_compress_data, jpeg_compress_data,\ 81 "JPEG compress data", jpeg_compress_data_enum_ptrs, jpeg_compress_data_reloc_ptrs, blocks) 82 83 typedef struct jpeg_decompress_data_s { 84 jpeg_stream_data_common; 85 /* dinfo must immediately follow the common fields, */ 86 /* so that it has same offset as cinfo. */ 87 struct jpeg_decompress_struct dinfo; 88 struct jpeg_source_mgr source; 89 long skip; /* # of bytes remaining to skip in input */ 90 bool input_eod; /* true when no more input data available */ 91 bool faked_eoi; /* true when fill_input_buffer inserted EOI */ 92 byte *scanline_buffer; /* buffer for oversize scanline, or NULL */ 93 uint bytes_in_scanline; /* # of bytes remaining to output from same */ 94 } jpeg_decompress_data; 95 96 #define private_st_jpeg_decompress_data() /* in zfdctd.c */\ 97 gs_private_st_ptrs2(st_jpeg_decompress_data, jpeg_decompress_data,\ 98 "JPEG decompress data", jpeg_decompress_data_enum_ptrs,\ 99 jpeg_decompress_data_reloc_ptrs, blocks, scanline_buffer) 100 101 /* The stream state itself. This is kept in garbage-collectable memory. */ 102 typedef struct stream_DCT_state_s { 103 stream_state_common; 104 /* The following are set before initialization. */ 105 /* Note that most JPEG parameters go straight into */ 106 /* the IJG data structures, not into this struct. */ 107 gs_const_string Markers; /* NULL if no Markers parameter */ 108 float QFactor; 109 int ColorTransform; /* -1 if not specified */ 110 bool NoMarker; /* DCTEncode only */ 111 gs_memory_t *jpeg_memory; /* heap for library allocations */ 112 /* This is a pointer to immovable storage. */ 113 union _jd { 114 jpeg_stream_data *common; 115 jpeg_compress_data *compress; 116 jpeg_decompress_data *decompress; 117 } data; 118 /* DCTEncode sets this before initialization; 119 * DCTDecode cannot set it until the JPEG headers are read. 120 */ 121 uint scan_line_size; 122 /* The following are updated dynamically. */ 123 int phase; 124 } stream_DCT_state; 125 126 /* The state descriptor is public only to allow us to split up */ 127 /* the encoding and decoding filters. */ 128 extern_st(st_DCT_state); 129 #define public_st_DCT_state() /* in sdctc.c */\ 130 gs_public_st_const_strings1_ptrs1(st_DCT_state, stream_DCT_state,\ 131 "DCTEncode/Decode state", dct_enum_ptrs, dct_reloc_ptrs, Markers, data.common) 132 /* 133 * NOTE: the client *must* invoke the set_defaults procedure in the 134 * template before calling the init procedure. 135 */ 136 extern const stream_template s_DCTD_template; 137 extern const stream_template s_DCTE_template; 138 139 /* Define an internal procedure for setting stream defaults. */ 140 /* Clients do not call this. */ 141 void s_DCT_set_defaults(stream_state * st); 142 143 #endif /* sdct_INCLUDED */ 144