JDK-8213783 : [Canvas] Add API in GraphicsContext to control image smoothing
  • Type: CSR
  • Component: javafx
  • Sub-Component: graphics
  • Priority: P3
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: openjfx12
  • Submitted: 2018-11-13
  • Updated: 2018-11-29
  • Resolved: 2018-11-29
Related Reports
CSR :  
Description
Summary
-------

Provide APIs in GraphicsContext to enable/disable image smoothing when an image is drawn using GraphicsContext.drawImage(all forms)

Problem
-------

When an image is drawn using any of GraphicsContext.drawImage(all forms), the image is always drawn smooth by applying bi-linear interpolation.
Currently this is default behavior, and a Programmer has no control of the image smoothing behavior.

Solution
--------

 - Provide APIs to control image smoothing behavior.
 - Add an image attribute for image smoothing state and,
 - Two APIs to control the state. 
 - IsImageSmoothing() : getter API
 - setImageSmoothing(boolean) : setter API
 - Webrevs under review : http://cr.openjdk.java.net/~arapte/fx/8204060/webrev.03
 - Fix review discussion : https://bugs.openjdk.java.net/browse/JDK-8204060
 - Fix proposal discussion : http://mail.openjdk.java.net/pipermail/openjfx-dev/2018-October/022689.html

Specification
-------------

Two APIs added to javafx.scene.canvas.GraphicsContext:

```
    /**
     * Sets the image smoothing state.
     * Image smoothing is an <a href="#image-attr">Image attribute</a>
     * used to enable or disable image smoothing for
     * {@link #drawImage(javafx.scene.image.Image, double, double) drawImage(all forms)}
     * as specified in the <a href="#attr-ops-table">Rendering Attributes Table</a>.<br>
     * If image smoothing is {@code true}, images will be scaled using a higher
     * quality filtering when transforming or scaling the source image to fit
     * in the destination rectangle.<br>
     * If image smoothing is {@code false}, images will be scaled without filtering
     * (or by using a lower quality filtering) when transforming or scaling the
     * source image to fit in the destination rectangle.
     *
     * @defaultValue {@code true}
     * @param imageSmoothing {@code true} to enable or {@code false} to disable smoothing
     * @since 12
     */
    public void setImageSmoothing(boolean imageSmoothing) {
    }

    /**
     * Gets the current image smoothing state.
     *
     * @defaultValue {@code true}
     * @return image smoothing state
     * @since 12
     */
    public boolean isImageSmoothing() {
    }

```

 - The image smoothing attribute is added to the table "List of Rendering Attributes"
 - Reference to existing doc: https://openjfx.io/javadoc/11/javafx.graphics/javafx/scene/canvas/GraphicsContext.html
 - This doc change alters the rendering attributes table size, hence providing the doc change in GraphicsContext as attachment: 8204060_GraphicsContext_Doc.patch
 - Entire fix is at webrev.03 : http://cr.openjdk.java.net/~arapte/fx/8204060/webrev.03




Comments
Moving to Approved.
29-11-2018

JavaFX boolean attributes and properties consistently use isXxxx() which is why Ambarish changed it. Thanks.
29-11-2018

I see in the review thread that the original name for "isImageSmoothing" was "getImageSmoothing"; the latter would seem more conventional to me paired with a setter method, but either are acceptable. Moving to Provisional.
29-11-2018

Looks good.
29-11-2018