]>
git.saurik.com Git - wxWidgets.git/blob - src/tiff/libtiff/mkg3states.c
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>
44 #define streq(a,b) (strcmp(a,b) == 0)
46 /* NB: can't use names in tif_fax3.h 'cuz they are declared const */
47 TIFFFaxTabEnt MainTable
[128];
48 TIFFFaxTabEnt WhiteTable
[4096];
49 TIFFFaxTabEnt BlackTable
[8192];
52 uint16 code
; /* right justified, lsb-first, zero filled */
53 uint16 val
; /* (pixel count)<<4 + code width */
56 static struct proto Pass
[] = {
61 static struct proto Horiz
[] = {
66 static struct proto V0
[] = {
71 static struct proto VR
[] = {
78 static struct proto VL
[] = {
85 static struct proto Ext
[] = {
90 static struct proto EOLV
[] = {
95 static struct proto MakeUpW
[] = {
126 static struct proto MakeUpB
[] = {
157 static struct proto MakeUp
[] = {
174 static struct proto TermW
[] = {
242 static struct proto TermB
[] = {
310 static struct proto EOLH
[] = {
316 FillTable(TIFFFaxTabEnt
*T
, int Size
, struct proto
*P
, int State
)
318 int limit
= 1 << Size
;
321 int width
= P
->val
& 15;
322 int param
= P
->val
>> 4;
323 int incr
= 1 << width
;
325 for (code
= P
->code
; code
< limit
; code
+= incr
) {
326 TIFFFaxTabEnt
*E
= T
+code
;
335 static char* storage_class
= "";
336 static char* const_class
= "";
337 static int packoutput
= 1;
338 static char* prebrace
= "";
339 static char* postbrace
= "";
342 WriteTable(FILE* fd
, const TIFFFaxTabEnt
* T
, int Size
, const char* name
)
347 fprintf(fd
, "%s %s TIFFFaxTabEnt %s[%d] = {",
348 storage_class
, const_class
, name
, Size
);
351 for (i
= 0; i
< Size
; i
++) {
352 fprintf(fd
, "%s%s%d,%d,%d%s",
353 sep
, prebrace
, T
->State
, T
->Width
, (int) T
->Param
, postbrace
);
354 if (((i
+1) % 10) == 0)
362 for (i
= 0; i
< Size
; i
++) {
363 fprintf(fd
, "%s%s%3d,%3d,%4d%s",
364 sep
, prebrace
, T
->State
, T
->Width
, (int) T
->Param
, postbrace
);
365 if (((i
+1) % 6) == 0)
372 fprintf(fd
, "\n};\n");
375 /* initialise the huffman code tables */
377 main(int argc
, char* argv
[])
385 while ((c
= getopt(argc
, argv
, "c:s:bp")) != -1)
388 const_class
= optarg
;
391 storage_class
= optarg
;
402 "usage: %s [-c const] [-s storage] [-p] [-b] file\n",
406 outputfile
= optind
< argc
? argv
[optind
] : "g3states.h";
407 fd
= fopen(outputfile
, "w");
409 fprintf(stderr
, "%s: %s: Cannot create output file.\n",
410 argv
[0], outputfile
);
413 FillTable(MainTable
, 7, Pass
, S_Pass
);
414 FillTable(MainTable
, 7, Horiz
, S_Horiz
);
415 FillTable(MainTable
, 7, V0
, S_V0
);
416 FillTable(MainTable
, 7, VR
, S_VR
);
417 FillTable(MainTable
, 7, VL
, S_VL
);
418 FillTable(MainTable
, 7, Ext
, S_Ext
);
419 FillTable(MainTable
, 7, EOLV
, S_EOL
);
420 FillTable(WhiteTable
, 12, MakeUpW
, S_MakeUpW
);
421 FillTable(WhiteTable
, 12, MakeUp
, S_MakeUp
);
422 FillTable(WhiteTable
, 12, TermW
, S_TermW
);
423 FillTable(WhiteTable
, 12, EOLH
, S_EOL
);
424 FillTable(BlackTable
, 13, MakeUpB
, S_MakeUpB
);
425 FillTable(BlackTable
, 13, MakeUp
, S_MakeUp
);
426 FillTable(BlackTable
, 13, TermB
, S_TermB
);
427 FillTable(BlackTable
, 13, EOLH
, S_EOL
);
429 fprintf(fd
, "/* WARNING, this file was automatically generated by the\n");
430 fprintf(fd
, " mkg3states program */\n");
431 fprintf(fd
, "#include \"tiff.h\"\n");
432 fprintf(fd
, "#include \"tif_fax3.h\"\n");
433 WriteTable(fd
, MainTable
, 128, "TIFFFaxMainTable");
434 WriteTable(fd
, WhiteTable
, 4096, "TIFFFaxWhiteTable");
435 WriteTable(fd
, BlackTable
, 8192, "TIFFFaxBlackTable");
440 /* vim: set ts=8 sts=8 sw=8 noet: */