|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectucar.unidata.ui.AnimatedGifEncoder
public class AnimatedGifEncoder
Class AnimatedGifEncoder - Encodes a GIF file consisting of one or more frames.
Extensively Modified for ImagePlus
Extended to handle 8 bit Images with more complex Color lookup tables with transparency index
Ryan Raz March 2002
raz@rraz.ca
Version 1.01
Extensively Modified for ImagePlus
Extended to handle 8 bit Images with more complex Color lookup tables with transparency index
Ryan Raz March 2002
ryan@rraz.ca
Version 1.01 Please report any bugs
Operation Manual
1) Load stack with 8 bit or RGB images it is possible to use the animated gif reader but because the color
table is lost it is best to also load a separate copy of the first image in the series this will allow
extraction of the original image color look up table (see 1below)
2)Check the option list to bring up the option list.
3)Experiment with the option list. I usually use a global color table to save space, set to do not dispose if
each consecutive image is overlayed on the previous image.
4)Color table can be imported from another image or extracted from 8bit stack images or loaded as the
first 256 RGB triplets from a RGB images, the last mode takes either a imported image or current
stack and creates the color table from scratch.
To do list
1) Modify existing Animated Gif reader plug in to import in 8 bit mode (currently only works in
RGB mode. Right now the best way to alter an animated gif is to save the first image separately
and then read the single gif and use the plugin animated reader to read the animated gif to the
stack. Let this plugin encode the stack using the single gif's color table.
2) Add support for background colors easy but I have no use for them
3) RGB to 8 bit converter is a linear search. Needs to be replaced with sorted list and fast search. But
this update could cause problems with some types of gifs. Easy fix get a faster computer.
4) Try updating NN color converter seems to be heavily weighted towards quantity of pixels.
example:
if there is 90% of the image covered in shades of one color or grey the 10% of other colors tend
to be poorly represented it over fits the shades and under fits the others. Works well if the
distribution is balanced.
5) Add support for all sizes of Color Look Up tables.
6) Re-code to be cleaner. This is my second Java program and I started with some code with too
many global variables and I added more switches so its a bit hard to follow.
Credits for the base conversion codes
No copyright asserted on the source code of this class. May be used
for any purpose, however, refer to the Unisys LZW patent for restrictions
on use of the associated LZWEncoder class. Please forward any corrections
to kweiner@fmsware.com.
| Field Summary | |
|---|---|
protected boolean |
autotransparent
_more_ |
protected boolean |
closeStream
_more_ |
protected int |
colorDepth
_more_ |
protected byte[] |
colorTab
_more_ |
protected int |
delay
_more_ |
protected int |
dispose
_more_ |
protected boolean |
firstFrame
_more_ |
protected byte[] |
gct
_more_ |
protected int |
GCTbl
_more_ |
protected int |
GCTcindex
_more_ |
protected boolean |
GCTextracted
_more_ |
protected int |
GCTgrn
_more_ |
protected boolean |
GCTloadedExternal
_more_ |
protected boolean |
GCToverideColor
_more_ |
protected boolean |
GCToverideIndex
_more_ |
protected int |
GCTred
_more_ |
protected boolean |
GCTsetTransparent
_more_ |
protected boolean |
gctused
_more_ |
protected int |
height
_more_ |
protected ij.ImagePlus |
image
_more_ |
protected byte[] |
indexedPixels
_more_ |
protected int |
lctSize
_more_ |
protected OutputStream |
out
_more_ |
protected byte[] |
pixels
_more_ |
protected int |
repeat
_more_ |
static int |
REPEAT_FOREVER
_more_ |
protected int |
sample
_more_ |
protected boolean |
sizeSet
_more_ |
protected boolean |
started
_more_ |
protected int |
transIndex
_more_ |
protected boolean |
transparent
_more_ |
protected int |
width
_more_ |
| Constructor Summary | |
|---|---|
AnimatedGifEncoder()
|
|
| Method Summary | |
|---|---|
boolean |
addFrame(ij.ImagePlus image)
Adds next GIF frame. |
boolean |
addFrame(ij.ImagePlus image,
int theDelay)
_more_ |
protected void |
analyzePixels()
Analyzes image colors and creates color map. |
static void |
createGif(OutputStream outputStream,
Image image)
_more_ |
static void |
createGif(String filename,
Image image)
_more_ |
static void |
createGif(String filename,
List images)
_more_ |
static void |
createGif(String filename,
List images,
int repeat,
int delay)
_more_ |
void |
extractGCTrgb(ij.ImagePlus image)
_more_ |
protected int |
findClosest(byte[] colorTab,
int r,
int g,
int b)
Returns index of palette color closest to c |
boolean |
finish()
Flushes any pending data and closes output file. |
void |
GlobalColorTableused(boolean gtu)
Set True for Global Color Table use This saves space in the output file but colors may not be so goodif the stack uses True color images |
void |
loadGCT8bit(ij.ImagePlus image)
_more_ |
void |
loadGCTrgb(ij.ImagePlus image)
_more_ |
void |
OverRideQuality(int npixs)
Sets Net sample size depending on image size |
void |
setDelay(int ms)
Sets the delay time between each frame, or changes it for subsequent frames (applies to last frame added). |
void |
setDispose(int code)
Sets the GIF frame disposal code for the last added frame and any subsequent frames. |
void |
setFrameRate(float fps)
Sets frame rate in frames per second. |
void |
setGCT(boolean flag)
If gct = true then a global color table is use |
void |
setoptions()
_more_ |
void |
setQuality(int quality)
Sets quality of color quantization (conversion of images to the maximum 256 colors allowed by the GIF specification). |
void |
setRepeat(int iter)
Sets the number of times the set of GIF frames should be played. |
void |
setSize(int w,
int h)
Sets the GIF frame size. |
void |
setTransparent(boolean c)
Sets the transparent color for the last added frame and any subsequent frames. |
boolean |
start(OutputStream os)
Initiates GIF file creation on the given stream. |
boolean |
start(String file)
Initiates writing of a GIF file with the specified name. |
protected void |
writeGraphicCtrlExt(int delay)
Writes Graphic Control Extension |
protected void |
writeImageDesc()
Writes Image Descriptor |
protected void |
writeLSD()
Writes Logical Screen Descriptor without global color table |
protected void |
writeLSDgct()
Writes Logical Screen Descriptor with global color table |
protected void |
writeNetscapeExt()
Writes Netscape application extension to define repeat count. |
protected void |
writePalette()
Writes color table |
protected void |
writePixels()
Encodes and writes pixel data |
protected void |
writeShort(int value)
Write 16-bit value to output stream, LSB first |
protected void |
writeString(String s)
Writes string to output stream |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int REPEAT_FOREVER
protected int width
protected int height
protected boolean transparent
protected int transIndex
protected int repeat
protected int delay
protected boolean started
protected OutputStream out
protected ij.ImagePlus image
protected byte[] pixels
protected byte[] indexedPixels
protected int colorDepth
protected byte[] colorTab
protected int lctSize
protected int dispose
protected boolean closeStream
protected boolean firstFrame
protected boolean sizeSet
protected int sample
protected byte[] gct
protected boolean gctused
protected boolean autotransparent
protected boolean GCTextracted
protected boolean GCTloadedExternal
protected int GCTred
protected int GCTgrn
protected int GCTbl
protected int GCTcindex
protected boolean GCTsetTransparent
protected boolean GCToverideIndex
protected boolean GCToverideColor
| Constructor Detail |
|---|
public AnimatedGifEncoder()
| Method Detail |
|---|
public static void createGif(String filename,
Image image)
filename - _more_image - _more_
public static void createGif(OutputStream outputStream,
Image image)
outputStream - image - _more_
public static void createGif(String filename,
List images)
filename - _more_images - _more_
public static void createGif(String filename,
List images,
int repeat,
int delay)
filename - _more_images - _more_repeat - _more_delay - _more_public boolean addFrame(ij.ImagePlus image)
finish() flushes all
frames. If setSize was not invoked, the size of the
first image is used for all subsequent frames.
image - _more_
public boolean addFrame(ij.ImagePlus image,
int theDelay)
image - _more_theDelay - _more_
public void setoptions()
public boolean finish()
public void loadGCT8bit(ij.ImagePlus image)
image - _more_public void extractGCTrgb(ij.ImagePlus image)
image - _more_public void loadGCTrgb(ij.ImagePlus image)
image - _more_public void setGCT(boolean flag)
flag - _more_public void setDelay(int ms)
ms - int delay time in millisecondspublic void setDispose(int code)
code - int disposal code.public void setFrameRate(float fps)
setDelay(1000/fps).
fps - float frame rate (frames per second)public void setQuality(int quality)
quality - int greater than 0.public void GlobalColorTableused(boolean gtu)
gtu - _more_public void setRepeat(int iter)
iter - int number of iterations.
public void setSize(int w,
int h)
w - int frame width.h - int frame width.public void setTransparent(boolean c)
c - Color to be treated as transparent on display.public boolean start(OutputStream os)
os - OutputStream on which GIF images are written.
public boolean start(String file)
file - String containing output file name.
public void OverRideQuality(int npixs)
npixs - _more_protected void analyzePixels()
protected int findClosest(byte[] colorTab,
int r,
int g,
int b)
colorTab - _more_r - _more_g - _more_b - _more_
protected void writeGraphicCtrlExt(int delay)
throws IOException
delay - _more_
IOException - _more_
protected void writeImageDesc()
throws IOException
IOException - _more_
protected void writeLSDgct()
throws IOException
IOException - _more_
protected void writeLSD()
throws IOException
IOException - _more_
protected void writeNetscapeExt()
throws IOException
IOException - _more_
protected void writePalette()
throws IOException
IOException - _more_
protected void writePixels()
throws IOException
IOException - _more_
protected void writeShort(int value)
throws IOException
value - _more_
IOException - _more_
protected void writeString(String s)
throws IOException
s - _more_
IOException - _more_
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||