]>
git.saurik.com Git - wxWidgets.git/blob - src/tiff/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 #if defined(unix) || defined(__unix)
42 #define streq(a,b) (strcmp(a,b) == 0)
44 /* NB: can't use names in tif_fax3.h 'cuz they are declared const */
45 TIFFFaxTabEnt MainTable
[128];
46 TIFFFaxTabEnt WhiteTable
[4096];
47 TIFFFaxTabEnt BlackTable
[8192];
50 uint16 code
; /* right justified, lsb-first, zero filled */
51 uint16 val
; /* (pixel count)<<4 + code width */
54 static struct proto Pass
[] = {
59 static struct proto Horiz
[] = {
64 static struct proto V0
[] = {
69 static struct proto VR
[] = {
76 static struct proto VL
[] = {
83 static struct proto Ext
[] = {
88 static struct proto EOLV
[] = {
93 static struct proto MakeUpW
[] = {
124 static struct proto MakeUpB
[] = {
155 static struct proto MakeUp
[] = {
172 static struct proto TermW
[] = {
240 static struct proto TermB
[] = {
308 static struct proto EOLH
[] = {
314 FillTable(TIFFFaxTabEnt
*T
, int Size
, struct proto
*P
, int State
)
316 int limit
= 1 << Size
;
319 int width
= P
->val
& 15;
320 int param
= P
->val
>> 4;
321 int incr
= 1 << width
;
323 for (code
= P
->code
; code
< limit
; code
+= incr
) {
324 TIFFFaxTabEnt
*E
= T
+code
;
333 static char* storage_class
= "";
334 static char* const_class
= "";
335 static int packoutput
= 1;
336 static char* prebrace
= "";
337 static char* postbrace
= "";
340 WriteTable(FILE* fd
, const TIFFFaxTabEnt
* T
, int Size
, const char* name
)
345 fprintf(fd
, "%s %s TIFFFaxTabEnt %s[%d] = {",
346 storage_class
, const_class
, name
, Size
);
349 for (i
= 0; i
< Size
; i
++) {
350 fprintf(fd
, "%s%s%d,%d,%d%s",
351 sep
, prebrace
, T
->State
, T
->Width
, (int) T
->Param
, postbrace
);
352 if (((i
+1) % 12) == 0)
360 for (i
= 0; i
< Size
; i
++) {
361 fprintf(fd
, "%s%s%3d,%3d,%4d%s",
362 sep
, prebrace
, T
->State
, T
->Width
, (int) T
->Param
, postbrace
);
363 if (((i
+1) % 6) == 0)
370 fprintf(fd
, "\n};\n");
373 /* initialise the huffman code tables */
375 main(int argc
, char* argv
[])
383 while ((c
= getopt(argc
, argv
, "c:s:bp")) != -1)
386 const_class
= optarg
;
389 storage_class
= optarg
;
400 "usage: %s [-c const] [-s storage] [-p] [-b] file\n",
404 outputfile
= optind
< argc
? argv
[optind
] : "g3states.h";
405 fd
= fopen(outputfile
, "w");
407 fprintf(stderr
, "%s: %s: Cannot create output file.\n",
408 argv
[0], outputfile
);
411 FillTable(MainTable
, 7, Pass
, S_Pass
);
412 FillTable(MainTable
, 7, Horiz
, S_Horiz
);
413 FillTable(MainTable
, 7, V0
, S_V0
);
414 FillTable(MainTable
, 7, VR
, S_VR
);
415 FillTable(MainTable
, 7, VL
, S_VL
);
416 FillTable(MainTable
, 7, Ext
, S_Ext
);
417 FillTable(MainTable
, 7, EOLV
, S_EOL
);
418 FillTable(WhiteTable
, 12, MakeUpW
, S_MakeUpW
);
419 FillTable(WhiteTable
, 12, MakeUp
, S_MakeUp
);
420 FillTable(WhiteTable
, 12, TermW
, S_TermW
);
421 FillTable(WhiteTable
, 12, EOLH
, S_EOL
);
422 FillTable(BlackTable
, 13, MakeUpB
, S_MakeUpB
);
423 FillTable(BlackTable
, 13, MakeUp
, S_MakeUp
);
424 FillTable(BlackTable
, 13, TermB
, S_TermB
);
425 FillTable(BlackTable
, 13, EOLH
, S_EOL
);
427 fprintf(fd
, "/* WARNING, this file was automatically generated by the\n");
428 fprintf(fd
, " mkg3states program */\n");
429 fprintf(fd
, "#include \"tiff.h\"\n");
430 fprintf(fd
, "#include \"tif_fax3.h\"\n");
431 WriteTable(fd
, MainTable
, 128, "TIFFFaxMainTable");
432 WriteTable(fd
, WhiteTable
, 4096, "TIFFFaxWhiteTable");
433 WriteTable(fd
, BlackTable
, 8192, "TIFFFaxBlackTable");