23#define NANOSVG_ALL_COLOR_KEYWORDS
24#define NANOSVG_IMPLEMENTATION
26#define NANOSVGRAST_IMPLEMENTATION
40static void Svg_free(DilloSvg *svg)
42 _MSG(
"Svg_free: svg=%p\n", svg);
61static void Svg_write(DilloSvg *svg,
void *Buf,
uint_t BufSize)
68 if (Buf == NULL || BufSize <= 0)
72 if (strstr(Buf,
"</svg>") == NULL)
77 unsigned fg_r = (svg->fgcolor >> 16) & 0xff;
78 unsigned fg_g = (svg->fgcolor >> 8) & 0xff;
79 unsigned fg_b = (svg->fgcolor >> 0) & 0xff;
80 unsigned curcolor = NSVG_RGB(fg_r, fg_g, fg_b);
88 MSG_ERR(
"Svg_write: cannot parse SVG image\n");
93 unsigned width = nimg->
width;
94 unsigned height = nimg->
height;
96 if (width == 0 || height == 0 || width >
IMAGE_MAX_AREA / height) {
97 MSG_WARN(
"Svg_write: suspicious image size request %u x %u\n", width, height);
103 unsigned stride = width * 4;
106 width, height, type, 1 / 2.2);
108 unsigned char *dest =
dNew(
unsigned char, height * stride);
110 nsvgRasterizeXY(rasterizer, nimg, 0, 0, 1, 1, dest, width, height, stride);
112 unsigned bg_blue = (svg->bgcolor) & 0xFF;
113 unsigned bg_green = (svg->bgcolor >> 8) & 0xFF;
114 unsigned bg_red = (svg->bgcolor >> 16) & 0xFF;
116 unsigned char *line =
dNew(
unsigned char, width * 3);
117 for (
unsigned i = 0; i < height; i++) {
118 for (
unsigned j = 0; j < width; j++) {
119 unsigned r = dest[i * stride + 4 * j];
120 unsigned g = dest[i * stride + 4 * j + 1];
121 unsigned b = dest[i * stride + 4 * j + 2];
122 unsigned alpha = dest[i * stride + 4 * j + 3];
124 line[3 * j + 0] = (r * alpha + (bg_red * (0xFF - alpha))) / 0xFF;
125 line[3 * j + 1] = (g * alpha + (bg_green * (0xFF - alpha))) / 0xFF;
126 line[3 * j + 2] = (b * alpha + (bg_blue * (0xFF - alpha))) / 0xFF;
142 Svg_close(Client->
CbData, Client);
153 DilloSvg *svg =
dNew0(DilloSvg, 1);
154 _MSG(
"a_Svg_new: svg=%p\n", svg);
158 svg->version = version;
void a_Dicache_set_parms(DilloUrl *url, int version, DilloImage *Image, uint_t width, uint_t height, DilloImgType type, double gamma)
Set image's width, height & type.
void a_Dicache_close(DilloUrl *url, int version, CacheClient_t *Client)
Implement the close method of the decoding process.
void a_Dicache_write(DilloUrl *url, int version, const uchar_t *buf, uint_t Y)
Implement the write method (Write a scan line into the Dicache entry) buf: row buffer Y : row number.
char * dStrndup(const char *s, size_t sz)
#define dNew0(type, count)
#define dNew(type, count)
NSVGimage * nsvgParse(char *input, const char *units, float dpi, unsigned current_color)
void nsvgDelete(NSVGimage *image)
NSVGrasterizer * nsvgCreateRasterizer(void)
void nsvgRasterizeXY(NSVGrasterizer *r, NSVGimage *image, float tx, float ty, float sx, float sy, unsigned char *dst, int w, int h, int stride)
struct NSVGrasterizer NSVGrasterizer
Data structure for cache clients.
void * CbData
Client function data.
uint_t BufSize
Valid size of cache-data.
void * Buf
Pointer to cache-data.
int32_t fg_color
Foreground color.
int32_t bg_color
Background color.