Debian Codegraph @

converter/ppm/sldtoppm.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2
3 Convert an AutoCAD slide (.sld) file to PPM format
4
5 An AutoCAD slide is a compressed sequence of vectors and filled
6 polygons. The ppmdraw package is used to scan convert these
7 geometrical objects into a portable pixmap.
8
9 Author:
10 John Walker
11 Autodesk SA
12 Avenue des Champs-Montants 14b
13 CH-2074 MARIN
14 Switzerland
15 Usenet: [email protected]
16 Fax: 038/33 88 15
17 Voice: 038/33 76 33
18
19 Permission to use, copy, modify, and distribute this software and
20 its documentation for any purpose and without fee is hereby
21 granted, without any conditions or restrictions. This software is
22 provided "as is" without express or implied warranty.
23
24 */
25
26 #include <limits.h>
27 #include <assert.h>
28 #include <string.h>
29 #include <math.h>
30
31 #include "pm_c_util.h"
32 #include "ppm.h"
33 #include "ppmdraw.h"
34 #include "nstring.h"
35
36 #include "autocad.h" /* AutoCAD standard color assignments */
37
38
39 /* Define a variable type accepting numbers -127 <= n <= 127. But note
40 that we still expect it to act UNSIGNED.
41 */
42
43 #define smallint unsigned char /* Small integers */
44
45 #define EOS '\0'
46
47 struct spoint {
48 /*----------------------------------------------------------------------------
49 A screen point
50 -----------------------------------------------------------------------------*/
51 int x, y;
52 };
53
54 struct spolygon {
55 /*----------------------------------------------------------------------------
56 A screen polygon
57 -----------------------------------------------------------------------------*/
58 int npoints; /* Number of points in polygon */
59 int fill; /* Fill type */
60 struct spoint pt[11]; /* The points */
61 };
62
63 struct svector {
64 /*----------------------------------------------------------------------------
65 A screen vector
66 -----------------------------------------------------------------------------*/
67 struct spoint f; /* From point */
68 struct spoint t; /* To point */
69 };
70
71 typedef void (slvecfn)(struct svector * vec, int color);
72 typedef void (slfloodfn)(struct spolygon * poly, int color);
73
74
75 static unsigned long const pixmaxval = 255; /* Largest pixel value */
76
77 static int ixdots, iydots; /* Screen size in dots */
78 static FILE * slfile; /* Slide file descriptor */
79 static bool blither; /* Dump slide file information ? */
80 static bool info; /* Print header information */
81 static pixel ** pixels; /* Pixel map */
82 static int pixcols, pixrows; /* Pixel map size */
83
84 struct slhead {
85 char slh[17]; /* Primate-readable header */
86 char sntype; /* Machine type (for number compat) */
87 char slevel; /* Format type */
88 short sxdots, sydots; /* Display X, Y dots */
89 double sdsar; /* Display aspect ratio */
90 short shwfill; /* Display hardware fill type */
91 char spad; /* Pad to even byte length */
92 };
93
94 static struct slhead slfrof; /* Slide file header */
95 static long xfac, yfac; /* Aspect ratio scale factors */
96
97 static bool sdrawkcab;
98 /* Slide drawing kinematic conversion of ass-backwards data flag */
99
100
101
102 static int
103 extend(unsigned char const ch) {
104 /*----------------------------------------------------------------------------
105 Turn a smallint into an int with sign extension, whether
106 or not that happens automatically.
107 -----------------------------------------------------------------------------*/
108 return ((int) ((ch & 0x80) ? (ch | ~0xFF) : ch));
109 }
110
111
112
113 static int
114 sli(void) {
115 /*----------------------------------------------------------------------------
116 Read and return a word from the slide file.
117 -----------------------------------------------------------------------------*/
118 short wd;
119
120 if (fread(&wd, sizeof wd, 1, slfile) != 1) {
121 pm_error("error reading slide file");
122 } else {
123 if (sdrawkcab) {
124 wd = ((wd >> 8) & 0xFF) | (wd << 8);
125 }
126 }
127 return wd;
128 }
129
130
131
132 static int
133 slib(void) {
134 /*----------------------------------------------------------------------------
135 Read and return a byte from the slide file.
136 -----------------------------------------------------------------------------*/
137 unsigned char ch;
138
139 if (fread(&ch, sizeof(ch), 1, slfile) != 1) {
140 pm_error("error reading slide file");
141 }
142 return extend(ch);
143 }
144
145
146
147 static void
148 vscale(int * const px,
149 int * const py) {
150 /*----------------------------------------------------------------------------
151 Scale screen coordinates for mismatched display.
152 -----------------------------------------------------------------------------*/
153 *px = (((unsigned) *px) * xfac) >> 16;
154 *py = (((unsigned) *py) * yfac) >> 16;
155 }
156
157
158
159 static void
160 upcase(const char * const sname,
161 char * const uname) {
162
163 unsigned int i;
164 const char * ip;
165
166 for (i = 0, ip = sname; i < 31; ++i) {
167 char const ch = *ip++;
168
169 if (ch != EOS)
170 uname[i] = islower(ch) ? toupper(ch) : ch;
171 }
172 uname[i] = EOS;
173 }
174
175
176
177 static void
178 skipBytes(FILE * const fileP,
179 unsigned int const count) {
180
181 unsigned int i;
182
183 for (i = 0; i < count; ++i)
184 getc(fileP);
185 }
186
187
188
189 static void
190 scanDirectory(FILE * const slFileP,
191 long const dirPos,
192 bool const dirOnly,
193 const char * const uname,
194 bool * const foundP) {
195 /*----------------------------------------------------------------------------
196 Scan the directory at the current position in *slFileP, either listing
197 the directory ('dirOnly' true) or searching for a slide named
198 'uname' ('dirOnly' false).
199
200 'dirPos' is the offset in the file of the directory, i.e. the current
201 position of *slFileP.
202
203 In the latter case, return as *foundP whether the slide name is there.
204 -----------------------------------------------------------------------------*/
205 bool found;
206 bool eof;
207 long pos;
208 unsigned char libent[36];
209
210 for (found = false, eof = false, pos = dirPos; !found && !eof; ) {
211 size_t readCt;
212 readCt = fread(libent, 36, 1, slFileP);
213 if (readCt != 1)
214 eof = true;
215 else {
216 /* The directory entry is 32 bytes of NUL-terminated slide name
217 followed by 4 bytes of offset of the next directory entry.
218 */
219 const char * const slideName = (const char *)(&libent[0]);
220 if (pm_strnlen(slideName, 32) == 32)
221 pm_error("Invalid input: slide name field is not "
222 "nul-terminated");
223 else {
224 if (strlen(slideName) == 0)
225 eof = true;
226 else {
227 pos += 36;
228 if (dirOnly) {
229 pm_message(" %s", slideName);
230 } else if (streq(slideName, uname)) {
231 long const dpos =
232 (((((libent[35] << 8) | libent[34]) << 8) |
233 libent[33]) << 8) | libent[32];
234
235 if ((slFileP == stdin) ||
236 (fseek(slFileP, dpos, 0) == -1)) {
237
238 skipBytes(slFileP, dpos - pos);
239 }
240 found = true;
241 }
242 }
243 }
244 }
245 }
246 *foundP = found;
247 }
248
249
250
251 static void
252 slidefind(const char * const slideName,
253 bool const dirOnly,
254 bool const ucasen) {
255 /*----------------------------------------------------------------------------
256 Find a slide in a library or, if DIRONLY is nonzero, print a directory
257 listing of the library. If UCASEN is nonzero, the requested slide name is
258 converted to upper case.
259 -----------------------------------------------------------------------------*/
260 char uname[32]; /* upper case translation of 'slideName' */
261 char header[32]; /* (supposed) header read from file */
262 bool found;
263
264 if (dirOnly)
265 pm_message("Slides in library:");
266 else {
267 upcase(slideName, uname);
268 }
269
270 /* Read slide library header and verify. */
271
272 if ((fread(header, 32, 1, slfile) != 1) ||
273 (!STRSEQ(header, "AutoCAD Slide Library 1.0\r\n\32"))) {
274 pm_error("not an AutoCAD slide library file.");
275 }
276
277 scanDirectory(slfile, 32, dirOnly, ucasen ? uname : slideName, &found);
278
279 if (!found && !dirOnly)
280 pm_error("slide '%s' not in library.", slideName);
281 }
282
283
284
285 static slvecfn draw;
286
287 static void
288 draw(struct svector * vec,
289 int color) {
290 /*----------------------------------------------------------------------------
291 Draw a vector in the given AutoCAD color.
292 -----------------------------------------------------------------------------*/
293 pixel rgbcolor;
294
295 if (blither) {
296 pm_message("Vector (%d, %d) - (%d, %d) Color %d",
297 vec->f.x, vec->f.y, vec->t.x, vec->t.y, color);
298 }
299 assert(vec->f.x >= 0 && vec->f.x < pixcols);
300 assert(vec->f.y >= 0 && vec->f.y < pixrows);
301 assert(vec->t.x >= 0 && vec->t.x < pixcols);
302 assert(vec->t.y >= 0 && vec->t.y < pixrows);
303 PPM_ASSIGN(rgbcolor,
304 acadcol[color][0], acadcol[color][1], acadcol[color][2]);
305 ppmd_line(pixels, pixcols, pixrows, pixmaxval,
306 vec->f.x, iydots - vec->f.y, vec->t.x, iydots - vec->t.y,
307 PPMD_NULLDRAWPROC,
308 (char *) &rgbcolor);
309 }
310
311
312
313 static slfloodfn flood;
314
315 static void
316 flood(struct spolygon * const poly,
317 int const color) {
318 /*----------------------------------------------------------------------------
319 Draw a filled polygon.
320 -----------------------------------------------------------------------------*/
321 unsigned int i;
322 struct fillobj * handle;
323 pixel rgbcolor;
324
325 handle = ppmd_fill_create();
326
327 if (blither) {
328 unsigned int i;
329 pm_message("Polygon: %d points, fill type %d, color %d",
330 poly->npoints, poly->fill, color);
331 for (i = 0; i < poly->npoints; i++) {
332 pm_message(" Point %d: (%d, %d)", i + 1,
333 poly->pt[i].x, poly->pt[i].y);
334 }
335 }
336
337 PPM_ASSIGN(rgbcolor,
338 acadcol[color][0], acadcol[color][1], acadcol[color][2]);
339 for (i = 0; i < poly->npoints; i++) {
340 assert(poly->pt[i].x >= 0 && poly->pt[i].x < pixcols);
341 assert(poly->pt[i].y >= 0 && poly->pt[i].y < pixrows);
342 ppmd_line(pixels, pixcols, pixrows, pixmaxval,
343 poly->pt[i].x, iydots - poly->pt[i].y,
344 poly->pt[(i + 1) % poly->npoints].x,
345 iydots - poly->pt[(i + 1) % poly->npoints].y,
346 ppmd_fill_drawproc, handle);
347 }
348 ppmd_fill(pixels, pixcols, pixrows, pixmaxval,
349 handle, PPMD_NULLDRAWPROC, (char *) &rgbcolor);
350
351 ppmd_fill_destroy(handle);
352 }
353
354
355
356 static void
357 computeSize(struct slhead const slfrof,
358 bool const wantAdjust,
359 double const uscale,
360 int const sxsize,
361 int const sysize,
362 int * const ixdotsP,
363 int * const iydotsP,
364 double * const dsarP) {
365 /*----------------------------------------------------------------------------
366 -----------------------------------------------------------------------------*/
367 double const originalDsar = ((double) slfrof.sxdots) / slfrof.sydots;
368
369 double ixdots, iydots;
370 /* Algorithmic variables -- value changes as algorithm progresses */
371 bool adjusted;
372
373 /*
374 If the display aspect ratio indicates that the pixels on the sending
375 screen were not square, adjust the size of the generated bitmap to
376 correct the aspect ratio to square the pixels.
377
378 We always correct the aspect ratio by adjusting the width of the image.
379 This guarantees that output from the SHADE command, which is essentially
380 scan-line data written in vector form, will not be corrupted.
381 */
382
383 if (fabs(slfrof.sdsar - originalDsar) > 0.0001) {
384 if (wantAdjust) {
385 ixdots = slfrof.sxdots * (slfrof.sdsar / originalDsar);
386 iydots = slfrof.sydots;
387 *dsarP = ixdots / iydots;
388 adjusted = true;
389 } else {
390 pm_message("Warning - pixels on source screen were non-square. "
391 "Specifying -adjust will correct image width "
392 "to compensate.");
393 ixdots = slfrof.sxdots;
394 iydots = slfrof.sydots;
395 *dsarP = slfrof.sdsar;
396 adjusted = false;
397 }
398 } else {
399 /* Source pixels were square. */
400 ixdots = slfrof.sxdots;
401 iydots = slfrof.sydots;
402 *dsarP = slfrof.sdsar;
403 adjusted = false;
404 }
405
406 if (uscale > 0) {
407 /* There is a uniform scale factor specified. Apply it. */
408 ixdots *= uscale;
409 iydots *= uscale;
410 }
411
412 /* If the image is to be stretched to a given width, set the
413 output image sizes accordingly. If only a height or width is
414 given, scale the other direction proportionally to preserve the
415 aspect ratio.
416 */
417
418 if (sxsize > 0) {
419 if (sysize > 0)
420 iydots = sysize - 1;
421 else {
422 double const stretchFactor = (sxsize - 1) / ixdots;
423 iydots = iydots * stretchFactor;
424 }
425 ixdots = sxsize - 1;
426 } else if (sysize > 0) {
427 if (sxsize > 0)
428 ixdots = sxsize - 1;
429 else {
430 double const stretchFactor = (sysize - 1) / iydots;
431 ixdots = ixdots * stretchFactor;
432 }
433 iydots = sysize - 1;
434 }
435
436 if (ixdots > INT_MAX-10)
437 pm_error("width is uncomputable large (%f dots)", ixdots);
438 else
439 *ixdotsP = ROUND(ixdots);
440 if (iydots > INT_MAX-10)
441 pm_error("height is uncomputable large (%f dots)", iydots);
442 else
443 *iydotsP = ROUND(iydots);
444
445 if (adjusted) {
446 pm_message(
447 "Resized from %dx%d to %dx%d to correct pixel aspect ratio.",
448 slfrof.sxdots + 1, slfrof.sydots + 1, *ixdotsP + 1, *iydotsP + 1);
449 }
450 }
451
452
453
454 static void
455 slider(slvecfn slvec,
456 slfloodfn slflood,
457 bool const wantAdjust,
458 double const uscale,
459 int const sxsize,
460 int const sysize) {
461 /*----------------------------------------------------------------------------
462 Read slide file. This is called with the name of the file to be read and
463 function pointers to the routines which process vectors and polygon fill
464 requests respectively.
465 -----------------------------------------------------------------------------*/
466 int i, rescale;
467 unsigned char ubfr[4]; /* Utility character buffer */
468 int lx, ly; /* Last x and y point */
469 int slx, sly; /* Last x and y scaled screen point */
470 struct svector vec; /* Screen vector */
471 struct spolygon poly; /* Screen polygon */
472 unsigned short cw; /* Control word */
473 double dsar; /* Screen aspect ratio */
474 long ldsar; /* Scaled long DSAR */
475 short rtest; /* Value to test byte reversal */
476 short btest = 0x1234; /* Value to test byte-reversal */
477 static struct slhead slhi = /* Master slide header sample */
478 {"AutoCAD Slide\r\n\32", 86,2, 0,0, 0.0, 0};
479 int curcolor = 7; /* Current vector color */
480 pixel rgbcolor; /* Pixel used to clear pixmap */
481
482 lx = ly = 32000;
483
484 /* Process the header of the slide file. */
485
486 sdrawkcab = false; /* Initially guess byte order is OK */
487 fread(slfrof.slh, 17, 1, slfile);
488 fread(&slfrof.sntype, sizeof(char), 1, slfile);
489 fread(&slfrof.slevel, sizeof(char), 1, slfile);
490 fread(&slfrof.sxdots, sizeof(short), 1, slfile);
491 fread(&slfrof.sydots, sizeof(short), 1, slfile);
492 fread(ubfr, 4, 1, slfile);
493 fread(&slfrof.shwfill, sizeof(short), 1, slfile);
494 fread(&rtest, sizeof rtest, 1, slfile);
495
496 /* Verify that slide format is compatible with this program. */
497
498 if (!STRSEQ(slfrof.slh, slhi.slh))
499 pm_error("this is not an AutoCAD slide file.");
500
501 /* Verify that the number format and file level in the header are
502 compatible. All slides written by versions of AutoCAD released
503 since September of 1987 are compatible with this format. */
504
505 if ((slfrof.sntype != slhi.sntype) || (slfrof.slevel != slhi.slevel))
506 pm_error("incompatible slide file format");
507
508 /* Build SDSAR value from long scaled version. */
509
510 ldsar = 0L;
511 for (i = 3; i >= 0; --i)
512 ldsar = (ldsar << 8) | ubfr[i];
513 slfrof.sdsar = ((double) ldsar) / 1E7;
514
515 /* Examine the byte order test value. If it's backwards, set the
516 byte-reversal flag and correct all of the values we've read in
517 so far.
518 */
519
520 if (btest != rtest) {
521 sdrawkcab = true;
522 #define rshort(x) x = ((x >> 8) & 0xFF) | (x << 8)
523 rshort(slfrof.sxdots);
524 rshort(slfrof.sydots);
525 rshort(slfrof.shwfill);
526 #undef rshort
527 }
528
529 /* Dump the header if we're blithering. */
530
531 if (blither || info) {
532 pm_message("Slide file type %d, level %d, hwfill type %d.",
533 slfrof.sntype, slfrof.slevel, slfrof.shwfill);
534 pm_message("Original screen size %dx%d, aspect ratio %.3f.",
535 slfrof.sxdots + 1, slfrof.sydots + 1, slfrof.sdsar);
536 pm_message("Byte order is %s.",
537 sdrawkcab ? "being reversed" : "the same");
538 }
539
540 computeSize(slfrof, wantAdjust, uscale, sxsize, sysize,
541 &ixdots, &iydots, &dsar);
542
543 /* Allocate image buffer and clear it to black. */
544
•545 overflow_add(ixdots, 1);
546 overflow_add(iydots, 1);
547 pixcols = ixdots + 1;
548 pixrows = iydots + 1;
549 pixels = ppm_allocarray(pixcols, pixrows);
550 PPM_ASSIGN(rgbcolor, 0, 0, 0);
551 ppmd_filledrectangle(pixels, pixcols, pixrows, pixmaxval, 0, 0,
552 pixcols, pixrows, PPMD_NULLDRAWPROC,
553 (char *) &rgbcolor);
554
555 if ((rescale = slfrof.sxdots != ixdots ||
556 slfrof.sydots != iydots ||
557 slfrof.sdsar != dsar) != 0) {
558
559 /* Rescale all coords. so they'll look (more or less)
560 right on this display.
561 */
562
563 xfac = (ixdots + 1) * 0x10000L;
564 xfac /= (long) (slfrof.sxdots + 1);
565 yfac = (iydots + 1) * 0x10000L;
566 yfac /= (long) (slfrof.sydots + 1);
567 if (dsar < slfrof.sdsar) {
568 yfac = yfac * dsar / slfrof.sdsar;
569 } else {
570 xfac = xfac * slfrof.sdsar / dsar;
571 }
572 }
573
574 poly.npoints = 0; /* No flood in progress. */
575
576 while ((cw = sli()) != 0xFC00) {
577 switch (cw & 0xFF00) {
578 case 0xFB00: /* Short vector compressed */
579 vec.f.x = lx + extend(cw & 0xFF);
580 vec.f.y = ly + slib();
581 vec.t.x = lx + slib();
582 vec.t.y = ly + slib();
583 lx = vec.f.x;
584 ly = vec.f.y;
585 if (rescale) {
586 vscale(&vec.f.x, &vec.f.y);
587 vscale(&vec.t.x, &vec.t.y);
588 }
589 (*slvec)(&vec, curcolor);/* Draw vector on screen */
590 slx = vec.f.x; /* Save scaled point */
591 sly = vec.f.y;
592 break;
593
594 case 0xFC00: /* End of file */
595 break;
596
597 case 0xFD00: /* Flood command */
598 vec.f.x = sli();
599 vec.f.y = sli();
600 if ((int) vec.f.y < 0) { /* start or end */
601 if (poly.npoints != 0) { /* end? */
602 if (poly.npoints > 2 && poly.npoints < 11) {
603 (*slflood)(&poly, curcolor);
604 } else {
605 pm_error("Bad polygon vertex count (%d)",
606 poly.npoints);
607 }
608 poly.npoints = 0;
609 } else {
610 poly.fill = -vec.f.y; /* Start */
611 }
612 } else { /* Polygon vertex */
613 if (poly.npoints < 10) {
614 if (rescale) {
615 vscale(&vec.f.x, &vec.f.y);
616 }
617 poly.pt[poly.npoints].x = vec.f.x;
618 poly.pt[poly.npoints].y = vec.f.y;
619 }
620 poly.npoints++;
621 }
622 break;
623
624 case 0xFE00: /* Common endpoint compressed */
625 vec.f.x = lx + extend(cw & 0xFF);
626 vec.f.y = ly + slib();
627 lx = vec.f.x;
628 ly = vec.f.y;
629 vec.t.x = slx;
630 vec.t.y = sly;
631 if (rescale) {
632 vscale(&vec.f.x, &vec.f.y);
633 }
634 (*slvec)(&vec, curcolor);/* Draw vector */
635 slx = vec.f.x; /* Save scaled point */
636 sly = vec.f.y;
637 break;
638
639 case 0xFF00: /* Change color */
640 curcolor = cw & 0xFF;
641 break;
642
643 default: /* Coordinates */
644 lx = vec.f.x = cw;
645 ly = vec.f.y = sli();
646 vec.t.x = sli();
647 vec.t.y = sli();
648 if (rescale) {
649 vscale(&vec.f.x, &vec.f.y);
650 vscale(&vec.t.x, &vec.t.y);
651 }
652 (*slvec)(&vec, curcolor);
653 slx = vec.f.x; /* Save scaled point */
654 sly = vec.f.y;
655 break;
656 }
657 }
658 }
659
660
661
662 int
663 main(int argc,
664 const char * argv[]) {
665
666 int argn;
667 const char * const usage = "[-verbose] [-info] [-adjust] [-scale <s>]\n\
668 [-dir] [-lib|-Lib <name>]\n\
669 [-xsize|-width <x>] [-ysize|-height <y>] [sldfile]";
670 bool dironly;
671 bool hgtspec;
672 bool widspec;
673 bool scalespec;
674 bool ucasen;
675 bool adjust; /* Adjust to correct aspect ratio ? */
676 double uscale; /* Uniform scale factor */
677 int sxsize, sysize; /* Scale to X, Y size ? */
678 const char * slobber; /* Slide library item */
679
680 pm_proginit(&argc, argv);
681 argn = 1;
682
683 slobber = NULL;
684 dironly = false;
685 hgtspec = false;
686 widspec = false;
687 scalespec = false;
688 ucasen = false;
689 blither = false;
690 info = false;
691 adjust = false;
692 uscale = -1.0;
693 sxsize = -1;
694 sysize = -1;
695
696 while (argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0') {
697 if (pm_keymatch(argv[argn], "-verbose", 2)) {
698 blither = true;
699 } else if (pm_keymatch(argv[argn], "-adjust", 2)) {
700 adjust = true;
701 } else if (pm_keymatch(argv[argn], "-dir", 2)) {
702 dironly = true;
703 } else if (pm_keymatch(argv[argn], "-info", 2)) {
704 info = true;
705 } else if (pm_keymatch(argv[argn], "-lib", 2)) {
706 if (slobber)
707 pm_error("already specified a library item");
708 ucasen = argv[argn][1] != 'L';
709 argn++;
710 if (argn == argc) {
711 pm_usage(usage);
712 }
713 slobber = argv[argn];
714 } else if (pm_keymatch(argv[argn], "-scale", 2)) {
715 if (scalespec) {
716 pm_error("already specified a scale factor");
717 }
718 argn++;
719 if ((argn == argc) || (sscanf(argv[argn], "%lf", &uscale) != 1))
720 pm_usage(usage);
721 if (uscale <= 0.0) {
722 pm_error("scale factor must be greater than 0");
723 }
724 scalespec = true;
725 } else if (pm_keymatch(argv[argn], "-xsize", 2) ||
726 pm_keymatch(argv[argn], "-width", 2)) {
727 if (widspec) {
728 pm_error("already specified a width/xsize");
729 }
730 argn++;
731 if ((argn == argc) || (sscanf(argv[argn], "%d", &sxsize) != 1))
732 pm_usage(usage);
733 widspec = true;
734 } else if (pm_keymatch(argv[argn], "-ysize", 2) ||
735 pm_keymatch(argv[argn], "-height", 2)) {
736 if (hgtspec) {
737 pm_error("already specified a height/ysize");
738 }
739 argn++;
740 if ((argn == argc) || (sscanf(argv[argn], "%d", &sysize) != 1))
741 pm_usage(usage);
742 hgtspec = true;
743 } else {
744 pm_usage(usage);
745 }
746 argn++;
747 }
748
749 /* If a file name is specified, open it. Otherwise read from
750 standard input.
751 */
752
753 if (argn < argc) {
754 slfile = pm_openr(argv[argn]);
755 argn++;
756 } else {
757 slfile = stdin;
758 }
759
760 if (argn != argc) { /* Extra bogus arguments ? */
761 pm_usage(usage);
762 }
763
764 /* If we're extracting an item from a slide library, position the
765 input stream to the start of the chosen slide.
766 */
767
768 if (dironly || slobber)
769 slidefind(slobber, dironly, ucasen);
770
771 if (!dironly) {
772 slider(draw, flood, adjust, uscale, sxsize, sysize);
773 ppm_writeppm(stdout, pixels, pixcols, pixrows, pixmaxval, 0);
774 }
775 pm_close(slfile);
776 pm_close(stdout);
777
778 return 0;
779 }
780
781
782