Discussion:
How to achieve transparency in PostScript?
(too old to reply)
bilalhaider
2009-05-18 06:23:53 UTC
Permalink
I need to achieve transparency in PostScript Level 2.
In pdf

%PS
<< /AllowTransparency true >> % enable transparency
setdistillerparams
gsave 100 100 translate % s e t p o s i tion on page
0.4 0.7 1 setrgbcolor % d r a w a pastel blue box
40 40 60 60 rectfill
[ /ca .6 /SetTransparency % s e t t h e t ransparency
pdfmark
1 0.5 0 setrgbcolor % d r a w transparent orange
20 20 60 60 rectfill
grestore showpage

When distilled with acrobat it gives the desired output.
How we can achieve this in PostScript Level 2.
ken
2009-05-18 07:05:11 UTC
Permalink
In article <a4fbbe1c-61e4-4437-87ec-40c3a5d2f2d2
@y33g2000prg.googlegroups.com>, ***@gmail.com says...
Post by bilalhaider
I need to achieve transparency in PostScript Level 2.
In pdf
[snipped PostScript fragment]
Post by bilalhaider
When distilled with acrobat it gives the desired output.
How we can achieve this in PostScript Level 2.
Fundamentally, you can't. The PostScript imaging model does not support
transparency (nor does PDF prior to version 1.4).

To achieve what you want you need to calculate the intersection of the
objects, and the colour of the combined objects, and then draw all three
objects. You could also calculate the objects representing the non-
transparent portions and draw those separately, but since PostScript
only has an opaque imaging model this is not neccesary as long as you
get the Z-order correct.

For limited transparency, provided you are using CMYK colours and your
output device supports it, you can use the setoverprint operator to turn
on overprinting. When overprint is true the 0% inks do not erase the
underlying objects on the page. So to paraphrase your example:

%!PS
true setoverprint
1 0 0 0 setcmykcolor % 100% cyan
0 0 100 100 rectfill % fill rectangle
0 0 1 0 setcmykcolor % 100% yellow
50 50 100 100 rectfill % fill rectangle
showpage

Will draw yellow and cyan rectangles, the intersection of the two will
be green (cyan + yellow).


Ken
bilalhaider
2009-05-18 07:38:09 UTC
Permalink
Post by ken
In article <a4fbbe1c-61e4-4437-87ec-40c3a5d2f2d2
@y33g2000prg.googlegroups.com>, ***@gmail.com says...
Post by bilalhaider
I need to achieve transparency in PostScript Level 2.
In pdf
[snipped PostScript fragment]
Post by bilalhaider
When distilled with acrobat it gives the desired output.
How we can achieve this in PostScript Level 2.
Fundamentally, you can't. The PostScript imaging model does not support
transparency (nor does PDF prior to version 1.4).
To achieve what you want you need to calculate the intersection of the
objects, and the colour of the combined objects, and then draw all three
objects. You could also calculate the objects representing the non-
transparent portions and draw those separately, but since PostScript
only has an opaque imaging model this is not neccesary as long as you
get the Z-order correct.
For limited transparency, provided you are using CMYK colours and your
output device supports it, you can use the setoverprint operator to turn
on overprinting. When overprint is true the 0% inks do not erase the
%!PS
true setoverprint
1 0 0 0 setcmykcolor    % 100% cyan
0 0 100 100 rectfill    % fill rectangle
0 0 1 0 setcmykcolor    % 100% yellow
50 50 100 100 rectfill  % fill rectangle
showpage
Will draw yellow and cyan rectangles, the intersection of the two will
be green (cyan + yellow).
                Ken
Hi ken!
Thank you very much ken for your quick responce. I run your code using
PS Alter and found that two rectangles are printing. Intersected Area
is Coverd by the Yellow rectangle and no green color is there. Y this
is happening so?
During Googling i found at Source: http://en.wikipedia.org/wiki/Transparent_pixels

"The PostScript language has limited support for full (not partial)
transparency, depending on the PostScript level.
Level 1

Level 1 PostScript offers transparency via two methods:

* A one-bit (monochrome) image can be treated as a mask. In this
case the 1-bits can be painted any single color, while the 0-bits are
not painted at all. This technique cannot be generalised to more than
one color, or to vector shapes.
* Clipping paths can be defined. These restrict what part of all
subsequent graphics can be seen. This can be used for any kind of
graphic, however in level 1, the maximum number of nodes in a path was
often limited to 1500, so complex paths (e.g. cutting around the hair
in a photograph of a person's head) often failed.

Level 2

Level 2 PostScript adds no specific transparency features. However, by
the use of patterns, arbitrary graphics can be painted through masks
defined by any vector or text operations. This is, however, complex to
implement. In addition, this too often reached implementation limits,
and few if any application programs ever offered this technique.

Level 3

Level 3 PostScript adds further transparency option for any raster
image. A transparent color, or range of colors, can be applied; or a
separate 1-bit mask can be used to provide an alpha channel."



Now as a beginner i am not getting this masking concept and how to
achieve this.
ken
2009-05-18 10:33:48 UTC
Permalink
In article <3c6f87b0-99cc-472c-8c62-b0a4d740f027
@s31g2000vbp.googlegroups.com>, ***@gmail.com says...
Post by bilalhaider
* A one-bit (monochrome) image can be treated as a mask. In this
case the 1-bits can be painted any single color, while the 0-bits are
not painted at all. This technique cannot be generalised to more than
one color, or to vector shapes.
* Clipping paths can be defined. These restrict what part of all
subsequent graphics can be seen. This can be used for any kind of
graphic, however in level 1, the maximum number of nodes in a path was
often limited to 1500, so complex paths (e.g. cutting around the hair
in a photograph of a person's head) often failed.
Level 2
Level 2 PostScript adds no specific transparency features. However, by
the use of patterns, arbitrary graphics can be painted through masks
defined by any vector or text operations. This is, however, complex to
implement. In addition, this too often reached implementation limits,
and few if any application programs ever offered this technique.
Level 3
Level 3 PostScript adds further transparency option for any raster
image. A transparent color, or range of colors, can be applied; or a
separate 1-bit mask can be used to provide an alpha channel."
Now as a beginner i am not getting this masking concept and how to
achieve this.
Mostly these refer to image data, not vector data. PostScript has
support for masked images, and image masks, which in effect turn pixels
of image data into *fully* transparent windows, the underlying data then
shines through. Or you can paint 'through' a mask (think of painting
over a stencil). In either case the paint is still 100% opaque, the mask
just defines where it gets drawn.

You can also define a vector clipping region which won't get painted
when you draw an operation over it.

What the spec means by 'full (not partial) transparency' is that either
a pixel is fully transparent, or fully opaque, alpha blending is either
0 or 100%, nothing in between.

What you were discussing was (basically) alpha blending, which is not
supported at all in PostScript.


Ken
ken
2009-05-18 11:05:54 UTC
Permalink
In article <3c6f87b0-99cc-472c-8c62-b0a4d740f027
@s31g2000vbp.googlegroups.com>, ***@gmail.com says...
Post by bilalhaider
Thank you very much ken for your quick responce. I run your code using
PS Alter and found that two rectangles are printing. Intersected Area
is Coverd by the Yellow rectangle and no green color is there. Y this
is happening so?
I would imagine that PSAlter simply does not support overprint, it is
optional. Also it only works if you are printing CMYK inks to a CMYK
device, the screen is an RGB device. Any colour space conversion defeats
overprint.

Ken
Alex Cherepanov
2009-05-19 04:33:39 UTC
Permalink
Post by ken
%!PS
true setoverprintmode % added in v. 3015
% or use DeviceN or Separation color space
Post by ken
true setoverprint
1 0 0 0 setcmykcolor % 100% cyan
0 0 100 100 rectfill % fill rectangle
0 0 1 0 setcmykcolor % 100% yellow
50 50 100 100 rectfill % fill rectangle
showpage
bilalhaider
2009-05-19 11:57:40 UTC
Permalink
Post by ken
%!PS
true setoverprintmode     % added in v. 3015
                           % or use DeviceN or Separation color space
Post by ken
true setoverprint
1 0 0 0 setcmykcolor    % 100% cyan
0 0 100 100 rectfill    % fill rectangle
0 0 1 0 setcmykcolor    % 100% yellow
50 50 100 100 rectfill  % fill rectangle
showpage
Alex Cherepanov
true setoverprintmode % added in v. 3015
Thanks for mentioning the version. Download link? I am unable to find
that.

Ken

How can i achieve the above functionality using imagemask? Can we
achieve the same transparent effect using image operator for Language
Level 2/3. I am unable to find any such dictionary value that helps to
achieve that? Does there any algo underlying the imagemask operator? I
am not getting the clear picture.

Thanks for your time.
ken
2009-05-19 15:31:23 UTC
Permalink
In article <17a1c201-6670-4af9-a3bb-ec7573ce1516
@g3g2000pra.googlegroups.com>, ***@gmail.com says...
Post by bilalhaider
How can i achieve the above functionality using imagemask?
If you mean alpha blending, then the answer is that you can't. The only
transparency supported in PostScript is fully transparent or fully
opaque.
Post by bilalhaider
Can we
achieve the same transparent effect using image operator for Language
Level 2/3. I am unable to find any such dictionary value that helps to
achieve that? Does there any algo underlying the imagemask operator? I
am not getting the clear picture.
The fundamental problem, I think, is that you want to do something which
isn't supported in the language.

What you (seem) to want to do is to draw two vector objects, and have
the intersection coloured in a way which is given by combining the
colour of the two objects. You can't do that in PostScript.

You can create a path which is the intersection of the two objects by
using clip, and you can fill that with a colour, but its up to you to
figure out the colour.

When the problem becomes more complicated it becomes more difficult to
determine which objects intersect, and the list of objects becomes
larger and unwieldy. Theoretically possible but probably impractical.


Ken
bilalhaider
2009-05-20 07:12:31 UTC
Permalink
Post by ken
In article <17a1c201-6670-4af9-a3bb-ec7573ce1516
@g3g2000pra.googlegroups.com>, ***@gmail.com says...
Post by bilalhaider
How can i achieve the above functionality using imagemask?
If you mean alpha blending, then the answer is that you can't. The only
transparency supported in PostScript is fully transparent or fully
opaque.
Post by bilalhaider
Can we
achieve the same transparent effect using image operator for Language
Level 2/3. I am unable to find any such dictionary value that helps to
achieve that? Does there any algo underlying the imagemask operator? I
am not getting the clear picture.
The fundamental problem, I think, is that you want to do something which
isn't supported in the language.
What you (seem) to want to do is to draw two vector objects, and have
the intersection coloured in a way which is given by combining the
colour of the two objects. You can't do that in PostScript.
You can create a path which is the intersection of the two objects by
using clip, and you can fill that with a colour, but its up to you to
figure out the colour.
When the problem becomes more complicated it becomes more difficult to
determine which objects intersect, and the list of objects becomes
larger and unwieldy. Theoretically possible but probably impractical.
                Ken
Hi Ken
Post by ken
What you (seem) to want to do is to draw two vector objects, and have
the intersection coloured in a way which is given by combining the
colour of the two objects. You can't do that in PostScript.
Yeah this is what i want. Ok. I am doing some experiments on these
techniques.
Your help is very practical.
Alan G Isaac
2009-05-22 23:35:28 UTC
Permalink
Post by bilalhaider
I need to achieve transparency in PostScript Level 2.
http://pages.cs.wisc.edu/~ghost/doc/AFPL/6.50/Language.htm#Transparency

fwiw,
Alan Isaac

Continue reading on narkive:
Loading...