Passing colors to Metafun and TeX's bitmapimage macros
Hi, list! I want to know if there's a handy way to pass predefined colors, either RGB or CMYK, e.g. those in svg or crayola, to Metafun's bitmapimage. Say, something like: \startMPpage % svg's gold definition draw bitmapimage(2, 2, "ffd700 ffd700 ffd700 000000") scaled 3cm; \stopMPpage using "gold" instead of its definition so that I can set bitmap image colors by name rather than numbers. In a similar vein, I wonder if something analogous is possible for ConTeXt's \bitmapimage macro. Thank you in advance. Cordially, Jairo
On 9/1/2021 1:08 PM, Jairo A. del Rio via ntg-context wrote:
Hi, list! I want to know if there's a handy way to pass predefined colors, either RGB or CMYK, e.g. those in svg or crayola, to Metafun's bitmapimage. Say, something like:
\startMPpage
% svg's gold definition
draw bitmapimage(2, 2, "ffd700 ffd700 ffd700 000000") scaled 3cm;
\stopMPpage
using "gold" instead of its definition so that I can set bitmap image colors by name rather than numbers. In a similar vein, I wonder if something analogous is possible for ConTeXt's \bitmapimage macro. Thank you in advance. it's mostly about 'what interface to use' and 'how is that documented and remembered at all'
\startluacode function MP.replacecolors(str,c) -- could be a helper, these two combined (never needed it): local m, a = attributes.colors.namedcolorattributes(c) local d = attributes.colors.values[a] local r = string.format("%02x%02x%02x", math.round(d[3]*255), math.round(d[4]*255), math.round(d[5]*255) ) mp.quoted((string.gsub(str,"444444",r))) end \stopluacode \definecolor[kindofgold][h=ffd700] \startMPpage draw bitmapimage(2, 2, "ffd700 ffd700 ffd700 000000") scaled 3cm; vardef mybitmapimage(expr n, m, s, c) = bitmapimage(2, 2, MP.replacecolors(s, c)) enddef ; draw mybitmapimage(2, 2, "444444 444444 444444 000000", "kindofgold") scaled 3cm shifted (0,-3cm); \stopMPpage ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
participants (2)
-
Hans Hagen
-
Jairo A. del Rio