[GRASS-dev] ps.map: raster always under vector map?
Glynn Clements
glynn at gclements.plus.com
Wed May 2 08:51:58 EDT 2007
Markus Neteler wrote:
> > > >>> Bear in mind that the raster map is always opaque, so it will obscure
> > > >>> anything which is drawn beneath it.
> > > >>>
> > > >> Markus:
> > > >>
> > > >>> That's exactly what I need: in my case the raster map contains a few
> > > >>> cells only, but I need it on top to not be covered by vector contour
> > > >>> lines etc.
> > > >>>
> > > >> ..
> > > >>
> > > >>> Maybe ps.map's raster command needs an additional parameter "ontop" or
> > > >>> something like this? Hacking C code as Hamish suggests might be asked
> > > >>> too much for the average user.
> > > >>>
> > > >> are the null areas solid white, not transparent?
> > > >>
> > > >
> > > > They are transparent. All fine.
> > > Of course I was too hasty. Nothing fine.
> > > > Just that the tons of contour
> > > > lines cover the scarse raster areas in the raster maps. That's
> > > > why I need them on top of the dense contour lines.
> > > >
> > > ... and it seems that NULL is not respected by ps.map (as you will know
> > > already).
> >
> > For masked images, you need to use the one-operand form of the "image"
> > operator with an image dictionary; see the RASTERMASK procedure in
> > lib/psdriver/psdriver.ps for an example. This requires support for
> > level 3 PostScript (present in GhostScript for a few years now; I
> > don't know about printers).
> >
> > Regarding the generation of the image data (ps/ps.map/ps_raster.c), a
> > masked image needs 2 (mono) or 4 (RGB) components, with the mask byte
> > first (i.e. AARRGGBB); see lib/psdriver/Raster.c.
>
> I am afraid that I am not able to implement this.
Try the attached patch.
It only works with single rasters, not R/G/B groups. Also, the masked
flag is currently hard-coded on; ultimately, this would need to be
made into an option to the raster/rgb/group commands.
--
Glynn Clements <glynn at gclements.plus.com>
-------------- next part --------------
Index: ps/ps.map/ps_raster.c
===================================================================
RCS file: /grassrepository/grass6/ps/ps.map/ps_raster.c,v
retrieving revision 1.5
diff -u -r1.5 ps_raster.c
--- ps/ps.map/ps_raster.c 8 Jan 2007 07:25:26 -0000 1.5
+++ ps/ps.map/ps_raster.c 2 May 2007 12:47:53 -0000
@@ -65,6 +65,7 @@
int i, n, r, g, b, rr, gg, bb, row, col, doing_color;
RASTER_MAP_TYPE map_type, grp_map_type[3];
void *cellbuf=NULL, *cbuf[3], *ptr;
+ int masked = 1;
if (!PS.do_raster && !grp.do_group) return 1;
@@ -84,7 +85,35 @@
fprintf(PS.fp, "%d %d scale\n",
(int)(PS.map_pix_wide + 0.5), (int)(PS.map_pix_high + 0.5));
-
+ if (masked)
+ {
+ /* make strings to hold image RGB values */
+ if (doing_color) fprintf(PS.fp, "/DeviceRGB setcolorspace\n");
+ else fprintf(PS.fp, "/DeviceGray setcolorspace\n");
+ if (doing_color) fprintf(PS.fp, "/imgstrg cw 4 mul string def\n");
+ else fprintf(PS.fp, "/imgstrg cw 2 mul string def\n");
+ fprintf(PS.fp, "4 dict dup begin\n");
+ fprintf(PS.fp, "/ImageType 3 def\n");
+ fprintf(PS.fp, "/InterleaveType 1 def\n");
+ fprintf(PS.fp, "/DataDict 7 dict def\n");
+ fprintf(PS.fp, "/MaskDict 6 dict def\n");
+ fprintf(PS.fp, "MaskDict begin\n");
+ fprintf(PS.fp, "/ImageType 1 def\n");
+ fprintf(PS.fp, "/Width cw def\n");
+ fprintf(PS.fp, "/Height ch def\n");
+ fprintf(PS.fp, "/ImageMatrix [cw 0 0 ch neg 0 ch] def\n");
+ fprintf(PS.fp, "/BitsPerComponent 8 def\n");
+ fprintf(PS.fp, "/Decode [0 1] def\n");
+ fprintf(PS.fp, "end\n");
+ fprintf(PS.fp, "MaskDict DataDict copy begin\n");
+ if (doing_color) fprintf(PS.fp, "/Decode [0 1 0 1 0 1] def\n");
+ fprintf(PS.fp, "/DataSource {currentfile imgstrg readhexstring pop} def\n");
+ fprintf(PS.fp, "end\n");
+ fprintf(PS.fp, "end\n");
+ fprintf(PS.fp, "image\n");
+ }
+ else
+ {
/* make strings to hold image RGB values */
if (doing_color) fprintf(PS.fp, "/imgstrg cw 3 mul string def\n");
else fprintf(PS.fp, "/imgstrg cw string def\n");
@@ -93,6 +122,7 @@
fprintf(PS.fp, "{currentfile imgstrg readhexstring pop}\n");
if (doing_color) fprintf(PS.fp, "false 3 colorimage\n");
else fprintf(PS.fp, "image\n");
+ }
/* let user know what's happenning */
if (PS.do_raster)
@@ -114,31 +144,62 @@
if ((row % PS.row_delta) == 0)
{ ptr = cellbuf;
for (col = 0; col < PS.w.cols; col += PS.col_delta)
- {
+ {
G_get_raster_color(ptr, &r, &g, &b, &PS.colors, map_type);
-
- /* if color raster */
- if (doing_color)
+
+ if (masked)
{
- fprintf(PS.fp, "%02X%02X%02X", r, g, b);
- if (++n == 13)
- {
- n = 0;
- fprintf(PS.fp, "\n");
- }
- }
+ int nul = G_is_null_value(ptr, map_type) ? 0xFF : 0x00;
+
+ /* if color raster */
+ if (doing_color)
+ {
+ fprintf(PS.fp, "%02X%02X%02X%02X", nul, r, g, b);
+ if (++n == 9)
+ {
+ n = 0;
+ fprintf(PS.fp, "\n");
+ }
+ }
- /* if grey raster */
+ /* if grey raster */
+ else
+ {
+ fprintf(PS.fp, "%02X%02X", nul,
+ (int)(.3 * (double)r + .59 * (double)g +
+ .11 * (double)b));
+ if (++n == 19)
+ {
+ n = 0;
+ fprintf(PS.fp, "\n");
+ }
+ }
+ }
else
{
- fprintf(PS.fp, "%02X",
- (int)(.3 * (double)r + .59 * (double)g +
- .11 * (double)b));
- if (++n == 39)
- {
- n = 0;
- fprintf(PS.fp, "\n");
- }
+ /* if color raster */
+ if (doing_color)
+ {
+ fprintf(PS.fp, "%02X%02X%02X", r, g, b);
+ if (++n == 13)
+ {
+ n = 0;
+ fprintf(PS.fp, "\n");
+ }
+ }
+
+ /* if grey raster */
+ else
+ {
+ fprintf(PS.fp, "%02X",
+ (int)(.3 * (double)r + .59 * (double)g +
+ .11 * (double)b));
+ if (++n == 39)
+ {
+ n = 0;
+ fprintf(PS.fp, "\n");
+ }
+ }
}
ptr = G_incr_void_ptr(ptr, G_raster_size(map_type) * PS.col_delta);
}
More information about the grass-dev
mailing list