if (this.counter == 0 && loops >= 0) {
IIOMetadata imageMetadata2 = writer.getDefaultImageMetadata(ImageTypeSpecifier.createFromRenderedImage(image), iwp);
try {
setDelay(imageMetadata2, duration);
setLoops(imageMetadata2, this.loops);
writer.writeToSequence(new IIOImage(image, null, imageMetadata2), iwp);
} catch (IIOInvalidTreeException e) {
throw new IOException(e.getMessage());
}
} else try {
setDelay(iiom, duration);
writer.writeToSequence(new IIOImage(image, null, iiom), iwp);
} catch (IIOInvalidTreeException e) {
throw new IOException(e.getMessage());
}
this.counter++;
}