]>
git.saurik.com Git - wxWidgets.git/blob - src/tiff/libtiff/mkg3states.c
1e1d9761c7114c86a50a7de9673e55e51f67325c
4 * Copyright (c) 1991-1997 Sam Leffler
5 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
7 * Permission to use, copy, modify, distribute, and sell this software and
8 * its documentation for any purpose is hereby granted without fee, provided
9 * that (i) the above copyright notices and this permission notice appear in
10 * all copies of the software and related documentation, and (ii) the names of
11 * Sam Leffler and Silicon Graphics may not be used in any advertising or
12 * publicity relating to the software without the specific, prior written
13 * permission of Sam Leffler and Silicon Graphics.
15 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
19 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
27 /* Initialise fax decoder tables
28 * Decoder support is derived, with permission, from the code
29 * in Frank Cringle's viewfax program;
30 * Copyright (C) 1990, 1995 Frank D. Cringle.
32 #include <tif_config.h>
45 extern int getopt(int, char**, char*);
48 #define streq(a,b) (strcmp(a,b) == 0)
50 /* NB: can't use names in tif_fax3.h 'cuz they are declared const */
51 TIFFFaxTabEnt MainTable
[128];
52 TIFFFaxTabEnt WhiteTable
[4096];
53 TIFFFaxTabEnt BlackTable
[8192];
56 uint16 code
; /* right justified, lsb-first, zero filled */
57 uint16 val
; /* (pixel count)<<4 + code width */
60 static struct proto Pass
[] = {
65 static struct proto Horiz
[] = {
70 static struct proto V0
[] = {
75 static struct proto VR
[] = {
82 static struct proto VL
[] = {
89 static struct proto Ext
[] = {
94 static struct proto EOLV
[] = {
99 static struct proto MakeUpW
[] = {
130 static struct proto MakeUpB
[] = {
161 static struct proto MakeUp
[] = {
178 static struct proto TermW
[] = {
246 static struct proto TermB
[] = {
314 static struct proto EOLH
[] = {
320 FillTable(TIFFFaxTabEnt
*T
, int Size
, struct proto
*P
, int State
)
322 int limit
= 1 << Size
;
325 int width
= P
->val
& 15;
326 int param
= P
->val
>> 4;
327 int incr
= 1 << width
;
329 for (code
= P
->code
; code
< limit
; code
+= incr
) {
330 TIFFFaxTabEnt
*E
= T
+code
;
339 static char* storage_class
= "";
340 static char* const_class
= "";
341 static int packoutput
= 1;
342 static char* prebrace
= "";
343 static char* postbrace
= "";
346 WriteTable(FILE* fd
, const TIFFFaxTabEnt
* T
, int Size
, const char* name
)
351 fprintf(fd
, "%s %s TIFFFaxTabEnt %s[%d] = {",
352 storage_class
, const_class
, name
, Size
);
355 for (i
= 0; i
< Size
; i
++) {
356 fprintf(fd
, "%s%s%d,%d,%d%s",
357 sep
, prebrace
, T
->State
, T
->Width
, (int) T
->Param
, postbrace
);
358 if (((i
+1) % 10) == 0)
366 for (i
= 0; i
< Size
; i
++) {
367 fprintf(fd
, "%s%s%3d,%3d,%4d%s",
368 sep
, prebrace
, T
->State
, T
->Width
, (int) T
->Param
, postbrace
);
369 if (((i
+1) % 6) == 0)
376 fprintf(fd
, "\n};\n");
379 /* initialise the huffman code tables */
381 main(int argc
, char* argv
[])
389 while ((c
= getopt(argc
, argv
, "c:s:bp")) != -1)
392 const_class
= optarg
;
395 storage_class
= optarg
;
406 "usage: %s [-c const] [-s storage] [-p] [-b] file\n",
410 outputfile
= optind
< argc
? argv
[optind
] : "g3states.h";
411 fd
= fopen(outputfile
, "w");
413 fprintf(stderr
, "%s: %s: Cannot create output file.\n",
414 argv
[0], outputfile
);
417 FillTable(MainTable
, 7, Pass
, S_Pass
);
418 FillTable(MainTable
, 7, Horiz
, S_Horiz
);
419 FillTable(MainTable
, 7, V0
, S_V0
);
420 FillTable(MainTable
, 7, VR
, S_VR
);
421 FillTable(MainTable
, 7, VL
, S_VL
);
422 FillTable(MainTable
, 7, Ext
, S_Ext
);
423 FillTable(MainTable
, 7, EOLV
, S_EOL
);
424 FillTable(WhiteTable
, 12, MakeUpW
, S_MakeUpW
);
425 FillTable(WhiteTable
, 12, MakeUp
, S_MakeUp
);
426 FillTable(WhiteTable
, 12, TermW
, S_TermW
);
427 FillTable(WhiteTable
, 12, EOLH
, S_EOL
);
428 FillTable(BlackTable
, 13, MakeUpB
, S_MakeUpB
);
429 FillTable(BlackTable
, 13, MakeUp
, S_MakeUp
);
430 FillTable(BlackTable
, 13, TermB
, S_TermB
);
431 FillTable(BlackTable
, 13, EOLH
, S_EOL
);
433 fprintf(fd
, "/* WARNING, this file was automatically generated by the\n");
434 fprintf(fd
, " mkg3states program */\n");
435 fprintf(fd
, "#include \"tiff.h\"\n");
436 fprintf(fd
, "#include \"tif_fax3.h\"\n");
437 WriteTable(fd
, MainTable
, 128, "TIFFFaxMainTable");
438 WriteTable(fd
, WhiteTable
, 4096, "TIFFFaxWhiteTable");
439 WriteTable(fd
, BlackTable
, 8192, "TIFFFaxBlackTable");
444 /* vim: set ts=8 sts=8 sw=8 noet: */