Category : C Source Code
Archive   : GP.ZIP
Filename : GP.C
Name PrintImage
Description - Prints a graphics image to an Epson compatible printer.
Allows for stretching height by a factor of 2. This improves the
appearance of images from CRTs with low vertical resolution.
Syntax printimage(int left, int top, int right, int bottom,
int stretch, int LPTX);
*-------------------------------------------------------------------*/
#include
#include
#include
#define ESC '\x1B'
#define LPT1 0
#define LPT2 1
#define LPT3 2
#define prn_putc(x) biosprint(0, (x), LPTX)
/* Sets Epson printer to bit image mode. */
static void bitImage(int numbytes, int LPTX)
{
register int n1, n2;
n2 = numbytes >> 8;
n1 = numbytes - (n2 << 8);
prn_putc(ESC); /* Set printer to CRT graphics mode */
prn_putc('*'); /* 640 horiz. dots in 8" i.e. mode 4*/
prn_putc(4); /* Matches EGA & Zenith laptop */
prn_putc(n1);
prn_putc(n2);
}
/* Get pixels from the screen and convert them to the printer's pin order.
*/
static unsigned char getScrBits(int x, int y, int stretch)
{
unsigned char firePins;
/* Use the following to obtain a pixel for pixel copy */
if (!stretch){
firePins = (getpixel(x, y++)==0)? 0: 0x80;
firePins |= (getpixel(x, y++)==0)? 0: 0x40;
firePins |= (getpixel(x, y++)==0)? 0: 0x20;
firePins |= (getpixel(x, y++)==0)? 0: 0x10;
firePins |= (getpixel(x, y++)==0)? 0: 0x08;
firePins |= (getpixel(x, y++)==0)? 0: 0x04;
firePins |= (getpixel(x, y++)==0)? 0: 0x02;
firePins |= (getpixel(x, y )==0)? 0: 0x01;
}
else
/* Use the following to stretch the height by a factor of two */
/* Every pixel fires two adjacent pins */
{
firePins = (getpixel(x, y++)==0)? 0: 0xC0;
firePins |= (getpixel(x, y++)==0)? 0: 0x30;
firePins |= (getpixel(x, y++)==0)? 0: 0x0C;
firePins |= (getpixel(x, y)==0)? 0: 0x03;
}
return firePins;
}
int printimage(int left, int top, int right, int bottom, int stretch,
int LPTX)
{
int x, y, width, height, inc = 8;
width = 1 + right - left; /* added one to get right edge */
height = 1 + bottom - top;
if (stretch)
inc = 4;
for (y=0; y < height; y += inc)
/* Increment by 8 for direct pixel to pin copy. Increment by 4 if
streching height by a factor of 2 */
{
prn_putc(ESC); /* Initialize line spacing to 7/72 i.e. ESC 1" */
prn_putc('3'); /* Put 1 here and delete next line. Leave alone */
prn_putc(22); /* and try 22/216" to make circles rounder */
bitImage(width, LPTX);
for (x = 0; x < width; x++)
prn_putc(getScrBits(x, y, stretch));
prn_putc('\n');
}
return 0;
}
/* Demonstrates a call to the printimage() function */
main(){
int driver, mode, x, y, stretch;
driver = DETECT; /* autodetect */
initgraph(&driver, &mode, "");
x=getmaxx();
y=getmaxy();
stretch = 0; /* flag. If height to be stretched, set to 1 */
printf ("X = %d, Y = %d", x, y);
/* draw something */
rectangle(0, 0, x, y);
circle(200, 100, 100);
circle(110, 010, 50);
circle(290, 010, 50);
circle(170, 070, 10);
circle(172, 073, 3);
circle(230, 070, 10);
circle(232, 073, 3);
circle(200, 100, 10);
moveto(180, 120);
lineto(190, 130);
lineto(210, 130);
lineto(220, 120);
moveto(635, 50);
lineto(639, 150);
/* print the entire screen */
printimage(0, 0, x, y, stretch, LPT1);
closegraph();
return 0;
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/