mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 00:59:39 +02:00
Enfore spaces for indentation
Although I'm in the tabs camp, Smack uses mostly spaces. Therefore it is the logical choice for the indentation style.
This commit is contained in:
parent
ffe9397e66
commit
ef0af66b21
125 changed files with 5336 additions and 5344 deletions
|
@ -26,9 +26,9 @@ import org.jivesoftware.smackx.jingleold.packet.JingleError;
|
|||
* @author Alvaro Saurin <alvaro.saurin@gmail.com>
|
||||
*/
|
||||
public class JingleException extends XMPPException {
|
||||
private static final long serialVersionUID = -1521230401958103382L;
|
||||
private static final long serialVersionUID = -1521230401958103382L;
|
||||
|
||||
private final JingleError error;
|
||||
private final JingleError error;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
|
|
|
@ -186,9 +186,9 @@ import org.jxmpp.jid.Jid;
|
|||
@SuppressWarnings("SynchronizeOnNonFinalField")
|
||||
public class JingleManager implements JingleSessionListener {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleManager.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleManager.class.getName());
|
||||
|
||||
// non-static
|
||||
// non-static
|
||||
|
||||
final List<JingleSession> jingleSessions = new ArrayList<JingleSession>();
|
||||
|
||||
|
|
|
@ -42,9 +42,9 @@ import org.jivesoftware.smackx.jingleold.listeners.JingleListener;
|
|||
*/
|
||||
public abstract class JingleNegotiator {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleNegotiator.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleNegotiator.class.getName());
|
||||
|
||||
//private XMPPConnection connection; // The connection associated
|
||||
//private XMPPConnection connection; // The connection associated
|
||||
|
||||
protected JingleSession session;
|
||||
|
||||
|
@ -238,12 +238,12 @@ public abstract class JingleNegotiator {
|
|||
|
||||
// CHECKSTYLE:OFF
|
||||
public void start() {
|
||||
isStarted = true;
|
||||
doStart();
|
||||
isStarted = true;
|
||||
doStart();
|
||||
}
|
||||
|
||||
public boolean isStarted() {
|
||||
return isStarted;
|
||||
return isStarted;
|
||||
}
|
||||
// CHECKSTYLE:ON
|
||||
|
||||
|
|
|
@ -62,9 +62,9 @@ import org.jxmpp.jid.Jid;
|
|||
*/
|
||||
public class JingleSession extends JingleNegotiator implements MediaReceivedListener {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleSession.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleSession.class.getName());
|
||||
|
||||
// static
|
||||
// static
|
||||
private static final HashMap<XMPPConnection, JingleSession> sessions = new HashMap<XMPPConnection, JingleSession>();
|
||||
|
||||
private static final Random randomGenerator = new Random();
|
||||
|
@ -299,13 +299,13 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
|
|||
// Each content negotiator may pass back a list of JingleContent for addition to the response packet.
|
||||
// CHECKSTYLE:OFF
|
||||
for (ContentNegotiator contentNegotiator : contentNegotiators) {
|
||||
// If at this point the content negotiator isn't started, it's because we sent a session-init jingle
|
||||
// packet from startOutgoing() and we're waiting for the other side to let us know they're ready
|
||||
// to take jingle packets. (This packet might be a session-terminate, but that will get handled
|
||||
// later.
|
||||
if (!contentNegotiator.isStarted()) {
|
||||
contentNegotiator.start();
|
||||
}
|
||||
// If at this point the content negotiator isn't started, it's because we sent a session-init jingle
|
||||
// packet from startOutgoing() and we're waiting for the other side to let us know they're ready
|
||||
// to take jingle packets. (This packet might be a session-terminate, but that will get handled
|
||||
// later.
|
||||
if (!contentNegotiator.isStarted()) {
|
||||
contentNegotiator.start();
|
||||
}
|
||||
responses.addAll(contentNegotiator.dispatchIncomingPacket(iq, responseId));
|
||||
}
|
||||
// CHECKSTYLE:ON
|
||||
|
@ -475,7 +475,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
|
|||
// The the packet.
|
||||
// CHECKSTYLE:OFF
|
||||
if ((getConnection() != null) && (getConnection().isConnected()))
|
||||
getConnection().sendStanza(jout);
|
||||
getConnection().sendStanza(jout);
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
return jout;
|
||||
|
@ -649,11 +649,11 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
|
|||
|
||||
private void removeConnectionListener() {
|
||||
// CHECKSTYLE:OFF
|
||||
if (connectionListener != null) {
|
||||
getConnection().removeConnectionListener(connectionListener);
|
||||
if (connectionListener != null) {
|
||||
getConnection().removeConnectionListener(connectionListener);
|
||||
|
||||
LOGGER.fine("JINGLE SESSION: REMOVE CONNECTION LISTENER");
|
||||
}
|
||||
LOGGER.fine("JINGLE SESSION: REMOVE CONNECTION LISTENER");
|
||||
}
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
|
||||
|
@ -830,10 +830,10 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
|
|||
public void transportEstablished(TransportCandidate local, TransportCandidate remote) throws NotConnectedException, InterruptedException {
|
||||
if (isFullyEstablished()) {
|
||||
// CHECKSTYLE:OFF
|
||||
// Indicate that this session is active.
|
||||
setSessionState(JingleSessionStateActive.getInstance());
|
||||
// Indicate that this session is active.
|
||||
setSessionState(JingleSessionStateActive.getInstance());
|
||||
|
||||
for (ContentNegotiator contentNegotiator : contentNegotiators) {
|
||||
for (ContentNegotiator contentNegotiator : contentNegotiators) {
|
||||
// CHECKSTYLE:ON
|
||||
if (contentNegotiator.getNegotiatorState() == JingleNegotiatorState.SUCCEEDED)
|
||||
contentNegotiator.triggerContentEstablished();
|
||||
|
|
|
@ -35,9 +35,9 @@ import org.jxmpp.jid.Jid;
|
|||
*/
|
||||
public class JingleSessionRequest {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleSessionRequest.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleSessionRequest.class.getName());
|
||||
|
||||
private final Jingle jingle; // The Jingle packet
|
||||
private final Jingle jingle; // The Jingle packet
|
||||
|
||||
private final JingleManager manager; // The manager associated to this
|
||||
|
||||
|
@ -130,15 +130,15 @@ public class JingleSessionRequest {
|
|||
JingleSession session = null;
|
||||
synchronized (manager) {
|
||||
try {
|
||||
session = manager.createIncomingJingleSession(this);
|
||||
// Acknowledge the IQ reception
|
||||
session.setSid(this.getSessionID());
|
||||
//session.sendAck(this.getJingle());
|
||||
session.updatePacketListener();
|
||||
session.terminate("Declined");
|
||||
} catch (Exception e) {
|
||||
LOGGER.log(Level.SEVERE, "Exception in reject", e);
|
||||
}
|
||||
session = manager.createIncomingJingleSession(this);
|
||||
// Acknowledge the IQ reception
|
||||
session.setSid(this.getSessionID());
|
||||
//session.sendAck(this.getJingle());
|
||||
session.updatePacketListener();
|
||||
session.terminate("Declined");
|
||||
} catch (Exception e) {
|
||||
LOGGER.log(Level.SEVERE, "Exception in reject", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,9 +29,9 @@ import org.jivesoftware.smackx.jingleold.packet.JingleError;
|
|||
*/
|
||||
public class JingleSessionStateEnded extends JingleSessionState {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleSessionStateEnded.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleSessionStateEnded.class.getName());
|
||||
|
||||
private static JingleSessionStateEnded INSTANCE = null;
|
||||
private static JingleSessionStateEnded INSTANCE = null;
|
||||
|
||||
protected JingleSessionStateEnded() {
|
||||
// Prevent instantiation of the class.
|
||||
|
|
|
@ -46,9 +46,9 @@ import org.jivesoftware.smackx.jingleold.packet.JingleError;
|
|||
*/
|
||||
public class MediaNegotiator extends JingleNegotiator {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(MediaNegotiator.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(MediaNegotiator.class.getName());
|
||||
|
||||
//private JingleSession session; // The session this negotiation
|
||||
//private JingleSession session; // The session this negotiation
|
||||
|
||||
private final JingleMediaManager mediaManager;
|
||||
|
||||
|
|
|
@ -32,11 +32,11 @@ import com.sun.media.util.Registry;
|
|||
|
||||
public class JMFInit extends Frame implements Runnable {
|
||||
|
||||
private static final long serialVersionUID = 6476412003260641680L;
|
||||
private static final long serialVersionUID = 6476412003260641680L;
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(JMFInit.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(JMFInit.class.getName());
|
||||
|
||||
private String tempDir = "/tmp";
|
||||
private String tempDir = "/tmp";
|
||||
|
||||
private boolean done = false;
|
||||
|
||||
|
|
|
@ -69,9 +69,9 @@ import org.jivesoftware.smackx.jingleold.media.JingleMediaSession;
|
|||
*/
|
||||
public class AudioChannel {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(AudioChannel.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(AudioChannel.class.getName());
|
||||
|
||||
private MediaLocator locator;
|
||||
private MediaLocator locator;
|
||||
private String localIpAddress;
|
||||
private String remoteIpAddress;
|
||||
private int localPort;
|
||||
|
|
|
@ -40,9 +40,9 @@ import org.jivesoftware.smackx.jingleold.nat.TransportCandidate;
|
|||
*/
|
||||
public class AudioMediaSession extends JingleMediaSession {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(AudioMediaSession.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(AudioMediaSession.class.getName());
|
||||
|
||||
private AudioChannel audioChannel;
|
||||
private AudioChannel audioChannel;
|
||||
|
||||
/**
|
||||
* Creates a org.jivesoftware.jingleaudio.jmf.AudioMediaSession with defined payload type, remote and local candidates.
|
||||
|
|
|
@ -47,9 +47,9 @@ import org.jivesoftware.smackx.jingleold.media.JingleMediaSession;
|
|||
public class AudioReceiver implements ReceiveStreamListener, SessionListener,
|
||||
ControllerListener {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(AudioReceiver.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(AudioReceiver.class.getName());
|
||||
|
||||
boolean dataReceived = false;
|
||||
boolean dataReceived = false;
|
||||
|
||||
final Object dataSync;
|
||||
JingleMediaSession jingleMediaSession;
|
||||
|
|
|
@ -40,9 +40,9 @@ import org.jivesoftware.smackx.jingleold.nat.TransportCandidate;
|
|||
*/
|
||||
public class JmfMediaManager extends JingleMediaManager {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(JmfMediaManager.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(JmfMediaManager.class.getName());
|
||||
|
||||
public static final String MEDIA_NAME = "JMF";
|
||||
public static final String MEDIA_NAME = "JMF";
|
||||
|
||||
|
||||
private List<PayloadType> payloads = new ArrayList<PayloadType>();
|
||||
|
|
|
@ -52,9 +52,9 @@ import org.jivesoftware.smackx.jingleold.nat.TransportCandidate;
|
|||
|
||||
public class AudioMediaSession extends JingleMediaSession implements MediaSessionListener {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(AudioMediaSession.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(AudioMediaSession.class.getName());
|
||||
|
||||
private MediaSession mediaSession;
|
||||
private MediaSession mediaSession;
|
||||
|
||||
/**
|
||||
* Create a Session using Speex Codec.
|
||||
|
|
|
@ -40,9 +40,9 @@ import org.jivesoftware.smackx.jingleold.nat.TransportCandidate;
|
|||
*/
|
||||
public class SpeexMediaManager extends JingleMediaManager {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(SpeexMediaManager.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(SpeexMediaManager.class.getName());
|
||||
|
||||
public static final String MEDIA_NAME = "Speex";
|
||||
public static final String MEDIA_NAME = "Speex";
|
||||
|
||||
private List<PayloadType> payloads = new ArrayList<PayloadType>();
|
||||
|
||||
|
|
|
@ -50,9 +50,9 @@ import org.jivesoftware.smackx.jingleold.nat.TransportCandidate;
|
|||
*/
|
||||
public class ScreenShareSession extends JingleMediaSession {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(ScreenShareSession.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(ScreenShareSession.class.getName());
|
||||
|
||||
private ImageTransmitter transmitter = null;
|
||||
private ImageTransmitter transmitter = null;
|
||||
private ImageReceiver receiver = null;
|
||||
private int width = 600;
|
||||
private int height = 600;
|
||||
|
|
|
@ -50,9 +50,9 @@ public abstract class AbstractBufferedImageOp implements BufferedImageOp, Clonea
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for getting ARGB pixels from an image. This tries to avoid the performance
|
||||
* penalty of BufferedImage.getRGB unmanaging the image.
|
||||
/**
|
||||
* A convenience method for getting ARGB pixels from an image. This tries to avoid the performance
|
||||
* penalty of BufferedImage.getRGB unmanaging the image.
|
||||
* @param image a BufferedImage object
|
||||
* @param x the left edge of the pixel block
|
||||
* @param y the right edge of the pixel block
|
||||
|
@ -62,16 +62,16 @@ public abstract class AbstractBufferedImageOp implements BufferedImageOp, Clonea
|
|||
* @return the pixels
|
||||
* @see #setRGB
|
||||
*/
|
||||
public int[] getRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) {
|
||||
int type = image.getType();
|
||||
if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB)
|
||||
return (int [])image.getRaster().getDataElements(x, y, width, height, pixels);
|
||||
return image.getRGB(x, y, width, height, pixels, 0, width);
|
||||
public int[] getRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) {
|
||||
int type = image.getType();
|
||||
if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB)
|
||||
return (int [])image.getRaster().getDataElements(x, y, width, height, pixels);
|
||||
return image.getRGB(x, y, width, height, pixels, 0, width);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for setting ARGB pixels in an image. This tries to avoid the performance
|
||||
* penalty of BufferedImage.setRGB unmanaging the image.
|
||||
/**
|
||||
* A convenience method for setting ARGB pixels in an image. This tries to avoid the performance
|
||||
* penalty of BufferedImage.setRGB unmanaging the image.
|
||||
* @param image a BufferedImage object
|
||||
* @param x the left edge of the pixel block
|
||||
* @param y the right edge of the pixel block
|
||||
|
@ -79,21 +79,21 @@ public abstract class AbstractBufferedImageOp implements BufferedImageOp, Clonea
|
|||
* @param height the height of the pixel arry
|
||||
* @param pixels the array of pixels to set
|
||||
* @see #getRGB
|
||||
*/
|
||||
public void setRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) {
|
||||
int type = image.getType();
|
||||
if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB)
|
||||
image.getRaster().setDataElements(x, y, width, height, pixels);
|
||||
else
|
||||
image.setRGB(x, y, width, height, pixels, 0, width);
|
||||
*/
|
||||
public void setRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) {
|
||||
int type = image.getType();
|
||||
if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB)
|
||||
image.getRaster().setDataElements(x, y, width, height, pixels);
|
||||
else
|
||||
image.setRGB(x, y, width, height, pixels, 0, width);
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
try {
|
||||
return super.clone();
|
||||
}
|
||||
catch (CloneNotSupportedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public Object clone() {
|
||||
try {
|
||||
return super.clone();
|
||||
}
|
||||
catch (CloneNotSupportedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ import java.util.logging.Logger;
|
|||
public class ImageReceiver extends Canvas {
|
||||
private static final Logger LOGGER = Logger.getLogger(ImageReceiver.class.getName());
|
||||
|
||||
private static final long serialVersionUID = -7000112305305269025L;
|
||||
private boolean on = true;
|
||||
private static final long serialVersionUID = -7000112305305269025L;
|
||||
private boolean on = true;
|
||||
private DatagramSocket socket;
|
||||
private BufferedImage[][] tiles;
|
||||
private static final int tileWidth = ImageTransmitter.tileWidth;
|
||||
|
|
|
@ -38,9 +38,9 @@ import java.util.logging.Logger;
|
|||
*/
|
||||
public class ImageTransmitter implements Runnable {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(ImageTransmitter.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(ImageTransmitter.class.getName());
|
||||
|
||||
private Robot robot;
|
||||
private Robot robot;
|
||||
private InetAddress localHost;
|
||||
private InetAddress remoteHost;
|
||||
private int localPort;
|
||||
|
|
|
@ -29,260 +29,260 @@ import java.util.logging.Logger;
|
|||
*/
|
||||
public class OctTreeQuantizer implements Quantizer {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(OctTreeQuantizer.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(OctTreeQuantizer.class.getName());
|
||||
|
||||
/**
|
||||
* The greatest depth the tree is allowed to reach
|
||||
*/
|
||||
final static int MAX_LEVEL = 5;
|
||||
/**
|
||||
* The greatest depth the tree is allowed to reach
|
||||
*/
|
||||
final static int MAX_LEVEL = 5;
|
||||
|
||||
/**
|
||||
* An Octtree node.
|
||||
*/
|
||||
class OctTreeNode {
|
||||
int children;
|
||||
int level;
|
||||
OctTreeNode parent;
|
||||
OctTreeNode[] leaf = new OctTreeNode[8];
|
||||
boolean isLeaf;
|
||||
int count;
|
||||
int totalRed;
|
||||
int totalGreen;
|
||||
int totalBlue;
|
||||
int index;
|
||||
/**
|
||||
* An Octtree node.
|
||||
*/
|
||||
class OctTreeNode {
|
||||
int children;
|
||||
int level;
|
||||
OctTreeNode parent;
|
||||
OctTreeNode[] leaf = new OctTreeNode[8];
|
||||
boolean isLeaf;
|
||||
int count;
|
||||
int totalRed;
|
||||
int totalGreen;
|
||||
int totalBlue;
|
||||
int index;
|
||||
|
||||
/**
|
||||
* A debugging method which prints the tree out.
|
||||
*/
|
||||
public void list(PrintStream s, int level) {
|
||||
String indentStr = "";
|
||||
for (int i = 0; i < level; i++)
|
||||
indentStr += " ";
|
||||
if (count == 0)
|
||||
LOGGER.fine(indentStr + index + ": count=" + count);
|
||||
else
|
||||
LOGGER.fine(indentStr + index + ": count=" + count + " red=" + (totalRed/count) + " green=" + (totalGreen / count) + " blue=" + (totalBlue / count));
|
||||
for (int i = 0; i < 8; i++)
|
||||
if (leaf[i] != null)
|
||||
leaf[i].list(s, level+2);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* A debugging method which prints the tree out.
|
||||
*/
|
||||
public void list(PrintStream s, int level) {
|
||||
String indentStr = "";
|
||||
for (int i = 0; i < level; i++)
|
||||
indentStr += " ";
|
||||
if (count == 0)
|
||||
LOGGER.fine(indentStr + index + ": count=" + count);
|
||||
else
|
||||
LOGGER.fine(indentStr + index + ": count=" + count + " red=" + (totalRed/count) + " green=" + (totalGreen / count) + " blue=" + (totalBlue / count));
|
||||
for (int i = 0; i < 8; i++)
|
||||
if (leaf[i] != null)
|
||||
leaf[i].list(s, level+2);
|
||||
}
|
||||
}
|
||||
|
||||
private int nodes = 0;
|
||||
private OctTreeNode root;
|
||||
private int reduceColors;
|
||||
private int maximumColors;
|
||||
private int colors = 0;
|
||||
private List<Vector<OctTreeNode>> colorList;
|
||||
private int nodes = 0;
|
||||
private OctTreeNode root;
|
||||
private int reduceColors;
|
||||
private int maximumColors;
|
||||
private int colors = 0;
|
||||
private List<Vector<OctTreeNode>> colorList;
|
||||
|
||||
public OctTreeQuantizer() {
|
||||
setup(256);
|
||||
colorList = new ArrayList<>(MAX_LEVEL+1);
|
||||
for (int i = 0; i < MAX_LEVEL+1; i++)
|
||||
colorList.add(i, new Vector<OctTreeNode>());
|
||||
root = new OctTreeNode();
|
||||
}
|
||||
setup(256);
|
||||
colorList = new ArrayList<>(MAX_LEVEL+1);
|
||||
for (int i = 0; i < MAX_LEVEL+1; i++)
|
||||
colorList.add(i, new Vector<OctTreeNode>());
|
||||
root = new OctTreeNode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the quantizer. This should be called before adding any pixels.
|
||||
* @param numColors the number of colors we're quantizing to.
|
||||
*/
|
||||
public void setup(int numColors) {
|
||||
maximumColors = numColors;
|
||||
reduceColors = Math.max(512, numColors * 2);
|
||||
}
|
||||
/**
|
||||
* Initialize the quantizer. This should be called before adding any pixels.
|
||||
* @param numColors the number of colors we're quantizing to.
|
||||
*/
|
||||
public void setup(int numColors) {
|
||||
maximumColors = numColors;
|
||||
reduceColors = Math.max(512, numColors * 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add pixels to the quantizer.
|
||||
* @param pixels the array of ARGB pixels
|
||||
* @param offset the offset into the array
|
||||
* @param count the count of pixels
|
||||
*/
|
||||
public void addPixels(int[] pixels, int offset, int count) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
insertColor(pixels[i+offset]);
|
||||
if (colors > reduceColors)
|
||||
reduceTree(reduceColors);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Add pixels to the quantizer.
|
||||
* @param pixels the array of ARGB pixels
|
||||
* @param offset the offset into the array
|
||||
* @param count the count of pixels
|
||||
*/
|
||||
public void addPixels(int[] pixels, int offset, int count) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
insertColor(pixels[i+offset]);
|
||||
if (colors > reduceColors)
|
||||
reduceTree(reduceColors);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color table index for a color.
|
||||
* @param rgb the color
|
||||
* @return the index
|
||||
*/
|
||||
public int getIndexForColor(int rgb) {
|
||||
int red = (rgb >> 16) & 0xff;
|
||||
int green = (rgb >> 8) & 0xff;
|
||||
int blue = rgb & 0xff;
|
||||
public int getIndexForColor(int rgb) {
|
||||
int red = (rgb >> 16) & 0xff;
|
||||
int green = (rgb >> 8) & 0xff;
|
||||
int blue = rgb & 0xff;
|
||||
|
||||
OctTreeNode node = root;
|
||||
OctTreeNode node = root;
|
||||
|
||||
for (int level = 0; level <= MAX_LEVEL; level++) {
|
||||
OctTreeNode child;
|
||||
int bit = 0x80 >> level;
|
||||
for (int level = 0; level <= MAX_LEVEL; level++) {
|
||||
OctTreeNode child;
|
||||
int bit = 0x80 >> level;
|
||||
|
||||
int index = 0;
|
||||
if ((red & bit) != 0)
|
||||
index += 4;
|
||||
if ((green & bit) != 0)
|
||||
index += 2;
|
||||
if ((blue & bit) != 0)
|
||||
index += 1;
|
||||
int index = 0;
|
||||
if ((red & bit) != 0)
|
||||
index += 4;
|
||||
if ((green & bit) != 0)
|
||||
index += 2;
|
||||
if ((blue & bit) != 0)
|
||||
index += 1;
|
||||
|
||||
child = node.leaf[index];
|
||||
child = node.leaf[index];
|
||||
|
||||
if (child == null)
|
||||
return node.index;
|
||||
else if (child.isLeaf)
|
||||
return child.index;
|
||||
else
|
||||
node = child;
|
||||
}
|
||||
LOGGER.fine("getIndexForColor failed");
|
||||
return 0;
|
||||
}
|
||||
if (child == null)
|
||||
return node.index;
|
||||
else if (child.isLeaf)
|
||||
return child.index;
|
||||
else
|
||||
node = child;
|
||||
}
|
||||
LOGGER.fine("getIndexForColor failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void insertColor(int rgb) {
|
||||
int red = (rgb >> 16) & 0xff;
|
||||
int green = (rgb >> 8) & 0xff;
|
||||
int blue = rgb & 0xff;
|
||||
private void insertColor(int rgb) {
|
||||
int red = (rgb >> 16) & 0xff;
|
||||
int green = (rgb >> 8) & 0xff;
|
||||
int blue = rgb & 0xff;
|
||||
|
||||
OctTreeNode node = root;
|
||||
OctTreeNode node = root;
|
||||
|
||||
// LOGGER.fine("insertColor="+Integer.toHexString(rgb));
|
||||
for (int level = 0; level <= MAX_LEVEL; level++) {
|
||||
OctTreeNode child;
|
||||
int bit = 0x80 >> level;
|
||||
// LOGGER.fine("insertColor="+Integer.toHexString(rgb));
|
||||
for (int level = 0; level <= MAX_LEVEL; level++) {
|
||||
OctTreeNode child;
|
||||
int bit = 0x80 >> level;
|
||||
|
||||
int index = 0;
|
||||
if ((red & bit) != 0)
|
||||
index += 4;
|
||||
if ((green & bit) != 0)
|
||||
index += 2;
|
||||
if ((blue & bit) != 0)
|
||||
index += 1;
|
||||
int index = 0;
|
||||
if ((red & bit) != 0)
|
||||
index += 4;
|
||||
if ((green & bit) != 0)
|
||||
index += 2;
|
||||
if ((blue & bit) != 0)
|
||||
index += 1;
|
||||
|
||||
child = node.leaf[index];
|
||||
child = node.leaf[index];
|
||||
|
||||
if (child == null) {
|
||||
node.children++;
|
||||
if (child == null) {
|
||||
node.children++;
|
||||
|
||||
child = new OctTreeNode();
|
||||
child.parent = node;
|
||||
node.leaf[index] = child;
|
||||
node.isLeaf = false;
|
||||
nodes++;
|
||||
colorList.get(level).addElement(child);
|
||||
child = new OctTreeNode();
|
||||
child.parent = node;
|
||||
node.leaf[index] = child;
|
||||
node.isLeaf = false;
|
||||
nodes++;
|
||||
colorList.get(level).addElement(child);
|
||||
|
||||
if (level == MAX_LEVEL) {
|
||||
child.isLeaf = true;
|
||||
child.count = 1;
|
||||
child.totalRed = red;
|
||||
child.totalGreen = green;
|
||||
child.totalBlue = blue;
|
||||
child.level = level;
|
||||
colors++;
|
||||
return;
|
||||
}
|
||||
if (level == MAX_LEVEL) {
|
||||
child.isLeaf = true;
|
||||
child.count = 1;
|
||||
child.totalRed = red;
|
||||
child.totalGreen = green;
|
||||
child.totalBlue = blue;
|
||||
child.level = level;
|
||||
colors++;
|
||||
return;
|
||||
}
|
||||
|
||||
node = child;
|
||||
} else if (child.isLeaf) {
|
||||
child.count++;
|
||||
child.totalRed += red;
|
||||
child.totalGreen += green;
|
||||
child.totalBlue += blue;
|
||||
return;
|
||||
} else
|
||||
node = child;
|
||||
}
|
||||
LOGGER.fine("insertColor failed");
|
||||
}
|
||||
node = child;
|
||||
} else if (child.isLeaf) {
|
||||
child.count++;
|
||||
child.totalRed += red;
|
||||
child.totalGreen += green;
|
||||
child.totalBlue += blue;
|
||||
return;
|
||||
} else
|
||||
node = child;
|
||||
}
|
||||
LOGGER.fine("insertColor failed");
|
||||
}
|
||||
|
||||
private void reduceTree(int numColors) {
|
||||
for (int level = MAX_LEVEL-1; level >= 0; level--) {
|
||||
Vector<OctTreeNode> v = colorList.get(level);
|
||||
if (v != null && v.size() > 0) {
|
||||
for (int j = 0; j < v.size(); j++) {
|
||||
OctTreeNode node = v.elementAt(j);
|
||||
if (node.children > 0) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
OctTreeNode child = node.leaf[i];
|
||||
if (child != null) {
|
||||
if (!child.isLeaf)
|
||||
LOGGER.fine("not a leaf!");
|
||||
node.count += child.count;
|
||||
node.totalRed += child.totalRed;
|
||||
node.totalGreen += child.totalGreen;
|
||||
node.totalBlue += child.totalBlue;
|
||||
node.leaf[i] = null;
|
||||
node.children--;
|
||||
colors--;
|
||||
nodes--;
|
||||
colorList.get(level+1).removeElement(child);
|
||||
}
|
||||
}
|
||||
node.isLeaf = true;
|
||||
colors++;
|
||||
if (colors <= numColors)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void reduceTree(int numColors) {
|
||||
for (int level = MAX_LEVEL-1; level >= 0; level--) {
|
||||
Vector<OctTreeNode> v = colorList.get(level);
|
||||
if (v != null && v.size() > 0) {
|
||||
for (int j = 0; j < v.size(); j++) {
|
||||
OctTreeNode node = v.elementAt(j);
|
||||
if (node.children > 0) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
OctTreeNode child = node.leaf[i];
|
||||
if (child != null) {
|
||||
if (!child.isLeaf)
|
||||
LOGGER.fine("not a leaf!");
|
||||
node.count += child.count;
|
||||
node.totalRed += child.totalRed;
|
||||
node.totalGreen += child.totalGreen;
|
||||
node.totalBlue += child.totalBlue;
|
||||
node.leaf[i] = null;
|
||||
node.children--;
|
||||
colors--;
|
||||
nodes--;
|
||||
colorList.get(level+1).removeElement(child);
|
||||
}
|
||||
}
|
||||
node.isLeaf = true;
|
||||
colors++;
|
||||
if (colors <= numColors)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LOGGER.fine("Unable to reduce the OctTree");
|
||||
}
|
||||
LOGGER.fine("Unable to reduce the OctTree");
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the color table.
|
||||
* @return the color table
|
||||
*/
|
||||
public int[] buildColorTable() {
|
||||
int[] table = new int[colors];
|
||||
buildColorTable(root, table, 0);
|
||||
return table;
|
||||
}
|
||||
public int[] buildColorTable() {
|
||||
int[] table = new int[colors];
|
||||
buildColorTable(root, table, 0);
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* A quick way to use the quantizer. Just create a table the right size and pass in the pixels.
|
||||
/**
|
||||
* A quick way to use the quantizer. Just create a table the right size and pass in the pixels.
|
||||
* @param inPixels the input colors
|
||||
* @param table the output color table
|
||||
*/
|
||||
public void buildColorTable(int[] inPixels, int[] table) {
|
||||
int count = inPixels.length;
|
||||
maximumColors = table.length;
|
||||
for (int i = 0; i < count; i++) {
|
||||
insertColor(inPixels[i]);
|
||||
if (colors > reduceColors)
|
||||
reduceTree(reduceColors);
|
||||
}
|
||||
if (colors > maximumColors)
|
||||
reduceTree(maximumColors);
|
||||
buildColorTable(root, table, 0);
|
||||
}
|
||||
public void buildColorTable(int[] inPixels, int[] table) {
|
||||
int count = inPixels.length;
|
||||
maximumColors = table.length;
|
||||
for (int i = 0; i < count; i++) {
|
||||
insertColor(inPixels[i]);
|
||||
if (colors > reduceColors)
|
||||
reduceTree(reduceColors);
|
||||
}
|
||||
if (colors > maximumColors)
|
||||
reduceTree(maximumColors);
|
||||
buildColorTable(root, table, 0);
|
||||
}
|
||||
|
||||
private int buildColorTable(OctTreeNode node, int[] table, int index) {
|
||||
if (colors > maximumColors)
|
||||
reduceTree(maximumColors);
|
||||
private int buildColorTable(OctTreeNode node, int[] table, int index) {
|
||||
if (colors > maximumColors)
|
||||
reduceTree(maximumColors);
|
||||
|
||||
if (node.isLeaf) {
|
||||
int count = node.count;
|
||||
table[index] = 0xff000000 |
|
||||
((node.totalRed/count) << 16) |
|
||||
((node.totalGreen/count) << 8) |
|
||||
node.totalBlue/count;
|
||||
node.index = index++;
|
||||
} else {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (node.leaf[i] != null) {
|
||||
node.index = index;
|
||||
index = buildColorTable(node.leaf[i], table, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
if (node.isLeaf) {
|
||||
int count = node.count;
|
||||
table[index] = 0xff000000 |
|
||||
((node.totalRed/count) << 16) |
|
||||
((node.totalGreen/count) << 8) |
|
||||
node.totalBlue/count;
|
||||
node.index = index++;
|
||||
} else {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (node.leaf[i] != null) {
|
||||
node.index = index;
|
||||
index = buildColorTable(node.leaf[i], table, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -26,199 +26,199 @@ import java.util.Random;
|
|||
*/
|
||||
public class PixelUtils {
|
||||
|
||||
public final static int REPLACE = 0;
|
||||
public final static int NORMAL = 1;
|
||||
public final static int MIN = 2;
|
||||
public final static int MAX = 3;
|
||||
public final static int ADD = 4;
|
||||
public final static int SUBTRACT = 5;
|
||||
public final static int DIFFERENCE = 6;
|
||||
public final static int MULTIPLY = 7;
|
||||
public final static int HUE = 8;
|
||||
public final static int SATURATION = 9;
|
||||
public final static int VALUE = 10;
|
||||
public final static int COLOR = 11;
|
||||
public final static int SCREEN = 12;
|
||||
public final static int AVERAGE = 13;
|
||||
public final static int OVERLAY = 14;
|
||||
public final static int CLEAR = 15;
|
||||
public final static int EXCHANGE = 16;
|
||||
public final static int DISSOLVE = 17;
|
||||
public final static int DST_IN = 18;
|
||||
public final static int ALPHA = 19;
|
||||
public final static int ALPHA_TO_GRAY = 20;
|
||||
public final static int REPLACE = 0;
|
||||
public final static int NORMAL = 1;
|
||||
public final static int MIN = 2;
|
||||
public final static int MAX = 3;
|
||||
public final static int ADD = 4;
|
||||
public final static int SUBTRACT = 5;
|
||||
public final static int DIFFERENCE = 6;
|
||||
public final static int MULTIPLY = 7;
|
||||
public final static int HUE = 8;
|
||||
public final static int SATURATION = 9;
|
||||
public final static int VALUE = 10;
|
||||
public final static int COLOR = 11;
|
||||
public final static int SCREEN = 12;
|
||||
public final static int AVERAGE = 13;
|
||||
public final static int OVERLAY = 14;
|
||||
public final static int CLEAR = 15;
|
||||
public final static int EXCHANGE = 16;
|
||||
public final static int DISSOLVE = 17;
|
||||
public final static int DST_IN = 18;
|
||||
public final static int ALPHA = 19;
|
||||
public final static int ALPHA_TO_GRAY = 20;
|
||||
|
||||
private static Random randomGenerator = new Random();
|
||||
private static Random randomGenerator = new Random();
|
||||
|
||||
/**
|
||||
* Clamp a value to the range 0..255.
|
||||
*/
|
||||
public static int clamp(int c) {
|
||||
if (c < 0)
|
||||
return 0;
|
||||
if (c > 255)
|
||||
return 255;
|
||||
return c;
|
||||
}
|
||||
/**
|
||||
* Clamp a value to the range 0..255.
|
||||
*/
|
||||
public static int clamp(int c) {
|
||||
if (c < 0)
|
||||
return 0;
|
||||
if (c > 255)
|
||||
return 255;
|
||||
return c;
|
||||
}
|
||||
|
||||
public static int interpolate(int v1, int v2, float f) {
|
||||
return clamp((int)(v1+f*(v2-v1)));
|
||||
}
|
||||
public static int interpolate(int v1, int v2, float f) {
|
||||
return clamp((int)(v1+f*(v2-v1)));
|
||||
}
|
||||
|
||||
public static int brightness(int rgb) {
|
||||
int r = (rgb >> 16) & 0xff;
|
||||
int g = (rgb >> 8) & 0xff;
|
||||
int b = rgb & 0xff;
|
||||
return (r+g+b)/3;
|
||||
}
|
||||
public static int brightness(int rgb) {
|
||||
int r = (rgb >> 16) & 0xff;
|
||||
int g = (rgb >> 8) & 0xff;
|
||||
int b = rgb & 0xff;
|
||||
return (r+g+b)/3;
|
||||
}
|
||||
|
||||
public static boolean nearColors(int rgb1, int rgb2, int tolerance) {
|
||||
int r1 = (rgb1 >> 16) & 0xff;
|
||||
int g1 = (rgb1 >> 8) & 0xff;
|
||||
int b1 = rgb1 & 0xff;
|
||||
int r2 = (rgb2 >> 16) & 0xff;
|
||||
int g2 = (rgb2 >> 8) & 0xff;
|
||||
int b2 = rgb2 & 0xff;
|
||||
return Math.abs(r1-r2) <= tolerance && Math.abs(g1-g2) <= tolerance && Math.abs(b1-b2) <= tolerance;
|
||||
}
|
||||
public static boolean nearColors(int rgb1, int rgb2, int tolerance) {
|
||||
int r1 = (rgb1 >> 16) & 0xff;
|
||||
int g1 = (rgb1 >> 8) & 0xff;
|
||||
int b1 = rgb1 & 0xff;
|
||||
int r2 = (rgb2 >> 16) & 0xff;
|
||||
int g2 = (rgb2 >> 8) & 0xff;
|
||||
int b2 = rgb2 & 0xff;
|
||||
return Math.abs(r1-r2) <= tolerance && Math.abs(g1-g2) <= tolerance && Math.abs(b1-b2) <= tolerance;
|
||||
}
|
||||
|
||||
private final static float[] hsb1 = new float[3];//FIXME-not thread safe
|
||||
private final static float[] hsb2 = new float[3];//FIXME-not thread safe
|
||||
private final static float[] hsb1 = new float[3];//FIXME-not thread safe
|
||||
private final static float[] hsb2 = new float[3];//FIXME-not thread safe
|
||||
|
||||
// Return rgb1 painted onto rgb2
|
||||
public static int combinePixels(int rgb1, int rgb2, int op) {
|
||||
return combinePixels(rgb1, rgb2, op, 0xff);
|
||||
}
|
||||
// Return rgb1 painted onto rgb2
|
||||
public static int combinePixels(int rgb1, int rgb2, int op) {
|
||||
return combinePixels(rgb1, rgb2, op, 0xff);
|
||||
}
|
||||
|
||||
public static int combinePixels(int rgb1, int rgb2, int op, int extraAlpha, int channelMask) {
|
||||
return (rgb2 & ~channelMask) | combinePixels(rgb1 & channelMask, rgb2, op, extraAlpha);
|
||||
}
|
||||
public static int combinePixels(int rgb1, int rgb2, int op, int extraAlpha, int channelMask) {
|
||||
return (rgb2 & ~channelMask) | combinePixels(rgb1 & channelMask, rgb2, op, extraAlpha);
|
||||
}
|
||||
|
||||
public static int combinePixels(int rgb1, int rgb2, int op, int extraAlpha) {
|
||||
if (op == REPLACE)
|
||||
return rgb1;
|
||||
int a1 = (rgb1 >> 24) & 0xff;
|
||||
int r1 = (rgb1 >> 16) & 0xff;
|
||||
int g1 = (rgb1 >> 8) & 0xff;
|
||||
int b1 = rgb1 & 0xff;
|
||||
int a2 = (rgb2 >> 24) & 0xff;
|
||||
int r2 = (rgb2 >> 16) & 0xff;
|
||||
int g2 = (rgb2 >> 8) & 0xff;
|
||||
int b2 = rgb2 & 0xff;
|
||||
public static int combinePixels(int rgb1, int rgb2, int op, int extraAlpha) {
|
||||
if (op == REPLACE)
|
||||
return rgb1;
|
||||
int a1 = (rgb1 >> 24) & 0xff;
|
||||
int r1 = (rgb1 >> 16) & 0xff;
|
||||
int g1 = (rgb1 >> 8) & 0xff;
|
||||
int b1 = rgb1 & 0xff;
|
||||
int a2 = (rgb2 >> 24) & 0xff;
|
||||
int r2 = (rgb2 >> 16) & 0xff;
|
||||
int g2 = (rgb2 >> 8) & 0xff;
|
||||
int b2 = rgb2 & 0xff;
|
||||
|
||||
switch (op) {
|
||||
case NORMAL:
|
||||
break;
|
||||
case MIN:
|
||||
r1 = Math.min(r1, r2);
|
||||
g1 = Math.min(g1, g2);
|
||||
b1 = Math.min(b1, b2);
|
||||
break;
|
||||
case MAX:
|
||||
r1 = Math.max(r1, r2);
|
||||
g1 = Math.max(g1, g2);
|
||||
b1 = Math.max(b1, b2);
|
||||
break;
|
||||
case ADD:
|
||||
r1 = clamp(r1+r2);
|
||||
g1 = clamp(g1+g2);
|
||||
b1 = clamp(b1+b2);
|
||||
break;
|
||||
case SUBTRACT:
|
||||
r1 = clamp(r2-r1);
|
||||
g1 = clamp(g2-g1);
|
||||
b1 = clamp(b2-b1);
|
||||
break;
|
||||
case DIFFERENCE:
|
||||
r1 = clamp(Math.abs(r1-r2));
|
||||
g1 = clamp(Math.abs(g1-g2));
|
||||
b1 = clamp(Math.abs(b1-b2));
|
||||
break;
|
||||
case MULTIPLY:
|
||||
r1 = clamp(r1*r2/255);
|
||||
g1 = clamp(g1*g2/255);
|
||||
b1 = clamp(b1*b2/255);
|
||||
break;
|
||||
case DISSOLVE:
|
||||
if ((randomGenerator.nextInt() & 0xff) <= a1) {
|
||||
r1 = r2;
|
||||
g1 = g2;
|
||||
b1 = b2;
|
||||
}
|
||||
break;
|
||||
case AVERAGE:
|
||||
r1 = (r1+r2)/2;
|
||||
g1 = (g1+g2)/2;
|
||||
b1 = (b1+b2)/2;
|
||||
break;
|
||||
case HUE:
|
||||
case SATURATION:
|
||||
case VALUE:
|
||||
case COLOR:
|
||||
Color.RGBtoHSB(r1, g1, b1, hsb1);
|
||||
Color.RGBtoHSB(r2, g2, b2, hsb2);
|
||||
switch (op) {
|
||||
case HUE:
|
||||
hsb2[0] = hsb1[0];
|
||||
break;
|
||||
case SATURATION:
|
||||
hsb2[1] = hsb1[1];
|
||||
break;
|
||||
case VALUE:
|
||||
hsb2[2] = hsb1[2];
|
||||
break;
|
||||
case COLOR:
|
||||
hsb2[0] = hsb1[0];
|
||||
hsb2[1] = hsb1[1];
|
||||
break;
|
||||
}
|
||||
rgb1 = Color.HSBtoRGB(hsb2[0], hsb2[1], hsb2[2]);
|
||||
r1 = (rgb1 >> 16) & 0xff;
|
||||
g1 = (rgb1 >> 8) & 0xff;
|
||||
b1 = rgb1 & 0xff;
|
||||
break;
|
||||
case SCREEN:
|
||||
r1 = 255 - ((255 - r1) * (255 - r2)) / 255;
|
||||
g1 = 255 - ((255 - g1) * (255 - g2)) / 255;
|
||||
b1 = 255 - ((255 - b1) * (255 - b2)) / 255;
|
||||
break;
|
||||
case OVERLAY:
|
||||
int m, s;
|
||||
s = 255 - ((255 - r1) * (255 - r2)) / 255;
|
||||
m = r1 * r2 / 255;
|
||||
r1 = (s * r1 + m * (255 - r1)) / 255;
|
||||
s = 255 - ((255 - g1) * (255 - g2)) / 255;
|
||||
m = g1 * g2 / 255;
|
||||
g1 = (s * g1 + m * (255 - g1)) / 255;
|
||||
s = 255 - ((255 - b1) * (255 - b2)) / 255;
|
||||
m = b1 * b2 / 255;
|
||||
b1 = (s * b1 + m * (255 - b1)) / 255;
|
||||
break;
|
||||
case CLEAR:
|
||||
r1 = g1 = b1 = 0xff;
|
||||
break;
|
||||
case DST_IN:
|
||||
r1 = clamp((r2*a1)/255);
|
||||
g1 = clamp((g2*a1)/255);
|
||||
b1 = clamp((b2*a1)/255);
|
||||
a1 = clamp((a2*a1)/255);
|
||||
return (a1 << 24) | (r1 << 16) | (g1 << 8) | b1;
|
||||
case ALPHA:
|
||||
a1 = a1*a2/255;
|
||||
return (a1 << 24) | (r2 << 16) | (g2 << 8) | b2;
|
||||
case ALPHA_TO_GRAY:
|
||||
int na = 255-a1;
|
||||
return (a1 << 24) | (na << 16) | (na << 8) | na;
|
||||
}
|
||||
if (extraAlpha != 0xff || a1 != 0xff) {
|
||||
a1 = a1*extraAlpha/255;
|
||||
int a3 = (255-a1)*a2/255;
|
||||
r1 = clamp((r1*a1+r2*a3)/255);
|
||||
g1 = clamp((g1*a1+g2*a3)/255);
|
||||
b1 = clamp((b1*a1+b2*a3)/255);
|
||||
a1 = clamp(a1+a3);
|
||||
}
|
||||
return (a1 << 24) | (r1 << 16) | (g1 << 8) | b1;
|
||||
}
|
||||
switch (op) {
|
||||
case NORMAL:
|
||||
break;
|
||||
case MIN:
|
||||
r1 = Math.min(r1, r2);
|
||||
g1 = Math.min(g1, g2);
|
||||
b1 = Math.min(b1, b2);
|
||||
break;
|
||||
case MAX:
|
||||
r1 = Math.max(r1, r2);
|
||||
g1 = Math.max(g1, g2);
|
||||
b1 = Math.max(b1, b2);
|
||||
break;
|
||||
case ADD:
|
||||
r1 = clamp(r1+r2);
|
||||
g1 = clamp(g1+g2);
|
||||
b1 = clamp(b1+b2);
|
||||
break;
|
||||
case SUBTRACT:
|
||||
r1 = clamp(r2-r1);
|
||||
g1 = clamp(g2-g1);
|
||||
b1 = clamp(b2-b1);
|
||||
break;
|
||||
case DIFFERENCE:
|
||||
r1 = clamp(Math.abs(r1-r2));
|
||||
g1 = clamp(Math.abs(g1-g2));
|
||||
b1 = clamp(Math.abs(b1-b2));
|
||||
break;
|
||||
case MULTIPLY:
|
||||
r1 = clamp(r1*r2/255);
|
||||
g1 = clamp(g1*g2/255);
|
||||
b1 = clamp(b1*b2/255);
|
||||
break;
|
||||
case DISSOLVE:
|
||||
if ((randomGenerator.nextInt() & 0xff) <= a1) {
|
||||
r1 = r2;
|
||||
g1 = g2;
|
||||
b1 = b2;
|
||||
}
|
||||
break;
|
||||
case AVERAGE:
|
||||
r1 = (r1+r2)/2;
|
||||
g1 = (g1+g2)/2;
|
||||
b1 = (b1+b2)/2;
|
||||
break;
|
||||
case HUE:
|
||||
case SATURATION:
|
||||
case VALUE:
|
||||
case COLOR:
|
||||
Color.RGBtoHSB(r1, g1, b1, hsb1);
|
||||
Color.RGBtoHSB(r2, g2, b2, hsb2);
|
||||
switch (op) {
|
||||
case HUE:
|
||||
hsb2[0] = hsb1[0];
|
||||
break;
|
||||
case SATURATION:
|
||||
hsb2[1] = hsb1[1];
|
||||
break;
|
||||
case VALUE:
|
||||
hsb2[2] = hsb1[2];
|
||||
break;
|
||||
case COLOR:
|
||||
hsb2[0] = hsb1[0];
|
||||
hsb2[1] = hsb1[1];
|
||||
break;
|
||||
}
|
||||
rgb1 = Color.HSBtoRGB(hsb2[0], hsb2[1], hsb2[2]);
|
||||
r1 = (rgb1 >> 16) & 0xff;
|
||||
g1 = (rgb1 >> 8) & 0xff;
|
||||
b1 = rgb1 & 0xff;
|
||||
break;
|
||||
case SCREEN:
|
||||
r1 = 255 - ((255 - r1) * (255 - r2)) / 255;
|
||||
g1 = 255 - ((255 - g1) * (255 - g2)) / 255;
|
||||
b1 = 255 - ((255 - b1) * (255 - b2)) / 255;
|
||||
break;
|
||||
case OVERLAY:
|
||||
int m, s;
|
||||
s = 255 - ((255 - r1) * (255 - r2)) / 255;
|
||||
m = r1 * r2 / 255;
|
||||
r1 = (s * r1 + m * (255 - r1)) / 255;
|
||||
s = 255 - ((255 - g1) * (255 - g2)) / 255;
|
||||
m = g1 * g2 / 255;
|
||||
g1 = (s * g1 + m * (255 - g1)) / 255;
|
||||
s = 255 - ((255 - b1) * (255 - b2)) / 255;
|
||||
m = b1 * b2 / 255;
|
||||
b1 = (s * b1 + m * (255 - b1)) / 255;
|
||||
break;
|
||||
case CLEAR:
|
||||
r1 = g1 = b1 = 0xff;
|
||||
break;
|
||||
case DST_IN:
|
||||
r1 = clamp((r2*a1)/255);
|
||||
g1 = clamp((g2*a1)/255);
|
||||
b1 = clamp((b2*a1)/255);
|
||||
a1 = clamp((a2*a1)/255);
|
||||
return (a1 << 24) | (r1 << 16) | (g1 << 8) | b1;
|
||||
case ALPHA:
|
||||
a1 = a1*a2/255;
|
||||
return (a1 << 24) | (r2 << 16) | (g2 << 8) | b2;
|
||||
case ALPHA_TO_GRAY:
|
||||
int na = 255-a1;
|
||||
return (a1 << 24) | (na << 16) | (na << 8) | na;
|
||||
}
|
||||
if (extraAlpha != 0xff || a1 != 0xff) {
|
||||
a1 = a1*extraAlpha/255;
|
||||
int a3 = (255-a1)*a2/255;
|
||||
r1 = clamp((r1*a1+r2*a3)/255);
|
||||
g1 = clamp((g1*a1+g2*a3)/255);
|
||||
b1 = clamp((b1*a1+b2*a3)/255);
|
||||
a1 = clamp(a1+a3);
|
||||
}
|
||||
return (a1 << 24) | (r1 << 16) | (g1 << 8) | b1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,150 +29,150 @@ import java.awt.Rectangle;
|
|||
*/
|
||||
public class QuantizeFilter extends WholeImageFilter {
|
||||
|
||||
/**
|
||||
* Floyd-Steinberg dithering matrix.
|
||||
*/
|
||||
protected final static int[] matrix = {
|
||||
0, 0, 0,
|
||||
0, 0, 7,
|
||||
3, 5, 1,
|
||||
};
|
||||
private int sum = 3+5+7+1;
|
||||
/**
|
||||
* Floyd-Steinberg dithering matrix.
|
||||
*/
|
||||
protected final static int[] matrix = {
|
||||
0, 0, 0,
|
||||
0, 0, 7,
|
||||
3, 5, 1,
|
||||
};
|
||||
private int sum = 3+5+7+1;
|
||||
|
||||
private boolean dither;
|
||||
private int numColors = 256;
|
||||
private boolean serpentine = true;
|
||||
private boolean dither;
|
||||
private int numColors = 256;
|
||||
private boolean serpentine = true;
|
||||
|
||||
/**
|
||||
* Set the number of colors to quantize to.
|
||||
* @param numColors the number of colors. The default is 256.
|
||||
*/
|
||||
public void setNumColors(int numColors) {
|
||||
this.numColors = Math.min(Math.max(numColors, 8), 256);
|
||||
}
|
||||
/**
|
||||
* Set the number of colors to quantize to.
|
||||
* @param numColors the number of colors. The default is 256.
|
||||
*/
|
||||
public void setNumColors(int numColors) {
|
||||
this.numColors = Math.min(Math.max(numColors, 8), 256);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of colors to quantize to.
|
||||
* @return the number of colors.
|
||||
*/
|
||||
public int getNumColors() {
|
||||
return numColors;
|
||||
}
|
||||
/**
|
||||
* Get the number of colors to quantize to.
|
||||
* @return the number of colors.
|
||||
*/
|
||||
public int getNumColors() {
|
||||
return numColors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to use dithering or not. If not, the image is posterized.
|
||||
* @param dither true to use dithering
|
||||
*/
|
||||
public void setDither(boolean dither) {
|
||||
this.dither = dither;
|
||||
}
|
||||
/**
|
||||
* Set whether to use dithering or not. If not, the image is posterized.
|
||||
* @param dither true to use dithering
|
||||
*/
|
||||
public void setDither(boolean dither) {
|
||||
this.dither = dither;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the dithering setting.
|
||||
* @return the current setting
|
||||
*/
|
||||
public boolean getDither() {
|
||||
return dither;
|
||||
}
|
||||
/**
|
||||
* Return the dithering setting.
|
||||
* @return the current setting
|
||||
*/
|
||||
public boolean getDither() {
|
||||
return dither;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to use a serpentine pattern for return or not. This can reduce 'avalanche' artifacts in the output.
|
||||
* @param serpentine true to use serpentine pattern
|
||||
*/
|
||||
public void setSerpentine(boolean serpentine) {
|
||||
this.serpentine = serpentine;
|
||||
}
|
||||
/**
|
||||
* Set whether to use a serpentine pattern for return or not. This can reduce 'avalanche' artifacts in the output.
|
||||
* @param serpentine true to use serpentine pattern
|
||||
*/
|
||||
public void setSerpentine(boolean serpentine) {
|
||||
this.serpentine = serpentine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the serpentine setting.
|
||||
* @return the current setting
|
||||
*/
|
||||
public boolean getSerpentine() {
|
||||
return serpentine;
|
||||
}
|
||||
/**
|
||||
* Return the serpentine setting.
|
||||
* @return the current setting
|
||||
*/
|
||||
public boolean getSerpentine() {
|
||||
return serpentine;
|
||||
}
|
||||
|
||||
public void quantize(int[] inPixels, int[] outPixels, int width, int height, int numColors, boolean dither, boolean serpentine) {
|
||||
int count = width*height;
|
||||
Quantizer quantizer = new OctTreeQuantizer();
|
||||
quantizer.setup(numColors);
|
||||
quantizer.addPixels(inPixels, 0, count);
|
||||
int[] table = quantizer.buildColorTable();
|
||||
public void quantize(int[] inPixels, int[] outPixels, int width, int height, int numColors, boolean dither, boolean serpentine) {
|
||||
int count = width*height;
|
||||
Quantizer quantizer = new OctTreeQuantizer();
|
||||
quantizer.setup(numColors);
|
||||
quantizer.addPixels(inPixels, 0, count);
|
||||
int[] table = quantizer.buildColorTable();
|
||||
|
||||
if (!dither) {
|
||||
for (int i = 0; i < count; i++)
|
||||
outPixels[i] = table[quantizer.getIndexForColor(inPixels[i])];
|
||||
} else {
|
||||
int index = 0;
|
||||
for (int y = 0; y < height; y++) {
|
||||
boolean reverse = serpentine && (y & 1) == 1;
|
||||
int direction;
|
||||
if (reverse) {
|
||||
index = y*width+width-1;
|
||||
direction = -1;
|
||||
} else {
|
||||
index = y*width;
|
||||
direction = 1;
|
||||
}
|
||||
for (int x = 0; x < width; x++) {
|
||||
int rgb1 = inPixels[index];
|
||||
int rgb2 = table[quantizer.getIndexForColor(rgb1)];
|
||||
if (!dither) {
|
||||
for (int i = 0; i < count; i++)
|
||||
outPixels[i] = table[quantizer.getIndexForColor(inPixels[i])];
|
||||
} else {
|
||||
int index = 0;
|
||||
for (int y = 0; y < height; y++) {
|
||||
boolean reverse = serpentine && (y & 1) == 1;
|
||||
int direction;
|
||||
if (reverse) {
|
||||
index = y*width+width-1;
|
||||
direction = -1;
|
||||
} else {
|
||||
index = y*width;
|
||||
direction = 1;
|
||||
}
|
||||
for (int x = 0; x < width; x++) {
|
||||
int rgb1 = inPixels[index];
|
||||
int rgb2 = table[quantizer.getIndexForColor(rgb1)];
|
||||
|
||||
outPixels[index] = rgb2;
|
||||
outPixels[index] = rgb2;
|
||||
|
||||
int r1 = (rgb1 >> 16) & 0xff;
|
||||
int g1 = (rgb1 >> 8) & 0xff;
|
||||
int b1 = rgb1 & 0xff;
|
||||
int r1 = (rgb1 >> 16) & 0xff;
|
||||
int g1 = (rgb1 >> 8) & 0xff;
|
||||
int b1 = rgb1 & 0xff;
|
||||
|
||||
int r2 = (rgb2 >> 16) & 0xff;
|
||||
int g2 = (rgb2 >> 8) & 0xff;
|
||||
int b2 = rgb2 & 0xff;
|
||||
int r2 = (rgb2 >> 16) & 0xff;
|
||||
int g2 = (rgb2 >> 8) & 0xff;
|
||||
int b2 = rgb2 & 0xff;
|
||||
|
||||
int er = r1-r2;
|
||||
int eg = g1-g2;
|
||||
int eb = b1-b2;
|
||||
int er = r1-r2;
|
||||
int eg = g1-g2;
|
||||
int eb = b1-b2;
|
||||
|
||||
for (int i = -1; i <= 1; i++) {
|
||||
int iy = i+y;
|
||||
if (0 <= iy && iy < height) {
|
||||
for (int j = -1; j <= 1; j++) {
|
||||
int jx = j+x;
|
||||
if (0 <= jx && jx < width) {
|
||||
int w;
|
||||
if (reverse)
|
||||
w = matrix[(i+1)*3-j+1];
|
||||
else
|
||||
w = matrix[(i+1)*3+j+1];
|
||||
if (w != 0) {
|
||||
int k = reverse ? index - j : index + j;
|
||||
rgb1 = inPixels[k];
|
||||
r1 = (rgb1 >> 16) & 0xff;
|
||||
g1 = (rgb1 >> 8) & 0xff;
|
||||
b1 = rgb1 & 0xff;
|
||||
r1 += er * w/sum;
|
||||
g1 += eg * w/sum;
|
||||
b1 += eb * w/sum;
|
||||
inPixels[k] = (PixelUtils.clamp(r1) << 16) | (PixelUtils.clamp(g1) << 8) | PixelUtils.clamp(b1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
index += direction;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = -1; i <= 1; i++) {
|
||||
int iy = i+y;
|
||||
if (0 <= iy && iy < height) {
|
||||
for (int j = -1; j <= 1; j++) {
|
||||
int jx = j+x;
|
||||
if (0 <= jx && jx < width) {
|
||||
int w;
|
||||
if (reverse)
|
||||
w = matrix[(i+1)*3-j+1];
|
||||
else
|
||||
w = matrix[(i+1)*3+j+1];
|
||||
if (w != 0) {
|
||||
int k = reverse ? index - j : index + j;
|
||||
rgb1 = inPixels[k];
|
||||
r1 = (rgb1 >> 16) & 0xff;
|
||||
g1 = (rgb1 >> 8) & 0xff;
|
||||
b1 = rgb1 & 0xff;
|
||||
r1 += er * w/sum;
|
||||
g1 += eg * w/sum;
|
||||
b1 += eb * w/sum;
|
||||
inPixels[k] = (PixelUtils.clamp(r1) << 16) | (PixelUtils.clamp(g1) << 8) | PixelUtils.clamp(b1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
index += direction;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected int[] filterPixels(int width, int height, int[] inPixels, Rectangle transformedSpace) {
|
||||
int[] outPixels = new int[width*height];
|
||||
protected int[] filterPixels(int width, int height, int[] inPixels, Rectangle transformedSpace) {
|
||||
int[] outPixels = new int[width*height];
|
||||
|
||||
quantize(inPixels, outPixels, width, height, numColors, dither, serpentine);
|
||||
quantize(inPixels, outPixels, width, height, numColors, dither, serpentine);
|
||||
|
||||
return outPixels;
|
||||
}
|
||||
return outPixels;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Colors/Quantize...";
|
||||
}
|
||||
public String toString() {
|
||||
return "Colors/Quantize...";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,32 +22,32 @@ package org.jivesoftware.smackx.jingleold.mediaimpl.sshare.api;
|
|||
* calling the buildColorTable method.
|
||||
*/
|
||||
public interface Quantizer {
|
||||
/**
|
||||
* Initialize the quantizer. This should be called before adding any pixels.
|
||||
* @param numColors the number of colors we're quantizing to.
|
||||
*/
|
||||
public void setup(int numColors);
|
||||
/**
|
||||
* Initialize the quantizer. This should be called before adding any pixels.
|
||||
* @param numColors the number of colors we're quantizing to.
|
||||
*/
|
||||
public void setup(int numColors);
|
||||
|
||||
/**
|
||||
* Add pixels to the quantizer.
|
||||
* @param pixels the array of ARGB pixels
|
||||
* @param offset the offset into the array
|
||||
* @param count the count of pixels
|
||||
*/
|
||||
public void addPixels(int[] pixels, int offset, int count);
|
||||
/**
|
||||
* Add pixels to the quantizer.
|
||||
* @param pixels the array of ARGB pixels
|
||||
* @param offset the offset into the array
|
||||
* @param count the count of pixels
|
||||
*/
|
||||
public void addPixels(int[] pixels, int offset, int count);
|
||||
|
||||
/**
|
||||
* Build a color table from the added pixels.
|
||||
* @return an array of ARGB pixels representing a color table
|
||||
*/
|
||||
public int[] buildColorTable();
|
||||
/**
|
||||
* Build a color table from the added pixels.
|
||||
* @return an array of ARGB pixels representing a color table
|
||||
*/
|
||||
public int[] buildColorTable();
|
||||
|
||||
/**
|
||||
* Using the previously-built color table, return the index into that table for a pixel.
|
||||
* This is guaranteed to return a valid index - returning the index of a color closer
|
||||
* to that requested if necessary.
|
||||
* @param rgb the pixel to find
|
||||
* @return the pixel's index in the color table
|
||||
*/
|
||||
public int getIndexForColor(int rgb);
|
||||
/**
|
||||
* Using the previously-built color table, return the index into that table for a pixel.
|
||||
* This is guaranteed to return a valid index - returning the index of a color closer
|
||||
* to that requested if necessary.
|
||||
* @param rgb the pixel to find
|
||||
* @return the pixel's index in the color table
|
||||
*/
|
||||
public int getIndexForColor(int rgb);
|
||||
}
|
||||
|
|
|
@ -27,53 +27,53 @@ import java.awt.image.WritableRaster;
|
|||
*/
|
||||
public abstract class WholeImageFilter extends AbstractBufferedImageOp {
|
||||
|
||||
/**
|
||||
/**
|
||||
* The output image bounds.
|
||||
*/
|
||||
protected Rectangle transformedSpace;
|
||||
|
||||
/**
|
||||
/**
|
||||
* The input image bounds.
|
||||
*/
|
||||
protected Rectangle originalSpace;
|
||||
protected Rectangle originalSpace;
|
||||
|
||||
/**
|
||||
* Construct a WholeImageFilter.
|
||||
*/
|
||||
public WholeImageFilter() {
|
||||
}
|
||||
/**
|
||||
* Construct a WholeImageFilter.
|
||||
*/
|
||||
public WholeImageFilter() {
|
||||
}
|
||||
|
||||
public BufferedImage filter(BufferedImage src, BufferedImage dst) {
|
||||
int width = src.getWidth();
|
||||
int height = src.getHeight();
|
||||
int type = src.getType();
|
||||
WritableRaster srcRaster = src.getRaster();
|
||||
int type = src.getType();
|
||||
WritableRaster srcRaster = src.getRaster();
|
||||
|
||||
originalSpace = new Rectangle(0, 0, width, height);
|
||||
transformedSpace = new Rectangle(0, 0, width, height);
|
||||
transformSpace(transformedSpace);
|
||||
originalSpace = new Rectangle(0, 0, width, height);
|
||||
transformedSpace = new Rectangle(0, 0, width, height);
|
||||
transformSpace(transformedSpace);
|
||||
|
||||
if (dst == null) {
|
||||
ColorModel dstCM = src.getColorModel();
|
||||
dst = new BufferedImage(dstCM, dstCM.createCompatibleWritableRaster(transformedSpace.width, transformedSpace.height), dstCM.isAlphaPremultiplied(), null);
|
||||
}
|
||||
WritableRaster dstRaster = dst.getRaster();
|
||||
dst = new BufferedImage(dstCM, dstCM.createCompatibleWritableRaster(transformedSpace.width, transformedSpace.height), dstCM.isAlphaPremultiplied(), null);
|
||||
}
|
||||
WritableRaster dstRaster = dst.getRaster();
|
||||
|
||||
int[] inPixels = getRGB(src, 0, 0, width, height, null);
|
||||
inPixels = filterPixels(width, height, inPixels, transformedSpace);
|
||||
setRGB(dst, 0, 0, transformedSpace.width, transformedSpace.height, inPixels);
|
||||
int[] inPixels = getRGB(src, 0, 0, width, height, null);
|
||||
inPixels = filterPixels(width, height, inPixels, transformedSpace);
|
||||
setRGB(dst, 0, 0, transformedSpace.width, transformedSpace.height, inPixels);
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Calculate output bounds for given input bounds.
|
||||
* @param rect input and output rectangle
|
||||
*/
|
||||
protected void transformSpace(Rectangle rect) {
|
||||
}
|
||||
protected void transformSpace(Rectangle rect) {
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Actually filter the pixels.
|
||||
* @param width the image width
|
||||
* @param height the image height
|
||||
|
@ -81,6 +81,6 @@ public abstract class WholeImageFilter extends AbstractBufferedImageOp {
|
|||
* @param transformedSpace the output bounds
|
||||
* @return the output pixels
|
||||
*/
|
||||
protected abstract int[] filterPixels(int width, int height, int[] inPixels, Rectangle transformedSpace);
|
||||
protected abstract int[] filterPixels(int width, int height, int[] inPixels, Rectangle transformedSpace);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,9 +32,9 @@ import java.util.logging.Logger;
|
|||
*/
|
||||
public class HttpServer {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(HttpServer.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(HttpServer.class.getName());
|
||||
|
||||
public HttpServer(int port) {
|
||||
public HttpServer(int port) {
|
||||
ServerSocket server_socket;
|
||||
|
||||
try {
|
||||
|
|
|
@ -32,9 +32,9 @@ import java.util.logging.Logger;
|
|||
*/
|
||||
public class ICECandidate extends TransportCandidate implements Comparable<ICECandidate> {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(ICECandidate.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(ICECandidate.class.getName());
|
||||
|
||||
private String id; // An identification
|
||||
private String id; // An identification
|
||||
|
||||
private String username;
|
||||
|
||||
|
@ -415,14 +415,14 @@ public class ICECandidate extends TransportCandidate implements Comparable<ICECa
|
|||
* object is less than, equal to, or greater than the specified
|
||||
* object
|
||||
*/
|
||||
public int compareTo(ICECandidate arg) {
|
||||
if (getPreference() < arg.getPreference()) {
|
||||
return -1;
|
||||
} else if (getPreference() > arg.getPreference()) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public int compareTo(ICECandidate arg) {
|
||||
if (getPreference() < arg.getPreference()) {
|
||||
return -1;
|
||||
} else if (getPreference() > arg.getPreference()) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ import de.javawi.jstun.util.UtilityException;
|
|||
*/
|
||||
public class ICEResolver extends TransportResolver {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(ICEResolver.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(ICEResolver.class.getName());
|
||||
|
||||
XMPPConnection connection;
|
||||
Random random = new Random();
|
||||
|
@ -73,13 +73,13 @@ public class ICEResolver extends TransportResolver {
|
|||
// of the STUN server are much, much faster.
|
||||
if (negociatorsMap.get(server) == null) {
|
||||
// CHECKSTYLE:OFF
|
||||
ICENegociator iceNegociator = new ICENegociator(server, port, (short) 1);
|
||||
negociatorsMap.put(server, iceNegociator);
|
||||
ICENegociator iceNegociator = new ICENegociator(server, port, (short) 1);
|
||||
negociatorsMap.put(server, iceNegociator);
|
||||
|
||||
// gather candidates
|
||||
iceNegociator.gatherCandidateAddresses();
|
||||
// priorize candidates
|
||||
iceNegociator.prioritizeCandidates();
|
||||
// gather candidates
|
||||
iceNegociator.gatherCandidateAddresses();
|
||||
// priorize candidates
|
||||
iceNegociator.prioritizeCandidates();
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
|
||||
|
@ -125,21 +125,21 @@ public class ICEResolver extends TransportResolver {
|
|||
|
||||
// JBW/GW - 17JUL08: Figure out the zero-based NIC number for this candidate.
|
||||
short nicNum = 0;
|
||||
try {
|
||||
Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
|
||||
short i = 0;
|
||||
NetworkInterface nic = NetworkInterface.getByInetAddress(candidate.getAddress().getInetAddress());
|
||||
while(nics.hasMoreElements()) {
|
||||
NetworkInterface checkNIC = nics.nextElement();
|
||||
if (checkNIC.equals(nic)) {
|
||||
nicNum = i;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
} catch (SocketException e1) {
|
||||
LOGGER.log(Level.WARNING, "exeption", e1);
|
||||
}
|
||||
try {
|
||||
Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
|
||||
short i = 0;
|
||||
NetworkInterface nic = NetworkInterface.getByInetAddress(candidate.getAddress().getInetAddress());
|
||||
while(nics.hasMoreElements()) {
|
||||
NetworkInterface checkNIC = nics.nextElement();
|
||||
if (checkNIC.equals(nic)) {
|
||||
nicNum = i;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
} catch (SocketException e1) {
|
||||
LOGGER.log(Level.WARNING, "exeption", e1);
|
||||
}
|
||||
|
||||
TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress().getHostAddress(), 1, nicNum, String.valueOf(Math.abs(random.nextLong())), candidate.getPort(), "1", candidate.getPriority(), iceType);
|
||||
transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
|
||||
|
|
|
@ -52,9 +52,9 @@ import org.xmlpull.v1.XmlPullParserException;
|
|||
*/
|
||||
public class RTPBridge extends IQ {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(RTPBridge.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(RTPBridge.class.getName());
|
||||
|
||||
private String sid;
|
||||
private String sid;
|
||||
private String pass;
|
||||
private String ip;
|
||||
private String name;
|
||||
|
|
|
@ -46,9 +46,9 @@ import org.xmlpull.v1.XmlPullParserException;
|
|||
*/
|
||||
public class STUN extends SimpleIQ {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(STUN.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(STUN.class.getName());
|
||||
|
||||
private List<StunServerAddress> servers = new ArrayList<StunServerAddress>();
|
||||
private List<StunServerAddress> servers = new ArrayList<StunServerAddress>();
|
||||
|
||||
private String publicIp = null;
|
||||
|
||||
|
|
|
@ -46,9 +46,9 @@ import de.javawi.jstun.test.DiscoveryTest;
|
|||
*/
|
||||
public class STUNResolver extends TransportResolver {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(STUNResolver.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(STUNResolver.class.getName());
|
||||
|
||||
// The filename where the STUN servers are stored.
|
||||
// The filename where the STUN servers are stored.
|
||||
public final static String STUNSERVERS_FILENAME = "META-INF/stun-config.xml";
|
||||
|
||||
// Current STUN server we are using
|
||||
|
|
|
@ -33,9 +33,9 @@ import java.util.logging.Logger;
|
|||
*/
|
||||
public class TcpUdpBridgeClient {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(TcpUdpBridgeClient.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(TcpUdpBridgeClient.class.getName());
|
||||
|
||||
private String remoteTcpHost = null;
|
||||
private String remoteTcpHost = null;
|
||||
private String remoteUdpHost = null;
|
||||
private int remoteTcpPort = -1;
|
||||
private int remoteUdpPort = -1;
|
||||
|
|
|
@ -35,9 +35,9 @@ import java.util.logging.Logger;
|
|||
*/
|
||||
public class TcpUdpBridgeServer {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(TcpUdpBridgeServer.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(TcpUdpBridgeServer.class.getName());
|
||||
|
||||
private String remoteTcpHost = null;
|
||||
private String remoteTcpHost = null;
|
||||
private String remoteUdpHost = null;
|
||||
private int remoteTcpPort = -1;
|
||||
private int remoteUdpPort = -1;
|
||||
|
|
|
@ -47,9 +47,9 @@ import org.jxmpp.jid.Jid;
|
|||
@SuppressWarnings("EqualsHashCode")
|
||||
public abstract class TransportCandidate {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(TransportCandidate.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(TransportCandidate.class.getName());
|
||||
|
||||
private String name;
|
||||
private String name;
|
||||
|
||||
private String ip; // IP address
|
||||
|
||||
|
@ -359,7 +359,7 @@ public abstract class TransportCandidate {
|
|||
|
||||
try {
|
||||
// CHECKSTYLE:OFF
|
||||
InetAddress candAddress = InetAddress.getByName(getIp());
|
||||
InetAddress candAddress = InetAddress.getByName(getIp());
|
||||
// CHECKSTYLE:ON
|
||||
isUsable = true;//candAddress.isReachable(TransportResolver.CHECK_TIMEOUT);
|
||||
}
|
||||
|
@ -771,8 +771,8 @@ public abstract class TransportCandidate {
|
|||
|
||||
// CHECKSTYLE:OFF
|
||||
if (pass.equals(password)
|
||||
&& transportCandidate.getIp().indexOf(ip) != -1
|
||||
&& transportCandidate.getPort() == Integer.parseInt(pt)) {
|
||||
&& transportCandidate.getIp().indexOf(ip) != -1
|
||||
&& transportCandidate.getPort() == Integer.parseInt(pt)) {
|
||||
// CHECKSTYLE:ON
|
||||
LOGGER.fine("ECHO OK: " + candidate.getIp() + ":" + candidate.getPort() + " <-> " + transportCandidate.getIp() + ":" + transportCandidate.getPort());
|
||||
TestResult testResult = new TestResult();
|
||||
|
|
|
@ -52,9 +52,9 @@ import org.jivesoftware.smackx.jingleold.packet.JingleTransport.JingleTransportC
|
|||
*/
|
||||
public abstract class TransportNegotiator extends JingleNegotiator {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(TransportNegotiator.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(TransportNegotiator.class.getName());
|
||||
|
||||
// The time we give to the candidates check before we accept or decline the
|
||||
// The time we give to the candidates check before we accept or decline the
|
||||
// transport (in milliseconds)
|
||||
public final static int CANDIDATES_ACCEPT_PERIOD = 4000;
|
||||
|
||||
|
@ -911,12 +911,12 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
int highest = -1;
|
||||
ICECandidate chose = null;
|
||||
for (TransportCandidate transportCandidate : cands) {
|
||||
if (transportCandidate instanceof ICECandidate) {
|
||||
ICECandidate icecandidate = (ICECandidate) transportCandidate;
|
||||
if (icecandidate.getPreference() > highest) {
|
||||
chose = icecandidate;
|
||||
highest = icecandidate.getPreference();
|
||||
}
|
||||
if (transportCandidate instanceof ICECandidate) {
|
||||
ICECandidate icecandidate = (ICECandidate) transportCandidate;
|
||||
if (icecandidate.getPreference() > highest) {
|
||||
chose = icecandidate;
|
||||
highest = icecandidate.getPreference();
|
||||
}
|
||||
}
|
||||
}
|
||||
result = chose;
|
||||
|
|
|
@ -40,9 +40,9 @@ import org.jivesoftware.smackx.jingleold.JingleSession;
|
|||
*/
|
||||
public abstract class TransportResolver {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(TransportResolver.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(TransportResolver.class.getName());
|
||||
|
||||
public enum Type {
|
||||
public enum Type {
|
||||
|
||||
rawupd, ice
|
||||
}
|
||||
|
|
|
@ -283,12 +283,12 @@ public abstract class JingleContentDescription implements ExtensionElement {
|
|||
StringBuilder buf = new StringBuilder();
|
||||
PayloadType pt = getPayloadType();
|
||||
if (pt instanceof PayloadType.Audio) {
|
||||
PayloadType.Audio pta = (PayloadType.Audio) pt;
|
||||
PayloadType.Audio pta = (PayloadType.Audio) pt;
|
||||
|
||||
buf.append(" clockrate=\"").append(pta.getClockRate()).append("\" ");
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
buf.append(" clockrate=\"").append(pta.getClockRate()).append("\" ");
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,7 +148,7 @@ public class JingleContentInfo implements ExtensionElement {
|
|||
public static class Ringing extends Audio {
|
||||
public Ringing() {
|
||||
super(ContentInfo.Audio.RINGING);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,9 +32,9 @@ import org.jivesoftware.smackx.jingleold.media.PayloadType;
|
|||
*/
|
||||
public abstract class JingleDescription implements ExtensionElement {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleDescription.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleDescription.class.getName());
|
||||
|
||||
// static
|
||||
// static
|
||||
|
||||
public static final String NODENAME = "description";
|
||||
|
||||
|
|
|
@ -119,8 +119,8 @@ public class JingleError implements ExtensionElement {
|
|||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
||||
public static class Provider extends ExtensionElementProvider<ExtensionElement> {
|
||||
|
||||
|
|
|
@ -127,6 +127,6 @@ public abstract class JingleContentDescriptionProvider extends ExtensionElementP
|
|||
*/
|
||||
protected JingleContentDescription getInstance() {
|
||||
return new JingleContentDescription.Audio();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ public class JingleContentInfoProvider {
|
|||
public static class Ringing extends Audio {
|
||||
public Ringing() {
|
||||
super(new JingleContentInfo.Audio.Ringing());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue