home *** CD-ROM | disk | FTP | other *** search
- /* pnmsig.c - read a portable anymap produce a numeric signature
- **
- ** Copyright 1990 George Phillips
- **
- ** Permission to use, copy, modify, and distribute this software and its
- ** documentation for any purpose and without fee is hereby granted, provided
- ** that the above copyright notice appear in all copies and that both that
- ** copyright notice and this permission notice appear in supporting
- ** documentation. This software is provided "as is" without express or
- ** implied warranty.
- */
-
- #include <stdio.h>
- #include "pnm.h"
-
- #ifdef PPM
- #include "ppm.h"
- #include "libppm.h"
- #endif /*PPM*/
-
- #ifdef PGM
- #include "pgm.h"
- #include "libpgm.h"
- #endif /*PGM*/
-
- #ifdef PBM
- #include "pbm.h"
- #include "libpbm.h"
- #endif /*PBM*/
-
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- int i;
-
- pm_progname = argv[0];
-
- if (argc < 2)
- pnm_sig(NULL);
- else {
- for (i = 1; i < argc; i++)
- pnm_sig(argv[i]);
- }
- exit(0);
- }
-
- pnm_sig(fname)
- char* fname;
- {
- FILE* ifp;
- xelval maxval;
- register xel *xelrow, *xP;
- int rows, cols, format, row, col, sig;
-
- if (fname != NULL)
- ifp = pm_openr(fname);
- else
- ifp = stdin;
-
- pnm_readpnminit(ifp, &cols, &rows, &maxval, &format);
- xelrow = pnm_allocrow(cols);
- sig = 0;
-
- for (row = 0; row < rows; row++) {
- pnm_readpnmrow(ifp, xelrow, cols, maxval, format);
- for (col = 0, xP = xelrow; col < cols; col++, xP++)
- switch (format) {
- #ifdef PPM
- case PPM_FORMAT:
- case RPPM_FORMAT:
- sig += PPM_GETR(*xP) + PPM_GETG(*xP) + PPM_GETB(*xP);
- break;
- #endif /*PPM*/
-
- #ifdef PGM
- case PGM_FORMAT:
- case RPGM_FORMAT:
- sig += (gray) PNM_GET1(*xP);
- break;
- #endif /*PGM*/
-
- #ifdef PBM
- case PBM_FORMAT:
- case RPBM_FORMAT:
- sig += (bit) PNM_GET1(*xP);
- break;
- #endif /*PBM*/
-
- default:
- pm_error( "can't happen", 0,0,0,0,0 );
- }
- }
-
- if (fname != NULL) {
- pm_close(ifp);
- printf("%s: ", fname);
- }
- printf("%d x %d x ", cols, rows);
- switch (format) {
- #ifdef PPM
- case PPM_FORMAT:
- case RPPM_FORMAT:
- printf("%d colour", maxval + 1);
- break;
- #endif /*PPM*/
- #ifdef PGM
- case PGM_FORMAT:
- case RPGM_FORMAT:
- printf("%d grayscale", maxval + 1);
- break;
- #endif /*PGM*/
- #ifdef PBM
- case PBM_FORMAT:
- case RPBM_FORMAT:
- printf("2 bitmap");
- break;
- #endif /*PBM*/
- }
- printf(" [%d]\n", sig);
-
- pnm_freerow(xelrow);
- }
-