[comp.lang.postscript] Bitmap driver for Ghostscript 2.1

jos@bull.nl (Jos Vos) (06/10/91)

Because a lot of people asked me if they could get my bitmap driver
for Ghostscript 2.1, I decided to post the stuff.
It is derived from the original laserjet/deskjet driver.
Read the file README.bitmap for further details.

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	README.bmap
#	gdevbmap.c
#	makefile.bmap
# This archive created: Sun Jun  9 19:47:21 1991
# By:	Jos Vos ()
export PATH; PATH=/bin:/usr/bin:$PATH
if test -f 'README.bmap'
then
	echo shar: "will not over-write existing file 'README.bmap'"
else
cat << \SHAR_EOF > 'README.bmap'
A pilot version of a bitmap device for Ghostscript 2.1.

-  Include the 'makefile.bmap' file at an appropriate place in your
   makefile (somewhere between the other devices).

-  Add 'bitmap' to the 'DEVICES=' line in your makefile.
   The index (starting at 0) of the word 'bitmap' is the device number.

-  Add '$(bitmap_)' to the 'DEVICE_OBJS=' line in your makefile.

-  Optionally edit the 'gdevbmap.c' file for changing the resolution and
   the size of the generated bitmap (default is A4 format with 300 dpi).
   Look for the section marked with the comment 'EDIT HERE'.

Now call 'make' to generate a new version of GhostScript.

-  The command '<index> getdevice setdevice' selects the bitmap device,
   where '<index>' is the index in the 'DEVICES=' line in your makefile
   (see above).

-  With the command 'currentdevice devicename ==' you can check if
   you are really using the bitmap device: it should say '(bitmap)'.

-  For each page a separate bitmap-file is produced (just as with some
   other devices like laserjet and deskjet). Also some information
   is listed about the generated bitmap.

Last change: June 9, 1991.

Jos Vos <jos@bull.nl>
SHAR_EOF
fi
if test -f 'gdevbmap.c'
then
	echo shar: "will not over-write existing file 'gdevbmap.c'"
else
cat << \SHAR_EOF > 'gdevbmap.c'
/* Copyright (C) 1989, 1990 Aladdin Enterprises.  All rights reserved.
   Distributed by Free Software Foundation, Inc.

This file is part of Ghostscript.

Ghostscript is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing.  Refer
to the Ghostscript General Public License for full details.

Everyone is granted permission to copy, modify and redistribute
Ghostscript, but only under the conditions described in the Ghostscript
General Public License.  A copy of this license is supposed to have been
given to you along with Ghostscript so you can know your rights and
responsibilities.  It should be in a file named COPYING.  Among other
things, the copyright notice and this notice must be preserved on all
copies.  */

/* gdevbmap.c */
/* Bitmap driver for GhostScript */

#define GS_PRN_DEVICE gs_bitmap_device
#define DEVICE_NAME "bitmap"

/* EDIT HERE: THE FOLLOWING VALUES CAN BE CHANGED IF YOU WISH TO !!! */

/* The size of the page in 10ths of inches. */
#define PAGE_WIDTH_10THS 82		/* nearly A4: 210 mm ~= 8.2677 inch */
#define PAGE_HEIGHT_10THS 116		/* nearly A4: 297 mm ~= 11.6929 inch */

/* The horizontal and vertical resolution in dots/inch. */
#define X_DPI 300		/* horizontal resolution: 300 dots/inch */
#define Y_DPI 300		/* vertical resolution: 300 dots/inch */

/* END OF THE SECTION WITH CHANGEABLE VALUES */

#define PRN_OPEN gdev_prn_open
#define PRN_CLOSE gdev_prn_close
#define PRN_OUTPUT_PAGE bmap_output_page
#define DRIVER				/* see gdevprn.h */
#include "gdevprn.h"

/* Forward references */
private int bmap_print_page(P2(gx_device_printer *, FILE *));

/* Send the page to the printer. */
private int
bmap_output_page(gx_device *dev)
{	int code = gdev_prn_open_printer(dev);
	if ( code < 0 ) return code;

	/* print the accumulated page description */
	bmap_print_page(prn_dev, prn_dev->file);

	gdev_prn_close_printer(dev);
	return 0;
}

/* ------ Internal routines ------ */

/* Send the page to the printer. */
private int
bmap_print_page(gx_device_printer *pdev, FILE *prn_stream)
{	char	data[LINE_SIZE + 4];

	/* Send each scan line in turn */
	   {	int lnum;
		int line_size = mem_bytes_per_scan_line(&pdev->mem);
		int num_blank_lines = 0;
		for ( lnum = 0; lnum < pdev->height; lnum++ )
		   {	mem_copy_scan_lines(&pdev->mem, lnum,
					    (byte *)data, line_size);
			fwrite(data, sizeof(char), LINE_SIZE, prn_stream);
		   }
	   }
	
	printf("The bitmap contains %d bytes (%d arrays of %d bytes):\n",
			pdev->height * LINE_SIZE, pdev->height, LINE_SIZE);
	printf("\tHorizontal: %.3f inch (%d dpi) needs %d dots (%d bytes),\n",
			(LINE_SIZE * 8) / (double) X_DPI, X_DPI,
			LINE_SIZE * 8, LINE_SIZE);
	printf("\tVertical  : %.3f inch (%d dpi) needs %d dots.\n",
			pdev->height / (double) Y_DPI, Y_DPI,
			pdev->height);

	return 0;
}
SHAR_EOF
fi
if test -f 'makefile.bmap'
then
	echo shar: "will not over-write existing file 'makefile.bmap'"
else
cat << \SHAR_EOF > 'makefile.bmap'
### ------------------ The BITMAP printer device ------------------------- ###

bitmap_=gdevbmap.$(OBJ) gvirtmem.$(OBJ) gdevprn.$(OBJ)
bitmap.dev: $(bitmap_)
	.$(DS)gssetdev bitmap.dev $(bitmap_)

gdevbmap.$(OBJ): gdevbmap.c $(PDEVH)
	$(CCA) gdevbmap.c

SHAR_EOF
fi
exit 0
#	End of shell archive

-- 
--    Jos Vos <jos@bull.nl>    (UUCP: ...!{uunet,mcsun,hp4nl}!nlbull!jos)
--    Bull Nederland NV, Product Support Unix, Amsterdam, The Netherlands

jos@bull.nl (Jos Vos) (06/13/91)

In article <1066@nlbull.bull.nl> I write:

>Because a lot of people asked me if they could get my bitmap driver
>for Ghostscript 2.1, I decided to post the stuff.

I just got Ghostscript 2.2 and I got it working on my Bull Unix system.
I will port my bitmap driver to 2.2 when I have time (it will be this month,
but more I can't promise) and I will post it when I receive more
than two requests for it.

Any further comments are welcome (by mail), and I will try to incorporate
them in my 2.2 port.

-- 
--    Jos Vos <jos@bull.nl>    (UUCP: ...!{uunet,mcsun,hp4nl}!nlbull!jos)
--    Bull Nederland NV, Product Support Unix, Amsterdam, The Netherlands