Closed justwiebe closed 1 year ago
For reference on what I mean about the frame, here is the first few frames on the original:
And here is the first few frames on the output:
I was able to fix this by manually removing pixels. It would be great to make this an option in the writer though.
StreamingGifWriter writer = new StreamingGifWriter(gif.getDelay(0), gif.getLoopCount() == 0);
try (StreamingGifWriter.GifStream stream = writer.prepareStream(output, gif.getFrame(0).getType())) {
BufferedImage last = null;
for (ImmutableImage frame : gif.getFrames()) {
BufferedImage image = frame.scale(scale, ScaleMethod.Lanczos3).toNewBufferedImage(BufferedImage.TYPE_INT_ARGB);
if (last != null) {
DataBuffer iBuf = image.getRaster().getDataBuffer();
DataBuffer lBuf = last.getRaster().getDataBuffer();
last = copy(image);
for (int i = 0; i < iBuf.getSize(); i++) {
if (iBuf.getElem(i) == lBuf.getElem(i)) {
iBuf.setElem(i, 0);
}
}
} else {
last = image;
}
stream.writeFrame(ImmutableImage.fromAwt(image));
}
}
I also would like to further optimize it by cropping the frame to fit the actual pixels and then setting the top/left metadata on the stream, but there's no option for setting that metadata
Thanks, I've adapted your work and added withCompression(true) option to the StreamingGifWriter. Will include this in 4.0.33 which I will release shortly.
@sksamuel Thanks! One note, is it looks like that option will be ignored if you call writeFrame
with any options
I can do a follow up release.
On Mon, 16 Jan 2023 at 11:17, BakoviDagi @.***> wrote:
@sksamuel https://github.com/sksamuel Thanks! One note, is it looks like that option will be ignored if you call writeFrame with any options
— Reply to this email directly, view it on GitHub https://github.com/sksamuel/scrimage/issues/256#issuecomment-1384350309, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFVSGWYVBBQ7Q2I2X26I3TWSV7AZANCNFSM6AAAAAAT2USABY . You are receiving this because you were mentioned.Message ID: @.***>
I am starting with a GIF that is 628kb, but after scaling each frame down 10%, it's now 2.8MB. It looks like each frame now has full pixels
Test GIF:
Test Output: