Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!mit-eddie!uw-beaver!ubc-vision!majka From: majka@ubc-vision.UUCP Newsgroups: comp.graphics,comp.sources.wanted Subject: Re: Wanted: bitmap to PostScript Message-ID: <449@ubc-vision.UUCP> Date: Mon, 13-Apr-87 11:42:50 EST Article-I.D.: ubc-visi.449 Posted: Mon Apr 13 11:42:50 1987 Date-Received: Wed, 15-Apr-87 05:14:17 EST References: <302@voodoo.UUCP> Reply-To: majka@ubc-vision.UUCP (Marc Majka) Distribution: world Organization: UBC Computational Vision Lab, Vancouver, B.C., Canada Lines: 43 Xref: utgpu comp.graphics:456 comp.sources.wanted:879 In article <302@voodoo.UUCP> bhagwan@voodoo.UUCP (The Bhagwan) writes: > Does anyone have a generic C routine to convert a bitmap > (1 or 8 bits/pixel) to postscript? I tried the easy way, > one HUGE hex string --- and VMerror. I don't think there is any way of getting around lots of hex, but the trick is not to put it all in one string. See the PostScript Cookbook section on using the "image" operator. Here is the guts of a C program that produces what the Cookbook suggests. /* nr, nc = number of rows, columns x1, y1 = starting coordinates x2, y2 = ending coordinates */ printf ("gsave\n"); printf ("initgraphics\n"); printf ("0.24 0.24 scale\n"); printf ("/imline %d string def\n",nc); printf ("/drawimage {\n"); printf (" %d %d 8\n",nc,nr); printf (" [%d 0 0 %d 0 %d]\n",nc,-1*nr,nr); printf (" { currentfile imline readhexstring pop } image\n"); printf ("} def\n"); printf ("%d %d translate\n",x1,y2); printf ("%d %d scale\n",x2-x1,y1-y2); printf ("drawimage\n"); for (r = 0; r < nr; r++) for (c = 0; c < nc; c++) { pix = getc(ifp); puthexpix(pix); } printf ("showpage\n"); printf ("grestore\n"); Notice that it doesn't try to read the whole image at once, just one line. I recall that I had a bit of trouble with this if nc was odd, or if it was too big. This code works for at least nc = 512. --- Marc Majka