ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Shading and transparency
@ 2018-07-11 18:45 Marco Patzer
  2018-07-11 21:11 ` Hans Hagen
  0 siblings, 1 reply; 7+ messages in thread
From: Marco Patzer @ 2018-07-11 18:45 UTC (permalink / raw)
  To: mailing list for ConTeXt users

[-- Attachment #1: Type: text/plain, Size: 689 bytes --]

Hi!

It's shadings and transparency again.

For most things transparency is not required since the background
colour (white) can be used instead, to achieve the same effect
(thanks Hans for the reimplementation/cleanup a while ago). For one
use case I worked around this by including an external file and
overlay the external file (see attached example).

Background: In the actual documents the transparent overlays overlay
images to have the edges fade into the page background (only the
centre is of interest).

Is there a method that does not require an external file or
pre-processing? Using the external file works. Just wondering if
there's a better - more integrated - way.

Marco

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 5Z7.mkvi --]
[-- Type: text/x-tex, Size: 873 bytes --]

\definecolor [transparent] [a=multiply, t=1, s=1]

\startuseMPgraphic{trans}
  fill OverlayBox
    withshademethod "linear" withshadevector (3, 0)
    %% (white, "transparent") doesn't work here
    withshadecolors (white, white) withtransparency (0, .7);
\stopuseMPgraphic

%% to illustrate the effect, actual background is white
\setupbackgrounds [page] [background=color, backgroundcolor=lightgray]

\defineoverlay [gradient-mp]  [\useMPgraphic{trans}]
%% requires external file gradient-t.pdf
\defineoverlay [gradient-img] [{\externalfigure[gradient-t][width=\overlaywidth,height=\overlayheight]}]

\starttext
  using external image:
  \startframedtext [background={foreground, gradient-img}]
    \input knuth
  \stopframedtext
  metapost:
  \startframedtext [background={foreground, gradient-mp}]
    \input knuth
  \stopframedtext
\stoptext

[-- Attachment #3: 5Z7.pdf --]
[-- Type: application/pdf, Size: 11484 bytes --]

[-- Attachment #4: gradient-t.pdf --]
[-- Type: application/pdf, Size: 2425 bytes --]

[-- Attachment #5: Type: text/plain, Size: 492 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Shading and transparency
  2018-07-11 18:45 Shading and transparency Marco Patzer
@ 2018-07-11 21:11 ` Hans Hagen
  2018-07-11 21:40   ` Marco Patzer
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Hagen @ 2018-07-11 21:11 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Marco Patzer

On 7/11/2018 8:45 PM, Marco Patzer wrote:
> Hi!
> 
> It's shadings and transparency again.
> 
> For most things transparency is not required since the background
> colour (white) can be used instead, to achieve the same effect
> (thanks Hans for the reimplementation/cleanup a while ago). For one
> use case I worked around this by including an external file and
> overlay the external file (see attached example).
> 
> Background: In the actual documents the transparent overlays overlay
> images to have the edges fade into the page background (only the
> centre is of interest).
> 
> Is there a method that does not require an external file or
> pre-processing? Using the external file works. Just wondering if
> there's a better - more integrated - way.
i guess that with some experimenting you can come close but the external 
file that you use uses masks (actually we do support masks in external 
figures) and multiple shades over something in the page stream, stuff 
i'd only look into  when i have to (in principle one can make all kind 
of fancy mechanisms but does it pay off ... seldom)

Hans





-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Shading and transparency
  2018-07-11 21:11 ` Hans Hagen
@ 2018-07-11 21:40   ` Marco Patzer
  2018-07-12  9:21     ` Hans Hagen
  0 siblings, 1 reply; 7+ messages in thread
From: Marco Patzer @ 2018-07-11 21:40 UTC (permalink / raw)
  To: Hans Hagen; +Cc: mailing list for ConTeXt users

On Wed, 11 Jul 2018 23:11:31 +0200
Hans Hagen <j.hagen@xs4all.nl> wrote:

> > Is there a method that does not require an external file or
> > pre-processing? Using the external file works. Just wondering if
> > there's a better - more integrated - way.  
> i guess that with some experimenting you can come close but the
> external file that you use uses masks (actually we do support masks
> in external figures) and multiple shades over something in the page
> stream

For the old implementation (pre 2016-ish) I had a working solution
because shading to transparent colours just worked (at least in my
case of a simple transparent shade, nothing fancy), but not so any
longer. With the new implementation I couldn't get it working. But
we discussed that at some point in the past. I believe the gist of
it was “shade-to-transparent is gone”.

> stuff i'd only look into  when i have to (in principle one
> can make all kind of fancy mechanisms but does it pay off ... seldom)

If there's no easy solution, it's alright. If have a workaround. No
need to waste time on exotic features (as long as masks in external
figures keep working). Still, if you happen to know a trick to pull
that off in ConTeXt, let me know.

Marco
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Shading and transparency
  2018-07-11 21:40   ` Marco Patzer
@ 2018-07-12  9:21     ` Hans Hagen
  2018-07-12 20:08       ` Marco Patzer
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Hagen @ 2018-07-12  9:21 UTC (permalink / raw)
  To: Marco Patzer; +Cc: mailing list for ConTeXt users

On 7/11/2018 11:40 PM, Marco Patzer wrote:
> On Wed, 11 Jul 2018 23:11:31 +0200
> Hans Hagen <j.hagen@xs4all.nl> wrote:
> 
>>> Is there a method that does not require an external file or
>>> pre-processing? Using the external file works. Just wondering if
>>> there's a better - more integrated - way.
>> i guess that with some experimenting you can come close but the
>> external file that you use uses masks (actually we do support masks
>> in external figures) and multiple shades over something in the page
>> stream
> 
> For the old implementation (pre 2016-ish) I had a working solution
> because shading to transparent colours just worked (at least in my
> case of a simple transparent shade, nothing fancy), but not so any
> longer. With the new implementation I couldn't get it working. But
> we discussed that at some point in the past. I believe the gist of
> it was “shade-to-transparent is gone”.

i'm not ssure what shade to transparency means ... shades can be 
transparent currently .. so how did that old file (uncompressed pdf) 
look like then

>> stuff i'd only look into  when i have to (in principle one
>> can make all kind of fancy mechanisms but does it pay off ... seldom)
> 
> If there's no easy solution, it's alright. If have a workaround. No
> need to waste time on exotic features (as long as masks in external
> figures keep working). Still, if you happen to know a trick to pull
> that off in ConTeXt, let me know.
> 
> Marco
> 


-- 

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Shading and transparency
  2018-07-12  9:21     ` Hans Hagen
@ 2018-07-12 20:08       ` Marco Patzer
  2018-07-12 20:59         ` Hans Hagen
  0 siblings, 1 reply; 7+ messages in thread
From: Marco Patzer @ 2018-07-12 20:08 UTC (permalink / raw)
  To: Hans Hagen; +Cc: mailing list for ConTeXt users

On Thu, 12 Jul 2018 11:21:45 +0200
Hans Hagen <j.hagen@xs4all.nl> wrote:

> > For the old implementation (pre 2016-ish) I had a working solution
> > because shading to transparent colours just worked (at least in my
> > case of a simple transparent shade, nothing fancy), but not so any
> > longer. With the new implementation I couldn't get it working. But
> > we discussed that at some point in the past. I believe the gist of
> > it was “shade-to-transparent is gone”.  
> 
> i'm not ssure what shade to transparency means

I mean a shade from a colour (e.g. black) to transparent. For
instance this used to work pre 2016:

\setupbackgrounds [page] [background=color, backgroundcolor=lightgray]
\definecolor [trans] [a=multiply, t=1, s=1]
\starttext
\startMPcode
  path p; p:=fullsquare xyscaled (5cm, 5cm);
  fill p
    withshading("linear", ulcorner p, llcorner p)
    withfromshadecolor \MPcolor{white}
    withtoshadecolor   \MPcolor{trans};
\stopMPcode
\stoptext

The shade goes from white to transparent (here lightgray, that's the
page colour). I assume you have an older context laying around to
run the example above.

> ... shades can be transparent currently

Yes, but the *whole* shade is made transparent. Currently I don't
know a way to shade from e.g. black to transparent (no colour). The
colour involved in the shading can't have transparency, or if they
do one has to use \MPcoloronly to get rid of the transparency part.

So the above old syntax roughly translated to the current
implementation:

\setupbackgrounds [page] [background=color, backgroundcolor=lightgray]
\definecolor [trans] [a=multiply, t=1, s=1]
\starttext
\startMPcode
  path p; p:=fullsquare xyscaled (5cm, 5cm);
    fill p
      withshademethod "linear"
      withshadevector (3, 0)
      %% since "trans" contains transparency, one has to use
\MPcoloronly withshadecolors (white, \MPcoloronly{trans})
      withtransparency (.5, .5)
      %% withtransparency \MPtransparency{trans}
      ;
  \stopMPcode
\stoptext

> .. so how did that old file (uncompressed pdf) look like then

Just run the first example with an old context version. The file
gradient-t from my last mail was created using inkscape as I don't
want a single project to depend on two different context versions.

Marco
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Shading and transparency
  2018-07-12 20:08       ` Marco Patzer
@ 2018-07-12 20:59         ` Hans Hagen
  2018-07-12 21:53           ` Marco Patzer
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Hagen @ 2018-07-12 20:59 UTC (permalink / raw)
  To: Marco Patzer; +Cc: mailing list for ConTeXt users

On 7/12/2018 10:08 PM, Marco Patzer wrote:
> On Thu, 12 Jul 2018 11:21:45 +0200
> Hans Hagen <j.hagen@xs4all.nl> wrote:
> 
>>> For the old implementation (pre 2016-ish) I had a working solution
>>> because shading to transparent colours just worked (at least in my
>>> case of a simple transparent shade, nothing fancy), but not so any
>>> longer. With the new implementation I couldn't get it working. But
>>> we discussed that at some point in the past. I believe the gist of
>>> it was “shade-to-transparent is gone”.
>>
>> i'm not ssure what shade to transparency means
> 
> I mean a shade from a colour (e.g. black) to transparent. For
> instance this used to work pre 2016:
> 
> \setupbackgrounds [page] [background=color, backgroundcolor=lightgray]
> \definecolor [trans] [a=multiply, t=1, s=1]
> \starttext
> \startMPcode
>    path p; p:=fullsquare xyscaled (5cm, 5cm);
>    fill p
>      withshading("linear", ulcorner p, llcorner p)
>      withfromshadecolor \MPcolor{white}
>      withtoshadecolor   \MPcolor{trans};
> \stopMPcode
> \stoptext
> 
> The shade goes from white to transparent (here lightgray, that's the
> page colour). I assume you have an older context laying around to
> run the example above.
> 
>> ... shades can be transparent currently
> 
> Yes, but the *whole* shade is made transparent. Currently I don't
> know a way to shade from e.g. black to transparent (no colour). The
> colour involved in the shading can't have transparency, or if they
> do one has to use \MPcoloronly to get rid of the transparency part.

hm, I'm puzzled as a shade doesn't go between colors + transparent but 
from one color to another (in the same color space) and transparency is 
just a different mechanism

maybe it was some side effect of chosen values / vectors that gave the 
combined impression (which is why i want to see the pdf made by context 
that you use as reference)

anyway, it helps to be in the same color space

\setupbackgrounds [page] [background=color, backgroundcolor=lightgray]

\starttext

\startuseMPgraphic{test}
     graycolor white; white := 1 ;
     fill OverlayBox
         withshademethod "linear"
         withshadedirection shadedup
         withshadefactor 1.5
         withshadecolors (.85white,white)
       % withtransparency (multiplytransparent,.7)
         withtransparency (normaltransparent,.7)
\stopuseMPgraphic

\defineoverlay[test][\useMPgraphic{test}]

\framed
   [align=middle,background={foreground,test}]
   {\samplefile{sapolsky}}

\stoptext


> So the above old syntax roughly translated to the current
> implementation:
> 
> \setupbackgrounds [page] [background=color, backgroundcolor=lightgray]
> \definecolor [trans] [a=multiply, t=1, s=1]
> \starttext
> \startMPcode
>    path p; p:=fullsquare xyscaled (5cm, 5cm);
>      fill p
>        withshademethod "linear"
>        withshadevector (3, 0)
>        %% since "trans" contains transparency, one has to use
> \MPcoloronly withshadecolors (white, \MPcoloronly{trans})
>        withtransparency (.5, .5)
>        %% withtransparency \MPtransparency{trans}
>        ;
>    \stopMPcode
> \stoptext
> 
>> .. so how did that old file (uncompressed pdf) look like then
> 
> Just run the first example with an old context version. The file
> gradient-t from my last mail was created using inkscape as I don't
> want a single project to depend on two different context versions.
you're kidding ... i have no old context on my machine

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Shading and transparency
  2018-07-12 20:59         ` Hans Hagen
@ 2018-07-12 21:53           ` Marco Patzer
  0 siblings, 0 replies; 7+ messages in thread
From: Marco Patzer @ 2018-07-12 21:53 UTC (permalink / raw)
  To: Hans Hagen; +Cc: mailing list for ConTeXt users

[-- Attachment #1: Type: text/plain, Size: 2082 bytes --]

On Thu, 12 Jul 2018 22:59:05 +0200
Hans Hagen <j.hagen@xs4all.nl> wrote:

> hm, I'm puzzled as a shade doesn't go between colors + transparent
> but from one color to another (in the same color space) and
> transparency is just a different mechanism
> 
> maybe it was some side effect of chosen values / vectors that gave
> the combined impression (which is why i want to see the pdf made by
> context that you use as reference)

I just checked some older projects and the older versions. I used a
mix between

- linear_shade…
- withshading("linear"…
- withshademethod "linear" …

depending on the age of the project. And I fail to find a project
using transparent shading where the transparency is done in context.
I could not get it working now on the older versions. Maybe you're
right and it has never worked the way I thought it had. Sorry for
the noise.

> \setupbackgrounds [page] [background=color, backgroundcolor=lightgray]
> 
> \starttext
> 
> \startuseMPgraphic{test}
>      graycolor white; white := 1 ;
>      fill OverlayBox
>          withshademethod "linear"
>          withshadedirection shadedup
>          withshadefactor 1.5
>          withshadecolors (.85white,white)
>        % withtransparency (multiplytransparent,.7)
>          withtransparency (normaltransparent,.7)
> \stopuseMPgraphic
> 
> \defineoverlay[test][\useMPgraphic{test}]
> 
> \framed
>    [align=middle,background={foreground,test}]
>    {\samplefile{sapolsky}}
> 
> \stoptext

That's basically shading to the background colour, which gives the
impression of transparency. I've been using that. Works most of the
time. But it's not the same. See the attached file and compare.

I guess I'll keep using the external file overlay then.

> > Just run the first example with an old context version. The file
> > gradient-t from my last mail was created using inkscape as I don't
> > want a single project to depend on two different context versions.  
> you're kidding ... i have no old context on my machine

Silly me :)

Marco

[-- Attachment #2: 0nC.pdf --]
[-- Type: application/pdf, Size: 11557 bytes --]

[-- Attachment #3: Type: text/plain, Size: 492 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-07-12 21:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-11 18:45 Shading and transparency Marco Patzer
2018-07-11 21:11 ` Hans Hagen
2018-07-11 21:40   ` Marco Patzer
2018-07-12  9:21     ` Hans Hagen
2018-07-12 20:08       ` Marco Patzer
2018-07-12 20:59         ` Hans Hagen
2018-07-12 21:53           ` Marco Patzer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).