You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What steps will reproduce the problem?
1. Make a grayscale image called test.png with dimensions 160x120
2. Run the following code:
public static void main(String[] args) throws IOException {
final int scale = 2;
final String testFile = "test.png";
BufferedImage srcImg = ImageIO.read(new File(testFile));
final int SRC_W = srcImg.getWidth();
final int SRC_H = srcImg.getHeight();
final int DST_W = SRC_W * scale;
final int DST_H = SRC_H * scale;
ResampleOp box = new ResampleOp(SRC_W, SRC_H);
box.setFilter(ResampleFilters.getBoxFilter());
box.setNumberOfThreads(1);
ResampleOp tri = new ResampleOp(SRC_W, SRC_H);
tri.setFilter(ResampleFilters.getTriangleFilter());
tri.setNumberOfThreads(1);
BufferedImage boxImg = box.doFilter(srcImg, null, DST_W, DST_H);
BufferedImage triImg = tri.doFilter(srcImg, null, DST_W, DST_H);
ImageIO.write(boxImg, "png", new File("boxImg.png"));
ImageIO.write(triImg, "png", new File("triImg.png"));
}
3. Compare the boxImg.png and triImg.png images in an editor
_Additional test_
1. Open test.png in Gimp image editor
2. Under Image menu, select Scale Image
3. Set Width and Height percent to 200%
4. Set Interpolation to Linear
5. Finish scaling
6. Compare the Gimp scaled image to triImg.png
What is the expected output? What do you see instead?
Expected to see interpolated pixels centered where original pixels were
located, like Gimp does.
Instead it appears the image is shifted to the top left a fraction of a pixel.
What version of the product are you using? On what operating system?
Java Image Scaling 0.8.5
Windows XP SP 3
Java 1.6.0_12; Java HotSpot(TM) Client VM 11.2-b01
Please provide any additional information below.
Changing ResampleOp.java line 225 from
float center= i / scale;
to
float center= i / scale - 0.25;
seems to fix the offset when scaled at 2x.
Original issue reported on code.google.com by jpsx...@gmail.com on 29 Jan 2011 at 2:57
The text was updated successfully, but these errors were encountered:
I think I found the correct fix to the shifting.
http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=11143
Attached is a patch that hopefully fixes everything (not fully tested).
Original comment by jpsx...@gmail.com on 4 Jun 2011 at 6:48
Original issue reported on code.google.com by
jpsx...@gmail.com
on 29 Jan 2011 at 2:57The text was updated successfully, but these errors were encountered: