[NTG-context] metapost: remapping colors of an SVG picture

mf massifr at fastwebnet.it
Tue Feb 18 12:18:16 CET 2020


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sample.svg
Type: image/svg+xml
Size: 2796 bytes
Desc: not available
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20200218/f0ae4faa/attachment.svg>


More information about the ntg-context mailing list