2 * Copyright (c) 1991-1997 Sam Leffler
3 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that (i) the above copyright notices and this permission notice appear in
8 * all copies of the software and related documentation, and (ii) the names of
9 * Sam Leffler and Silicon Graphics may not be used in any advertising or
10 * publicity relating to the software without the specific, prior written
11 * permission of Sam Leffler and Silicon Graphics.
13 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
17 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
25 /* Initialise fax decoder tables
26 * Decoder support is derived, with permission, from the code
27 * in Frank Cringle's viewfax program;
28 * Copyright (C) 1990, 1995 Frank D. Cringle.
30 #include "tif_config.h"
43 extern int getopt(int, char**, char*);
46 #define streq(a,b) (strcmp(a,b) == 0)
48 /* NB: can't use names in tif_fax3.h 'cuz they are declared const */
49 TIFFFaxTabEnt MainTable
[128];
50 TIFFFaxTabEnt WhiteTable
[4096];
51 TIFFFaxTabEnt BlackTable
[8192];
54 uint16 code
; /* right justified, lsb-first, zero filled */
55 uint16 val
; /* (pixel count)<<4 + code width */
58 static struct proto Pass
[] = {
63 static struct proto Horiz
[] = {
68 static struct proto V0
[] = {
73 static struct proto VR
[] = {
80 static struct proto VL
[] = {
87 static struct proto Ext
[] = {
92 static struct proto EOLV
[] = {
97 static struct proto MakeUpW
[] = {
128 static struct proto MakeUpB
[] = {
159 static struct proto MakeUp
[] = {
176 static struct proto TermW
[] = {
244 static struct proto TermB
[] = {
312 static struct proto EOLH
[] = {
318 FillTable(TIFFFaxTabEnt
*T
, int Size
, struct proto
*P
, int State
)
320 int limit
= 1 << Size
;
323 int width
= P
->val
& 15;
324 int param
= P
->val
>> 4;
325 int incr
= 1 << width
;
327 for (code
= P
->code
; code
< limit
; code
+= incr
) {
328 TIFFFaxTabEnt
*E
= T
+code
;
337 static char* storage_class
= "";
338 static char* const_class
= "";
339 static int packoutput
= 1;
340 static char* prebrace
= "";
341 static char* postbrace
= "";
344 WriteTable(FILE* fd
, const TIFFFaxTabEnt
* T
, int Size
, const char* name
)
349 fprintf(fd
, "%s %s TIFFFaxTabEnt %s[%d] = {",
350 storage_class
, const_class
, name
, Size
);
353 for (i
= 0; i
< Size
; i
++) {
354 fprintf(fd
, "%s%s%d,%d,%d%s",
355 sep
, prebrace
, T
->State
, T
->Width
, (int) T
->Param
, postbrace
);
356 if (((i
+1) % 10) == 0)
364 for (i
= 0; i
< Size
; i
++) {
365 fprintf(fd
, "%s%s%3d,%3d,%4d%s",
366 sep
, prebrace
, T
->State
, T
->Width
, (int) T
->Param
, postbrace
);
367 if (((i
+1) % 6) == 0)
374 fprintf(fd
, "\n};\n");
377 /* initialise the huffman code tables */
379 main(int argc
, char* argv
[])
385 #if !HAVE_DECL_OPTARG
390 while ((c
= getopt(argc
, argv
, "c:s:bp")) != -1)
393 const_class
= optarg
;
396 storage_class
= optarg
;
407 "usage: %s [-c const] [-s storage] [-p] [-b] file\n",
411 outputfile
= optind
< argc
? argv
[optind
] : "g3states.h";
412 fd
= fopen(outputfile
, "w");
414 fprintf(stderr
, "%s: %s: Cannot create output file.\n",
415 argv
[0], outputfile
);
418 FillTable(MainTable
, 7, Pass
, S_Pass
);
419 FillTable(MainTable
, 7, Horiz
, S_Horiz
);
420 FillTable(MainTable
, 7, V0
, S_V0
);
421 FillTable(MainTable
, 7, VR
, S_VR
);
422 FillTable(MainTable
, 7, VL
, S_VL
);
423 FillTable(MainTable
, 7, Ext
, S_Ext
);
424 FillTable(MainTable
, 7, EOLV
, S_EOL
);
425 FillTable(WhiteTable
, 12, MakeUpW
, S_MakeUpW
);
426 FillTable(WhiteTable
, 12, MakeUp
, S_MakeUp
);
427 FillTable(WhiteTable
, 12, TermW
, S_TermW
);
428 FillTable(WhiteTable
, 12, EOLH
, S_EOL
);
429 FillTable(BlackTable
, 13, MakeUpB
, S_MakeUpB
);
430 FillTable(BlackTable
, 13, MakeUp
, S_MakeUp
);
431 FillTable(BlackTable
, 13, TermB
, S_TermB
);
432 FillTable(BlackTable
, 13, EOLH
, S_EOL
);
434 fprintf(fd
, "/* WARNING, this file was automatically generated by the\n");
435 fprintf(fd
, " mkg3states program */\n");
436 fprintf(fd
, "#include \"tiff.h\"\n");
437 fprintf(fd
, "#include \"tif_fax3.h\"\n");
438 WriteTable(fd
, MainTable
, 128, "TIFFFaxMainTable");
439 WriteTable(fd
, WhiteTable
, 4096, "TIFFFaxWhiteTable");
440 WriteTable(fd
, BlackTable
, 8192, "TIFFFaxBlackTable");
445 /* vim: set ts=8 sts=8 sw=8 noet: */