title: Why is javafx mangling my semi-transparent cursors?
body: <p>Below are two PNG images:</p>
  
  <p><a href="https://i.stack.imgur.com/2C2Lj.png" rel="noreferrer"><img src="https://i.stack.imgur.com/2C2Lj.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/QqHPR.png" rel="noreferrer"><img src="https://i.stack.imgur.com/QqHPR.png" alt="enter image description here"></a></p>
  
  <p>Visually they are exactly identical - the only difference is that one has the semi-transparent background in some of the pixels (you can download the images to check it).</p>
  
  <p>But when I use those images as an image cursor on JavaFX nodes, I get the following result:</p>
  
  <p><a href="https://i.stack.imgur.com/VyHIW.png" rel="noreferrer"><img src="https://i.stack.imgur.com/VyHIW.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/exITg.png" rel="noreferrer"><img src="https://i.stack.imgur.com/exITg.png" alt="enter image description here"></a></p>
  
  <p>First cursor (without partially transparent pixels) is still crisp, but the second gets distorted.</p>
  
  <p>After fighting with the problem for a while, I discovered the algorithm that accounts for this difference - blending mode:</p>
  
  <ul>
  <li><p>"Expected" way (that you can see in this browser, for example) is to take the sum of values per channel, weighted by alpha values: <code>(1 - alpha) * background_color + alpha * foreground_color</code>.</p></li>
  <li><p>"JavaFX Cursor" gives the different formula: <code>(1 - alpha) * background_color + alpha^2 * foreground_color</code> (note the square).</p></li>
  </ul>
  
  <p>I discovered the distortion, but I can't figure out what I did wrong and how I can correct this problem. </p>
  
  <p>Here's the complete runnable source code for my testing program:</p>
  
  <pre><code>import javafx.application.Application;
  import javafx.scene.Scene;
  import javafx.scene.control.Button;
  import javafx.scene.layout.StackPane;
  import javafx.stage.Stage;
  import javafx.scene.ImageCursor;
  import javafx.scene.image.Image;
  
  public class HelloWorld extends Application {
  
      public static void main(String[] args) {
          launch(args);
      }
  
      @Override
      public void start(Stage primaryStage) {
          System.out.println(ImageCursor.getBestSize(32, 32));
  
          primaryStage.setTitle("Hello World!");
  
          StackPane root = new StackPane();
          root.setCursor(new ImageCursor(new Image("/test-cursor.png"), 0, 0));
  
          primaryStage.setScene(new Scene(root, 100, 100));
          primaryStage.show();
      }
  }
  </code></pre>
  
  <p>How can I achieve proper rendering of such semi-transparent cursors?</p>