home *** CD-ROM | disk | FTP | other *** search
- /*
- * pccdump.c
- *
- * Practical Algorithms for Image Analysis
- *
- * Copyright (c) 1997, 1998, 1999 MLMSoftwareGroup, LLC
- */
-
- /* PCCDUMP: program reads PCC code, and outputs dump of raw code
- * with features shown
- * usage: pccdump infile [-L]
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "pcc2.h" /* header file for PCC programs */
- extern void print_sos_lic ();
-
- unsigned char *fcCode; /* code storage */
- long nByteCode; /* no. bytes in storage */
-
- long pccdedump (short);
- long usage (short);
- long input (int, char **, short *);
-
- main (argc, argv)
- int argc;
- char *argv[];
- {
- long widthI, heightI; /* size of image */
- short featsFlag; /* flag = 1 to print PCC feats; 0 otherwise */
-
- if (input (argc, argv, &featsFlag) < 0)
- return (-1);
-
- /* open input PCC file */
- if (pccread (argv[1], &fcCode, &nByteCode, &widthI, &heightI) == -1)
- exit (1);
- printf ("image size: %dx%d, PCC length = %d\n",
- widthI, heightI, nByteCode);
-
- /* construct tables of feature chain decodes */
- pccdecodes ();
-
- /* perform feature chain decoding and write out dump of code */
- printf ("PCC dump includes following information:\n");
- printf ("codeword number, feature type, feature (x,y), PCC chain codes.\n");
- printf ("(Locations (x,y) only displayed for start and break features.)\n");
- pccdedump (featsFlag);
-
- return (0);
- }
-
-
-
- /* PCCDEDUMP: function reads PCC code from code storage, and writes
- * out code, indicating features
- * usage: pccdedump ()
- */
-
- #include <images.h> /* images information file */
-
- #define MAXWRDSPERLINE 6 /* max code words per line of screen */
-
- long
- pccdedump (featsFlag)
- short featsFlag; /* flag = 1 to print PCC feats; 0 otherwise */
- {
- register long iByteCode, /* code storage incrementor */
- codeWord, /* code word contains up to 3 dirn.s */
- x, y; /* feature coordinates */
- long wrdsPerLine; /* remaining code words per line of screen */
-
- /* decode from storage region, and write out code and features */
-
- wrdsPerLine = MAXWRDSPERLINE;
-
- for (iByteCode = 0; iByteCode < nByteCode;) {
- codeWord = (int) fcCode[iByteCode++];
-
- if (codeWord >= MINFEATCODE) {
- wrdsPerLine = MAXWRDSPERLINE;
-
- switch (codeWord) {
- case BIFCODE:
- printf ("\n%5d: %5d = BIFCODE\t\t\t",
- iByteCode, codeWord);
- break;
- case CROSSCODE:
- printf ("\n%5d: %5d = CROSSCODE\t\t\t",
- iByteCode, codeWord);
- break;
- case ENDCODE: /* pop branches */
- printf ("\n%5d: %5d = ENDCODE\t\t\t",
- iByteCode, codeWord);
- break;
- case STARTCODE:
- x = (long) *(fcCode + iByteCode)
- | ((long) *(fcCode + iByteCode + 1) << 8);
- iByteCode += 2;
- y = (long) *(fcCode + iByteCode)
- | ((long) *(fcCode + iByteCode + 1) << 8);
- iByteCode += 2;
- printf ("\n%5d: %5d = STARTCODE (%3d,%3d)\t",
- iByteCode, codeWord, x, y);
- break;
- case LINEBRCODE:
- x = (long) *(fcCode + iByteCode)
- | ((long) *(fcCode + iByteCode + 1) << 8);
- iByteCode += 2;
- y = (long) *(fcCode + iByteCode)
- | ((long) *(fcCode + iByteCode + 1) << 8);
- iByteCode += 2;
- printf ("\n%5d: %5d = LINEBRCODE (%3d, %3d)\t",
- iByteCode, codeWord, x, y);
- break;
- case BIFBRCODE:
- x = (long) *(fcCode + iByteCode)
- | ((long) *(fcCode + iByteCode + 1) << 8);
- iByteCode += 2;
- y = (long) *(fcCode + iByteCode)
- | ((long) *(fcCode + iByteCode + 1) << 8);
- iByteCode += 2;
- printf ("\n%5d: %5d = BIFBRCODE (%3d, %3d)\t",
- iByteCode, codeWord, x, y);
- break;
- case CROSSBRCODE:
- x = (long) *(fcCode + iByteCode)
- | ((long) *(fcCode + iByteCode + 1) << 8);
- iByteCode += 2;
- y = (long) *(fcCode + iByteCode)
- | ((long) *(fcCode + iByteCode + 1) << 8);
- iByteCode += 2;
- printf ("\n%5d: %5d = CROSSBRCODE (%3d, %3d)\t",
- iByteCode, codeWord, x, y);
- break;
- case LINECODE:
- printf ("\n%5d: %5d = LINECODE\t\t\t",
- iByteCode, codeWord);
- break;
- case STOPCODE:
- printf ("\n%5d: %5d = STOPCODE\n", iByteCode, codeWord);
- return (0);
- default:
- break;
- }
- }
- else if (!featsFlag) {
- if (wrdsPerLine == 0) {
- printf ("\n\t\t\t\t\t");
- wrdsPerLine = MAXWRDSPERLINE;
- }
- printf ("%5d", codeWord);
- wrdsPerLine--;
- }
- }
-
- printf ("\nPCCDECODE: missing STOPCODE in PCC storage \n");
-
- return (-1);
- }
-
-
- /* USAGE: function gives instructions on usage of program
- * usage: usage (flag)
- * When flag is 1, the long message is given, 0 gives short.
- */
-
- long
- usage (flag)
- short flag; /* flag =1 for long message; =0 for short message */
- {
-
- /* print short usage message or long */
- printf ("USAGE: pccdump infile [-L]\n");
- if (flag == 0)
- return (-1);
-
- printf ("\npccdump prints out PCC features and code\n");
- printf ("stored in .pcc file and writes this output.\n\n");
- printf ("ARGUMENTS:\n");
- printf (" infile: input filename (.pcc) containing PCC (BINARY)\n\n");
- printf ("OPTIONS:\n");
- printf (" -f: FEATURES_FLAG; when set, displays only\n");
- printf (" PCC features, not chains.\n");
- printf (" -L: print Software License for this module\n");
-
- return (-1);
- }
-
-
- /* INPUT: function reads input parameters
- * usage: input (argc, argv, &featsFlag)
- */
-
- #define USAGE_EXIT(VALUE) {usage (VALUE); return (-1);}
-
- long
- input (argc, argv, featsFlag)
- int argc;
- char *argv[];
- short *featsFlag; /* flag=1 to print only PCC feats; or 0 */
- {
- long n;
-
- if (argc == 1)
- USAGE_EXIT (1);
-
- *featsFlag = 0;
-
- for (n = 2; n < argc; n++) {
- if (strcmp (argv[n], "-f") == 0)
- *featsFlag = 1;
- else if (strcmp (argv[n], "-L") == 0) {
- print_sos_lic ();
- exit (0);
- }
- else
- USAGE_EXIT (0);
- }
-
- return (0);
- }
-