ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

mkg3states.c
Go to the documentation of this file.
00001 /* "$Id: mkg3states.c,v 1.10.2.1 2010-06-08 18:50:41 bfriesen Exp $ */
00002 
00003 /*
00004  * Copyright (c) 1991-1997 Sam Leffler
00005  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
00006  *
00007  * Permission to use, copy, modify, distribute, and sell this software and 
00008  * its documentation for any purpose is hereby granted without fee, provided
00009  * that (i) the above copyright notices and this permission notice appear in
00010  * all copies of the software and related documentation, and (ii) the names of
00011  * Sam Leffler and Silicon Graphics may not be used in any advertising or
00012  * publicity relating to the software without the specific, prior written
00013  * permission of Sam Leffler and Silicon Graphics.
00014  * 
00015  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
00016  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
00017  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
00018  * 
00019  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
00020  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
00021  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
00022  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
00023  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
00024  * OF THIS SOFTWARE.
00025  */
00026 
00027 /* Initialise fax decoder tables
00028  * Decoder support is derived, with permission, from the code
00029  * in Frank Cringle's viewfax program;
00030  *      Copyright (C) 1990, 1995  Frank D. Cringle.
00031  */
00032 #include "tif_config.h"
00033 
00034 #include <stdio.h>
00035 #include <stdlib.h>
00036 #include <string.h>
00037 
00038 #ifdef HAVE_UNISTD_H
00039 # include <unistd.h>
00040 #endif
00041 
00042 #include "tif_fax3.h"
00043 
00044 #ifndef HAVE_GETOPT
00045 extern int getopt(int, char**, char*);
00046 #endif
00047 
00048 #define streq(a,b)  (strcmp(a,b) == 0)
00049 
00050 /* NB: can't use names in tif_fax3.h 'cuz they are declared const */
00051 TIFFFaxTabEnt MainTable[128];
00052 TIFFFaxTabEnt WhiteTable[4096];
00053 TIFFFaxTabEnt BlackTable[8192];
00054 
00055 struct proto {
00056     uint16 code;        /* right justified, lsb-first, zero filled */
00057     uint16 val;     /* (pixel count)<<4 + code width  */
00058 };
00059 
00060 static struct proto Pass[] = {
00061 { 0x0008, 4 },
00062 { 0, 0 }
00063 };
00064 
00065 static struct proto Horiz[]  = {
00066 { 0x0004, 3 },
00067 { 0, 0 }
00068 };
00069 
00070 static struct proto V0[]  = {
00071 { 0x0001, 1 },
00072 { 0, 0 }
00073 };
00074 
00075 static struct proto VR[]  = {
00076 { 0x0006, (1<<4)+3 },
00077 { 0x0030, (2<<4)+6 },
00078 { 0x0060, (3<<4)+7 },
00079 { 0, 0 }
00080 };
00081 
00082 static struct proto VL[]  = {
00083 { 0x0002, (1<<4)+3 },
00084 { 0x0010, (2<<4)+6 },
00085 { 0x0020, (3<<4)+7 },
00086 { 0, 0 }
00087 };
00088 
00089 static struct proto Ext[]  = {
00090 { 0x0040, 7 },
00091 { 0, 0 }
00092 };
00093 
00094 static struct proto EOLV[]  = {
00095 { 0x0000, 7 },
00096 { 0, 0 }
00097 };
00098 
00099 static struct proto MakeUpW[] = {
00100 { 0x001b, 1029 },
00101 { 0x0009, 2053 },
00102 { 0x003a, 3078 },
00103 { 0x0076, 4103 },
00104 { 0x006c, 5128 },
00105 { 0x00ec, 6152 },
00106 { 0x0026, 7176 },
00107 { 0x00a6, 8200 },
00108 { 0x0016, 9224 },
00109 { 0x00e6, 10248 },
00110 { 0x0066, 11273 },
00111 { 0x0166, 12297 },
00112 { 0x0096, 13321 },
00113 { 0x0196, 14345 },
00114 { 0x0056, 15369 },
00115 { 0x0156, 16393 },
00116 { 0x00d6, 17417 },
00117 { 0x01d6, 18441 },
00118 { 0x0036, 19465 },
00119 { 0x0136, 20489 },
00120 { 0x00b6, 21513 },
00121 { 0x01b6, 22537 },
00122 { 0x0032, 23561 },
00123 { 0x0132, 24585 },
00124 { 0x00b2, 25609 },
00125 { 0x0006, 26630 },
00126 { 0x01b2, 27657 },
00127 { 0, 0 }
00128 };
00129 
00130 static struct proto MakeUpB[] = {
00131 { 0x03c0, 1034 },
00132 { 0x0130, 2060 },
00133 { 0x0930, 3084 },
00134 { 0x0da0, 4108 },
00135 { 0x0cc0, 5132 },
00136 { 0x02c0, 6156 },
00137 { 0x0ac0, 7180 },
00138 { 0x06c0, 8205 },
00139 { 0x16c0, 9229 },
00140 { 0x0a40, 10253 },
00141 { 0x1a40, 11277 },
00142 { 0x0640, 12301 },
00143 { 0x1640, 13325 },
00144 { 0x09c0, 14349 },
00145 { 0x19c0, 15373 },
00146 { 0x05c0, 16397 },
00147 { 0x15c0, 17421 },
00148 { 0x0dc0, 18445 },
00149 { 0x1dc0, 19469 },
00150 { 0x0940, 20493 },
00151 { 0x1940, 21517 },
00152 { 0x0540, 22541 },
00153 { 0x1540, 23565 },
00154 { 0x0b40, 24589 },
00155 { 0x1b40, 25613 },
00156 { 0x04c0, 26637 },
00157 { 0x14c0, 27661 },
00158 { 0, 0 }
00159 };
00160 
00161 static struct proto MakeUp[] = {
00162 { 0x0080, 28683 },
00163 { 0x0180, 29707 },
00164 { 0x0580, 30731 },
00165 { 0x0480, 31756 },
00166 { 0x0c80, 32780 },
00167 { 0x0280, 33804 },
00168 { 0x0a80, 34828 },
00169 { 0x0680, 35852 },
00170 { 0x0e80, 36876 },
00171 { 0x0380, 37900 },
00172 { 0x0b80, 38924 },
00173 { 0x0780, 39948 },
00174 { 0x0f80, 40972 },
00175 { 0, 0 }
00176 };
00177 
00178 static struct proto TermW[] = {
00179 { 0x00ac, 8 },
00180 { 0x0038, 22 },
00181 { 0x000e, 36 },
00182 { 0x0001, 52 },
00183 { 0x000d, 68 },
00184 { 0x0003, 84 },
00185 { 0x0007, 100 },
00186 { 0x000f, 116 },
00187 { 0x0019, 133 },
00188 { 0x0005, 149 },
00189 { 0x001c, 165 },
00190 { 0x0002, 181 },
00191 { 0x0004, 198 },
00192 { 0x0030, 214 },
00193 { 0x000b, 230 },
00194 { 0x002b, 246 },
00195 { 0x0015, 262 },
00196 { 0x0035, 278 },
00197 { 0x0072, 295 },
00198 { 0x0018, 311 },
00199 { 0x0008, 327 },
00200 { 0x0074, 343 },
00201 { 0x0060, 359 },
00202 { 0x0010, 375 },
00203 { 0x000a, 391 },
00204 { 0x006a, 407 },
00205 { 0x0064, 423 },
00206 { 0x0012, 439 },
00207 { 0x000c, 455 },
00208 { 0x0040, 472 },
00209 { 0x00c0, 488 },
00210 { 0x0058, 504 },
00211 { 0x00d8, 520 },
00212 { 0x0048, 536 },
00213 { 0x00c8, 552 },
00214 { 0x0028, 568 },
00215 { 0x00a8, 584 },
00216 { 0x0068, 600 },
00217 { 0x00e8, 616 },
00218 { 0x0014, 632 },
00219 { 0x0094, 648 },
00220 { 0x0054, 664 },
00221 { 0x00d4, 680 },
00222 { 0x0034, 696 },
00223 { 0x00b4, 712 },
00224 { 0x0020, 728 },
00225 { 0x00a0, 744 },
00226 { 0x0050, 760 },
00227 { 0x00d0, 776 },
00228 { 0x004a, 792 },
00229 { 0x00ca, 808 },
00230 { 0x002a, 824 },
00231 { 0x00aa, 840 },
00232 { 0x0024, 856 },
00233 { 0x00a4, 872 },
00234 { 0x001a, 888 },
00235 { 0x009a, 904 },
00236 { 0x005a, 920 },
00237 { 0x00da, 936 },
00238 { 0x0052, 952 },
00239 { 0x00d2, 968 },
00240 { 0x004c, 984 },
00241 { 0x00cc, 1000 },
00242 { 0x002c, 1016 },
00243 { 0, 0 }
00244 };
00245 
00246 static struct proto TermB[] = {
00247 { 0x03b0, 10 },
00248 { 0x0002, 19 },
00249 { 0x0003, 34 },
00250 { 0x0001, 50 },
00251 { 0x0006, 67 },
00252 { 0x000c, 84 },
00253 { 0x0004, 100 },
00254 { 0x0018, 117 },
00255 { 0x0028, 134 },
00256 { 0x0008, 150 },
00257 { 0x0010, 167 },
00258 { 0x0050, 183 },
00259 { 0x0070, 199 },
00260 { 0x0020, 216 },
00261 { 0x00e0, 232 },
00262 { 0x0030, 249 },
00263 { 0x03a0, 266 },
00264 { 0x0060, 282 },
00265 { 0x0040, 298 },
00266 { 0x0730, 315 },
00267 { 0x00b0, 331 },
00268 { 0x01b0, 347 },
00269 { 0x0760, 363 },
00270 { 0x00a0, 379 },
00271 { 0x0740, 395 },
00272 { 0x00c0, 411 },
00273 { 0x0530, 428 },
00274 { 0x0d30, 444 },
00275 { 0x0330, 460 },
00276 { 0x0b30, 476 },
00277 { 0x0160, 492 },
00278 { 0x0960, 508 },
00279 { 0x0560, 524 },
00280 { 0x0d60, 540 },
00281 { 0x04b0, 556 },
00282 { 0x0cb0, 572 },
00283 { 0x02b0, 588 },
00284 { 0x0ab0, 604 },
00285 { 0x06b0, 620 },
00286 { 0x0eb0, 636 },
00287 { 0x0360, 652 },
00288 { 0x0b60, 668 },
00289 { 0x05b0, 684 },
00290 { 0x0db0, 700 },
00291 { 0x02a0, 716 },
00292 { 0x0aa0, 732 },
00293 { 0x06a0, 748 },
00294 { 0x0ea0, 764 },
00295 { 0x0260, 780 },
00296 { 0x0a60, 796 },
00297 { 0x04a0, 812 },
00298 { 0x0ca0, 828 },
00299 { 0x0240, 844 },
00300 { 0x0ec0, 860 },
00301 { 0x01c0, 876 },
00302 { 0x0e40, 892 },
00303 { 0x0140, 908 },
00304 { 0x01a0, 924 },
00305 { 0x09a0, 940 },
00306 { 0x0d40, 956 },
00307 { 0x0340, 972 },
00308 { 0x05a0, 988 },
00309 { 0x0660, 1004 },
00310 { 0x0e60, 1020 },
00311 { 0, 0 }
00312 };
00313 
00314 static struct proto EOLH[] = {
00315 { 0x0000, 11 },
00316 { 0, 0 }
00317 };
00318 
00319 static void
00320 FillTable(TIFFFaxTabEnt *T, int Size, struct proto *P, int State)
00321 {
00322     int limit = 1 << Size;
00323 
00324     while (P->val) {
00325     int width = P->val & 15;
00326     int param = P->val >> 4;
00327     int incr = 1 << width;
00328     int code;
00329     for (code = P->code; code < limit; code += incr) {
00330         TIFFFaxTabEnt *E = T+code;
00331         E->State = State;
00332         E->Width = width;
00333         E->Param = param;
00334     }
00335     P++;
00336     }
00337 }
00338 
00339 static  char* storage_class = "";
00340 static  char* const_class = "";
00341 static  int packoutput = 1;
00342 static  char* prebrace = "";
00343 static  char* postbrace = "";
00344 
00345 void
00346 WriteTable(FILE* fd, const TIFFFaxTabEnt* T, int Size, const char* name)
00347 {
00348     int i;
00349     char* sep;
00350 
00351     fprintf(fd, "%s %s TIFFFaxTabEnt %s[%d] = {",
00352     storage_class, const_class, name, Size);
00353     if (packoutput) {
00354     sep = "\n";
00355     for (i = 0; i < Size; i++) {
00356         fprintf(fd, "%s%s%d,%d,%d%s",
00357         sep, prebrace, T->State, T->Width, (int) T->Param, postbrace);
00358         if (((i+1) % 10) == 0)
00359             sep = ",\n";
00360         else
00361             sep = ",";
00362         T++;
00363     }
00364     } else {
00365     sep = "\n ";
00366     for (i = 0; i < Size; i++) {
00367         fprintf(fd, "%s%s%3d,%3d,%4d%s",
00368         sep, prebrace, T->State, T->Width, (int) T->Param, postbrace);
00369         if (((i+1) % 6) == 0)
00370             sep = ",\n ";
00371         else
00372             sep = ",";
00373         T++;
00374     }
00375     }
00376     fprintf(fd, "\n};\n");
00377 }
00378 
00379 /* initialise the huffman code tables */
00380 int
00381 main(int argc, char* argv[])
00382 {
00383     FILE* fd;
00384     char* outputfile;
00385     int c;
00386     extern int optind;
00387     extern char* optarg;
00388 
00389     while ((c = getopt(argc, argv, "c:s:bp")) != -1)
00390     switch (c) {
00391     case 'c':
00392         const_class = optarg;
00393         break;
00394     case 's':
00395         storage_class = optarg;
00396         break;
00397     case 'p':
00398         packoutput = 0;
00399         break;
00400     case 'b':
00401         prebrace = "{";
00402         postbrace = "}";
00403         break;
00404     case '?':
00405         fprintf(stderr,
00406         "usage: %s [-c const] [-s storage] [-p] [-b] file\n",
00407         argv[0]);
00408         return (-1);
00409     }
00410     outputfile = optind < argc ? argv[optind] : "g3states.h";
00411     fd = fopen(outputfile, "w");
00412     if (fd == NULL) {
00413     fprintf(stderr, "%s: %s: Cannot create output file.\n",
00414         argv[0], outputfile);
00415     return (-2);
00416     }
00417     FillTable(MainTable, 7, Pass, S_Pass);
00418     FillTable(MainTable, 7, Horiz, S_Horiz);
00419     FillTable(MainTable, 7, V0, S_V0);
00420     FillTable(MainTable, 7, VR, S_VR);
00421     FillTable(MainTable, 7, VL, S_VL);
00422     FillTable(MainTable, 7, Ext, S_Ext);
00423     FillTable(MainTable, 7, EOLV, S_EOL);
00424     FillTable(WhiteTable, 12, MakeUpW, S_MakeUpW);
00425     FillTable(WhiteTable, 12, MakeUp, S_MakeUp);
00426     FillTable(WhiteTable, 12, TermW, S_TermW);
00427     FillTable(WhiteTable, 12, EOLH, S_EOL);
00428     FillTable(BlackTable, 13, MakeUpB, S_MakeUpB);
00429     FillTable(BlackTable, 13, MakeUp, S_MakeUp);
00430     FillTable(BlackTable, 13, TermB, S_TermB);
00431     FillTable(BlackTable, 13, EOLH, S_EOL);
00432 
00433     fprintf(fd, "/* WARNING, this file was automatically generated by the\n");
00434     fprintf(fd, "    mkg3states program */\n");
00435     fprintf(fd, "#include \"tiff.h\"\n");
00436     fprintf(fd, "#include \"tif_fax3.h\"\n");
00437     WriteTable(fd, MainTable, 128, "TIFFFaxMainTable");
00438     WriteTable(fd, WhiteTable, 4096, "TIFFFaxWhiteTable");
00439     WriteTable(fd, BlackTable, 8192, "TIFFFaxBlackTable");
00440     fclose(fd);
00441     return (0);
00442 }
00443 
00444 /* vim: set ts=8 sts=8 sw=8 noet: */
00445 /*
00446  * Local Variables:
00447  * mode: c
00448  * c-basic-offset: 8
00449  * fill-column: 78
00450  * End:
00451  */

Generated on Thu May 24 2012 04:19:42 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.