do not recreate tree model every time

This commit is contained in:
honfika@gmail.com
2015-03-07 14:38:26 +01:00
parent 99ec0a592c
commit 3c995f42e3
21 changed files with 625 additions and 145 deletions

View File

@@ -1,9 +1,9 @@
/*
* @(#)AbstractVideoCodec.java
*
*
* Copyright (c) 2011 Werner Randelshofer, Goldau, Switzerland.
* All rights reserved.
*
*
* You may not use, copy or modify this file, except in compliance with the
* license agreement you entered into with Werner Randelshofer.
* For details see accompanying license terms.
@@ -21,7 +21,8 @@ import java.awt.image.DirectColorModel;
import java.awt.image.WritableRaster;
import java.io.IOException;
import javax.imageio.stream.ImageOutputStream;
import static org.monte.media.VideoFormatKeys.*;
import static org.monte.media.VideoFormatKeys.HeightKey;
import static org.monte.media.VideoFormatKeys.WidthKey;
/**
* {@code AbstractVideoCodec}.
@@ -37,7 +38,10 @@ public abstract class AbstractVideoCodec extends AbstractCodec {
super(supportedInputFormats, supportedOutputFormats);
}
/** Gets 8-bit indexed pixels from a buffer. Returns null if conversion failed. */
/**
* Gets 8-bit indexed pixels from a buffer. Returns null if conversion
* failed.
*/
protected byte[] getIndexed8(Buffer buf) {
if (buf.data instanceof byte[]) {
return (byte[]) buf.data;
@@ -51,7 +55,9 @@ public abstract class AbstractVideoCodec extends AbstractCodec {
return null;
}
/** Gets 15-bit RGB pixels from a buffer. Returns null if conversion failed. */
/**
* Gets 15-bit RGB pixels from a buffer. Returns null if conversion failed.
*/
protected short[] getRGB15(Buffer buf) {
if (buf.data instanceof int[]) {
return (short[]) buf.data;
@@ -80,7 +86,11 @@ public abstract class AbstractVideoCodec extends AbstractCodec {
}
return null;
}
/** Gets 16-bit RGB-5-6-5 pixels from a buffer. Returns null if conversion failed. */
/**
* Gets 16-bit RGB-5-6-5 pixels from a buffer. Returns null if conversion
* failed.
*/
protected short[] getRGB16(Buffer buf) {
if (buf.data instanceof int[]) {
return (short[]) buf.data;
@@ -110,8 +120,9 @@ public abstract class AbstractVideoCodec extends AbstractCodec {
return null;
}
/** Gets 24-bit RGB pixels from a buffer. Returns null if conversion failed. */
/**
* Gets 24-bit RGB pixels from a buffer. Returns null if conversion failed.
*/
protected int[] getRGB24(Buffer buf) {
if (buf.data instanceof int[]) {
return (int[]) buf.data;
@@ -133,7 +144,9 @@ public abstract class AbstractVideoCodec extends AbstractCodec {
return null;
}
/** Gets 32-bit ARGB pixels from a buffer. Returns null if conversion failed. */
/**
* Gets 32-bit ARGB pixels from a buffer. Returns null if conversion failed.
*/
protected int[] getARGB32(Buffer buf) {
if (buf.data instanceof int[]) {
return (int[]) buf.data;
@@ -155,13 +168,16 @@ public abstract class AbstractVideoCodec extends AbstractCodec {
return null;
}
/** Gets a buffered image from a buffer. Returns null if conversion failed. */
/**
* Gets a buffered image from a buffer. Returns null if conversion failed.
*/
protected BufferedImage getBufferedImage(Buffer buf) {
if (buf.data instanceof BufferedImage) {
return (BufferedImage) buf.data;
}
return null;
}
private byte[] byteBuf = new byte[4];
protected void writeInt24(ImageOutputStream out, int v) throws IOException {
@@ -216,7 +232,9 @@ public abstract class AbstractVideoCodec extends AbstractCodec {
out.write(b, 0, len * 3);
}
/** Copies a buffered image. */
/**
* Copies a buffered image.
*/
protected static BufferedImage copyImage(BufferedImage img) {
ColorModel cm = img.getColorModel();
boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();

View File

@@ -1,9 +1,9 @@
/*
* @(#)DefaultRegistry.java
*
* @(#)DefaultRegistry.java
*
* Copyright (c) 2011 Werner Randelshofer, Goldau, Switzerland.
* All rights reserved.
*
*
* You may not use, copy or modify this file, except in compliance onlyWith the
* license agreement you entered into onlyWith Werner Randelshofer.
* For details see accompanying license terms.
@@ -16,13 +16,41 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import static org.monte.media.VideoFormatKeys.*;
import static org.monte.media.AudioFormatKeys.*;
import static org.monte.media.AudioFormatKeys.ENCODING_AVI_PCM;
import static org.monte.media.AudioFormatKeys.ENCODING_PCM_SIGNED;
import static org.monte.media.AudioFormatKeys.ENCODING_PCM_UNSIGNED;
import static org.monte.media.AudioFormatKeys.ENCODING_QUICKTIME_IN24_PCM;
import static org.monte.media.AudioFormatKeys.ENCODING_QUICKTIME_IN32_PCM;
import static org.monte.media.AudioFormatKeys.ENCODING_QUICKTIME_RAW_PCM;
import static org.monte.media.AudioFormatKeys.ENCODING_QUICKTIME_SOWT_PCM;
import static org.monte.media.AudioFormatKeys.ENCODING_QUICKTIME_TWOS_PCM;
import static org.monte.media.FormatKeys.EncodingKey;
import static org.monte.media.FormatKeys.MIME_ANIM;
import static org.monte.media.FormatKeys.MIME_AVI;
import static org.monte.media.FormatKeys.MIME_JAVA;
import static org.monte.media.FormatKeys.MIME_QUICKTIME;
import org.monte.media.FormatKeys.MediaType;
import static org.monte.media.FormatKeys.MediaTypeKey;
import static org.monte.media.FormatKeys.MimeTypeKey;
import static org.monte.media.VideoFormatKeys.COMPRESSOR_NAME_AVI_TECHSMITH_SCREEN_CAPTURE;
import static org.monte.media.VideoFormatKeys.CompressorNameKey;
import static org.monte.media.VideoFormatKeys.ENCODING_AVI_DIB;
import static org.monte.media.VideoFormatKeys.ENCODING_AVI_DOSBOX_SCREEN_CAPTURE;
import static org.monte.media.VideoFormatKeys.ENCODING_AVI_MJPG;
import static org.monte.media.VideoFormatKeys.ENCODING_AVI_PNG;
import static org.monte.media.VideoFormatKeys.ENCODING_AVI_RLE;
import static org.monte.media.VideoFormatKeys.ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE;
import static org.monte.media.VideoFormatKeys.ENCODING_BITMAP_IMAGE;
import static org.monte.media.VideoFormatKeys.ENCODING_BUFFERED_IMAGE;
import static org.monte.media.VideoFormatKeys.ENCODING_QUICKTIME_ANIMATION;
import static org.monte.media.VideoFormatKeys.ENCODING_QUICKTIME_JPEG;
import static org.monte.media.VideoFormatKeys.ENCODING_QUICKTIME_PNG;
import static org.monte.media.VideoFormatKeys.ENCODING_QUICKTIME_RAW;
/**
* {@code DefaultRegistry}.
* {@code DefaultRegistry}.
* <p>
* FIXME - The registry should be read from a file.
* FIXME - The registry should be read from a file.
*
* @author Werner Randelshofer
* @version $Id: DefaultRegistry.java 299 2013-01-03 07:40:18Z werner $
@@ -30,8 +58,11 @@ import static org.monte.media.AudioFormatKeys.*;
public class DefaultRegistry extends Registry {
private HashMap<String, LinkedList<RegistryEntry>> codecMap;
private HashMap<String, LinkedList<RegistryEntry>> readerMap;
private HashMap<String, LinkedList<RegistryEntry>> writerMap;
private HashMap<String, Format> fileFormatMap;
@Override
@@ -52,7 +83,9 @@ public class DefaultRegistry extends Registry {
private static class RegistryEntry {
Format inputFormat;
Format outputFormat;
String className;
public RegistryEntry(Format inputFormat, Format outputFormat, String className) {
@@ -147,8 +180,8 @@ public class DefaultRegistry extends Registry {
"org.monte.media.png.PNGCodec");
putBidiCodec(
new Format(MediaTypeKey, MediaType.VIDEO, MimeTypeKey, MIME_QUICKTIME,
EncodingKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE, CompressorNameKey, COMPRESSOR_NAME_AVI_TECHSMITH_SCREEN_CAPTURE),
new Format(MediaTypeKey, MediaType.VIDEO, MimeTypeKey, MIME_QUICKTIME,
EncodingKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE, CompressorNameKey, COMPRESSOR_NAME_AVI_TECHSMITH_SCREEN_CAPTURE),
new Format(MediaTypeKey, MediaType.VIDEO, MimeTypeKey, MIME_JAVA, EncodingKey, ENCODING_BUFFERED_IMAGE),
"org.monte.media.avi.TechSmithCodec");
@@ -197,7 +230,6 @@ public class DefaultRegistry extends Registry {
new Format(MediaTypeKey, MediaType.AUDIO, MimeTypeKey, MIME_QUICKTIME, EncodingKey, ENCODING_QUICKTIME_RAW_PCM),
"org.monte.media.quicktime.QuickTimePCMAudioCodec");
putReader(new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_AVI), "org.monte.media.avi.AVIReader");
putReader(new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_QUICKTIME), "org.monte.media.quicktime.QuickTimeReader");
putReader(new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_ANIM), "org.monte.media.anim.ANIMReader");
@@ -211,10 +243,12 @@ public class DefaultRegistry extends Registry {
}
/**
*
* @param inputFormat Must have {@code MediaTypeKey}, {@code EncodingKey}, {@code MimeTypeKey}.
* @param outputFormat Must have {@code MediaTypeKey}, {@code EncodingKey}, {@code MimeTypeKey}.
* @param codecClass
*
* @param inputFormat Must have {@code MediaTypeKey}, {@code EncodingKey},
* {@code MimeTypeKey}.
* @param outputFormat Must have {@code MediaTypeKey}, {@code EncodingKey},
* {@code MimeTypeKey}.
* @param codecClass
*/
public void putBidiCodec(Format inputFormat, Format outputFormat, String codecClass) {
putCodec(inputFormat, outputFormat, codecClass);
@@ -222,10 +256,12 @@ public class DefaultRegistry extends Registry {
}
/**
*
* @param inputFormat Must have {@code MediaTypeKey}, {@code EncodingKey}, {@code MimeTypeKey}.
* @param outputFormat Must have {@code MediaTypeKey}, {@code EncodingKey}, {@code MimeTypeKey}.
* @param codecClass
*
* @param inputFormat Must have {@code MediaTypeKey}, {@code EncodingKey},
* {@code MimeTypeKey}.
* @param outputFormat Must have {@code MediaTypeKey}, {@code EncodingKey},
* {@code MimeTypeKey}.
* @param codecClass
*/
@Override
public void putCodec(Format inputFormat, Format outputFormat, String codecClass) {
@@ -244,9 +280,9 @@ public class DefaultRegistry extends Registry {
}
/**
*
*
* @param fileFormat Must have {@code MediaTypeKey}, {@code MimeTypeKey}.
* @param readerClass
* @param readerClass
*/
@Override
public void putReader(Format fileFormat, String readerClass) {
@@ -261,9 +297,9 @@ public class DefaultRegistry extends Registry {
}
/**
*
*
* @param fileFormat Must have {@code MediaTypeKey}, {@code MimeTypeKey}.
* @param writerClass
* @param writerClass
*/
@Override
public void putWriter(Format fileFormat, String writerClass) {
@@ -380,16 +416,14 @@ public class DefaultRegistry extends Registry {
@Override
public void unregisterCodec(String codecClass) {
for (Map.Entry<String, LinkedList<RegistryEntry>> i:codecMap.entrySet()) {
LinkedList<RegistryEntry> ll=i.getValue();
for (Iterator<RegistryEntry> j=ll.iterator();j.hasNext();) {
RegistryEntry e=j.next();
for (Map.Entry<String, LinkedList<RegistryEntry>> i : codecMap.entrySet()) {
LinkedList<RegistryEntry> ll = i.getValue();
for (Iterator<RegistryEntry> j = ll.iterator(); j.hasNext();) {
RegistryEntry e = j.next();
if (e.className.equals(codecClass)) {
j.remove();
}
}
}
}
}