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