| 1 |
/* pbmtopi3.c - read a PBM image and produce a Atari Degas .pi3 file |
| 2 |
** |
| 3 |
** Module created from other pbmplus tools by David Beckemeyer. |
| 4 |
** |
| 5 |
** Copyright (C) 1988 by David Beckemeyer and Jef Poskanzer. |
| 6 |
** |
| 7 |
** Permission to use, copy, modify, and distribute this software and its |
| 8 |
** documentation for any purpose and without fee is hereby granted, provided |
| 9 |
** that the above copyright notice appear in all copies and that both that |
| 10 |
** copyright notice and this permission notice appear in supporting |
| 11 |
** documentation. This software is provided "as is" without express or |
| 12 |
** implied warranty. |
| 13 |
*/ |
| 14 |
|
| 15 |
/* Output file should always be 32034 bytes. */ |
| 16 |
|
| 17 |
#include <stdio.h> |
| 18 |
#include "pm_c_util.h" |
| 19 |
#include "pbm.h" |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
static void |
| 24 |
putinit(FILE * const ofP) { |
| 25 |
|
| 26 |
unsigned int i; |
| 27 |
|
| 28 |
pm_writebigshort(ofP, (short) 2); |
| 29 |
pm_writebigshort(ofP, (short) 0x777); |
| 30 |
|
| 31 |
for (i = 1; i < 16; ++i) { |
| 32 |
pm_writebigshort (ofP, (short) 0); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
int |
| 39 |
main(int argc, const char ** argv) { |
| 40 |
|
| 41 |
unsigned int const outRows = 400; |
| 42 |
unsigned int const outCols = 640; |
| 43 |
unsigned int const outColByteCt = pbm_packed_bytes(outCols); |
| 44 |
|
| 45 |
FILE * ifP; |
| 46 |
|
| 47 |
int inRows, inCols, format; |
| 48 |
unsigned int row; |
| 49 |
unsigned int inColByteCt; |
| 50 |
unsigned int i; |
| 51 |
bit * bitrow; |
| 52 |
|
| 53 |
pm_proginit(&argc, argv); |
| 54 |
|
| 55 |
if (argc-1 < 1) |
| 56 |
ifP = stdin; |
| 57 |
else { |
| 58 |
ifP = pm_openr(argv[1]); |
| 59 |
|
| 60 |
if (argc-1 > 1) |
| 61 |
pm_error("Too many arguments. The only possible argument " |
| 62 |
"is the input file name"); |
| 63 |
} |
| 64 |
|
| 65 |
pbm_readpbminit(ifP, &inCols, &inRows, &format); |
| 66 |
|
| 67 |
inColByteCt = pbm_packed_bytes(inCols); |
| 68 |
|
| 69 |
bitrow = pbm_allocrow_packed(MAX(outCols, inCols)); |
| 70 |
|
| 71 |
/* Add padding to round cols up to 640 */ |
| 72 |
for (i = inColByteCt; i < outColByteCt; ++i) |
| 73 |
bitrow[i] = 0x00; |
| 74 |
|
| 75 |
putinit(stdout); |
| 76 |
|
| 77 |
for (row = 0; row < MIN(inRows, outRows); ++row) { |
| 78 |
pbm_readpbmrow_packed(ifP, bitrow, inCols, format); |
| 79 |
pbm_cleanrowend_packed(bitrow, inCols); |
| 80 |
fwrite (bitrow, outColByteCt, 1, stdout); |
| 81 |
} |
| 82 |
pm_close(ifP); |
| 83 |
|
| 84 |
if (row < outRows) { |
| 85 |
unsigned int i; |
| 86 |
|
| 87 |
/* Clear entire row */ |
| 88 |
for (i = 0; i < outColByteCt; ++i) |
| 89 |
bitrow[i] = 0x00; |
| 90 |
|
| 91 |
while (row++ < outRows) |
| 92 |
fwrite(bitrow, outColByteCt, 1, stdout); |
| 93 |
} |
| 94 |
|
| 95 |
pbm_freerow_packed(bitrow); |
| 96 |
|
| 97 |
return 0; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|