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)  

libpnm2.c
Go to the documentation of this file.
1 /* libpnm2.c - pnm utility library part 2
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 #if __STDC__
25 void
26 pnm_writepnminit( FILE* file, int cols, int rows, xelval maxval, int format, int forceplain )
27 #else /*__STDC__*/
28 void
30  FILE* file;
31  int cols, rows, format;
32  xelval maxval;
33  int forceplain;
34 #endif /*__STDC__*/
35  {
36  switch ( PNM_FORMAT_TYPE(format) )
37  {
38  case PPM_TYPE:
39  ppm_writeppminit( file, cols, rows, (pixval) maxval, forceplain );
40  break;
41 
42  case PGM_TYPE:
43  pgm_writepgminit( file, cols, rows, (gray) maxval, forceplain );
44  break;
45 
46  case PBM_TYPE:
47  pbm_writepbminit( file, cols, rows, forceplain );
48  break;
49 
50  default:
51  pm_error( "invalid format argument received by pnm_writepnminit(): %d\n"
52  "PNM_FORMAT_TYPE(format) must be %d, %d, or %d",
54  }
55  }
56 
57 #if __STDC__
58 void
59 pnm_writepnmrow( FILE* file, xel* xelrow, int cols, xelval maxval, int format, int forceplain )
60 #else /*__STDC__*/
61 void
62 pnm_writepnmrow( file, xelrow, cols, maxval, format, forceplain )
63  FILE* file;
64  xel* xelrow;
65  int cols, format;
66  xelval maxval;
67  int forceplain;
68 #endif /*__STDC__*/
69  {
70  register int col;
71  register xel* xP;
72  gray* grayrow;
73  register gray* gP;
74  bit* bitrow;
75  register bit* bP;
76 
77  switch ( PNM_FORMAT_TYPE(format) )
78  {
79  case PPM_TYPE:
80  ppm_writeppmrow( file, (pixel*) xelrow, cols, (pixval) maxval, forceplain );
81  break;
82 
83  case PGM_TYPE:
85  for ( col = 0, gP = grayrow, xP = xelrow; col < cols; ++col, ++gP, ++xP )
86  *gP = PNM_GET1( *xP );
87  pgm_writepgmrow( file, grayrow, cols, (gray) maxval, forceplain );
89  break;
90 
91  case PBM_TYPE:
92  bitrow = pbm_allocrow( cols );
93  for ( col = 0, bP = bitrow, xP = xelrow; col < cols; ++col, ++bP, ++xP )
94  *bP = PNM_GET1( *xP ) == 0 ? PBM_BLACK : PBM_WHITE;
95  pbm_writepbmrow( file, bitrow, cols, forceplain );
96  pbm_freerow( bitrow );
97  break;
98 
99  default:
100  pm_error( "invalid format argument received by pnm_writepnmrow(): %d\n"
101  "PNM_FORMAT_TYPE(format) must be %d, %d, or %d",
103  }
104  }
105 
106 #if __STDC__
107 void
108 pnm_writepnm( FILE* file, xel** xels, int cols, int rows, xelval maxval, int format, int forceplain )
109 #else /*__STDC__*/
110 void
111 pnm_writepnm( file, xels, cols, rows, maxval, format, forceplain )
112  FILE* file;
113  xel** xels;
114  xelval maxval;
115  int cols, rows, format;
116  int forceplain;
117 #endif /*__STDC__*/
118  {
119  int row;
120 
121  pnm_writepnminit( file, cols, rows, maxval, format, forceplain );
122 
123  for ( row = 0; row < rows; ++row )
124  pnm_writepnmrow( file, xels[row], cols, maxval, format, forceplain );
125  }
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 pbm_writepbminit(FILE *file, int cols, int rows, int forceplain)
Definition: libpbm3.c:22
void pbm_writepbmrow(FILE *file, bit *bitrow, int cols, int forceplain)
Definition: libpbm3.c:95
#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
#define PBM_WHITE
Definition: pbm.h:10
static int rows
Definition: pbmclean.c:15
static int format
Definition: pbmclean.c:15
static int cols
Definition: pbmmask.c:21
void pgm_writepgminit(FILE *file, int cols, int rows, gray maxval, int forceplain)
Definition: libpgm2.c:21
void pgm_writepgmrow(FILE *file, gray *grayrow, int cols, gray maxval, int forceplain)
Definition: libpgm2.c:125
#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_writepnminit(FILE *file, int cols, int rows, xelval maxval, int format, int forceplain)
Definition: libpnm2.c:29
void pnm_writepnmrow(FILE *file, xel *xelrow, int cols, xelval maxval, int format, int forceplain)
Definition: libpnm2.c:62
void pnm_writepnm(FILE *file, xel **xels, int cols, int rows, xelval maxval, int format, int forceplain)
Definition: libpnm2.c:111
#define PNM_GET1(x)
Definition: pnm.h:12
#define PNM_FORMAT_TYPE(f)
Definition: pnm.h:15
pixval xelval
Definition: pnm.h:9
void ppm_writeppmrow(FILE *file, pixel *pixelrow, int cols, pixval maxval, int forceplain)
Definition: libppm2.c:129
void ppm_writeppminit(FILE *file, int cols, int rows, pixval maxval, int forceplain)
Definition: libppm2.c:23
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