Closed rendaw closed 5 years ago
Yikes, thanks for reporting this. I'm able to reproduce it, but it's been a long time since I looked at the GIF spec, so it may take me a while to debug the issue.
Here's a very minimal repro with a single frame:
import com.squareup.gifencoder.*;
import java.io.*;
public class Main {
public static void main(String[] arg) throws Exception {
int width = 64;
int height = 64;
try (OutputStream stream = new FileOutputStream("render1.gif")) {
GifEncoder gifEncoder = new GifEncoder(stream, width, height, 0);
ImageOptions options = new ImageOptions();
int[][] rgb = new int[height][width];
gifEncoder.addImage(rgb, options);
gifEncoder.finishEncoding();
}
}
}
The problem seems to come up when the color table only has one or two colors. When I modified rgb
to have 3+ unique colors, it seemed to work.
Ah, that sounds right. My original data was also simple b/w frames and adding a couple fake colors solved things. Thank you for looking into this!
Fixed by @rendaw in #15.
Meta note: @dlubarov Just sent you an invite for write access to the repo so you can manage issues and merge PRs since you're the original author.
I've tried opening the resultant gif in
gimp
,chrome
,firefox
,mpv
, and a couple other pieces of software and all of them fail to display the gif - either giving errors or showing nothing.mpv
shows:and shows a small (maybe 100x100?) window with the transparent checker pattern.
Am I doing something crazy here?
file
reports the correct file size, andmpv
at least gets the duration correct even if it doesn't show any of the image data.Here's my minimal reproduction:
On a side note, it would be very nice to have the Image addImage exposed since the data appears to go down that channel anyway and it saves a lot of effort both on converting and dealing with bytes/unsigned nonsense.
I get the same result regardless of what I put in for colors, thought it might have been my image data but I replaced everything with green and get the same result.
Version 0.9.1.
Compiling for Java 8 (1.8), OpenJDK 11, Maven compiler plugin 3.8.0 FWIW.
I also tried Java 8 via Oracle JDK 8.
Trying the code on 0.9.0 gives me this error when opening in mpv:
and it hangs displaying nothing (still responsive to quit key).