ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* metapost: remapping colors of an SVG picture
@ 2020-02-18 11:18 mf
  2020-02-18 13:53 ` Hans Hagen
  0 siblings, 1 reply; 7+ messages in thread
From: mf @ 2020-02-18 11:18 UTC (permalink / raw)
  To: ntg-context

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

Hello list,
I tried this:

\starttext
\startMPcode
picture p ; p := lmt_svg [ filename = "sample.svg" ] ;
draw p ;
color black_rgb ; black_rgb := ( 0, 0, 0 ) ;
color red_rgb   ; red_rgb   := ( 1, 0, 0 ) ;
remapcolor( black_rgb, red_rgb ) ;
recolor p ;
draw p shifted ( bbwidth(p) + 5mm, 0) ;
\stopMPcode
\stoptext

but recolor gives an error:
metapost log    > >> picture
metapost log    > ! Wrong picture color model: redpart of grey object.
metapost log    > <for(picture)> _f_:=(redpart(EXPR0),
metapost log    > 
greenpart(EXPR0),bluepart(EXPR0));if.bou...
metapost log    >
metapost log    > repathed->...fi;fi;else:addto._p_.also.i;fi;endfor
metapost log    > 
;setbounds._p_.to._b_;_p_....
metapost log    > <to be read again>
metapost log    >                    ;
metapost log    > <*> ...apcolor( black_rgb, red_rgb ) ; recolor p ;
metapost log    > 
draw grayed p shifted ( b...
metapost log    >

My goal is to remap colors of an SVG image, like this:

\starttext
\startMPcode
picture p ; p := lmt_svg [ filename = "sample.svg" ] ;
draw p ;
color black_rgb      ; black_rgb  := ( 0, 0, 0 ) ;
cmykcolor black_cmyk ; black_cmyk := ( 0, 0, 0, 1 ) ;
remapcolor( black_rgb, black_cmyk ) ;
recolor p ;
draw p shifted ( bbwidth(p) + 5mm, 0) ;
\stopMPcode
\stoptext

It relates to a recent thread in the mailing list about color management.
It's an attempt to use inkscape-made SVG graphics inside a CMYK 
workflow, without using color management.

Naturally it would work under some constraints, but there's a lot of 
graphics you can do with Inkscape that falls inside these:
- the number of colors in the input SVG should be limited, so that every 
color gets converted
- no embedded bitmaps, only vector graphics
- perhaps some other constraints on gradients, transparency, etc.

A good alternative would be a remapper based on a custom lua function 
like this:

function rgb2cmyk( r, g, b )
   ...
   return c, m, y, k
end

Massi

[-- Attachment #2: sample.svg --]
[-- Type: image/svg+xml, Size: 2796 bytes --]

[-- Attachment #3: Type: text/plain, Size: 493 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: metapost: remapping colors of an SVG picture
  2020-02-18 11:18 metapost: remapping colors of an SVG picture mf
@ 2020-02-18 13:53 ` Hans Hagen
  2020-02-18 18:07   ` Jan U. Hasecke
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Hagen @ 2020-02-18 13:53 UTC (permalink / raw)
  To: mailing list for ConTeXt users, mf

On 2/18/2020 12:18 PM, mf wrote:
> Hello list,
> I tried this:
> 
> \starttext
> \startMPcode
> picture p ; p := lmt_svg [ filename = "sample.svg" ] ;
> draw p ;
> color black_rgb ; black_rgb := ( 0, 0, 0 ) ;
> color red_rgb   ; red_rgb   := ( 1, 0, 0 ) ;
> remapcolor( black_rgb, red_rgb ) ;
> recolor p ;
> draw p shifted ( bbwidth(p) + 5mm, 0) ;
> \stopMPcode
> \stoptext

\setupcolors[rgb=no]
\startMPcode
     draw lmt_svg [ filename = "sample.svg" ] ;
\stopMPcode


> but recolor gives an error:
> metapost log    > >> picture
> metapost log    > ! Wrong picture color model: redpart of grey object.
> metapost log    > <for(picture)> _f_:=(redpart(EXPR0),
> metapost log    > greenpart(EXPR0),bluepart(EXPR0));if.bou...
> metapost log    >
> metapost log    > repathed->...fi;fi;else:addto._p_.also.i;fi;endfor
> metapost log    > ;setbounds._p_.to._b_;_p_....
> metapost log    > <to be read again>
> metapost log    >                    ;
> metapost log    > <*> ...apcolor( black_rgb, red_rgb ) ; recolor p ;
> metapost log    > draw grayed p shifted ( b...
> metapost log    >
> 
> My goal is to remap colors of an SVG image, like this:
> 
> \starttext
> \startMPcode
> picture p ; p := lmt_svg [ filename = "sample.svg" ] ;
> draw p ;
> color black_rgb      ; black_rgb  := ( 0, 0, 0 ) ;
> cmykcolor black_cmyk ; black_cmyk := ( 0, 0, 0, 1 ) ;
> remapcolor( black_rgb, black_cmyk ) ;
> recolor p ;
> draw p shifted ( bbwidth(p) + 5mm, 0) ;
> \stopMPcode
> \stoptext
> 
> It relates to a recent thread in the mailing list about color management.
> It's an attempt to use inkscape-made SVG graphics inside a CMYK 
> workflow, without using color management.
> 
> Naturally it would work under some constraints, but there's a lot of 
> graphics you can do with Inkscape that falls inside these:
> - the number of colors in the input SVG should be limited, so that every 
> color gets converted
> - no embedded bitmaps, only vector graphics
> - perhaps some other constraints on gradients, transparency, etc.
> 
> A good alternative would be a remapper based on a custom lua function 
> like this:
> 
> function rgb2cmyk( r, g, b )
>    ...
>    return c, m, y, k
> end
> 
> Massi
> 
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________
> 


-- 

-----------------------------------------------------------------
                                           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: metapost: remapping colors of an SVG picture
  2020-02-18 13:53 ` Hans Hagen
@ 2020-02-18 18:07   ` Jan U. Hasecke
  2020-02-18 18:17     ` mf
  0 siblings, 1 reply; 7+ messages in thread
From: Jan U. Hasecke @ 2020-02-18 18:07 UTC (permalink / raw)
  To: ntg-context

Am 18.02.20 um 14:53 schrieb Hans Hagen:

> 
> \setupcolors[rgb=no]
> \startMPcode
>     draw lmt_svg [ filename = "sample.svg" ] ;
> \stopMPcode

I get this error.

! Not implemented: (unknown numeric)=(string).
<to be read again>
]
<*> ... ; p := lmt_svg [ filename = "sample.svg" ]


juh
___________________________________________________________________________________
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: metapost: remapping colors of an SVG picture
  2020-02-18 18:07   ` Jan U. Hasecke
@ 2020-02-18 18:17     ` mf
  2020-02-18 18:24       ` Jan U. Hasecke
  0 siblings, 1 reply; 7+ messages in thread
From: mf @ 2020-02-18 18:17 UTC (permalink / raw)
  To: ntg-context

Il 18/02/20 19:07, Jan U. Hasecke ha scritto:
> Am 18.02.20 um 14:53 schrieb Hans Hagen:
>
>> \setupcolors[rgb=no]
>> \startMPcode
>>      draw lmt_svg [ filename = "sample.svg" ] ;
>> \stopMPcode
> I get this error.
>
> ! Not implemented: (unknown numeric)=(string).
> <to be read again>
> ]
> <*> ... ; p := lmt_svg [ filename = "sample.svg" ]
>
That's because it's LMTX only (the "lmt" prefix of "lmt_svg" should 
stand for "luametatex").

You find documentation about that in LMTX docs, luametafun.pdf, chapter 
"SVG".

Best wishes,

Massi

___________________________________________________________________________________
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: metapost: remapping colors of an SVG picture
  2020-02-18 18:17     ` mf
@ 2020-02-18 18:24       ` Jan U. Hasecke
  2020-02-20  9:29         ` Jan U. Hasecke
  0 siblings, 1 reply; 7+ messages in thread
From: Jan U. Hasecke @ 2020-02-18 18:24 UTC (permalink / raw)
  To: ntg-context

Am 18.02.20 um 19:17 schrieb mf:
> Il 18/02/20 19:07, Jan U. Hasecke ha scritto:
>> Am 18.02.20 um 14:53 schrieb Hans Hagen:
>>
>>> \setupcolors[rgb=no]
>>> \startMPcode
>>>      draw lmt_svg [ filename = "sample.svg" ] ;
>>> \stopMPcode
>> I get this error.
>>
>> ! Not implemented: (unknown numeric)=(string).
>> <to be read again>
>> ]
>> <*> ... ; p := lmt_svg [ filename = "sample.svg" ]
>>
> That's because it's LMTX only (the "lmt" prefix of "lmt_svg" should
> stand for "luametatex").

Yes, with lmtx it works but there is no image in the resulting file.

juh
___________________________________________________________________________________
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: metapost: remapping colors of an SVG picture
  2020-02-18 18:24       ` Jan U. Hasecke
@ 2020-02-20  9:29         ` Jan U. Hasecke
  2020-02-20 17:30           ` Hans Hagen
  0 siblings, 1 reply; 7+ messages in thread
From: Jan U. Hasecke @ 2020-02-20  9:29 UTC (permalink / raw)
  To: ntg-context

Am 18.02.20 um 19:24 schrieb Jan U. Hasecke:
> Am 18.02.20 um 19:17 schrieb mf:
>> Il 18/02/20 19:07, Jan U. Hasecke ha scritto:
>>> Am 18.02.20 um 14:53 schrieb Hans Hagen:
>>>
>>>> \setupcolors[rgb=no]
>>>> \startMPcode
>>>>      draw lmt_svg [ filename = "sample.svg" ] ;
>>>> \stopMPcode
>>> I get this error.
>>>
>>> ! Not implemented: (unknown numeric)=(string).
>>> <to be read again>
>>> ]
>>> <*> ... ; p := lmt_svg [ filename = "sample.svg" ]
>>>
>> That's because it's LMTX only (the "lmt" prefix of "lmt_svg" should
>> stand for "luametatex").
> 
> Yes, with lmtx it works but there is no image in the resulting file.

Sorry for digging deeper.

I am very thrilled by the idea that I could simply adjust a RGB SVG to
well defined CMYK colors with this trick.

Can anybody confirm if this works?

juh
___________________________________________________________________________________
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: metapost: remapping colors of an SVG picture
  2020-02-20  9:29         ` Jan U. Hasecke
@ 2020-02-20 17:30           ` Hans Hagen
  0 siblings, 0 replies; 7+ messages in thread
From: Hans Hagen @ 2020-02-20 17:30 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Jan U. Hasecke

On 2/20/2020 10:29 AM, Jan U. Hasecke wrote:
> Am 18.02.20 um 19:24 schrieb Jan U. Hasecke:
>> Am 18.02.20 um 19:17 schrieb mf:
>>> Il 18/02/20 19:07, Jan U. Hasecke ha scritto:
>>>> Am 18.02.20 um 14:53 schrieb Hans Hagen:
>>>>
>>>>> \setupcolors[rgb=no]
>>>>> \startMPcode
>>>>>       draw lmt_svg [ filename = "sample.svg" ] ;
>>>>> \stopMPcode
>>>> I get this error.
>>>>
>>>> ! Not implemented: (unknown numeric)=(string).
>>>> <to be read again>
>>>> ]
>>>> <*> ... ; p := lmt_svg [ filename = "sample.svg" ]
>>>>
>>> That's because it's LMTX only (the "lmt" prefix of "lmt_svg" should
>>> stand for "luametatex").
>>
>> Yes, with lmtx it works but there is no image in the resulting file.
> 
> Sorry for digging deeper.
> 
> I am very thrilled by the idea that I could simply adjust a RGB SVG to
> well defined CMYK colors with this trick.
> 
> Can anybody confirm if this works?
mf and i are playing with an overload mechanism (actually pretty 
trivial) ... more later but in principle the answer is yes, but

- first we have to play around a bit
- then it needs to end up in the core
- then there need to be a new context upload
- and mf has to wikify it

so, some patience is needed

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

end of thread, other threads:[~2020-02-20 17:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-18 11:18 metapost: remapping colors of an SVG picture mf
2020-02-18 13:53 ` Hans Hagen
2020-02-18 18:07   ` Jan U. Hasecke
2020-02-18 18:17     ` mf
2020-02-18 18:24       ` Jan U. Hasecke
2020-02-20  9:29         ` Jan U. Hasecke
2020-02-20 17:30           ` Hans Hagen

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