From 68b51fcf5b928905c8910bb8fbb69f8f5bdd1806 Mon Sep 17 00:00:00 2001 From: Christopher Cameron Date: Wed, 1 Oct 2025 10:58:01 +0000 Subject: [PATCH 1/2] Add tone mapping enum --- source | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/source b/source index 877761a9424..397cee4a41a 100644 --- a/source +++ b/source @@ -75526,7 +75526,19 @@ interface OffscreenCanvasRenderingContext2D {
Color spaces and color space conversion
-
enum PredefinedColorSpace { "srgb", "display-p3" };
+
enum PredefinedColorSpace {
+  "srgb",
+  "display-p3"
+};
+
+enum CanvasToneMappingMode {
+  "standard",
+  "extended",
+};
+
+dictionary CanvasToneMapping {
+  CanvasToneMappingMode mode = "standard";
+};

The PredefinedColorSpace enumeration is used to specify the color space of the canvas's backing store.

@@ -75548,6 +75560,57 @@ interface OffscreenCanvasRenderingContext2D { a color profile that specifies the same color space as the canvas's backing store. CSSCOLOR

+

The CanvasToneMappingMode enumeration specifies the tone mapping + to perform when rendering the context's output bitmap to the screen.

+ +

The "standard" value indicates that + color values within the standard dynamic range of the screen shall be unchanged, and + all other color values shall be projected to the standard dynamic range of the screen.

+ +

This projection is often accomplished by clamping color values in the color + space of the screen to the [0, 1] interval.

+ +
+

Suppose that the value (1.035, -0.175, -0.140) is written to an output bitmap + with color space 'srgb'.

+ +

If this is presented to a screen that natively uses the 'srgb' color space, then + this value will be converted to 'srgb' (which is a no-op), then projected to the + [0, 1] cubed volume in that space. Using component-wise clamping, this would result in the + 'srgb' value (1.0, 0.0, 0.0).

+ +

If this is presented to a screen that natively uses the 'display-p3' color space, + then this will be converted to the value (0.948, 0.106, 0.01) in the 'display-p3' + color space, and no clamping will be needed.

+
+ +

The "extended" value indicates that + color values within the extended dynamic range of the screen shall be unchanged, and + all other color values shall be projected to the extended dynamic range of the screen.

+ +

This projection is often accomplished by clamping color values in the color + space of the screen to the interval of values that the screen is capable of displaying, + which can include values greater than 1.

+ +
+

Suppose that the value (2.5, -0.15, -0.15) is written to an output bitmap + with color space 'srgb'.

+ +

If this is presented to a screen that natively uses the 'srgb' color space and + is capable of displaying values in the [0, 4] interval in that color space, then this value will be + converted to 'srgb' (which is a no-op), then projected to the [0, 4] cubed volume in + that space. Using component-wise clamping, this would result in the 'srgb' value + (2.5, 0.0, 0.0).

+ +

If this is presented to a screen that natively uses the 'display-p3' color space + and is capable of displaying values in the [0, 2] interval in that color space, then this value + will be converted to the value (2.3, 0.545, 0.01) in the 'display-p3' color space, + and then projected to the [0, 2] cubed volume in that space. Using component-wise clamping, this + would result in the 'display-p3' value (2.0, 0.545, 0.386).

+
+ From 2d83fbe941e10440c489fd9bf6be60220139593a Mon Sep 17 00:00:00 2001 From: Christopher Cameron Date: Wed, 1 Oct 2025 11:19:19 +0000 Subject: [PATCH 2/2] Add settings and attributes --- source | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/source b/source index 397cee4a41a..d49067a2617 100644 --- a/source +++ b/source @@ -68907,6 +68907,7 @@ dictionary CanvasRenderingContext2DSettings { boolean alpha = true; boolean desynchronized = false; PredefinedColorSpace colorSpace = "srgb"; + CanvasToneMapping toneMapping = {}; CanvasColorType colorType = "unorm8"; boolean willReadFrequently = false; }; @@ -69167,7 +69168,7 @@ interface Path2D { objects.

-
context = canvas.getContext('2d' [, { [ alpha: true ] [, desynchronized: false ] [, colorSpace: 'srgb'] [, willReadFrequently: false ]} ])
+
context = canvas.getContext('2d' [, { [ alpha: true ] [, desynchronized: false ] [, colorSpace: 'srgb'] [, toneMapping: {}] [, willReadFrequently: false ]} ])

Returns a CanvasRenderingContext2D object that is permanently bound to a particular canvas element.

@@ -69184,6 +69185,10 @@ interface Path2D { specifies the color space of the rendering context.

+

The toneMapping member + specifies the tone mapping of the rendering + context.

+

The colorType member specifies the color type of the rendering context.

@@ -69212,6 +69217,10 @@ interface Path2D { a string indicating the context's color space. +
  • toneMapping member is + a dictionary indicating the context's tone mapping + behavior.
  • +
  • colorType member is a string indicating the context's color type.
  • @@ -69496,6 +69505,12 @@ context.fillRect(100,0,50,50); // only this square remains data-x="concept-canvas-color-space">color space indicates the color space for the output bitmap.

    +

    The CanvasSettings object also has a tone mapping setting of type + CanvasToneMapping. The CanvasSettings object's tone mapping indicates the tone mapping behavior + of the output bitmap.

    +

    The CanvasSettings object also has a color type setting of type CanvasColorType. The CanvasSettings object's settings["colorSpace"].

    +
  • Set context's tone mapping to + settings["toneMapping"].

  • +
  • Set context's color type to settings["colorType"].

  • @@ -69541,6 +69560,8 @@ context.fillRect(100,0,50,50); // only this square remains this's desynchronized, "colorSpace" → this's color space, "toneMapping" → this's + tone mapping, "colorType" → this's color type, "willReadFrequently" → @@ -75551,15 +75572,6 @@ dictionary CanvasToneMapping { data-x="dom-PredefinedColorSpace-display-p3">display-p3" value indicates the 'display-p3' color space.

    -

    Color space conversion must be applied to the canvas's - backing store when rendering the canvas to the output device.

    - -

    The algorithm for converting between color spaces can be found in the - Converting Colors section of CSS Color. This color space conversion is - identical to the color space conversion that would be applied to an img element with - a color profile that specifies the same color - space as the canvas's backing store. CSSCOLOR

    -

    The CanvasToneMappingMode enumeration specifies the tone mapping to perform when rendering the context's output bitmap to the screen.

    @@ -75611,6 +75623,15 @@ dictionary CanvasToneMapping { would result in the 'display-p3' value (2.0, 0.545, 0.386).

    +

    Color space conversion must be applied to the canvas's + backing store when rendering the canvas to the output device.

    + +

    The algorithm for converting between color spaces can be found in the + Converting Colors section of CSS Color. This color space conversion is + identical to the color space conversion that would be applied to an img element with + a color profile that specifies the same color + space as the canvas's backing store. CSSCOLOR

    +