bhagwan@voodoo.UUCP (04/09/87)
Hi, 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. Thanks,
majka@ubc-vision.UUCP (04/13/87)
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
ph@pixar.UUCP (Paul Heckbert) (04/20/87)
I've posted source in net.sources for a versatile picture file to postscript conversion program. The program has options for 1, 2, 4, or 8 bits per pixel, positioning on the page, negation, dithering, and a number of other capabilities.