How do I set a soft mask (luminosity) in PDF graphics state?

Q: Dou you have any simple to edit and change the soft mask
(luminosity) in PDF graphics state for arbitrary PDF element?
A: You could use element.GetGSate().SetSoftMask(smask_dict) to set the
soft mask that will affect subsequent elements on the page (please see
"Soft-Mask Dictionaries" in PDF Reference for more information).

The following pseudocode creates a 'Soft-Mask Dictionary':

Obj smask_dict = pdfdoc.CreateDictIndirect();
smask_dict.PutName("S", "Luminosity");
smask_dict.PutName("S", "Alpha");

// Use ElementBuilder to create a soft mask group ...
// A soft mask group can contain any path/text/image. The luminosity
channel from
// this layer will be used as a soft mask for elements in another
content stream.

ElementBuilder builder;
ElementWriter writer;

Element e = builder.CreateRect(x1, y1, x2, y2);
GState gs = e.GetGState();
gs.SetFillColor(ColorPt(1, 0, 0));

Obj transp_grp = builder.End();
smask_dict.Put("G", transp_grp);


// Later on when creating page content...

Please keep in mind that the above sample code is using PDF 'Soft
Mask' feature. In some cases you can achieve similar effects using
regular clipping path or an image mask.