Package org.jzy3d.io.gif
Class GifExporter
java.lang.Object
org.jzy3d.io.AbstractImageExporter
org.jzy3d.io.gif.GifExporter
- All Implemented Interfaces:
AWTImageExporter
An image exporter able to create a gif animation out of frame exported by a renderer.
Can work in two modes
- Export GIF with a regular - user defined - frame rate, in order to deal with high frame rate animations without generating too large GIF files. Frames should be either skipped or repeated if they aren't generated exactly at GIF frame rate.
- Export GIF with a variable frame rate, in order to deal with variable frame rate animations without skipping or repeating frames.
Export with global frame rate
The interframe delay is globally configured from constructor. Once initialized, the exporter is ready to receive images. It will start counting time as soon as a first image is received via a call toAbstractImageExporter.export(BufferedImage)
. Following calls to
AbstractImageExporter.export(BufferedImage)
will arrange a regular image registration : if the second (and
following) image is exported too early w.r.t. to the global delay, it will be skipped. If the it
arrives too late, the previously submitted image will be used for export. If it arrives more than
2 times the expected delay, it will repeated to fill the gaps.
Sizing examples :
- 10 seconds at 40 FPS (hence 25ms per frame) on 800x600 and no HiDPI lead to approx 26MB.
- 10 seconds at 10 FPS (hence 100ms per frame) on 800x600 and no HiDPI lead to approx 7MB
Export with frame-wise duration
Here there is no image interpolation. All images are exported and we simply write the inter-frame delay for each frame.Terminating export
Once the export is finished, one should invokeAbstractImageExporter.terminate(long, java.util.concurrent.TimeUnit)
where the parameters indicate how long
time you accept to wait before timeout. Indeed, depending on the number and size of exported
images, a stack of save tasks may be still be pending.
- If save completes before timeout, then everything is ok.
- If timeout is reached before the file is saved, then the file is in an unknown state (maybe readable but at least incomplete).
progress()
or
progressToConsole()
.
Background color
The exporter supports a background color which can be defined to ensure a translucent object won't be altered by the background color of the gif viewer. Setting this background to the chart's background color is the best choice. Warning : Number of image show that timing is not accurate! 1sec of real time is replayed a bit faster than 1 sec (approx 10%). This may depend on timing to execute the screenshot, hence on the user computer.- Author:
- Martin Pernollet
-
Field Summary
Modifier and TypeFieldDescriptionprotected Color
protected static int
protected AnimatedGifEncoder
protected File
protected TicToc
Fields inherited from class org.jzy3d.io.AbstractImageExporter
debug, executor, numberOfPendingImages, numberOfSavedImages, numberOfSkippedImages, numberSubmittedImages, outputFrameRate, previousImage
-
Constructor Summary
ConstructorDescriptionGifExporter
(File outputFile) GifExporter
(File outputFile, FrameRate outputFrameRate) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addFrameToEncoder
(BufferedImage image, boolean isLastImage) protected void
protected void
doAddFrameByRunnable
(BufferedImage image, boolean isLastImage) This method does the effective job of adding the image to an encoder.protected void
doAddFrameByRunnable
(BufferedImage image, int interframeDelay, boolean isLastImage) int
getDelay()
Return the delay in milisecond as currently set on the encoder.double
progress()
void
void
setBackgroundColor
(Color backgroundColor) Methods inherited from class org.jzy3d.io.AbstractImageExporter
export, exportWithContinuousFrameRate, exportWithVariableFrameRate, getNumberOfSavedImages, getNumberOfSkippedImages, getNumberSubmittedImages, getTimer, isContinuousFrameRate, isDebug, scheduleImageExport, scheduleImageExport, scheduleImageExport, scheduleImageExport, setDebug, setTimer, terminate
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.jzy3d.io.AWTImageExporter
export, terminate
-
Field Details
-
DEFAULT_MAX_FPS
protected static int DEFAULT_MAX_FPS -
outputFile
-
encoder
-
backgroundColor
-
timer
-
-
Constructor Details
-
GifExporter
-
GifExporter
-
-
Method Details
-
doAddFrameByRunnable
This method does the effective job of adding the image to an encoder. It is invoked by the superclass which will call it inside a dedicated thread to avoid slowing down the caller thread. Although the executor used to invoke a sequence of this method is made of a single thread, visual glitches, showing two images rendered into one have been observed. Making this method synchronized surprisingly solved the issue.- Specified by:
doAddFrameByRunnable
in classAbstractImageExporter
- Throws:
IOException
-
doAddFrameByRunnable
protected void doAddFrameByRunnable(BufferedImage image, int interframeDelay, boolean isLastImage) throws IOException - Specified by:
doAddFrameByRunnable
in classAbstractImageExporter
- Throws:
IOException
-
addFrameToEncoder
- Throws:
IOException
-
closeOutput
- Specified by:
closeOutput
in classAbstractImageExporter
- Throws:
IOException
-
getOutputFile
-
progress
public double progress() -
progressToConsole
public void progressToConsole() -
getBackgroundColor
-
setBackgroundColor
-
getDelay
public int getDelay()Return the delay in milisecond as currently set on the encoder.
-