Transparent raster in a PostScript file

Mark Neuhaus

June 6, 2002


The objective

We produce large format, multi-color geologic maps, using USGS quadrangles for our base map. We create a Mapinfo table of the geologic units, where we assign various colors and patterns to depict the rock type. In order to have the base map visible through these colors and patterns, we need to place the tables in the correct order. A typical order in our mapper window might be:

type and symbols
miscellaneous data
geologic units (polygon boundaries)
fault lines
transparent, 1-bit (2 color) DRG raster image
geologic units (patterns)
geologic units (color filled polygons)

Since we need to distribute our digital map in PDF format and on plotted paper, we need to be able to make a postscript file that can be used to run off the paper copies and be used to make the PDF.

The problem

Unfortunately, some problems occur when we try to plot postscript with transparent raster images. We get the base map coming out as a black area instead of a transparent area, thereby obscuring all data below it and rendering the map useless. This seems to be a common complaint on the MapInfo list for bitmapped images. Why can I see it correctly on screen but not on paper?

I downloaded a beta of MapInfo 7.0 because of it's promise to plot transparent images. Yikes!!! My map output file was 2 GIGS!!! And it took forever to plot in GhostScript and as a PDF. Totally unacceptable.

Our solution

When viewing the postscript output file in GhostScript before sending it to a plotter, I could see my colored polygons get drawn first, then the base map "lines" drawn black, then the obscuring black boxes, then the base map "lines" in the proper gray shade as assigned in the "raster -> adjust image styles" dialog box, and then any other layers on top of these. Why was the base map drawn more than once? Why was the transparency ignored? What if I could alter the postscript code? Hmmmmm....

I made a small test file of one polygon and a transparent base map and plotted it to file. I looked at the postscript code with a text editor and was able to work backwards in the file to see where the offending code was located. I was able to cut out the part of the file that drew the second base map. Now I had a solid black base map. Then I cut out the section that drew the obscuring black boxes. Now I had a base map left, but in black. But more importantly, I had my polygon showing through!

I wrote a little routine in qbasic (yes, that old, old standby from DOS days) that sequentially searched for a particular string in the postscript file which indicated the black box was about to be drawn. I then filtered the file until this section was done. A new file had been created during this process that contained the polygon and the first, essentially transparent basemap.

Derek Snyder of MapInfo Corp. recently explained how the output works when using Microsoft's "region" masking. Since I could see the base map and black boxes being drawn in pieces, I realized that the output file contained tiles of the map. Therefore, I had to loop through the postscript file until all the tiles had been cleaned of the black boxes and the second copy of the base map.

I didn't want a black base map, but rather, a gray shade to subdue it. Since I knew what line in the postscript file assigned the color to the base map "lines", I just re-assigned the values there to allow me to plot in a gray shade, or for that matter, any other color I wanted the base to be. A nice light brown or whatever, just assign the correct values for RGB (red, green, blue).

When I tested this on a full geology map, I got the desired results. Until I tried it on a second or third project, that is. Then I got an error message from qbasic about string memory. I tried my old copy of QuickBasic 4.5 and still got the error. Ah, jeez, now what? Well, a quick search on Google came up with a free cross-platform program called "xbasic" which claimed to eliminate the memory problems. Okay, worth a try. Got it from the official xbasic site. And bingo, after playing with it for a little while to learn it's commands, I got a routine working in xbasic that spit out my map just fine. Tested it with TWO transparent quads side by side, no problem. Another double quad, this time north and south, and it still spit it out. What magic! Made PDFs just fine. If you want to give it a try, you are welcome to email me for the code. It is not compiled, so you have to run it from the xbasic window. Insert your own file names and run it.

Now, I gotta say that there are a few restrictions.

I originally was able to get this to work with my hp3500 postscript driver but not with our 1055 driver. I could not get it to work with postscript version 3 either. I installed a driver for an HP755 plotter and have success with that. The only major problem is that I can't assign a custom page size so must use their built in sizes. I seem to remember something about editting the ppd file, but for the time being, I can use the sizes that already exist.

For this to work, the image must be a 1-bit, 2-color image. You know, black and white. We edit the DRGs we use in PaintShopPro. We edit the color pallette to change the green forest tint to white and then change all the other colors to black. Then we reduce the image to 2 color and load it to Mapinfo. Set transparency in the "raster -> adjust image styles" dialog box, and there you have it. It doesn't matter what values you set for contrast and brightness, because contrast is ignored when plotting to the postscript file, and my routine strips out the brightness value, as it is actually the base map drawn after the black boxes. That's why my routine will insert a value for you. We tested the base map from white to black with a typical colored geology map and found that brightness set to 70% was a happy compromise for allowing the base to show through the colors without overpowering other data being shown. In the postscript file, this setting would be .4 .4 .4 for the RGB values and is the default setting I coded. You're welcome to change it to anything you want, of course.

Disclaimer

And what's life without one? I make no promises that this will work for you or will work in the future. It seems to work for me in version 6.0 and that's what I was after.

You are welcome to contact me with questions and comments, especially if I can make this document clearer. I am not a postscript or programming guru. Just a manual, production cartographer grappling with the digital world.