Skip to content

Commit

Permalink
Improve upscaling performance
Browse files Browse the repository at this point in the history
Reduce memory reads for greater performance
  • Loading branch information
Eiim committed Feb 10, 2024
1 parent cfa9d97 commit a20aa41
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/main/java/chokistream/Interpolator.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ private static BufferedImage nearestNeighbor(BufferedImage in, double scale) {
if(in == null) {
return new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
}
int newW = (int)(scale*in.getWidth());
int newH = (int)(scale*in.getHeight());
BufferedImage out = new BufferedImage(newW, newH, in.getType());
for(int i = 0; i < newW; i++) {
for(int j = 0; j < newH; j++) {
out.setRGB(i, j, in.getRGB((int)(i/scale), (int)(j/scale)));
int oldW = in.getWidth();
int oldH = in.getHeight();
BufferedImage out = new BufferedImage((int)(scale*oldW), (int)(scale*oldH), in.getType());
for(int i = 0; i < oldW; i++) {
for(int j = 0; j < oldH; j++) {
int rgb = in.getRGB(i, j);
for(int i2 = (int)(scale*i); i2 < (int)(scale*(i+1)); i2++) {
for(int j2 = (int)(scale*j); j2 < (int)(scale*(j+1)); j2++) {
out.setRGB(i2, j2, rgb);
}
}
}
}
return out;
Expand Down

0 comments on commit a20aa41

Please sign in to comment.