1 /*************************************************************
2 Copyright (C) 1990, 1991, 1993 Andy C. Hung, all rights reserved.
3 PUBLIC DOMAIN LICENSE: Stanford University Portable Video Research
4 Group. If you use this software, you agree to the following: This
5 program package is purely experimental, and is licensed "as is".
6 Permission is granted to use, modify, and distribute this program
7 without charge for any purpose, provided this license/ disclaimer
8 notice appears in the copies.  No warranty or maintenance is given,
9 either expressed or implied.  In no event shall the author(s) be
10 liable to you or a third party for any special, incidental,
11 consequential, or other damages, arising out of the use or inability
12 to use the program for any purpose (or the loss of data), even if we
13 have been advised of such possibilities.  Any public reference or
14 advertisement of this source code should refer to it as the Portable
15 Video Research Group (PVRG) code, and not by any author(s) (or
16 Stanford University) name.
17 *************************************************************/
18 /*
19 ************************************************************
20 globals.h
21 
22 This file contains the global includes and other definitions.
23 
24 ************************************************************
25 */
26 
27 #ifndef GLOBAL_DONE
28 #define GLOBAL_DONE
29 
30 #include <stdio.h>
31 #include "prototypes.h"
32 #include "param.h"
33 #include "system.h"
34 
35 
36 /* Map stream functions to those used in stream.c (MSB) */
37 /* Makes for easy alterations for least-significant bit non-JPEG defns. */
38 
39 #define sropen mropen
40 #define srclose mrclose
41 #define swopen mwopen
42 #define swclose mwclose
43 
44 #define sgetb megetb
45 #define sgetv megetv
46 #define sputv meputv
47 
48 #define swtell mwtell
49 #define srtell mrtell
50 
51 #define swseek mwseek
52 #define srseek mrseek
53 
54 #define IMAGE struct Image_Definition
55 #define FRAME struct Frame_Definition
56 #define SCAN struct Scan_Definition
57 
58 #define MUTE 0
59 #define WHISPER 1
60 #define TALK 2
61 #define NOISY 3
62 #define SCREAM 4
63 
64 
65 /* The defined flag for encoding/decoding. */
66 #define J_DECODER 1
67 #define J_FULLHUFFMAN 2
68 #define J_DEFAULTHUFFMAN 4
69 #define J_LOSSLESS 8
70 
71 /* Some flags for JpegCustomScan() */
72 
73 #define CUSTOM_DO_DC 1
74 #define CUSTOM_DO_AC 2
75 
76 /* Error flags */
77 
78 #define ERROR_NONE 0
79 #define ERROR_BOUNDS 1            /*Input Values out of bounds */
80 #define ERROR_HUFFMAN_READ 2      /*Huffman Decoder finds bad code */
81 #define ERROR_HUFFMAN_ENCODE 3    /*Undefined value in encoder */
82 #define ERROR_MARKER 4            /*Error Found in Marker */
83 #define ERROR_INIT_FILE 5         /*Cannot initialize files */
84 #define ERROR_UNRECOVERABLE 6     /*No recovery mode specified */
85 #define ERROR_PREMATURE_EOF 7     /*End of file unexpected */
86 #define ERROR_MARKER_STRUCTURE 8  /*Bad Marker Structure */
87 #define ERROR_WRITE 9             /*Cannot write output */
88 #define ERROR_READ 10             /*Cannot write input */
89 #define ERROR_PARAMETER 11        /*System Parameter Error */
90 #define ERROR_MEMORY 12           /*Memory exceeded */
91 
92 typedef int iFunc();
93 typedef void vFunc();
94 
95 /* A flag obtaining macro */
96 #define GetFlag(value,flag) (((value) & (flag)) ? 1:0)
97 
98 /* MAX and MIN macros */
99 #define MAX(x,y) ((x > y) ? x:y)
100 #define MIN(x,y) ((x > y) ? y:x)
101 
102 /* BEGIN is used to start most routines. It sets up the Routine Name */
103 /* which is used in the WHEREAMI() macro */
104 #ifdef CODEC_DEBUG
105 #define BEGIN(name) static char RoutineName[]= name;
106 #else
107 #define BEGIN(name)
108 #endif /*CODEC_DEBUG*/
109 /* WHEREAMI prints out current location in code. */
110 #ifdef CODEC_DEBUG
111 #define WHEREAMI() printf("F>%s:R>%s:L>%d: ",\
112         __FILE__,RoutineName,__LINE__)
113 #else
114 #define WHEREAMI()
115 #endif /* CODEC_DEBUG */
116 
117 /* InBounds is used to test whether a value is in or out of bounds. */
118 #define InBounds(var,lo,hi,str)\
119 {if (((var) < (lo)) || ((var) > (hi)))\
120 {WHEREAMI(); printf("%s in %d\n",(str),(var));ErrorValue=ERROR_BOUNDS;}}
121 
122 /* MakeStructure makes the named structure */
123 #define MakeStructure(named_st) ((named_st *) malloc(sizeof(named_st)))
124 
125 IMAGE {
126 char *StreamFileName;            /* Name of compressed stream file */
127 int JpegMode;                    /* Mode of JPEG encoder */
128 int Jfif;                        /* If set, automatically drop JFIF marker */
129 int ImageSequence;               /* Index in image sequence */
130 int NumberQuantizationMatrices;  /* Number of quantization matrices */
131 int *QuantizationMatrices[MAXIMUM_DEVICES]; /* Pointers to q-matrices */
132 int NumberACTables;              /* Number of AC Huffman tables */
133 DHUFF *ACDhuff[MAXIMUM_DEVICES]; /* Decoder huffman tables */
134 EHUFF *ACEhuff[MAXIMUM_DEVICES]; /* Encoder huffman tables */
135 XHUFF *ACXhuff[MAXIMUM_DEVICES]; /* Transmittable huffman tables */
136 int NumberDCTables;              /* Number of DC Huffman tables */
137 DHUFF *DCDhuff[MAXIMUM_DEVICES]; /* Decoder huffman tables */
138 EHUFF *DCEhuff[MAXIMUM_DEVICES]; /* Encoder huffman tables */
139 XHUFF *DCXhuff[MAXIMUM_DEVICES]; /* Transmittable huffman tables */
140 };
141 
142 FRAME {
143 int Type;                       /* SOF(X) where X is type (4 bits) */
144 char *ComponentFileName[MAXIMUM_COMPONENTS]; /* image component file names */
145 int InsertDnl;                  /* DNL flag (-2 = AUTO) (-1 = ENABLE) (>0 ) */
146 int Q;                          /* Q Factor (0 disables) */
147 int DataPrecision;              /* Data Precision (not used) */
148 int GlobalHeight;               /* Dimensions of overall image */
149 int GlobalWidth;
150 int ResyncInterval;             /* Resync interval (0 disables) */
151 int GlobalNumberComponents;     /* Global number of components */
152 int cn[MAXIMUM_COMPONENTS];     /* Translation index used */
153 int hf[MAXIMUM_COMPONENTS];     /* Horizontal frequency */
154 int vf[MAXIMUM_COMPONENTS];     /* Vertical frequency */
155 int tq[MAXIMUM_COMPONENTS];     /* Quantization table used by */
156 int Width[MAXIMUM_COMPONENTS];  /* Dimensions of component files */
157 int Height[MAXIMUM_COMPONENTS];
158 int BufferSize;                 /* Buffer sizes used */
159 int Maxv, Maxh;                 /* Max Sampling Freq */
160 int MDUWide, MDUHigh;           /* Number MDU wide */
161 int tmpfile;
162 IMAGE *Image;
163 };
164 
165 SCAN {
166 int NumberComponents;               /* Number of components in scan */
167 int SSS;                            /* Spectral Selection Start (not used) */
168 int SSE;                            /* Spectral Selection End (not used) */
169 int SAH;                            /* Spectral approximation (not used) */
170 int SAL;                            /* Spectral approximation (not used) */
171 int *LastDC[MAXIMUM_SOURCES];       /* LastDC DPCM predictor */
172 int *ACFrequency[MAXIMUM_SOURCES];  /* Frequency charts for custom huffman */
173 int *DCFrequency[MAXIMUM_SOURCES];  /* table building */
174 int LosslessBuffer[MAXIMUM_SOURCES][LOSSLESSBUFFERSIZE];
175 int MDUWide, MDUHigh;
176                                     /* a integer buffer for lossless coding */
177 IOBUF *Iob[MAXIMUM_SOURCES];        /* IOB per scan index  */
178 int ci[MAXIMUM_SOURCES];            /* Index */
179 int ta[MAXIMUM_SOURCES];            /* AC Tables for that scan index */
180 int td[MAXIMUM_SOURCES];            /* DC Tables for scan index */
181 int NumberACTablesSend;             /* Number of tables to send */
182 int NumberDCTablesSend;
183 int NumberQTablesSend;
184 int sa[MAXIMUM_SOURCES];            /* AC table indices to send */
185 int sd[MAXIMUM_SOURCES];            /* DC table indices to send */
186 int sq[MAXIMUM_SOURCES];            /* Quantization table indices to send */
187 };
188 
189 #endif
190