* Copyright 1992 DigiBoard, Inc. All rights reserved
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted.
* This software is provided "as is" without express or implied warranty.
/* DigiBoard, Inc. DigiFAX driver for Ghostscript. */
# define PROTO_ARGS(X) ()
/*************************************************************************
* Format of page header in PC Research "group_3" FAX file
* Note that all "shorts" are stored LSB in lowest byte address
*************************************************************************/
#define FAXMAGIC "\000PC Research, Inc\000\000\000\000\000\000"
/*24*/ short pages
; /* Number of pages in file */
/*28*/ char msbfirst
; /* Coding used in file for codewords */
/* MUST be set to 1, meaning the codewords */
/* are filled starting with the most */
/*29*/ char hires
; /* Set to 1 for Hi resolution, else 0 */
/*30*/ char dirty
; /* File may contain T.4 errors if 1, else 0 */
/* e.g. it was received by FAX, not created */
/*32*/ short reserved
[12];
char jthires
; /* Set to 0x40 for Hi resolution, else 0 */
* This appears before each page in a FAX file
/**********************************************************************/
* Generic fax output library
/**********************************************************************/
private FAXOUT
*faxout_open
PROTO_ARGS((char *));
private FAXOUT
*faxout_open_fp
PROTO_ARGS((FILE *));
private int faxout_begin_page
PROTO_ARGS((FAXOUT
*, int));
private int faxout_eolcode
PROTO_ARGS((FAXOUT
*));
private int faxout_end_page
PROTO_ARGS((FAXOUT
*));
private int faxout_close
PROTO_ARGS((FAXOUT
*));
private unsigned short fax_ushort
PROTO_ARGS((unsigned short));
private void putwhitespan();
private void putblackspan();
private void flushbits();
/*************************************************************************
Redefine the device descriptor
*************************************************************************/
struct gx_device_dfax_s
{
typedef struct gx_device_dfax_s gx_device_dfax
;
/* Too bad the prn_device() macro doesn't let you specify the
* size of the gx_device structure -- we have to repeat it here
#define generic_prn_device(Struct, procs, dev_name, width_10ths, height_10ths, x_dpi, y_dpi, l_margin, b_margin, r_margin, t_margin, color_bits, print_page) {\
(int)((long)width_10ths * x_dpi / 10), /* width */\
(int)((long)height_10ths * y_dpi / 10), /* height */\
l_margin, b_margin, r_margin, t_margin,\
{ (color_bits > 1 ? 3 : 1), /* num_components */\
((color_bits > 1) & (color_bits < 8) ? 8 : color_bits), /* depth */\
(color_bits >= 8 ? 255 : 1), /* max_gray */\
(color_bits >= 8 ? 255 : color_bits > 1 ? 1 : 0), /* max_rgb */\
(color_bits >= 8 ? 5 : 2), /* dither_gray */\
(color_bits >= 8 ? 5 : color_bits > 1 ? 2 : 0), /* dither_rgb */\
0, /* not initialized yet */\
/* The device descriptor */
#define LINE_SIZE ((X_DPI * 85 / 10 + 7) / 8) /* bytes per line */
private dev_proc_open_device(dfax_prn_open
);
private dev_proc_print_page(dfax_print_page
);
private dev_proc_close_device(dfax_prn_close
);
gx_device_procs dfax_std_procs
=
prn_procs(dfax_prn_open
, gdev_prn_output_page
, dfax_prn_close
);
gx_device_dfax gs_dfaxhigh_device
=
85, /* width_10ths, 8.5" */
110, /* height_10ths, 11" */
gx_device_dfax gs_dfaxlow_device
=
85, /* width_10ths, 8.5" */
110, /* height_10ths, 11" */
/*************************************************************************
*************************************************************************/
dfax_prn_open(gx_device
*pdev
)
gx_device_dfax
*ddev
= (gx_device_dfax
*) pdev
;
rc
= gdev_prn_open(pdev
);
ddev
->fax
= faxout_open_fp(ddev
->file
);
dfax_print_page(gx_device_printer
*pdev
, FILE *prn_stream
)
gx_device_dfax
*ddev
= (gx_device_dfax
*) pdev
;
char data
[LINE_SIZE
+ 4];
/* For some odd reason, the file isn't open until now */
faxout_begin_page(fax
, ddev
->y_pixels_per_inch
> 120);
line_size
= gdev_mem_bytes_per_scan_line( (gx_device
*) pdev
);
for ( lnum
= 0; lnum
< pdev
->height
; lnum
++ )
gdev_prn_copy_scan_lines(pdev
, lnum
, (byte
*)data
, line_size
);
dfax_prn_close(gx_device
*pdev
)
gx_device_dfax
*ddev
= (gx_device_dfax
*) pdev
;
unsigned short p
= fax_ushort(fax
->pages
);
if (fseek(fax
->fp
, (long) OFFSET_PAGES
, 0) == 0)
fwrite((char*)&p
, sizeof(p
), 1, fax
->fp
);
rc
= gdev_prn_close(pdev
);
/*************************************************************************
*************************************************************************/
/************************Coding FAX Routines*************************/
* faxp = faxout_open(filename);
* faxp = faxout_open_fp(fp);
* faxout_begin_page(faxp, resolution);
* for(;;) tofax(faxp, linebuf);
faxp
= (FAXOUT
*) malloc(sizeof(*faxp
));
faxout_open(char *filename
)
fp
= fopen(filename
, "w");
return(faxout_open_fp(fp
));
faxout_begin_page(FAXOUT
*faxp
, int resolution
)
memset(&hdr
, 0, sizeof(hdr
));
memcpy(hdr
.id
.magic
, FAXMAGIC
, sizeof(hdr
.id
.magic
));
hdr
.info
.pagenum
= fax_ushort(++faxp
->pages
);
hdr
.info
.hires
= resolution
;
hdr
.jtinfo
.jthires
= resolution
? 0x40 : 0;
fwrite((char*)&hdr
, sizeof(hdr
), 1, faxp
->fp
);
faxout_end_page(FAXOUT
*faxp
)
faxout_close(FAXOUT
*faxp
)
unsigned short p
= fax_ushort(faxp
->pages
);
if (fseek(faxp
->fp
, (long) OFFSET_PAGES
, 0) == 0)
fwrite((char*)&p
, sizeof(p
), 1, faxp
->fp
);
fax_ushort(unsigned short v
)
static unsigned short x
= 0x1122;
static unsigned short *xp
= &x
;
if ( *((unsigned char *)xp
) == 0x22)
return ( ((v
>>8)&255) + (v
<<8) );
private unsigned char b_run_tbl
[8][256] =
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0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2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
* Macros to use tables in findrun.c
#define find_black_run() \
if (run = b_run_tbl[bit][*p]) \
if (bit < 0 && ++p < ep) { bit=7; continue;} \
#define find_white_run() \
if (run = w_run_tbl[bit][*p]) \
if (bit < 0 && ++p < ep) { bit=7; continue;} \
tofax(FAXOUT
*faxp
, unsigned char *p
)
/*************************************************************************
The rest of this file is a FAX encoding algorithm
derived from pbmplus. It is not the normal DigiFAX algorithm.
The following copyright applies.
** Copyright (C) 1989 by Paul Haeberli <paul@manray.sgi.com>.
** Permission to use, copy, modify, and distribute this software and its
** documentation for any purpose and without fee is hereby granted, provided
** that the above copyright notice appear in all copies and that both that
** copyright notice and this permission notice appear in supporting
** documentation. This software is provided "as is" without express or
*************************************************************************/
putwhitespan(register FAXOUT
*faxp
, int c
)
putblackspan(register FAXOUT
*faxp
, int c
)
putcode(register FAXOUT
*faxp
, tableentry
*te
)
register unsigned int mask
;
mask
= 1<<(te
->length
-1);
puteol(register FAXOUT
*faxp
)
putbit(register FAXOUT
*faxp
, int d
)
faxp
->fax_byte
= faxp
->fax_byte
|faxp
->fax_weight
;
faxp
->fax_weight
= faxp
->fax_weight
>>1;
if((faxp
->fax_weight
&0xff) == 0) {
putc(faxp
->fax_byte
, faxp
->fp
);
flushbits(register FAXOUT
*faxp
)
if (faxp
->fax_weight
!= 0x80) {
putc(faxp
->fax_byte
, faxp
->fp
);