Skip to content

Commit 10d28ce

Browse files
authored
guard against /0 in XYZ2Yxy (#4323)
Before this PR, converting to Yxy could leave -nan in pixels, eg.: $ vips colourspace k2.jpg x.v yxy $ vips avg x.v (vips:231364): GLib-GObject-CRITICAL **: 16:02:54.674: value "-nan" of type 'gdouble' is invalid or out of range for property 'out' of type 'gdouble' avg: parameter out not set This PR adds a check for 0 before divide.
1 parent 33ab2cc commit 10d28ce

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- threadpool: improve cooperative downsizing [kleisauke]
1212
- fix alpha shift during colourspace conversions [frederikrosenberg]
1313
- heifsave: set image orientation using irot and imir transformations [lovell]
14+
- XYZ2Yxy: guard against divide by zero
1415

1516
10/10/24 8.16.0
1617

libvips/colour/XYZ2Yxy.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,14 @@ vips_XYZ2Yxy_line(VipsColour *colour, VipsPel *out, VipsPel **in, int width)
7272

7373
p += 3;
7474

75-
x = X / total;
76-
y = Y / total;
75+
if (total == 0.0) {
76+
x = 0;
77+
y = 0;
78+
}
79+
else {
80+
x = X / total;
81+
y = Y / total;
82+
}
7783

7884
q[0] = Y;
7985
q[1] = x;

0 commit comments

Comments
 (0)