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