w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

libpnm1.c
Go to the documentation of this file.
1 /* libpnm1.c - pnm utility library part 1
2 **
3 ** Copyright (C) 1989 by Jef Poskanzer.
4 **
5 ** Permission to use, copy, modify, and distribute this software and its
6 ** documentation for any purpose and without fee is hereby granted, provided
7 ** that the above copyright notice appear in all copies and that both that
8 ** copyright notice and this permission notice appear in supporting
9 ** documentation. This software is provided "as is" without express or
10 ** implied warranty.
11 */
12 
13 #include "pnm.h"
14 
15 #include "ppm.h"
16 #include "libppm.h"
17 
18 #include "pgm.h"
19 #include "libpgm.h"
20 
21 #include "pbm.h"
22 #include "libpbm.h"
23 
24 void
25 pnm_init( argcP, argv )
26  int* argcP;
27  char* argv[];
28  {
29  ppm_init( argcP, argv );
30  }
31 
33 
34 void
35 pnm_readpnminit( file, colsP, rowsP, maxvalP, formatP )
36  FILE* file;
37  int* colsP;
38  int* rowsP;
39  int* formatP;
40  xelval* maxvalP;
41  {
42  gray gmaxval;
43 
44  /* Check magic number. */
45  *formatP = pbm_readmagicnumber( file );
46  switch ( PNM_FORMAT_TYPE(*formatP) )
47  {
48  case PPM_TYPE:
49  ppm_readppminitrest( file, colsP, rowsP, (pixval*) maxvalP );
50  break;
51 
52  case PGM_TYPE:
53  pgm_readpgminitrest( file, colsP, rowsP, &gmaxval );
54  *maxvalP = (xelval) gmaxval;
55  break;
56 
57  case PBM_TYPE:
58  pbm_readpbminitrest( file, colsP, rowsP );
59  *maxvalP = pnm_pbmmaxval;
60  break;
61 
62  default:
63  pm_error( "bad magic number - not a ppm, pgm, or pbm file" );
64  }
65  }
66 
67 #if __STDC__
68 void
69 pnm_readpnmrow( FILE* file, xel* xelrow, int cols, xelval maxval, int format )
70 #else /*__STDC__*/
71 void
73  FILE* file;
74  xel* xelrow;
75  xelval maxval;
76  int cols, format;
77 #endif /*__STDC__*/
78  {
79  register int col;
80  register xel* xP;
81  gray* grayrow;
82  register gray* gP;
83  bit* bitrow;
84  register bit* bP;
85 
86  switch ( PNM_FORMAT_TYPE(format) )
87  {
88  case PPM_TYPE:
89  ppm_readppmrow( file, (pixel*) xelrow, cols, (pixval) maxval, format );
90  break;
91 
92  case PGM_TYPE:
95  for ( col = 0, xP = xelrow, gP = grayrow; col < cols; ++col, ++xP, ++gP )
96  PNM_ASSIGN1( *xP, *gP );
98  break;
99 
100  case PBM_TYPE:
101  bitrow = pbm_allocrow( cols );
102  pbm_readpbmrow( file, bitrow, cols, format );
103  for ( col = 0, xP = xelrow, bP = bitrow; col < cols; ++col, ++xP, ++bP )
104  PNM_ASSIGN1( *xP, *bP == PBM_BLACK ? 0: pnm_pbmmaxval );
105  pbm_freerow( bitrow );
106  break;
107 
108  default:
109  pm_error( "can't happen" );
110  }
111  }
112 
113 xel**
114 pnm_readpnm( file, colsP, rowsP, maxvalP, formatP )
115  FILE* file;
116  int* colsP;
117  int* rowsP;
118  int* formatP;
119  xelval* maxvalP;
120  {
121  xel** xels;
122  int row;
123 
124  pnm_readpnminit( file, colsP, rowsP, maxvalP, formatP );
125 
126  xels = pnm_allocarray( *colsP, *rowsP );
127 
128  for ( row = 0; row < *rowsP; ++row )
129  pnm_readpnmrow( file, xels[row], *colsP, *maxvalP, *formatP );
130 
131  return xels;
132  }
static gray maxval
Definition: asciitopgm.c:38
int col
Definition: gsftopk.c:443
unsigned char * bP
Definition: hbf2gf.c:371
long grayrow[1023]
Definition: hbf2gf.c:383
void pgm_readpgminitrest(FILE *file, int *colsP, int *rowsP, gray *maxvalP)
Definition: libpgm1.c:27
void pbm_readpbminitrest(FILE *file, int *colsP, int *rowsP)
Definition: libpbm2.c:51
int pbm_readmagicnumber(FILE *file)
Definition: libpbm2.c:36
void pbm_readpbmrow(FILE *file, bit *bitrow, int cols, int format)
Definition: libpbm2.c:82
#define PBM_TYPE
Definition: pbm.h:21
#define pbm_allocrow(cols)
Definition: pbm.h:36
unsigned char bit
Definition: pbm.h:9
#define pbm_freerow(bitrow)
Definition: pbm.h:38
#define PBM_BLACK
Definition: pbm.h:11
static int format
Definition: pbmclean.c:15
static int cols
Definition: pbmmask.c:21
void pgm_readpgmrow(FILE *file, gray *grayrow, int cols, gray maxval, int format)
Definition: libpgm1.c:104
#define pgm_allocrow(cols)
Definition: pgm.h:58
#define PGM_TYPE
Definition: pgm.h:45
unsigned int gray
Definition: pgm.h:10
#define pgm_freerow(grayrow)
Definition: pgm.h:60
#define pm_error
Definition: png22pnm.c:118
void pnm_readpnmrow(FILE *file, xel *xelrow, int cols, xelval maxval, int format)
Definition: libpnm1.c:72
xelval pnm_pbmmaxval
Definition: libpnm1.c:32
xel ** pnm_readpnm(FILE *file, int *colsP, int *rowsP, xelval *maxvalP, int *formatP)
Definition: libpnm1.c:114
void pnm_init(int *argcP, argv)
Definition: libpnm1.c:25
void pnm_readpnminit(FILE *file, int *colsP, int *rowsP, xelval *maxvalP, int *formatP)
Definition: libpnm1.c:35
#define pnm_allocarray(cols, rows)
Definition: pnm.h:21
#define PNM_ASSIGN1(x, v)
Definition: pnm.h:13
#define PNM_FORMAT_TYPE(f)
Definition: pnm.h:15
pixval xelval
Definition: pnm.h:9
void ppm_readppmrow(FILE *file, pixel *pixelrow, int cols, pixval maxval, int format)
Definition: libppm1.c:87
void ppm_init(int *argcP, argv)
Definition: libppm1.c:21
void ppm_readppminitrest(FILE *file, int *colsP, int *rowsP, pixval *maxvalP)
Definition: libppm1.c:29
gray pixval
Definition: ppm.h:9
#define PPM_TYPE
Definition: ppm.h:59
static int row
Definition: ps2pk.c:587
Definition: filedef.h:30
Definition: ppm.h:33
#define FILE
Definition: t1stdio.h:34
char * file
Definition: t4ht.c:931
#define argv
Definition: xmain.c:270