Skip to content

Commit 035f6bd

Browse files
committed
svgload: renamed rgb128 to high_bitdepth flag
1 parent 10433b3 commit 035f6bd

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ master
3333
need libjxl 0.11 at minimum)
3434
- increase minimum version of libheif dependency to 1.11.0
3535
- heifload: limit per-image memory usage to 2GB (requires libheif 1.20.0+).
36+
- svgload: introduce high_bitdepth parameter for SVG 128-bit load support [kstanikviacbs]
3637

3738
8.16.1
3839

libvips/foreign/cairo.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ vips__bgra2rgba(guint32 *restrict p, int n)
133133
* Processes ''n'' pixels in the ''p'' buffer.
134134
* The data is assumed to be RGBA (R, G, B, A) 32-bit floats per pixel.
135135
*/
136-
void vips__rgba128f_unpremultiplied(float *p, int n) {
136+
void
137+
vips__premultiplied_rgb1282scrgba(float *p, int n)
138+
{
137139
float *restrict pixel = p;
138140
for (int x = 0; x < n; x++) {
139141
float r = pixel[0];

libvips/foreign/svgload.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
* - support rsvg_handle_get_intrinsic_size_in_pixels()
2929
* 5/6/22
3030
* - allow random access
31+
* 20/5/25
32+
* - support high bit depth rendering (128-bit)
3133
*/
3234

3335
/*
@@ -119,9 +121,9 @@ typedef struct _VipsForeignLoadSvg {
119121
*/
120122
gboolean unlimited;
121123

122-
/* Enables 128-bit SVG rendering.
124+
/* Enables scRGB 128-bit output (32-bit per channel).
123125
*/
124-
gboolean rgb128;
126+
gboolean high_bitdepth;
125127

126128
/* Custom CSS.
127129
*/
@@ -343,9 +345,9 @@ vips_foreign_load_svg_build(VipsObject *object)
343345
#endif /*DEBUG*/
344346

345347
#ifndef HAVE_128BIT_SVG_RENDERING
346-
if (svg->rgb128) {
347-
g_warning("setting rgb128 unsupported");
348-
svg->rgb128 = FALSE;
348+
if (svg->high_bitdepth) {
349+
g_warning("setting high_bitdepth unsupported");
350+
svg->high_bitdepth = FALSE;
349351
}
350352
#endif /*HAVE_128BIT_SVG_RENDERING*/
351353

@@ -579,9 +581,9 @@ vips_foreign_load_svg_parse(VipsForeignLoadSvg *svg, VipsImage *out)
579581

580582
vips_image_init_fields(out,
581583
width, height, 4,
582-
svg->rgb128 ? VIPS_FORMAT_FLOAT : VIPS_FORMAT_UCHAR,
584+
svg->high_bitdepth ? VIPS_FORMAT_FLOAT : VIPS_FORMAT_UCHAR,
583585
VIPS_CODING_NONE,
584-
svg->rgb128 ? VIPS_INTERPRETATION_scRGB : VIPS_INTERPRETATION_sRGB,
586+
svg->high_bitdepth ? VIPS_INTERPRETATION_scRGB : VIPS_INTERPRETATION_sRGB,
585587
res, res);
586588

587589
/* We use a tilecache, so it's smalltile.
@@ -624,7 +626,7 @@ vips_foreign_load_svg_generate(VipsRegion *out_region,
624626
vips_region_black(out_region);
625627

626628
#ifdef HAVE_128BIT_SVG_RENDERING
627-
cairo_format_t format = svg->rgb128 ? CAIRO_FORMAT_RGBA128F : CAIRO_FORMAT_ARGB32;
629+
cairo_format_t format = svg->high_bitdepth ? CAIRO_FORMAT_RGBA128F : CAIRO_FORMAT_ARGB32;
628630
#else
629631
cairo_format_t format = CAIRO_FORMAT_ARGB32;
630632
#endif /*HAVE_128BIT_SVG_RENDERING*/
@@ -699,12 +701,12 @@ vips_foreign_load_svg_generate(VipsRegion *out_region,
699701
cairo_destroy(cr);
700702

701703
#endif /*LIBRSVG_CHECK_VERSION(2, 46, 0)*/
702-
if (svg->rgb128) {
704+
if (svg->high_bitdepth) {
703705
/* Assuming the surface is RGBA128F and the data is premultiplied.
704706
Loop through each row and unpremultiply the float data.
705707
*/
706708
for (int y = 0; y < r->height; y++)
707-
vips__rgba128f_unpremultiplied(
709+
vips__premultiplied_rgb1282scrgba(
708710
(float *) VIPS_REGION_ADDR(out_region, r->left, r->top + y),
709711
r->width);
710712
}
@@ -741,7 +743,7 @@ vips_foreign_load_svg_load(VipsForeignLoad *load)
741743
return -1;
742744

743745
VipsImage *in = t[1];
744-
if (svg->rgb128) {
746+
if (svg->high_bitdepth) {
745747
if (vips_gamma(in, &t[2], NULL))
746748
return -1;
747749
in = t[2];
@@ -811,11 +813,11 @@ vips_foreign_load_svg_class_init(VipsForeignLoadSvgClass *class)
811813
G_STRUCT_OFFSET(VipsForeignLoadSvg, stylesheet),
812814
NULL);
813815

814-
VIPS_ARG_BOOL(class, "rgb128", 25,
815-
_("RGB128"),
816-
_("Enable 128-bit SVG rendering"),
816+
VIPS_ARG_BOOL(class, "high_bitdepth", 25,
817+
_("HIGH_BITDEPTH"),
818+
_("Enable scRGB 128-bit output (32-bit per channel)"),
817819
VIPS_ARGUMENT_OPTIONAL_INPUT,
818-
G_STRUCT_OFFSET(VipsForeignLoadSvg, rgb128),
820+
G_STRUCT_OFFSET(VipsForeignLoadSvg, high_bitdepth),
819821
FALSE);
820822
}
821823

@@ -1113,11 +1115,14 @@ vips_foreign_load_svg_buffer_init(VipsForeignLoadSvgBuffer *buffer)
11131115
* During the CSS cascade, the specified stylesheet will be applied with a
11141116
* User Origin. This feature requires librsvg 2.48.0 or later.
11151117
*
1118+
* Setting @high_bitdepth TRUE enables 128-bit scRGB output."
1119+
*
11161120
* ::: tip "Optional arguments"
11171121
* * @dpi: `gdouble`, render at this DPI
11181122
* * @scale: `gdouble`, scale render by this factor
11191123
* * @unlimited: `gboolean`, allow SVGs of any size
11201124
* * @stylesheet: `gchararray`, custom CSS
1125+
* * @high_bitdepth: `gboolean`, enable scRGB 128-bit output
11211126
*
11221127
* ::: seealso
11231128
* [ctor@Image.new_from_file].
@@ -1155,6 +1160,7 @@ vips_svgload(const char *filename, VipsImage **out, ...)
11551160
* * @scale: `gdouble`, scale render by this factor
11561161
* * @unlimited: `gboolean`, allow SVGs of any size
11571162
* * @stylesheet: `gchararray`, custom CSS
1163+
* * @high_bitdepth: `gboolean`, enable scRGB 128-bit output
11581164
*
11591165
* ::: seealso
11601166
* [ctor@Image.svgload].
@@ -1195,6 +1201,7 @@ vips_svgload_buffer(void *buf, size_t len, VipsImage **out, ...)
11951201
* * @scale: `gdouble`, scale render by this factor
11961202
* * @unlimited: `gboolean`, allow SVGs of any size
11971203
* * @stylesheet: `gchararray`, custom CSS
1204+
* * @high_bitdepth: `gboolean`, enable scRGB 128-bit output
11981205
*
11991206
* ::: seealso
12001207
* [ctor@Image.svgload].

0 commit comments

Comments
 (0)