Skip to content

Commit

Permalink
Implement image resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
0xD3ADCODE committed Nov 12, 2024
1 parent be0c9bb commit cdc9ae3
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main/java/javafx/iio/plugin/avif/AVIFLoader.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package javafx.iio.plugin.avif;

import javafx.iio.IIO;
import javafx.iio.IIOImageFrame;
import javafx.iio.IIOLoader;
import javafx.iio.IIOSignature;
import javafx.iio.*;

import javax.imageio.IIOException;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -39,7 +36,15 @@ public IIOImageFrame decode(int imageIndex, int rWidth, int rHeight, boolean pre
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(length);
byteBuffer.put(baos.toByteArray(), 0, length);

return Avif.getInstance().decode(byteBuffer, length);
IIOImageFrame imageFrame = Avif.getInstance().decode(byteBuffer, length);

int[] outWH = IIOImageTools.computeDimensions(imageFrame.getWidth(), imageFrame.getHeight(), rWidth, rHeight, preserveAspectRatio);
rWidth = outWH[0];
rHeight = outWH[1];

return imageFrame.getWidth() != rWidth || imageFrame.getHeight() != rHeight
? IIOImageTools.scaleImageFrame(imageFrame, rWidth, rHeight, smooth)
: imageFrame;
} catch (Exception e) {
throw new IIOException(e.getMessage(), e);
}
Expand Down

0 comments on commit cdc9ae3

Please sign in to comment.