home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 2
/
goldfish_vol2_cd1.bin
/
files
/
comm
/
misc
/
elcheapofax
/
rcs
/
fax2iff.c,v
< prev
next >
Wrap
Text File
|
1993-12-21
|
8KB
|
415 lines
head 1.5;
access;
symbols
OCT93:1.5;
locks;
comment @ * @;
1.5
date 93.10.25.02.14.27; author Rhialto; state Exp;
branches;
next 1.4;
1.4
date 93.08.20.02.48.24; author Rhialto; state Exp;
branches;
next 1.3;
1.3
date 93.07.01.00.44.20; author Rhialto; state Exp;
branches;
next 1.2;
1.2
date 93.06.11.16.33.37; author Rhialto; state Exp;
branches;
next 1.1;
1.1
date 93.06.11.14.53.53; author Rhialto; state Exp;
branches;
next ;
desc
@Convert g3 files to IFF ILBM
@
1.5
log
@Make +FBOR flexible; fix RTC detection bug.
@
text
@/*
* fax2iff.c
*
* $Id: fax2iff.c,v 1.4 1993/08/20 02:48:24 Rhialto Exp $
* $Log: fax2iff.c,v $
* Revision 1.4 1993/08/20 02:48:24 Rhialto
* Add hack for auto-detecting fax bit order, and an option
* to specify it explicitly.
*
* Revision 1.3 1993/07/01 00:44:20 Rhialto
* Add CMAP and CAMG chunk. Create CAT only for multiple input files.
*
* Revision 1.2 1993/06/11 16:33:37 Rhialto
* First real RCS checkin
*
*/
#include <stdlib.h>
#include "iffp/iff.h"
#include "iffp/ilbm.h"
#include "iffp/packer.h"
#include "faxfile.h"
#ifdef DEBUG
#define debug(x) printf x
#else
#define debug(x)
#endif
void *IFFParseBase;
struct ParseInfo ParseInfo;
int verbose;
int invert;
int bitorder = -1;
int nocat;
/* Assumes malloc()ed pointer */
void
meminvert(unsigned char *d, int size)
{
while (size >= 4) {
*(long *)d ^= 0xFFFFFFFF;
d += 4;
size -= 4;
}
while (size > 0) {
*d++ ^= 0xFF;
size--;
}
}
long
dobody(FILE *faxfile, struct ParseInfo *pi)
{
unsigned char *planedata;
unsigned char *bodydata;
int planedatasize;
int bodydatasize;
int lines;
planedatasize = BytesPerRow(LINE_BITS);
bodydatasize = MaxPackedSize(BytesPerRow(LINE_BITS));
planedata = malloc(4 + planedatasize);
bodydata = malloc(4 + bodydatasize);
for (lines=0;;lines++) {
unsigned char *p, *b;
long size;
memset(planedata, 0, planedatasize);
size = fromfax(faxfile, planedata);
if (size == -1) {
debug(("size = -1 = fromfax()\n"));
break;
}
if (invert)
meminvert(planedata, planedatasize);
p = planedata;
b = bodydata;
size = PackRow(&p, &b, LINE_BITS / 8);
WriteChunkBytes(pi->iff, bodydata, size);
}
free(bodydata);
free(planedata);
return lines;
}
long
dopage(FILE *faxfile, struct ParseInfo *pi)
{
long bmhdpos;
long currpos;
int lines;
FILE *ifffile;
UBYTE cm[] = {
255, 255, 255, /* color 0: white */
0, 0, 0, /* color 1: black */
};
CamgChunk camg = { HIRES | LACE };
BitMapHeader bmhd = {
LINE_BITS, 9999, /* w, h (unknown yet) */
0, 0, /* x, y */
1, /* nPlanes */
mskNone, /* masking */
cmpByteRun1, /* compression */
0, /* reserved1 */
0, /* transparentcolor */
Y_DPI, X_DPI, /* xAspect, yAspect */
LINE_BITS, 9999, /* pageWidth, pageHeight */
};
PushChunk(pi->iff, ID_ILBM, ID_FORM, IFFSIZE_UNKNOWN);
PutCk(pi->iff, ID_CMAP, sizeof(cm), (BYTE *)cm);
PutCk(pi->iff, ID_CAMG, sizeof(camg), (BYTE *)&camg);
/*
* This is DIRTY DIRTY DIRTY!!
* We need to update the BitMapHeader later on because we
* don't know the y size yet.
*/
ifffile = (FILE *)pi->iff->iff_Stream;
bmhdpos = ftell(ifffile) + 8;
putbmhd(pi->iff, &bmhd);
PushChunk(pi->iff, ID_ILBM, ID_BODY, IFFSIZE_UNKNOWN);
lines = dobody(faxfile, pi);
debug(("lines = %d = dobody()\n", lines));
PopChunk(pi->iff); /* BODY */
PopChunk(pi->iff); /* FORM ILBM */
/* Update BMHD */
bmhd.h = lines;
bmhd.pageHeight = lines;
currpos = ftell(ifffile);
if (fseek(ifffile, bmhdpos, SEEK_SET) == 0) {
fwrite(&bmhd, sizeof(bmhd), 1, ifffile);
fseek(ifffile, currpos, SEEK_SET);
} else {
fprintf(stderr, "fseek on iff-file failed\n");
}
return 0;
}
long
dofile(char *faxname, struct ParseInfo *pi)
{
FILE *faxfile;
long error;
faxfile = fopen(faxname, "rb");
if (faxfile == NULL)
return 1;
error = faxin_open_fp(faxfile, 0, bitorder);
debug(("%d = faxin_open_fp(%s)\n", error, faxname));
while (error == 0 && faxin_begin_page(faxfile) == 0) {
debug(("0 = faxin_begin_page\n"));
error = dopage(faxfile, pi);
debug(("%d = dopage()\n", error));
}
error:
fclose(faxfile);
return error;
}
/*
* Clean up system stuff in case of exit
*/
void
cleanup(void)
{
if (IFFParseBase) {
if (ParseInfo.iff) {
closeifile(&ParseInfo);
FreeIFF(ParseInfo.iff);
}
CloseLibrary(IFFParseBase);
}
}
int
main(int argc, char **argv)
{
struct IFFHandle *iff;
char *outfile = "fax.iff";
extern char *optarg;
extern int optind;
extern int getopt(int, char **, char *);
int errflg = 0;
int c;
while ((c = getopt(argc, argv, "1b:io:v")) != -1) {
switch (c) {
case '1':
nocat = 1;
break;
case 'b':
bitorder = *optarg ? atoi(optarg) : 1;
break;
case 'i':
invert = 1;
break;
case 'o':
outfile = optarg;
break;
case 'v':
verbose = TRUE;
break;
case '?':
errflg++;
break;
}
}
if (errflg || optind >= argc) {
printf(
"Usage: fax2iff [-o iff-file (fax.iff)] [-v] [-i (invert)] [-1]\n"
" [-b0/1 (bitorder)] fax-files\n");
exit(EXIT_FAILURE);
}
atexit(cleanup);
IFFParseBase = OpenLibrary("iffparse.library", 0);
if (IFFParseBase == NULL) {
printf("Needs iffparse.library.\n");
exit(10);
}
if (optind == argc - 1)
nocat = !nocat;
iff = AllocIFF();
ParseInfo.iff = iff;
openifile(&ParseInfo, outfile, IFFF_WRITE);
if (!nocat)
PushChunk(iff, ID_ILBM, ID_CAT, IFFSIZE_UNKNOWN);
while (optind < argc) {
debug(("calling dofile '%s'\n", argv[optind]));
dofile(argv[optind], &ParseInfo);
optind++;
if (nocat)
break;
}
if (!nocat)
PopChunk(iff); /* CAT */
closeifile(&ParseInfo);
FreeIFF(iff);
ParseInfo.iff = NULL;
/*CloseLibrary(IFFParseBase);*/
}
@
1.4
log
@Add hack for auto-detecting fax bit order, and an option
to specify it explicitly.
@
text
@d4 1
a4 1
* $Id: fax2iff.c,v 1.3 1993/07/01 00:44:20 Rhialto Exp $
d6 4
d35 1
a35 1
int reverse = -1;
d160 1
a160 1
error = faxin_open_fp(faxfile, 0, reverse);
d201 1
a201 1
while ((c = getopt(argc, argv, "1io:r:v")) != -1) {
d206 3
a214 3
case 'r':
reverse = *optarg ? atoi(optarg) : 1;
break;
d227 1
a227 1
" [-r0/1 (reverse bits)] fax-files\n");
@
1.3
log
@Add CMAP and CAMG chunk. Create CAT only for multiple input files.
@
text
@d4 1
a4 1
* $Id: fax2iff.c,v 1.2 1993/06/11 16:33:37 Rhialto Exp $
d6 3
d21 6
d31 1
d69 2
a70 1
if (size == -1)
d72 1
d127 1
d156 2
a157 1
error = faxin_open_fp(faxfile, 0);
d160 1
d162 1
d197 1
a197 1
while ((c = getopt(argc, argv, "1io:v")) != -1) {
d208 3
d222 2
a223 1
"Usage: fax2iff [-o iff-file (fax.iff)] [-v] [-i (invert)] [-1] fax-files\n");
d231 1
a231 1
printf("Needs iffparse.\n");
d244 1
d252 1
a252 1
PopChunk(iff); /* CAT */
@
1.2
log
@First real RCS checkin
@
text
@d4 5
a8 2
* $Id$
* $Log$
d22 1
d82 5
d100 2
d181 1
a181 1
while ((c = getopt(argc, argv, "io:v")) != -1) {
d183 3
d203 1
a203 1
"Usage: fax2iff [-o iff-file (fax.iff)] [-v] [-i (invert)] fax-files\n");
d215 2
d220 2
a221 1
PushChunk(iff, ID_ILBM, ID_CAT, IFFSIZE_UNKNOWN);
d226 2
d230 2
a231 1
PopChunk(iff);
@
1.1
log
@Initial revision
@
text
@d3 3
@