1 /* -*-C-*- 2 ****************************************************************************** 3 * 4 * File: encoder.h 5 * RCS: $Header: /ImageMagick/delegates/fpx/jpeg/encoder.h,v 1.3 2000/12/23 22:37:48 bfriesen Exp $ 6 * Description: A Flashpix-friendly interface for the HP JPEG Encoder. 7 * Author: Kirt Winter 8 * Created: Fri Mar 1 11:09:55 1995 9 * Initial Source Release: Thursday, March 7 1996 10 * Language: C 11 * Package: Hewlett-Packard JPEG Encoder/Decoder 12 * 13 * Copyright (c) 1999 Digital Imaging Group, Inc. 14 * For conditions of distribution and use, see copyright notice 15 * in Flashpix.h 16 * 17 ****************************************************************************** 18 */ 19 #include <stdlib.h> 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 /************************************************************************* 26 The simplest JPEG scenario involves RGB data (no alpha) passed to the 27 encoder. With calls to eJPEG_Init, then eJPEG_CreateHeader (or 28 eJPEG_ConcatenateHeader if you want to embed the JPEG header in the tile 29 data), then eJPEG_EncodeTile, you get no subsampling, internal RGB->YCbCr, 30 Q-Factor of 50, internal Huffman tables. Other routines allow you to 31 disable some or all of the internal subsampling and YCbCr conversions. 32 33 A single call to eJPEG_DisableInternalYCbCr allows opponent color spaces 34 (like Photo-YCC) to be used. This new sequence would be eJPEG_Init, 35 eJPEG_DisableInternalYCbCr, eJPEG_CreateHeader, then eJPEG_EncodeTile. 36 37 All modifications to the encoder's behavior come between the calls 38 eJPEG_Init and eJPEG_. 39 **************************************************************************/ 40 41 /* No matter what else you do, you have to call this. */ 42 JPEGEXPORT 43 int eJPEG_Init(void **encoder); /* save the return value for later use */ 44 45 /* 46 If you want to do any required subsampling, call this next. NOTE: Internal 47 subsampling will only be performed if you later call eJPEG_SetSubsampling with 48 arguments that will call for it. 49 Once more, with feeling... 50 By disabling internal subsampling, you're telling the eJPEG_EncodeTile 51 function that tile data passed to it has already been subsampled correctly. 52 */ 53 JPEGEXPORT 54 int eJPEG_DisableInternalSubsampling(void *encoder); 55 56 57 /* If you already have opponent color data (like FPX-YCC), call this. You might 58 also want to pass RGB data to the encoder (in which case, you probably don't want 59 it subsampled either, see above), or for some strange reason you might want to 60 do the YCbCr conversion yourself. In any case, be sure to set the "Internal 61 color conversion" field of the compression subtype correctly. 62 */ 63 JPEGEXPORT 64 int eJPEG_DisableInternalYCbCr(void *encoder); 65 66 67 /* Pass the same value to this function as you would put in the compression subtype's 68 "Chroma subsampling." Note, however, that this particular encoder will not support 69 */ 70 JPEGEXPORT 71 int eJPEG_SetSubsampling( 72 void *encoder, /* same value returned by eJPEG_Init */ 73 unsigned char subSampling /* pass the same value you'd put in the FlashPix 74 compression subtype field for JPEG data */ 75 ); 76 77 78 /* Call this routine to enable internal color conversion (the default). 79 Reason to use this function is if different tiles have different color space 80 properties, and we need to reenable the color rotation after disabling it 81 for prior tiles. 82 */ 83 JPEGEXPORT 84 int eJPEG_EnableInternalYCbCr( void *encoder ); 85 86 87 /* default is to have channel interleave enabled. Call this 88 routine only if channel interleave has been disabled 89 for a previous tile. 90 */ 91 JPEGEXPORT 92 int eJPEG_EnableChannelInterleave(void *encoder); 93 94 95 JPEGEXPORT 96 int eJPEG_DisableChannelInterleave(void *encoder); 97 98 99 /* Call this routine to change from the default Q factor. */ 100 JPEGEXPORT 101 int eJPEG_SetQFactor( 102 void *encoder, /* same value returned by eJPEG_Init */ 103 int quality /* default is 50 */ 104 ); 105 106 /* Call this routine if you want to use custom Huffman Tables. 107 The custom tables are specified in the HuffTables array of 108 huffman tables. The tables in that array should alternate 109 DC-AC-DC-AC ... (a maximum of eight tables).Be careful with 110 the 'ident' values set. JPEG requires that these values be 111 0,1,2,or 3 for extended JPEG systems, but only 0 or 1 for 112 baseline JPEG systems. 113 */ 114 JPEGEXPORT 115 int eJPEG_SetHuffTables( 116 void *encoder, 117 int NumbHuffTables, 118 JPEGHuffTable **HuffTables, 119 unsigned char * CompDCHuffIdent, 120 unsigned char * CompACHuffIdent); 121 122 123 /* Call this routine if you want to use custom Quantization Tables. 124 The custom tables are specified in the QuantTables array of 125 QuantTables tables. The ident field of these tables 126 should have the values 0,1,2 or 3. 127 */ 128 JPEGEXPORT 129 int eJPEG_SetQuantTables( 130 void* encoder, 131 int NumbQuantTables, 132 JPEGQuantTable **QuantTables, 133 unsigned char *CompQuantIdent); 134 135 /* Note that currently, if you set 4-bytes per pixel, you don't get subsampling */ 136 JPEGEXPORT 137 int eJPEG_SetTileSize( 138 void *encoder, /* same value returned by eJPEG_Init */ 139 int hSize, /* in pixels, the width of a tile */ 140 int vSize, /* in pixels, the height of a tile */ 141 int bytesPerPixel /* how many bytes per pixel */ 142 ); 143 144 145 /* The next two functions are an either/or situation. If you want the 146 data in each tile to be a fully compliant JFIF stream, you call 147 eJPEG_ConcatenateHeader. If you want to store the header separately 148 from all the tiles, you call eJPEG_CreateHeader, which will return 149 you a header that you can store in the JPEG Tables section of one 150 of the far too numerous FlashPix property sets (compression information 151 property group). Note that putting the proper ID in the JPEG tables 152 selector of the tile's compression subtype field is your job. 153 */ 154 JPEGEXPORT 155 int eJPEG_CreateHeader( 156 void *encoder, /* same value returned by eJPEG_Init */ 157 long hdrBufferSize, /* the size of the <hdrBuffer> in bytes */ 158 unsigned char *hdrBuffer,/* the buffer itself */ 159 long *hdrBufferUsed /* upon return shows the amount of 160 hdrbuffer that was used */ 161 ); 162 163 /* see above */ 164 JPEGEXPORT 165 int eJPEG_ConcatenateHeader( 166 void *encoder 167 ); 168 169 JPEGEXPORT 170 long eJPEG_EncodeTile( 171 void *encoder, /* same value returned by eJPEG_Init */ 172 unsigned char *inbuf, /* assumed to be the size of a tile or sub- 173 sampled tile! */ 174 unsigned char *outbuf,/* the buffer to put the compressed tile into */ 175 size_t outbuf_size /* size of the output buffer */ 176 ); 177 178 /* called at the end of using the encoder project */ 179 JPEGEXPORT 180 int eJPEG_Shutdown(void* encoder); 181 182 #ifdef __cplusplus 183 } 184 #endif 185 186 /* An internal routine called form eJPEG_Init() */ 187 int SetDefaultTables(void* encoder); 188 189 /* CHG_FILE_ERR - unified JPEG error values by offsetting the values by 0x0200 */ 190 #define eJPEG_NO_ERROR 0 191 #define eJPEG_SUBSAMPLING_NOT_SUPPORTED 0x0201 192 #define eJPEG_INVALID_ENCODER 0x0202 193 #define eJPEG_UNSUPPORTED_SUBSAMPLING 0x0203 194 #define eJPEG_UNSUPPORTED_BYTES_PER_PIXEL 0x0204 195 #define eJPEG_MEMORY_ERROR 0x0205 196 #define eJPEG_BAD_HUFFMAN_TABLE 0x0206 197 #define eJPEG_BAD_QUANT_TABLE 0x0207 198 199