[comp.lang.postscript] How to paint a non-rectangular image?

jef@ace.ee.lbl.gov (Jef Poskanzer) (02/10/90)

I want to do a PostScript image operation with a mask.  I do not mean
imagemask -- that paints a 1-bit deep image with 1's getting the
current color and 0's getting left alone.  What I want to do is paint
an N-bit image, and have a separate 1-bit mask controlling which parts
of the N-bit image get transferred and which parts get ignored.

I could do it by lasooing the border of the 1-bit mask and converting
it into a clipping list, but that seems extremely grody.  Does anyone
see a better way?
---
Jef

  Jef Poskanzer  jef@well.sf.ca.us  {ucbvax, apple, hplabs}!well!jef
    "When more and more people are thrown out of work, unemployment
                     results." -- Calvin Coolidge

amanda@mermaid.intercon.com (Amanda Walker) (02/10/90)

In article <4829@helios.ee.lbl.gov>, jef@ace.ee.lbl.gov (Jef Poskanzer) writes:
> I could do it by lasooing the border of the 1-bit mask and converting
> it into a clipping list, but that seems extremely grody.  Does anyone
> see a better way?

What I would do is to do two imagemask commands.  The first paints the
mask bitmap with white, and the second paints the image bitmap in black
(or whatever).

This gets the effect I think you want :-).

--
Amanda Walker
InterCon Systems Corporation

"Many of the truths we cling to depend greatly upon our own point of view."
	--Obi-Wan Kenobi in "Return of the Jedi"

jef@surf.ee.lbl.gov (Jef Poskanzer) (02/11/90)

In the referenced message, amanda@mermaid.intercon.com (Amanda Walker) wrote:
}What I would do is to do two imagemask commands.  The first paints the
}mask bitmap with white, and the second paints the image bitmap in black
}(or whatever).

Hmmmmmm....  This doesn't solve the precise problem I posed, since I
want to paint a grayscale image, but it's very close.  With a little
image hacking using my PBMPLUS toolkit I was able to make this trick
work quite well.  Thanks!

For the benefit of any other PBMPLUS/PostScript hackers out there
(and for my own future reference), here's what I did:

    pgmtopbm face.pgm > face.pbm
    {manually edit face.pbm to remove background, giving clipped.pbm}
    pbmmask clipped.pbm | pnminvert > mask.pbm
    pnmenlarge 5 face.pgm > face5.pgm
    pnmenlarge 5 mask.pbm > mask5.pbm
    ppmarith -mul face5.pgm mask5.pbm | ppmtopgm | pgmtopbm > clipped5.pbm
    pgmtops mask5.pbm > mask5.ps
    pgmtopbm clipped5.pbm > clipped5.ps

Then turn mask5.ps into an imagemask command with invert true and
0 setgray; turn clipped5.ps into an imagemask with invert true and
1 setgray; and adjust the translate and scale commands to shrink
the result back down by a factor of five.
---
Jef

  Jef Poskanzer  jef@well.sf.ca.us  {ucbvax, apple, hplabs}!well!jef
  A witty saying proves nothing, but saying something pointless gets
                          people's attention.

geof@aurora.com (Geoffrey H. Cooper) (02/13/90)

In article <4829@helios.ee.lbl.gov> Jef Poskanzer <jef@well.sf.ca.us> writes:
>I want to do a PostScript image operation with a mask.  I do not mean
>imagemask -- that paints a 1-bit deep image with 1's getting the
>current color and 0's getting left alone.  What I want to do is paint
>an N-bit image, and have a separate 1-bit mask controlling which parts
>of the N-bit image get transferred and which parts get ignored.
>
>I could do it by lasooing the border of the 1-bit mask and converting
>it into a clipping list, but that seems extremely grody.  Does anyone
>see a better way?

That is the only way to do it "right." A simpler and faster technique
would work if you happen to know that the background is a particular
uniform color.  Assuming wlog that the background is white, image the
grey level image, then image the clipping bitmap over it, inverted,
with currentgray set to white.  That will "erase" the image wherever
you didn't want it painted. 

- Geof
-- 
geof@aurora.com / aurora!geof@decwrl.dec.com / geof%aurora.com@decwrl.dec.com