JDK-8266314 : Add property to Canvas to control antialiasing when transformed
  • Type: Enhancement
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: openjfx16
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2021-04-24
  • Updated: 2021-05-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
Regardless of setImageSmoothing, smooth filtering is applied when a Canvas is transformed in the scene graph.  The original issue JDK-8204060 spoke of nearest-neighbor filtering at various zoom levels but this doesn't appear to happen with the fix.

Working around is impractical in a complex scene - it would require detecting scene scaling changes and applying an inverse scale and redrawing, which is both slow and results in artifacts due to floating point error with the inverse scale.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Scale a canvas with an image drawn with setImageScaling(false).

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Pixel boundaries are clearly visible.
ACTUAL -
Pixel boundaries are not possible to see do to smoothing.

---------- BEGIN SOURCE ----------
public class Appn extends Application {
    public static byte[] bytes = {
            (byte) 0x89,
            (byte) 0x50,
            (byte) 0x4e,
            (byte) 0x47,
            (byte) 0x0d,
            (byte) 0x0a,
            (byte) 0x1a,
            (byte) 0x0a,
            (byte) 0x00,
            (byte) 0x00,
            (byte) 0x00,
            (byte) 0x0d,
            (byte) 0x49,
            (byte) 0x48,
            (byte) 0x44,
            (byte) 0x52,
            (byte) 0x00,
            (byte) 0x00,
            (byte) 0x00,
            (byte) 0x04,
            (byte) 0x00,
            (byte) 0x00,
            (byte) 0x00,
            (byte) 0x04,
            (byte) 0x08,
            (byte) 0x02,
            (byte) 0x00,
            (byte) 0x00,
            (byte) 0x00,
            (byte) 0x26,
            (byte) 0x93,
            (byte) 0x09,
            (byte) 0x29,
            (byte) 0x00,
            (byte) 0x00,
            (byte) 0x00,
            (byte) 0x3a,
            (byte) 0x49,
            (byte) 0x44,
            (byte) 0x41,
            (byte) 0x54,
            (byte) 0x08,
            (byte) 0xd7,
            (byte) 0x05,
            (byte) 0xc1,
            (byte) 0xb1,
            (byte) 0x09,
            (byte) 0x00,
            (byte) 0x41,
            (byte) 0x08,
            (byte) 0x04,
            (byte) 0x40,
            (byte) 0x85,
            (byte) 0xc7,
            (byte) 0x06,
            (byte) 0x6c,
            (byte) 0xc5,
            (byte) 0x7c,
            (byte) 0x7b,
            (byte) 0xb0,
            (byte) 0x60,
            (byte) 0x6b,
            (byte) 0x11,
            (byte) 0x8c,
            (byte) 0xcc,
            (byte) 0xe5,
            (byte) 0xd2,
            (byte) 0xfd,
            (byte) 0x19,
            (byte) 0x8d,
            (byte) 0x08,
            (byte) 0x00,
            (byte) 0x99,
            (byte) 0x69,
            (byte) 0x66,
            (byte) 0x1f,
            (byte) 0x00,
            (byte) 0x77,
            (byte) 0xbf,
            (byte) 0xbb,
            (byte) 0xaa,
            (byte) 0xd2,
            (byte) 0xdd,
            (byte) 0x15,
            (byte) 0x91,
            (byte) 0xee,
            (byte) 0x9e,
            (byte) 0x19,
            (byte) 0x25,
            (byte) 0x29,
            (byte) 0x22,
            (byte) 0xef,
            (byte) 0x3d,
            (byte) 0x92,
            (byte) 0x3f,
            (byte) 0xf7,
            (byte) 0x60,
            (byte) 0x19,
            (byte) 0x55,
            (byte) 0xa2,
            (byte) 0x53,
            (byte) 0x51,
            (byte) 0xb3,
            (byte) 0x00,
            (byte) 0x00,
            (byte) 0x00,
            (byte) 0x00,
            (byte) 0x49,
            (byte) 0x45,
            (byte) 0x4e,
            (byte) 0x44,
            (byte) 0xae,
            (byte) 0x42,
            (byte) 0x60,
            (byte) 0x82,
    };

    public static void main(String[] argv) {
        launch(argv);
    }

    public void start(Stage stage) throws Exception {
        Canvas canvas = new Canvas();
        canvas.setWidth(4);
        canvas.setHeight(4);
        canvas.setScaleX(100);
        canvas.setScaleY(100);
        canvas.setLayoutX(200);
        canvas.setLayoutY(200);
        GraphicsContext ctx = canvas.getGraphicsContext2D();
        ctx.setImageSmoothing(false);
        ctx.drawImage(new Image(new ByteArrayInputStream(bytes)), 0, 0);
        Pane container = new Pane();
        container.setPrefWidth(400);
        container.setPrefHeight(400);
        container.getChildren().add(canvas);
        stage.setScene(new Scene(new HBox(container)));
        stage.show();
        stage.sizeToScene();
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Generating a proxy for com.sun.prism.Graphics that calls "setLinearFiltering(false)" before any method that takes a Texture as an argument, subclassing NGImageView to use the proxy in renderContent, then somehow getting ImageView to create the NGImageView subclass (I used an agent with some additional method indirection).  Lots of command line flags to open/export modules is also required.


Comments
This isn't directly related to setImageSmoothing.When a scale is applied to a Canvas node, it is the rendered image buffer of the Canvas node itself that is being scaled and smoothed, regardless of what was used to draw into the Canvas. Addressing this would require adding a property on the Canvas node. Note that there is a similar enhancement request for ImageView, JDK-8090349, although the default is different in that case for the reasons explained in that bug. This would be a new enhancement request, so I'm changing the issue type to Enhancement.
29-04-2021

Checked with attached testcase in Ubuntu 20.04 , openjfx11, 15, 16, and 17ea, attached screen shot for further review.
29-04-2021