$NetBSD: patch-ag,v 1.1 1999/01/10 23:52:16 tron Exp $ --- pbm/pbmto10x.c.orig Mon Oct 4 10:10:42 1993 +++ pbm/pbmto10x.c Sun Jan 10 23:48:40 1999 @@ -1,6 +1,6 @@ /* pbmto10x.c - read a portable bitmap and produce a Gemini 10X printer file ** -** Copyright (C) 1990 by Ken Yap +** Copyright (C) 1990, 1994 by Ken Yap ** ** Permission to use, copy, modify, and distribute this software and its ** documentation for any purpose and without fee is hereby granted, provided @@ -8,6 +8,8 @@ ** copyright notice and this permission notice appear in supporting ** documentation. This software is provided "as is" without express or ** implied warranty. +** +** Modified to shorten stripes and eliminate blank stripes. Dec 1994. */ #include "pbm.h" @@ -52,15 +54,40 @@ } static void +outstripe(stripe, sP, reschar) + register char *stripe, *sP; + register int reschar; +{ + register int ncols; + + /* scan backwards, removing empty columns */ + while (sP != stripe) + if (*--sP != 0) + { + ++sP; + break; + } + ncols = sP - stripe; + if (ncols > 0) + { + printf("\033%c%c%c", reschar, ncols % 256, ncols / 256); + fwrite(stripe, sizeof(char), ncols, stdout); + } + putchar('\n'); /* flush buffer */ +} + +static void res_60x72() { register int i, item, npins, row, col; bit *bitrows[LOW_RES_ROWS], *bP[LOW_RES_ROWS]; + char *stripe, *sP; + stripe = malloc(cols); for (i = 0; i < LOW_RES_ROWS; ++i) bitrows[i] = pbm_allocrow(cols); printf("\033A\010"); /* '\n' = 8/72 */ - for (row = 0; row < rows; row += LOW_RES_ROWS) + for (row = 0, sP = stripe; row < rows; row += LOW_RES_ROWS, sP = stripe) { if (row + LOW_RES_ROWS <= rows) npins = LOW_RES_ROWS; @@ -68,17 +95,18 @@ npins = rows - row; for (i = 0; i < npins; ++i) pbm_readpbmrow(ifp, bP[i] = bitrows[i], cols, format); - printf("\033K%c%c", cols % 256, cols / 256); for (col = 0; col < cols; ++col) { item = 0; for (i = 0; i < npins; ++i) if (*(bP[i]++) == PBM_BLACK) item |= 1 << (7 - i); - putchar(item); + *sP++ = item; } - putchar('\n'); + outstripe(stripe, sP, 'K'); } + printf("\033@"); + free(stripe); } static void @@ -86,11 +114,13 @@ { register int i, pin, item, npins, row, col; bit *bitrows[HIGH_RES_ROWS], *bP[HIGH_RES_ROWS]; + char *stripe, *sP; + stripe = malloc(cols); for (i = 0; i < HIGH_RES_ROWS; ++i) bitrows[i] = pbm_allocrow(cols); - putchar('\033'); putchar('3'); putchar('\0'); - for (row = 0; row < rows; row += HIGH_RES_ROWS) + printf("\0333\001"); /* \n = 1/144" */ + for (row = 0, sP = stripe; row < rows; row += HIGH_RES_ROWS, sP = stripe) { if (row + HIGH_RES_ROWS <= rows) npins = HIGH_RES_ROWS; @@ -98,7 +128,6 @@ npins = rows - row; for (i = 0; i < npins; ++i) pbm_readpbmrow(ifp, bP[i] = bitrows[i], cols, format); - printf("\033L%c%c", cols % 256, cols / 256); for (col = 0; col < cols; ++col) { item = 0; @@ -106,11 +135,10 @@ for (pin = i = 0; i < npins; i += 2, ++pin) if (*(bP[i]++) == PBM_BLACK) item |= 1 << (7 - pin); - putchar(item); + *sP++ = item; } - putchar('\n'); /* flush buffer */ - printf("\033J\001"); /* 1/144 down */ - printf("\033L%c%c", cols % 256, cols / 256); + outstripe(stripe, sP, 'L'); + sP = stripe; for (col = 0; col < cols; ++col) { item = 0; @@ -118,9 +146,11 @@ for (i = 1, pin = 0; i < npins; i += 2, ++pin) if (*(bP[i]++) == PBM_BLACK) item |= 1 << (7 - pin); - putchar(item); + *sP++ = item; } - putchar('\n'); /* flush buffer */ - printf("\033J\017"); /* 15/144 down */ + outstripe(stripe, sP, 'L'); + printf("\033J\016"); /* 14/144 down, \n did 1/144 */ } + printf("\033@"); + free(stripe); }