From dad50b23855fc2f650c89d224e5536a6442504ef Mon Sep 17 00:00:00 2001 From: Christopher Cameron <32557109+ccameron-chromium@users.noreply.github.com> Date: Tue, 1 Aug 2023 00:01:55 +0200 Subject: [PATCH] Do not change default return type for getImageData (#105) --- canvas_float.md | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/canvas_float.md b/canvas_float.md index 1cbf566..4b0345e 100644 --- a/canvas_float.md +++ b/canvas_float.md @@ -95,10 +95,7 @@ In the interface `CanvasImageData`, the functions `createImageData` and `getImag If the `ImageDataSettings` specifies `colorType`, then the resulting `ImageData` will have that specified `colorType`. -If the `ImageDataSettings` does not specify `colorType`, then the resulting `ImageData`'s `colorType` will be as follows: - -* If the `CanvasImageData` has a `colorType` of `"unorm8"`, then the `ImageData`'s `colorType` will be `"unorm8"`. -* If the `CanvasImageData` has a `colorType` of `"float16"`, then the `ImageData`'s `colorType` will be `"float32"`. +If the `ImageDataSettings` does not specify `colorType`, then the resulting `ImageData`'s `colorType` will be `"unorm8"`. ### Values outside of the `[0, 1]` interval @@ -277,17 +274,14 @@ E.g, one would write `255` instead of `1.0`. This can be avoided by examining the `colorType` member the `ImageData`. -### Choice of defaulting `getImageData` to `Float32Array` for `"float16"` canvas - -There exists a trade-off in the default behavior of `getImageData` for a `"float16"` canvas. +### Choice of defaulting `getImageData` to `"unorm8"` -Suppose one is to default to returning a `Uint8ClampedArray`. -The benefit of this behavior is that there is a lesser likelihood of falling into the above mentioned pitfall. -The downside of this behavior is that a `getImageData` and then `putImageData` round-trip will lose precision. +Historically, all calls to `getImageData` have returned an `ImageData` with a `Uint8ClampedArray`. -Suppose one is to default to returning a `Float32Array`. -The benefit of this behavior is that a `getImageData` and then `putImageData` round-trip will not lose precision. -The downside is that there is a higher likelihood of falling into the above mentioned pitfall. +Changing the default type that is returned by this function will break any software that relies on +that default type, which is currently all software that uses this function. -This is resolved in favor of preserving round-trip precision, following the decision with respect to the default behavior for `colorSpace` for `getImageData`. +Changing the default type that is returned by this function will significantly hinder the adoption +of `"float16"` canvas, because no application can change the backing of any canvas without first +ensuring that all libraries that it uses have been updated to support all possible return values.