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)  

pbmpscale.c
Go to the documentation of this file.
1 /* pbmpscale.c - pixel scaling with jagged edge smoothing.
2  * AJCD 13/8/90
3  */
4 
5 #include <stdio.h>
6 #include "pbm.h"
7 
8 /* prototypes */
9 void nextrow_pscale ARGS((FILE *ifd, int row));
10 int corner ARGS((int pat));
11 
12 /* input bitmap size and storage */
14 bit *inrow[3] ;
15 
16 #define thisrow (1)
17 
18 /* compass directions from west clockwise */
19 int xd_pscale[] = { -1, -1, 0, 1, 1, 1, 0, -1 } ;
20 int yd_pscale[] = { 0, -1, -1, -1, 0, 1, 1, 1 } ;
21 
22 /* starting positions for corners */
23 #define NE(f) ((f) & 3)
24 #define SE(f) (((f) >> 2) & 3)
25 #define SW(f) (((f) >> 4) & 3)
26 #define NW(f) (((f) >> 6) & 3)
27 
28 typedef unsigned short sixteenbits ;
29 
30 /* list of corner patterns; bit 7 is current colour, bits 0-6 are squares
31  * around (excluding square behind), going clockwise.
32  * The high byte of the patterns is a mask, which determines which bits are
33  * not ignored.
34  */
35 
36 sixteenbits patterns[] = { 0x0000, 0xd555, /* no corner */
37  0x0001, 0xffc1, 0xd514, /* normal corner */
38  0x0002, 0xd554, 0xd515, /* reduced corners */
39  0xbea2, 0xdfc0, 0xfd81,
40  0xfd80, 0xdf80,
41  0x0003, 0xbfa1, 0xfec2 /* reduced if > 1 */
42  };
43 
44 /* search for corner patterns, return type of corner found:
45  * 0 = no corner,
46  * 1 = normal corner,
47  * 2 = reduced corner,
48  * 3 = reduced if cutoff > 1
49  */
50 
51 int corner(pat)
52  int pat;
53 {
54  register int i, r=0;
55  for (i = 0; i < sizeof(patterns)/sizeof(sixteenbits); i++)
56  if (patterns[i] < 0x100)
57  r = patterns[i];
58  else if ((pat & (patterns[i] >> 8)) ==
59  (patterns[i] & (patterns[i] >> 8)))
60  return r;
61  return 0;
62 }
63 
64 /* get a new row
65  */
66 
67 void nextrow_pscale(ifd, row)
68  FILE *ifd;
69  int row;
70 {
71  bit *shuffle = inrow[0] ;
72  inrow[0] = inrow[1];
73  inrow[1] = inrow[2];
74  inrow[2] = shuffle ;
75  if (row < rows) {
76  if (shuffle == NULL)
77  inrow[2] = shuffle = pbm_allocrow(columns);
78  pbm_readpbmrow(ifd, inrow[2], columns, format) ;
79  } else inrow[2] = NULL; /* discard storage */
80 
81 }
82 
83 int
85  int argc;
86  char *argv[];
87 {
88  FILE *ifd;
89  register bit *outrow;
90  register int row, col, i, k;
91  int scale, cutoff, ucutoff ;
92  unsigned char *flags;
93 
94  pbm_init( &argc, argv );
95 
96  if (argc < 2)
97  pm_usage("scale [pbmfile]");
98 
99  scale = atoi(argv[1]);
100  if (scale < 1)
101  pm_perror("bad scale (< 1)");
102 
103  if (argc == 3)
104  ifd = pm_openr(argv[2]);
105  else
106  ifd = stdin ;
107 
108  inrow[0] = inrow[1] = inrow[2] = NULL;
109  pbm_readpbminit(ifd, &columns, &rows, &format) ;
110 
112  flags = (unsigned char *)malloc(sizeof(unsigned char)*columns) ;
113  if (flags == NULL) pm_perror("out of memory") ;
114 
116 
117  cutoff = scale / 2;
118  ucutoff = scale - 1 - cutoff;
119  nextrow_pscale(ifd, 0);
120  for (row = 0; row < rows; row++) {
121  nextrow_pscale(ifd, row+1);
122  for (col = 0; col < columns; col++) {
123  flags[col] = 0 ;
124  for (i = 0; i != 8; i += 2) {
125  int vec = inrow[thisrow][col] != PBM_WHITE;
126  for (k = 0; k < 7; k++) {
127  int x = col + xd_pscale[(k+i)&7] ;
128  int y = thisrow + yd_pscale[(k+i)&7] ;
129  vec <<= 1;
130  if (x >=0 && x < columns && inrow[y])
131  vec |= (inrow[y][x] != PBM_WHITE) ;
132  }
133  flags[col] |= corner(vec)<<i ;
134  }
135  }
136  for (i = 0; i < scale; i++) {
137  bit *ptr = outrow ;
138  int zone = (i > ucutoff) - (i < cutoff) ;
139  int cut = (zone < 0) ? (cutoff - i) :
140  (zone > 0) ? (i - ucutoff) : 0 ;
141 
142  for (col = 0; col < columns; col++) {
143  int pix = inrow[thisrow][col] ;
144  int flag = flags[col] ;
145  int cutl, cutr ;
146 
147  switch (zone) {
148  case -1:
149  switch (NW(flag)) {
150  case 0: cutl = 0; break;
151  case 1: cutl = cut; break;
152  case 2: cutl = cut ? cut-1 : 0; break;
153  case 3: cutl = (cut && cutoff > 1) ? cut-1 : cut; break;
154  default: cutl = 0; /* Should never reach here */
155  }
156  switch (NE(flag)) {
157  case 0: cutr = 0; break;
158  case 1: cutr = cut; break;
159  case 2: cutr = cut ? cut-1 : 0; break;
160  case 3: cutr = (cut && cutoff > 1) ? cut-1 : cut; break;
161  default: cutr = 0; /* Should never reach here */
162  }
163  break;
164  case 0:
165  cutl = cutr = 0;
166  break ;
167  case 1:
168  switch (SW(flag)) {
169  case 0: cutl = 0; break;
170  case 1: cutl = cut; break;
171  case 2: cutl = cut ? cut-1 : 0; break;
172  case 3: cutl = (cut && cutoff > 1) ? cut-1 : cut; break;
173  default: cutl = 0; /* should never reach here */
174  }
175  switch (SE(flag)) {
176  case 0: cutr = 0; break;
177  case 1: cutr = cut; break;
178  case 2: cutr = cut ? cut-1 : 0; break;
179  case 3: cutr = (cut && cutoff > 1) ? cut-1 : cut; break;
180  default: cutr = 0; /* should never reach here */
181  }
182  break;
183  default: cutl = 0; cutr = 0; /* Should never reach here */
184  }
185  for (k = 0; k < cutl; k++) /* left part */
186  *ptr++ = !pix ;
187  for (k = 0; k < scale-cutl-cutr; k++) /* centre part */
188  *ptr++ = pix ;
189  for (k = 0; k < cutr; k++) /* right part */
190  *ptr++ = !pix ;
191  }
193  }
194  }
195  pm_close(ifd);
196  exit(0);
197 }
END END END break
Definition: bibtex-3.c:1974
long int flag
Definition: f2c.h:53
int col
Definition: gsftopk.c:443
pix
Definition: in_pcx.cpp:383
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific i
Definition: afcover.h:80
FT_Vector * vec
Definition: ftbbox.c:469
void exit()
kerning y
Definition: ttdriver.c:212
int atoi(const char *)
static unsigned char pat[8]
Definition: pkfont.c:194
#define malloc
Definition: alloca.c:91
float x
Definition: cordic.py:15
int k
Definition: otp-parser.c:70
void pm_usage(char *usage)
Definition: libpbm1.c:343
void pbm_init(int *argcP, argv)
Definition: libpbm1.c:332
FILE * pm_openr(char *name)
Definition: libpbm1.c:600
void pm_perror(char *reason)
Definition: libpbm1.c:351
void pbm_readpbminit(FILE *file, int *colsP, int *rowsP, int *formatP)
Definition: libpbm2.c:62
void pbm_readpbmrow(FILE *file, bit *bitrow, int cols, int format)
Definition: libpbm2.c:82
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_allocrow(cols)
Definition: pbm.h:36
unsigned char bit
Definition: pbm.h:9
#define PBM_WHITE
Definition: pbm.h:10
#define ARGS(alist)
Definition: pbmplus.h:235
int rows
Definition: pbmpscale.c:13
int yd_pscale[]
Definition: pbmpscale.c:20
int format
Definition: pbmpscale.c:13
int columns
Definition: pbmpscale.c:13
int corner()
#define NW(f)
Definition: pbmpscale.c:26
int xd_pscale[]
Definition: pbmpscale.c:19
sixteenbits patterns[]
Definition: pbmpscale.c:36
#define thisrow
Definition: pbmpscale.c:16
unsigned short sixteenbits
Definition: pbmpscale.c:28
#define SE(f)
Definition: pbmpscale.c:24
#define SW(f)
Definition: pbmpscale.c:25
void nextrow_pscale()
bit * inrow[3]
Definition: pbmpscale.c:14
#define NE(f)
Definition: pbmpscale.c:23
int main(int argc, argv)
Definition: pbmpscale.c:84
static unsigned char * outrow
Definition: pbmtogem.c:107
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF ptr
#define pm_close(file)
Definition: png22pnm.c:120
double scale
Definition: pnmhistmap.c:38
int r
Definition: ppmqvga.c:68
static int row
Definition: ps2pk.c:587
#define flags
Definition: zic.c:110
#define FILE
Definition: t1stdio.h:34
#define argv
Definition: xmain.c:270
#define argc
Definition: xmain.c:269