Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix float casting when autoscaling int values to byte #4220

Merged
merged 1 commit into from
Sep 3, 2024

Conversation

melissalinkert
Copy link
Member

Fixes #4210.

Test code that uses the autoscale method:

$ cat AutoscaleTest.java 
import java.awt.image.BufferedImage;
import loci.formats.gui.AWTImageTools;

public class AutoscaleTest {
  public static void main(String[] args) throws Exception {
    int[] inputPixels = new int[] {40};
    BufferedImage input = AWTImageTools.makeImage(inputPixels, 1, 1, false);
    BufferedImage scaled = AWTImageTools.autoscale(input, 20, 120);
    byte[][] scaledPixels = (byte[][]) AWTImageTools.getPixels(scaled);
    System.out.println(scaledPixels[0][0]);
  }
}

Without this change, the value printed is 0. With this change, the value printed is 51.

The cast is the same strategy as used in the short[] case in line 1638.

@sbesson sbesson added this to the 8.0.0 milestone Sep 2, 2024
@sbesson sbesson merged commit e4ffbe8 into ome:develop Sep 3, 2024
18 checks passed
@melissalinkert melissalinkert deleted the gh-4210 branch September 6, 2024 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cast to float may be needed
2 participants