Skip to content

Commit 995701d

Browse files
committed
name the values in the gain map's cross checks
1 parent da38bc3 commit 995701d

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎src/gainmap.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,9 @@ export class GainMap {
229229
private __check__(): void {
230230
// (each value is checked when it is set; these are the checks between them)
231231
for (let c = 0; c < 3; c++)
232-
if (this.__max__[c] < this.__min__[c]) throw new RangeError('The gain map\'s max must be at least its min');
233-
if (this.__capacityMax__ <= this.__capacityMin__) throw new RangeError('The gain map\'s hdrCapacityMax must be above its hdrCapacityMin');
232+
if (this.__max__[c] < this.__min__[c]) throw new RangeError(`The gain map's max must be at least its min (${this.__max__[c]} < ${this.__min__[c]}; the values are checked together when the map is cloned or encoded)`);
233+
if (this.__capacityMax__ <= this.__capacityMin__)
234+
throw new RangeError(`The gain map's hdrCapacityMax (by default the largest max) must be above its hdrCapacityMin (${this.__capacityMax__} <= ${this.__capacityMin__})`);
234235
}
235236

236237
/** The map's pixels. Changes to them are written when the image is encoded */

‎tests/gainmap.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ const meanValue = (image, left, top, right, bottom) => {
106106
}
107107
}
108108

109+
// the checks between the values name them (they run when the map is cloned or encoded, not when one is set)
110+
{
111+
const map = new GainMap(new Image(4, 4).fill(0x808080ff), {max: 2});
112+
map.min = 5;
113+
let error = null;
114+
try { map.clone(); } catch (err) { error = err; }
115+
if (!(error instanceof RangeError) || !/max must be at least its min \(2 < 5.*cloned or encoded/.test(error.message)) panic(`min above max: ${error && error.message}`);
116+
error = null;
117+
try { new GainMap(new Image(4, 4), {max: 0}); } catch (err) { error = err; }
118+
if (!(error instanceof RangeError) || !/hdrCapacityMax \(by default the largest max\)/.test(error.message)) panic(`max 0: ${error && error.message}`);
119+
}
120+
109121
// made by hand: parameters checked, written and read back; per channel values
110122
{
111123
const image = new Image(64, 48).fill(0x808080ff);

0 commit comments

Comments
 (0)