ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* invert colors in \externalfigure
@ 2016-01-20 12:10 Pablo Rodriguez
  2016-01-20 12:19 ` Wolfgang Schuster
  2016-01-20 13:09 ` Marco Patzer
  0 siblings, 2 replies; 7+ messages in thread
From: Pablo Rodriguez @ 2016-01-20 12:10 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Dear list,

I have the following sample:

    \setuppapersize[A6]
    \setuplayout[width=middle]
    \starttext
    \startmakeup[standard][align=center]
    \dontleavehmode\externalfigure[cow][width=\textwidth]
    \stopmakeup
    \stoptext

How can I invert the colors in the external figure without having to
edit the image file?

Many thanks for your help,

Pablo
-- 
http://www.ousia.tk
___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: invert colors in \externalfigure
  2016-01-20 12:10 invert colors in \externalfigure Pablo Rodriguez
@ 2016-01-20 12:19 ` Wolfgang Schuster
  2016-01-20 16:56   ` Pablo Rodriguez
  2016-01-20 13:09 ` Marco Patzer
  1 sibling, 1 reply; 7+ messages in thread
From: Wolfgang Schuster @ 2016-01-20 12:19 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 767 bytes --]

> Pablo Rodriguez <mailto:oinos@gmx.es>
> 20. Januar 2016 um 13:10
> Dear list,
>
> I have the following sample:
>
> \setuppapersize[A6]
> \setuplayout[width=middle]
> \starttext
> \startmakeup[standard][align=center]
> \dontleavehmode\externalfigure[cow][width=\textwidth]
> \stopmakeup
> \stoptext
>
> How can I invert the colors in the external figure without having to
> edit the image file?
>
> Many thanks for your help,
You have to use the Adobe Reader to view the PDF.

\setupexternalfigure[location=default]

\starttext

\externalfigure[cow][width=\textwidth]

\startnegative
\externalfigure[cow][width=\textwidth]
\stopnegative

\startnegative
\externalfigure[cow][background=color,backgroundcolor=white,width=\textwidth]
\stopnegative

\stoptext

Wolfgang

[-- Attachment #1.2: Type: text/html, Size: 1839 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: invert colors in \externalfigure
  2016-01-20 12:10 invert colors in \externalfigure Pablo Rodriguez
  2016-01-20 12:19 ` Wolfgang Schuster
@ 2016-01-20 13:09 ` Marco Patzer
  2016-01-20 17:12   ` Pablo Rodriguez
  1 sibling, 1 reply; 7+ messages in thread
From: Marco Patzer @ 2016-01-20 13:09 UTC (permalink / raw)
  To: ntg-context

> How can I invert the colors in the external figure without having
> to edit the image file?

Based on Peter Münster's grph-downsample.lua here some lines that
should get you started. Note that you'll need graphicsmagick (or
imagemagick for that matter. In the latter case change the call from
`gm convert` to `convert`). This will do the conversion on the fly.

\startluacode
  local format = string.format
  local function invert(oldname, newname)
    local s = format("gm convert -negate %s %s", oldname, newname)
    os.execute(s)
  end
  local formats = {"png", "jpg", "gif"}
  for _, s in ipairs(formats) do
    figures.converters[s] = figures.converters[s] or {}
    figures.converters[s]["invert." .. s] = invert
  end
\stopluacode

\setupexternalfigures [conversion=invert.jpg]
\setupexternalfigures [location=default]

\starttext
  \externalfigure[hacker]
\stoptext

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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: invert colors in \externalfigure
  2016-01-20 12:19 ` Wolfgang Schuster
@ 2016-01-20 16:56   ` Pablo Rodriguez
  2016-01-20 18:35     ` Alan BRASLAU
  0 siblings, 1 reply; 7+ messages in thread
From: Pablo Rodriguez @ 2016-01-20 16:56 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 01/20/2016 01:19 PM, Wolfgang Schuster wrote:
>> Pablo Rodriguez 20. Januar 2016 um 13:10
>> [...]
>> How can I invert the colors in the external figure without having to
>> edit the image file?
>>
>> Many thanks for your help,
> You have to use the Adobe Reader to view the PDF.

Many thanks for your solution, Wolfgang.

I’m afraid that I’m on Linux and I don’t have Adobe Reader installed.

But it is fine for me, since I’m going to print the file with Adobe
Reader DC.

It seems that other viewers don’t implement the /TR entry from
/ExtGState dictionary (according to the PDF spec).

I’m going to report the issue for Ghostscript, mupdf and poppler, so
that they have the feature implemented.

Many thanks for your help,

Pablo


> \setupexternalfigure[location=default]
> 
> \starttext
> 
> \externalfigure[cow][width=\textwidth]
> 
> \startnegative
> \externalfigure[cow][width=\textwidth]
> \stopnegative
> 
> \startnegative
> \externalfigure[cow][background=color,backgroundcolor=white,width=\textwidth]
> \stopnegative
> 
> \stoptext
> 
> Wolfgang

-- 
http://www.ousia.tk
___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: invert colors in \externalfigure
  2016-01-20 13:09 ` Marco Patzer
@ 2016-01-20 17:12   ` Pablo Rodriguez
  0 siblings, 0 replies; 7+ messages in thread
From: Pablo Rodriguez @ 2016-01-20 17:12 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 01/20/2016 02:09 PM, Marco Patzer wrote:
>> How can I invert the colors in the external figure without having
>> to edit the image file?
> 
> Based on Peter Münster's grph-downsample.lua here some lines that
> should get you started. Note that you'll need graphicsmagick (or
> imagemagick for that matter. In the latter case change the call from
> `gm convert` to `convert`). This will do the conversion on the fly.

Many thanks for your reply, Marco.

I’m afraid it doesn’t work with PDF files. But it is fine for me, since
the solution provided by Wolfgang works fine.

Many thanks for your help,


Pablo
-- 
http://www.ousia.tk
___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: invert colors in \externalfigure
  2016-01-20 16:56   ` Pablo Rodriguez
@ 2016-01-20 18:35     ` Alan BRASLAU
  2016-01-22 20:39       ` Pablo Rodriguez
  0 siblings, 1 reply; 7+ messages in thread
From: Alan BRASLAU @ 2016-01-20 18:35 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Wed, 20 Jan 2016 17:56:53 +0100
Pablo Rodriguez <oinos@gmx.es> wrote:

> On 01/20/2016 01:19 PM, Wolfgang Schuster wrote:
> >> Pablo Rodriguez 20. Januar 2016 um 13:10
> >> [...]
> >> How can I invert the colors in the external figure without having
> >> to edit the image file?
> >>
> >> Many thanks for your help,  
> > You have to use the Adobe Reader to view the PDF.  
> 
> I’m afraid that I’m on Linux and I don’t have Adobe Reader installed.

Not just on Linux... (Adobe reader is a notorious security hole).


With MetaFun, you can invert the colors using:

\startMPcode
  draw whatever... ;
  currentpicture := inverted currentpicture ;
\stopMPcode

Unfortunately, this does *not* work with externalfigure, i.e.
  \startMPcode
    draw externalfigure("cow") ;
    currentpicture := inverted currentpicture ;
  \stopMPcode
or
  \startMPcode
    draw rawtextext("\externalfigure [cow]") ;
    currentpicture := inverted currentpicture ;
  \stopMPcode
as inverted (a macro) operates on all the elements of the picture.

I find it easiest to use ImageMagick or gimp to invert the colors and
save this in a second image file.

Alan
___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: invert colors in \externalfigure
  2016-01-20 18:35     ` Alan BRASLAU
@ 2016-01-22 20:39       ` Pablo Rodriguez
  0 siblings, 0 replies; 7+ messages in thread
From: Pablo Rodriguez @ 2016-01-22 20:39 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 01/20/2016 07:35 PM, Alan BRASLAU wrote:
> On Wed, 20 Jan 2016 17:56:53 +0100 Pablo Rodriguez  wrote:
> 
>> On 01/20/2016 01:19 PM, Wolfgang Schuster wrote:
>>>> Pablo Rodriguez 20. Januar 2016 um 13:10
>>>> [...]
>>>> How can I invert the colors in the external figure without having
>>>> to edit the image file?
>>>>
>>>> Many thanks for your help,  
>>> You have to use the Adobe Reader to view the PDF.  
>>
>> I’m afraid that I’m on Linux and I don’t have Adobe Reader installed.
> 
> Not just on Linux... (Adobe reader is a notorious security hole).

Many thanks for your reply, Alan.

\startnegative is the way of doing it, as Wolfgang suggested. Don’t
worry, I won’t install Adobe Reader.

Ghostscript also implements what actually is the /TR (transformation)
entry for /ExtGState (graphics state) dictionary. (I was wrong in my
previous message.)

Only poppler and mupdf should implement it.

Many thanks for your help,

Pablo
-- 
http://www.ousia.tk
___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

end of thread, other threads:[~2016-01-22 20:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-20 12:10 invert colors in \externalfigure Pablo Rodriguez
2016-01-20 12:19 ` Wolfgang Schuster
2016-01-20 16:56   ` Pablo Rodriguez
2016-01-20 18:35     ` Alan BRASLAU
2016-01-22 20:39       ` Pablo Rodriguez
2016-01-20 13:09 ` Marco Patzer
2016-01-20 17:12   ` Pablo Rodriguez

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).