Changed folder structure of test classes and renamed some packages
This commit is contained in:
parent
ccd50ec104
commit
884c5d64c3
76 changed files with 5305 additions and 5375 deletions
2
src/zutil/Hasher.java
Normal file → Executable file
2
src/zutil/Hasher.java
Normal file → Executable file
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
package zutil;
|
||||
|
||||
import zutil.converters.Converter;
|
||||
import zutil.converter.Converter;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.SecretKeyFactory;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
package zutil;
|
||||
|
||||
import zutil.converters.Converter;
|
||||
import zutil.converter.Converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
|
|
|||
|
|
@ -1,460 +1,460 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.converters;
|
||||
|
||||
import zutil.io.DynamicByteArrayStream;
|
||||
import zutil.parser.Base64Decoder;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.BitSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
public class Converter {
|
||||
private Converter(){}
|
||||
|
||||
/**
|
||||
* Converts an object to an array of bytes.
|
||||
*
|
||||
* @param object the object to convert.
|
||||
* @return the associated byte array.
|
||||
*/
|
||||
public static byte[] toBytes(Object object) throws IOException{
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(object);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Integer to an byte array
|
||||
*
|
||||
* @param num is the number to convert
|
||||
* @return a byte array of four bytes
|
||||
*/
|
||||
public static byte[] toBytes(int num){
|
||||
return new byte[]{
|
||||
(byte)(num & 0xff),
|
||||
(byte)((num >> 8)& 0xff),
|
||||
(byte)((num >> 16)& 0xff),
|
||||
(byte)((num >> 24)& 0xff)};
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Integer to a byte
|
||||
*
|
||||
* @param num is the number to convert
|
||||
* @return a byte value of the integer
|
||||
*/
|
||||
public static byte toByte(int num){
|
||||
return (byte)(num & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts hex string to a byte array
|
||||
*
|
||||
* @param hex a String containing data coded in hex
|
||||
* @return a byte array
|
||||
*/
|
||||
public static byte[] hexToByte(String hex){
|
||||
if(hex == null)
|
||||
return null;
|
||||
if(hex.startsWith("0x"))
|
||||
hex = hex.substring(2);
|
||||
byte[] b = new byte[(int)Math.ceil(hex.length()/2.0)];
|
||||
for(int i=hex.length()-1; i>=0; i-=2){
|
||||
if(i-1 < 0)
|
||||
b[(hex.length()-i-1)/2] = hexToByte(hex.charAt(i));
|
||||
else
|
||||
b[(hex.length()-i-1)/2] = hexToByte(hex.charAt(i-1), hex.charAt(i));
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts hex chars to a byte
|
||||
*
|
||||
* @param quad1 is the first hex value
|
||||
* @param quad2 is the second hex value
|
||||
* @return a byte that corresponds to the hex
|
||||
*/
|
||||
public static byte hexToByte( char quad1, char quad2){
|
||||
byte b = hexToByte( quad2 );
|
||||
b |= hexToByte( quad1 ) << 4;
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a hex chars to a byte
|
||||
*
|
||||
* @param hex is the hex value
|
||||
* @return a byte that corresponds to the hex
|
||||
*/
|
||||
public static byte hexToByte( char hex ){
|
||||
switch( Character.toLowerCase(hex) ){
|
||||
case '0': return 0x00;
|
||||
case '1': return 0x01;
|
||||
case '2': return 0x02;
|
||||
case '3': return 0x03;
|
||||
case '4': return 0x04;
|
||||
case '5': return 0x05;
|
||||
case '6': return 0x06;
|
||||
case '7': return 0x07;
|
||||
case '8': return 0x08;
|
||||
case '9': return 0x09;
|
||||
case 'a': return 0x0a;
|
||||
case 'b': return 0x0b;
|
||||
case 'c': return 0x0c;
|
||||
case 'd': return 0x0d;
|
||||
case 'e': return 0x0e;
|
||||
case 'f': return 0x0f;
|
||||
}
|
||||
return (byte)0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array of bytes back to its constituent object. The
|
||||
* input array is assumed to have been created from the original object.
|
||||
*
|
||||
* @param bytes the byte array to convert.
|
||||
* @return the associated object.
|
||||
*/
|
||||
public static Object toObject(byte[] bytes) throws Exception{
|
||||
Object object = null;
|
||||
|
||||
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
|
||||
object = ois.readObject();
|
||||
ois.close();
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array of bytes back to its constituent object. The
|
||||
* input array is assumed to have been created from the original object.
|
||||
*
|
||||
* @param bytes the byte array to convert.
|
||||
* @return the associated object.
|
||||
*/
|
||||
public static Object toObject(DynamicByteArrayStream bytes) throws Exception{
|
||||
Object object = null;
|
||||
|
||||
ObjectInputStream ois = new ObjectInputStream(bytes);
|
||||
object = ois.readObject();
|
||||
ois.close();
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
/** array needed for byteToHex */
|
||||
private static char[] HEX_CHARS = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
|
||||
/**
|
||||
* Converts a byte Array to a Hex String
|
||||
*
|
||||
* @param raw the byte array to convert
|
||||
* @return a hex String
|
||||
*/
|
||||
public static String toHexString(byte[][] raw){
|
||||
StringBuffer ret = new StringBuffer();
|
||||
|
||||
for(byte[] a : raw){
|
||||
for(byte b : a){
|
||||
ret.append(HEX_CHARS[(int) (b >>> 0x04)& 0x0F ]);
|
||||
ret.append(HEX_CHARS[(int) b & 0x0F ]);
|
||||
}
|
||||
}
|
||||
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
public static String toHexStringByColumn(byte[][] raw){
|
||||
StringBuffer ret = new StringBuffer();
|
||||
|
||||
for(int col=0; col<raw[0].length ;col++){
|
||||
for(int row=0; row<raw.length ;row++){
|
||||
ret.append(HEX_CHARS[(int) (raw[row][col] >>> 0x04)& 0x0F ]);
|
||||
ret.append(HEX_CHARS[(int) raw[row][col] & 0x0F ]);
|
||||
}
|
||||
}
|
||||
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a byte Array to a Hex String
|
||||
*
|
||||
* @param raw the byte array to convert
|
||||
* @return a hex String
|
||||
*/
|
||||
public static String toHexString(byte[] raw){
|
||||
StringBuffer ret = new StringBuffer();
|
||||
|
||||
for(byte b : raw){
|
||||
ret.append(HEX_CHARS[(int) (b >>> 0x04)& 0x0F ]);
|
||||
ret.append(HEX_CHARS[(int) b & 0x0F ]);
|
||||
}
|
||||
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a byte to a Hex String
|
||||
*
|
||||
* @param raw the byte to convert
|
||||
* @return a hex String
|
||||
*/
|
||||
public static String toHexString(byte raw){
|
||||
String ret = ""+HEX_CHARS[(int) (raw >>> 0x04)& 0x0F ];
|
||||
ret += ""+HEX_CHARS[(int) raw & 0x0F ];
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given byte to a String with 1's and 0's
|
||||
*
|
||||
* @param raw the byte to convert
|
||||
* @return a String with 1's and 0's
|
||||
*/
|
||||
public static String toString(byte raw){
|
||||
StringBuffer ret = new StringBuffer();
|
||||
for(int i=128; i>0 ;i=( i<1 ? i=0 : i/2 ) ){
|
||||
ret.append(( (raw & i) == 0 ? '0' : '1'));
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given byte array to a String with 1's and 0's
|
||||
*
|
||||
* @param raw the byte array to convert
|
||||
* @return a String with 1's and 0's
|
||||
*/
|
||||
public static String toString(byte[] raw){
|
||||
StringBuffer ret = new StringBuffer();
|
||||
for(byte b : raw){
|
||||
for(int i=128; i>0 ;i=( i<1 ? i=0 : i/2 ) ){
|
||||
ret.append(( (b & i) == 0 ? '0' : '1'));
|
||||
}
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a comma separated string with key and value pairs
|
||||
*
|
||||
* @return a comma separated String
|
||||
*/
|
||||
public static String toString(Map map){
|
||||
StringBuilder tmp = new StringBuilder();
|
||||
tmp.append("{");
|
||||
Iterator<Object> it = map.keySet().iterator();
|
||||
while(it.hasNext()){
|
||||
Object key = it.next();
|
||||
Object value = map.get(key);
|
||||
tmp.append(key);
|
||||
if (value != null) {
|
||||
if (value instanceof String)
|
||||
tmp.append(": \"").append(value).append("\"");
|
||||
else
|
||||
tmp.append(value);
|
||||
}
|
||||
else
|
||||
tmp.append("null");
|
||||
|
||||
if(it.hasNext())
|
||||
tmp.append(", ");
|
||||
}
|
||||
tmp.append('}');
|
||||
return tmp.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a BitSet to a Integer
|
||||
*
|
||||
* @param bits the BitSet to convert
|
||||
* @return a Integer
|
||||
*/
|
||||
public static int toInt(BitSet bits){
|
||||
int ret = 0;
|
||||
|
||||
for (int i = bits.nextSetBit(0); i >= 0; i = bits.nextSetBit(i+1)) {
|
||||
ret += Math.pow(2, i);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a boolean array(bit sequence whit most significant bit at index 0) to a Integer
|
||||
*
|
||||
* @param bits the boolean array to convert
|
||||
* @return a Integer
|
||||
*/
|
||||
public static int toInt(boolean[] bits){
|
||||
int ret = 0;
|
||||
|
||||
for (int i = bits.length-1; i >= 0; i--) {
|
||||
if(bits[i])ret += Math.pow(2, bits.length-i-1);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a byte to a integer
|
||||
*
|
||||
* @param b is the byte to convert
|
||||
* @return the integer value of the byte
|
||||
*/
|
||||
public static int toInt(byte b){
|
||||
return (int)(b & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a dynamic sized byte array to a integer
|
||||
*
|
||||
* @param b is the byte array of size 1-4
|
||||
* @return the int value of the byte array
|
||||
*/
|
||||
public static int toInt(byte[] b){
|
||||
int i = 0;
|
||||
switch (b.length){
|
||||
default:
|
||||
case 4:
|
||||
i |= 0xFF000000 & (b[0] << 24);
|
||||
i |= 0x00FF0000 & (b[1] << 16);
|
||||
i |= 0x0000FF00 & (b[2] << 8);
|
||||
i |= 0x000000FF & b[3];
|
||||
break;
|
||||
case 3:
|
||||
i |= 0x00FF0000 & (b[0] << 16);
|
||||
i |= 0x0000FF00 & (b[1] << 8);
|
||||
i |= 0x000000FF & b[2];
|
||||
break;
|
||||
case 2:
|
||||
i |= 0x0000FF00 & (b[0] << 8);
|
||||
i |= 0x000000FF & b[1];
|
||||
break;
|
||||
case 1:
|
||||
i |= 0x000000FF & b[0];
|
||||
break;
|
||||
case 0: break;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Integer to a BitSet
|
||||
*
|
||||
* @param num the Integer to convert
|
||||
* @return a BitSet object
|
||||
*/
|
||||
public static BitSet toBitSet(int num){
|
||||
BitSet ret = new BitSet();
|
||||
String tmp = Integer.toBinaryString(num);
|
||||
|
||||
for(int i=0; i<tmp.length() ;i++){
|
||||
ret.set(i , tmp.charAt(tmp.length()-i-1) != '0');
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts a given String to a specified class
|
||||
*
|
||||
* @param <T> is the resulting class
|
||||
* @param data is the String data to be converted
|
||||
* @param c is the class to convert to
|
||||
* @return a instance of the class with the value in the string or null if there was an problem
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T fromString(String data, Class<T> c){
|
||||
if(data == null || data.isEmpty())
|
||||
return null;
|
||||
try{
|
||||
if( c == String.class) return (T) data;
|
||||
else if(c == Integer.class) return (T) new Integer(data);
|
||||
else if(c == int.class) return (T) new Integer(data);
|
||||
else if(c == Long.class) return (T) new Long(data);
|
||||
else if(c == long.class) return (T) new Long(data);
|
||||
else if(c == Float.class) return (T) new Float(data);
|
||||
else if(c == float.class) return (T) new Float(data);
|
||||
else if(c == Double.class) return (T) new Double(data);
|
||||
else if(c == double.class) return (T) new Double(data);
|
||||
else if(c == Boolean.class) return (T) new Boolean(data);
|
||||
else if(c == boolean.class) return (T) new Boolean(data);
|
||||
else if(c == Byte.class) return (T) new Byte(data);
|
||||
else if(c == byte.class) return (T) new Byte(data);
|
||||
else if(byte[].class.isAssignableFrom(c))
|
||||
return (T) Base64Decoder.decode(data);
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces reserved and unsafe characters in URLs with hex values
|
||||
*/
|
||||
public static String urlEncode( String str ){
|
||||
StringBuilder out = new StringBuilder();
|
||||
for( char c : str.toCharArray() ){
|
||||
if( c>='0' && c<='9' || c>='A' && c<='Z' || c>='a' && c<='z' ||
|
||||
c=='$' || c=='-' || c=='_' || c=='.' || c=='+' || c=='!' ||
|
||||
c=='*' || c=='\'' || c=='(' || c==')' || c==',' )
|
||||
out.append( c );
|
||||
else{
|
||||
out.append( '%' ).append( toHexString((byte)c) );
|
||||
}
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces hex values from a URL with the proper characters
|
||||
*/
|
||||
public static String urlDecode( String str ){
|
||||
StringBuilder out = new StringBuilder();
|
||||
char[] array = str.toCharArray();
|
||||
for( int i=0; i<array.length ;i++ ){
|
||||
char c = array[i];
|
||||
if( c == '%' && i+2<array.length ){
|
||||
out.append( (char)hexToByte( array[++i], array[++i]) );
|
||||
}
|
||||
else
|
||||
out.append( c );
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.converter;
|
||||
|
||||
import zutil.io.DynamicByteArrayStream;
|
||||
import zutil.parser.Base64Decoder;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.BitSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
public class Converter {
|
||||
private Converter(){}
|
||||
|
||||
/**
|
||||
* Converts an object to an array of bytes.
|
||||
*
|
||||
* @param object the object to convert.
|
||||
* @return the associated byte array.
|
||||
*/
|
||||
public static byte[] toBytes(Object object) throws IOException{
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(object);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Integer to an byte array
|
||||
*
|
||||
* @param num is the number to convert
|
||||
* @return a byte array of four bytes
|
||||
*/
|
||||
public static byte[] toBytes(int num){
|
||||
return new byte[]{
|
||||
(byte)(num & 0xff),
|
||||
(byte)((num >> 8)& 0xff),
|
||||
(byte)((num >> 16)& 0xff),
|
||||
(byte)((num >> 24)& 0xff)};
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Integer to a byte
|
||||
*
|
||||
* @param num is the number to convert
|
||||
* @return a byte value of the integer
|
||||
*/
|
||||
public static byte toByte(int num){
|
||||
return (byte)(num & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts hex string to a byte array
|
||||
*
|
||||
* @param hex a String containing data coded in hex
|
||||
* @return a byte array
|
||||
*/
|
||||
public static byte[] hexToByte(String hex){
|
||||
if(hex == null)
|
||||
return null;
|
||||
if(hex.startsWith("0x"))
|
||||
hex = hex.substring(2);
|
||||
byte[] b = new byte[(int)Math.ceil(hex.length()/2.0)];
|
||||
for(int i=hex.length()-1; i>=0; i-=2){
|
||||
if(i-1 < 0)
|
||||
b[(hex.length()-i-1)/2] = hexToByte(hex.charAt(i));
|
||||
else
|
||||
b[(hex.length()-i-1)/2] = hexToByte(hex.charAt(i-1), hex.charAt(i));
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts hex chars to a byte
|
||||
*
|
||||
* @param quad1 is the first hex value
|
||||
* @param quad2 is the second hex value
|
||||
* @return a byte that corresponds to the hex
|
||||
*/
|
||||
public static byte hexToByte( char quad1, char quad2){
|
||||
byte b = hexToByte( quad2 );
|
||||
b |= hexToByte( quad1 ) << 4;
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a hex chars to a byte
|
||||
*
|
||||
* @param hex is the hex value
|
||||
* @return a byte that corresponds to the hex
|
||||
*/
|
||||
public static byte hexToByte( char hex ){
|
||||
switch( Character.toLowerCase(hex) ){
|
||||
case '0': return 0x00;
|
||||
case '1': return 0x01;
|
||||
case '2': return 0x02;
|
||||
case '3': return 0x03;
|
||||
case '4': return 0x04;
|
||||
case '5': return 0x05;
|
||||
case '6': return 0x06;
|
||||
case '7': return 0x07;
|
||||
case '8': return 0x08;
|
||||
case '9': return 0x09;
|
||||
case 'a': return 0x0a;
|
||||
case 'b': return 0x0b;
|
||||
case 'c': return 0x0c;
|
||||
case 'd': return 0x0d;
|
||||
case 'e': return 0x0e;
|
||||
case 'f': return 0x0f;
|
||||
}
|
||||
return (byte)0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array of bytes back to its constituent object. The
|
||||
* input array is assumed to have been created from the original object.
|
||||
*
|
||||
* @param bytes the byte array to convert.
|
||||
* @return the associated object.
|
||||
*/
|
||||
public static Object toObject(byte[] bytes) throws Exception{
|
||||
Object object = null;
|
||||
|
||||
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
|
||||
object = ois.readObject();
|
||||
ois.close();
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array of bytes back to its constituent object. The
|
||||
* input array is assumed to have been created from the original object.
|
||||
*
|
||||
* @param bytes the byte array to convert.
|
||||
* @return the associated object.
|
||||
*/
|
||||
public static Object toObject(DynamicByteArrayStream bytes) throws Exception{
|
||||
Object object = null;
|
||||
|
||||
ObjectInputStream ois = new ObjectInputStream(bytes);
|
||||
object = ois.readObject();
|
||||
ois.close();
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
/** array needed for byteToHex */
|
||||
private static char[] HEX_CHARS = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
|
||||
/**
|
||||
* Converts a byte Array to a Hex String
|
||||
*
|
||||
* @param raw the byte array to convert
|
||||
* @return a hex String
|
||||
*/
|
||||
public static String toHexString(byte[][] raw){
|
||||
StringBuffer ret = new StringBuffer();
|
||||
|
||||
for(byte[] a : raw){
|
||||
for(byte b : a){
|
||||
ret.append(HEX_CHARS[(int) (b >>> 0x04)& 0x0F ]);
|
||||
ret.append(HEX_CHARS[(int) b & 0x0F ]);
|
||||
}
|
||||
}
|
||||
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
public static String toHexStringByColumn(byte[][] raw){
|
||||
StringBuffer ret = new StringBuffer();
|
||||
|
||||
for(int col=0; col<raw[0].length ;col++){
|
||||
for(int row=0; row<raw.length ;row++){
|
||||
ret.append(HEX_CHARS[(int) (raw[row][col] >>> 0x04)& 0x0F ]);
|
||||
ret.append(HEX_CHARS[(int) raw[row][col] & 0x0F ]);
|
||||
}
|
||||
}
|
||||
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a byte Array to a Hex String
|
||||
*
|
||||
* @param raw the byte array to convert
|
||||
* @return a hex String
|
||||
*/
|
||||
public static String toHexString(byte[] raw){
|
||||
StringBuffer ret = new StringBuffer();
|
||||
|
||||
for(byte b : raw){
|
||||
ret.append(HEX_CHARS[(int) (b >>> 0x04)& 0x0F ]);
|
||||
ret.append(HEX_CHARS[(int) b & 0x0F ]);
|
||||
}
|
||||
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a byte to a Hex String
|
||||
*
|
||||
* @param raw the byte to convert
|
||||
* @return a hex String
|
||||
*/
|
||||
public static String toHexString(byte raw){
|
||||
String ret = ""+HEX_CHARS[(int) (raw >>> 0x04)& 0x0F ];
|
||||
ret += ""+HEX_CHARS[(int) raw & 0x0F ];
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given byte to a String with 1's and 0's
|
||||
*
|
||||
* @param raw the byte to convert
|
||||
* @return a String with 1's and 0's
|
||||
*/
|
||||
public static String toString(byte raw){
|
||||
StringBuffer ret = new StringBuffer();
|
||||
for(int i=128; i>0 ;i=( i<1 ? i=0 : i/2 ) ){
|
||||
ret.append(( (raw & i) == 0 ? '0' : '1'));
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given byte array to a String with 1's and 0's
|
||||
*
|
||||
* @param raw the byte array to convert
|
||||
* @return a String with 1's and 0's
|
||||
*/
|
||||
public static String toString(byte[] raw){
|
||||
StringBuffer ret = new StringBuffer();
|
||||
for(byte b : raw){
|
||||
for(int i=128; i>0 ;i=( i<1 ? i=0 : i/2 ) ){
|
||||
ret.append(( (b & i) == 0 ? '0' : '1'));
|
||||
}
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a comma separated string with key and value pairs
|
||||
*
|
||||
* @return a comma separated String
|
||||
*/
|
||||
public static String toString(Map map){
|
||||
StringBuilder tmp = new StringBuilder();
|
||||
tmp.append("{");
|
||||
Iterator<Object> it = map.keySet().iterator();
|
||||
while(it.hasNext()){
|
||||
Object key = it.next();
|
||||
Object value = map.get(key);
|
||||
tmp.append(key);
|
||||
if (value != null) {
|
||||
if (value instanceof String)
|
||||
tmp.append(": \"").append(value).append("\"");
|
||||
else
|
||||
tmp.append(value);
|
||||
}
|
||||
else
|
||||
tmp.append("null");
|
||||
|
||||
if(it.hasNext())
|
||||
tmp.append(", ");
|
||||
}
|
||||
tmp.append('}');
|
||||
return tmp.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a BitSet to a Integer
|
||||
*
|
||||
* @param bits the BitSet to convert
|
||||
* @return a Integer
|
||||
*/
|
||||
public static int toInt(BitSet bits){
|
||||
int ret = 0;
|
||||
|
||||
for (int i = bits.nextSetBit(0); i >= 0; i = bits.nextSetBit(i+1)) {
|
||||
ret += Math.pow(2, i);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a boolean array(bit sequence whit most significant bit at index 0) to a Integer
|
||||
*
|
||||
* @param bits the boolean array to convert
|
||||
* @return a Integer
|
||||
*/
|
||||
public static int toInt(boolean[] bits){
|
||||
int ret = 0;
|
||||
|
||||
for (int i = bits.length-1; i >= 0; i--) {
|
||||
if(bits[i])ret += Math.pow(2, bits.length-i-1);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a byte to a integer
|
||||
*
|
||||
* @param b is the byte to convert
|
||||
* @return the integer value of the byte
|
||||
*/
|
||||
public static int toInt(byte b){
|
||||
return (int)(b & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a dynamic sized byte array to a integer
|
||||
*
|
||||
* @param b is the byte array of size 1-4
|
||||
* @return the int value of the byte array
|
||||
*/
|
||||
public static int toInt(byte[] b){
|
||||
int i = 0;
|
||||
switch (b.length){
|
||||
default:
|
||||
case 4:
|
||||
i |= 0xFF000000 & (b[0] << 24);
|
||||
i |= 0x00FF0000 & (b[1] << 16);
|
||||
i |= 0x0000FF00 & (b[2] << 8);
|
||||
i |= 0x000000FF & b[3];
|
||||
break;
|
||||
case 3:
|
||||
i |= 0x00FF0000 & (b[0] << 16);
|
||||
i |= 0x0000FF00 & (b[1] << 8);
|
||||
i |= 0x000000FF & b[2];
|
||||
break;
|
||||
case 2:
|
||||
i |= 0x0000FF00 & (b[0] << 8);
|
||||
i |= 0x000000FF & b[1];
|
||||
break;
|
||||
case 1:
|
||||
i |= 0x000000FF & b[0];
|
||||
break;
|
||||
case 0: break;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Integer to a BitSet
|
||||
*
|
||||
* @param num the Integer to convert
|
||||
* @return a BitSet object
|
||||
*/
|
||||
public static BitSet toBitSet(int num){
|
||||
BitSet ret = new BitSet();
|
||||
String tmp = Integer.toBinaryString(num);
|
||||
|
||||
for(int i=0; i<tmp.length() ;i++){
|
||||
ret.set(i , tmp.charAt(tmp.length()-i-1) != '0');
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts a given String to a specified class
|
||||
*
|
||||
* @param <T> is the resulting class
|
||||
* @param data is the String data to be converted
|
||||
* @param c is the class to convert to
|
||||
* @return a instance of the class with the value in the string or null if there was an problem
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T fromString(String data, Class<T> c){
|
||||
if(data == null || data.isEmpty())
|
||||
return null;
|
||||
try{
|
||||
if( c == String.class) return (T) data;
|
||||
else if(c == Integer.class) return (T) new Integer(data);
|
||||
else if(c == int.class) return (T) new Integer(data);
|
||||
else if(c == Long.class) return (T) new Long(data);
|
||||
else if(c == long.class) return (T) new Long(data);
|
||||
else if(c == Float.class) return (T) new Float(data);
|
||||
else if(c == float.class) return (T) new Float(data);
|
||||
else if(c == Double.class) return (T) new Double(data);
|
||||
else if(c == double.class) return (T) new Double(data);
|
||||
else if(c == Boolean.class) return (T) new Boolean(data);
|
||||
else if(c == boolean.class) return (T) new Boolean(data);
|
||||
else if(c == Byte.class) return (T) new Byte(data);
|
||||
else if(c == byte.class) return (T) new Byte(data);
|
||||
else if(byte[].class.isAssignableFrom(c))
|
||||
return (T) Base64Decoder.decode(data);
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces reserved and unsafe characters in URLs with hex values
|
||||
*/
|
||||
public static String urlEncode( String str ){
|
||||
StringBuilder out = new StringBuilder();
|
||||
for( char c : str.toCharArray() ){
|
||||
if( c>='0' && c<='9' || c>='A' && c<='Z' || c>='a' && c<='z' ||
|
||||
c=='$' || c=='-' || c=='_' || c=='.' || c=='+' || c=='!' ||
|
||||
c=='*' || c=='\'' || c=='(' || c==')' || c==',' )
|
||||
out.append( c );
|
||||
else{
|
||||
out.append( '%' ).append( toHexString((byte)c) );
|
||||
}
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces hex values from a URL with the proper characters
|
||||
*/
|
||||
public static String urlDecode( String str ){
|
||||
StringBuilder out = new StringBuilder();
|
||||
char[] array = str.toCharArray();
|
||||
for( int i=0; i<array.length ;i++ ){
|
||||
char c = array[i];
|
||||
if( c == '%' && i+2<array.length ){
|
||||
out.append( (char)hexToByte( array[++i], array[++i]) );
|
||||
}
|
||||
else
|
||||
out.append( c );
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
}
|
||||
93
src/zutil/converter/ConverterTest.java
Executable file
93
src/zutil/converter/ConverterTest.java
Executable file
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.converter;
|
||||
|
||||
import org.junit.Test;
|
||||
import zutil.converter.Converter;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
public class ConverterTest {
|
||||
|
||||
@Test
|
||||
public void testHexToByte() {
|
||||
assertEquals( (byte)1, Converter.hexToByte('1') );
|
||||
assertEquals( (byte)5, Converter.hexToByte('5') );
|
||||
assertEquals( (byte)10, Converter.hexToByte('A') );
|
||||
assertEquals( (byte)10, Converter.hexToByte('a') );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHexToByte2() {
|
||||
assertEquals( 0x00, Converter.hexToByte('0','0') );
|
||||
assertEquals( 0x11, Converter.hexToByte('1','1') );
|
||||
assertEquals( 0x75, Converter.hexToByte('7','5') );
|
||||
assertEquals( 0xDA, Converter.hexToByte('D','A') & 0xFF );
|
||||
assertEquals( 0xFA, Converter.hexToByte('F','a') & 0xFF );
|
||||
assertEquals( 0xFF, Converter.hexToByte('f','f') & 0xFF );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHexStringToByte() {
|
||||
assertArrayEquals( null, Converter.hexToByte(null) );
|
||||
assertArrayEquals( new byte[]{}, Converter.hexToByte("") );
|
||||
assertArrayEquals( new byte[]{0x00}, Converter.hexToByte("0x00") );
|
||||
assertArrayEquals( new byte[]{0x00}, Converter.hexToByte("00") );
|
||||
assertArrayEquals(new byte[]{0x07,0x06,0x05,0x04,0x03,0x02,0x01},
|
||||
Converter.hexToByte("01020304050607") );
|
||||
assertArrayEquals( new byte[]{0x11,0x0F}, Converter.hexToByte("F11") );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUrlEncode() {
|
||||
assertEquals( "fas8dg7%20a0d1%2313f9g8d7%200h9a%25h0",
|
||||
Converter.urlEncode("fas8dg7 a0d1#13f9g8d7 0h9a%h0") );
|
||||
assertEquals( "9i34%202y9252%25%2623%20463765(%2f%26(",
|
||||
Converter.urlEncode("9i34 2y9252%&23 463765(/&(") );
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUrlDecode() {
|
||||
assertEquals( "fas8dg7 a0d1#13f9g8d7 0h9a%h0",
|
||||
Converter.urlDecode("fas8dg7%20a0d1%2313f9g8d7%200h9a%25h0") );
|
||||
assertEquals( "9i34 2y9252%&23 463765(/&(",
|
||||
Converter.urlDecode("9i34%202y9252%25%2623%20463765(%2f%26(") );
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void byteArrayToInt(){
|
||||
assertEquals(0, Converter.toInt(new byte[]{}));
|
||||
assertEquals(1, Converter.toInt(new byte[]{0b0000_0001}));
|
||||
assertEquals(1, Converter.toInt(new byte[]{0x00,0x01}));
|
||||
assertEquals(256, Converter.toInt(new byte[]{0x00,0x01,0x00}));
|
||||
assertEquals(-1, Converter.toInt(new byte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF}));
|
||||
assertEquals(Integer.MAX_VALUE, Converter.toInt(new byte[]{(byte)0x7F,(byte)0xFF,(byte)0xFF,(byte)0xFF}));
|
||||
assertEquals(Integer.MAX_VALUE, Converter.toInt(new byte[]{(byte)0x7F,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF}));
|
||||
}
|
||||
}
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.converters;
|
||||
package zutil.converter;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
96
src/zutil/converter/NumberToWordsConverterTest.java
Executable file
96
src/zutil/converter/NumberToWordsConverterTest.java
Executable file
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.converter;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import zutil.converter.NumberToWordsConverter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class NumberToWordsConverterTest {
|
||||
|
||||
@Parameters
|
||||
public static Collection<Object[]> parameters() {
|
||||
Object[][] data = new Object[][] {
|
||||
{-77, "minus seventy seven"}
|
||||
, {-2, "minus two"}
|
||||
, {1, "one"}
|
||||
, {0, "zero"}
|
||||
, {7, "seven"}
|
||||
, {11, "eleven"}
|
||||
, {12, "twelve"}
|
||||
, {17, "seventeen"}
|
||||
, {20, "twenty"}
|
||||
, {21, "twenty one"}
|
||||
, {23, "twenty three"}
|
||||
, {25, "twenty five"}
|
||||
, {30, "thirty"}
|
||||
, {34, "thirty four"}
|
||||
, {50, "fifty"}
|
||||
, {70, "seventy"}
|
||||
, {100, "one hundred"}
|
||||
, {110, "one hundred ten"}
|
||||
, {131, "one hundred thirty one"}
|
||||
, {222, "two hundred twenty two"}
|
||||
, {1000, "one thousand"}
|
||||
, {10_000, "ten thousand"}
|
||||
, {100_000, "one hundred thousand"}
|
||||
, {1000_000, "one million"}
|
||||
, {10_000_000, "ten million"}
|
||||
, {Integer.MAX_VALUE, "two billion one hundred forty seven million four hundred eighty three thousand six hundred forty seven"}
|
||||
, {Integer.MIN_VALUE, "minus two billion one hundred forty seven million four hundred eighty three thousand six hundred forty eight"}
|
||||
};
|
||||
return Arrays.asList(data);
|
||||
}
|
||||
|
||||
|
||||
private int input;
|
||||
private String expected;
|
||||
|
||||
|
||||
public NumberToWordsConverterTest(int input, String expected) {
|
||||
this.input = input;
|
||||
this.expected = expected;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert() {
|
||||
assertThat(new NumberToWordsConverter().convert(input)
|
||||
, is(equalTo(expected)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
144
src/zutil/converters/WGS84Converter.java → src/zutil/converter/WGS84Converter.java
Normal file → Executable file
144
src/zutil/converters/WGS84Converter.java → src/zutil/converter/WGS84Converter.java
Normal file → Executable file
|
|
@ -1,72 +1,72 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.converters;
|
||||
|
||||
public class WGS84Converter {
|
||||
public static void main(String[] args){
|
||||
System.out.println(toWGS84Decimal("N 59<35> 47' 43\"")+" "+toWGS84Decimal(" E 17<31> 42' 55\""));
|
||||
System.out.println(toWGS84Decimal("55<EFBFBD> 0' 0\"")+" "+toWGS84Decimal("68<EFBFBD> 59' 59,999\""));
|
||||
System.out.println(toWGS84Decimal("55<EFBFBD> 0.001'")+" "+toWGS84Decimal("68<EFBFBD> 59.999'"));
|
||||
System.out.println(toWGS84Decimal("3444.0000S")+" "+toWGS84Decimal("13521.0000E"));
|
||||
System.out.println(toWGS84Decimal("-44.0001")+" "+toWGS84Decimal("521.0001"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an WGS84 coordinate to an WGS84 decimal coordinate
|
||||
*
|
||||
* @param coordinate is the coordinate to convert
|
||||
* @return the new coordinate in decimal degrees, returns 0 if conversions fails
|
||||
*/
|
||||
public static float toWGS84Decimal(String coordinate){
|
||||
float deg=0, min=0, sec=0, neg=1;
|
||||
coordinate = coordinate.trim().replaceAll(",", ".").toUpperCase();
|
||||
if(coordinate.contains("S") || coordinate.contains("W"))
|
||||
neg = -1;
|
||||
|
||||
// 55<EFBFBD> 0' 68<EFBFBD> 59,999 or 55<EFBFBD> 0' 0" 68<36> 59' 59,999"
|
||||
if(coordinate.matches("[NSWE ]? ?[0-9]{1,3}<7D> [0-9]{1,2}.?[0-9]*'[ 0-9.\\\"]*")){
|
||||
coordinate = coordinate.replaceAll("[NSEW<45>'\\\"]", "").trim();
|
||||
String[] tmp = coordinate.split(" ");
|
||||
deg = Float.parseFloat(tmp[0]);
|
||||
min = Float.parseFloat(tmp[1]);
|
||||
if(tmp.length > 2){
|
||||
sec = Float.parseFloat(tmp[2]);
|
||||
}
|
||||
}
|
||||
// 3444.0000S 13521.0000E
|
||||
else if(coordinate.matches("[0-9]{4,5}.[0-9]*[NSEW]{1}")){
|
||||
coordinate = coordinate.replaceAll("[NS EW]", "");
|
||||
float tmpf = Float.parseFloat(coordinate);
|
||||
deg = (int)(tmpf/100);
|
||||
min = tmpf-(deg*100);
|
||||
}
|
||||
// 55.0 68.99999
|
||||
else if(coordinate.matches("\\-?[0-9]{2,3}.[0-9]*")){
|
||||
return Float.parseFloat(coordinate);
|
||||
}
|
||||
|
||||
return neg*(deg + min/60 + sec/3600);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.converter;
|
||||
|
||||
public class WGS84Converter {
|
||||
public static void main(String[] args){
|
||||
System.out.println(toWGS84Decimal("N 59<35> 47' 43\"")+" "+toWGS84Decimal(" E 17<31> 42' 55\""));
|
||||
System.out.println(toWGS84Decimal("55<EFBFBD> 0' 0\"")+" "+toWGS84Decimal("68<EFBFBD> 59' 59,999\""));
|
||||
System.out.println(toWGS84Decimal("55<EFBFBD> 0.001'")+" "+toWGS84Decimal("68<EFBFBD> 59.999'"));
|
||||
System.out.println(toWGS84Decimal("3444.0000S")+" "+toWGS84Decimal("13521.0000E"));
|
||||
System.out.println(toWGS84Decimal("-44.0001")+" "+toWGS84Decimal("521.0001"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an WGS84 coordinate to an WGS84 decimal coordinate
|
||||
*
|
||||
* @param coordinate is the coordinate to convert
|
||||
* @return the new coordinate in decimal degrees, returns 0 if conversions fails
|
||||
*/
|
||||
public static float toWGS84Decimal(String coordinate){
|
||||
float deg=0, min=0, sec=0, neg=1;
|
||||
coordinate = coordinate.trim().replaceAll(",", ".").toUpperCase();
|
||||
if(coordinate.contains("S") || coordinate.contains("W"))
|
||||
neg = -1;
|
||||
|
||||
// 55<EFBFBD> 0' 68<EFBFBD> 59,999 or 55<EFBFBD> 0' 0" 68<36> 59' 59,999"
|
||||
if(coordinate.matches("[NSWE ]? ?[0-9]{1,3}<7D> [0-9]{1,2}.?[0-9]*'[ 0-9.\\\"]*")){
|
||||
coordinate = coordinate.replaceAll("[NSEW<45>'\\\"]", "").trim();
|
||||
String[] tmp = coordinate.split(" ");
|
||||
deg = Float.parseFloat(tmp[0]);
|
||||
min = Float.parseFloat(tmp[1]);
|
||||
if(tmp.length > 2){
|
||||
sec = Float.parseFloat(tmp[2]);
|
||||
}
|
||||
}
|
||||
// 3444.0000S 13521.0000E
|
||||
else if(coordinate.matches("[0-9]{4,5}.[0-9]*[NSEW]{1}")){
|
||||
coordinate = coordinate.replaceAll("[NS EW]", "");
|
||||
float tmpf = Float.parseFloat(coordinate);
|
||||
deg = (int)(tmpf/100);
|
||||
min = tmpf-(deg*100);
|
||||
}
|
||||
// 55.0 68.99999
|
||||
else if(coordinate.matches("\\-?[0-9]{2,3}.[0-9]*")){
|
||||
return Float.parseFloat(coordinate);
|
||||
}
|
||||
|
||||
return neg*(deg + min/60 + sec/3600);
|
||||
}
|
||||
}
|
||||
2
src/zutil/db/DBQueue.java
Normal file → Executable file
2
src/zutil/db/DBQueue.java
Normal file → Executable file
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
package zutil.db;
|
||||
|
||||
import zutil.converters.Converter;
|
||||
import zutil.converter.Converter;
|
||||
import zutil.io.MultiPrintStream;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
|
|
|
|||
234
src/zutil/image/filters/BlurFilter.java → src/zutil/image/filter/BlurFilter.java
Normal file → Executable file
234
src/zutil/image/filters/BlurFilter.java → src/zutil/image/filter/BlurFilter.java
Normal file → Executable file
|
|
@ -1,117 +1,117 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filters;
|
||||
|
||||
import zutil.image.ImageFilterProcessor;
|
||||
import zutil.image.RAWImageUtil;
|
||||
import zutil.math.ZMath;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class BlurFilter extends ImageFilterProcessor{
|
||||
private int blurValue;
|
||||
|
||||
/**
|
||||
* Creates a blur effect on the image
|
||||
* @param img The image to blur
|
||||
*/
|
||||
public BlurFilter(BufferedImage img){
|
||||
this(img, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a blur effect on the image
|
||||
* @param img The image to blur
|
||||
* @param blur The amount to blur
|
||||
*/
|
||||
public BlurFilter(BufferedImage img, int blur){
|
||||
super(img);
|
||||
blurValue = blur;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[][][] process(int[][][] data, int startX, int startY, int stopX, int stopY) {
|
||||
int inputPeak = RAWImageUtil.getPeakValue(data);
|
||||
|
||||
int[][][] tmpData = new int[data.length][data[0].length][4];
|
||||
int[][][] output = RAWImageUtil.copyArray(data);
|
||||
//Perform the convolution one or more times in succession
|
||||
int redSum, greenSum, blueSum, outputPeak;
|
||||
for(int i=0; i<blurValue ;i++){
|
||||
//Iterate on each pixel as a registration point.
|
||||
for(int y=startY; y<stopY ;y++){
|
||||
setProgress(ZMath.percent(0, (blurValue-1)*(stopY-startY-2), i*(stopY-startY-2)+y));
|
||||
for(int x=startX; x<stopX ;x++){
|
||||
if(x == 0 || x == output[0].length-1 || y == 0 || y == output.length-1){
|
||||
redSum = output[y][x][1] * 9;
|
||||
greenSum = output[y][x][2] * 9;
|
||||
blueSum = output[y][x][3] * 9;
|
||||
}
|
||||
else{
|
||||
redSum =
|
||||
output[y - 1][x - 1][1] +
|
||||
output[y - 1][x - 0][1] +
|
||||
output[y - 1][x + 1][1] +
|
||||
output[y - 0][x - 1][1] +
|
||||
output[y - 0][x - 0][1] +
|
||||
output[y - 0][x + 1][1] +
|
||||
output[y + 1][x - 1][1] +
|
||||
output[y + 1][x - 0][1] +
|
||||
output[y + 1][x + 1][1];
|
||||
greenSum =
|
||||
output[y - 1][x - 1][2] +
|
||||
output[y - 1][x - 0][2] +
|
||||
output[y - 1][x + 1][2] +
|
||||
output[y - 0][x - 1][2] +
|
||||
output[y - 0][x - 0][2] +
|
||||
output[y - 0][x + 1][2] +
|
||||
output[y + 1][x - 1][2] +
|
||||
output[y + 1][x - 0][2] +
|
||||
output[y + 1][x + 1][2];
|
||||
blueSum =
|
||||
output[y - 1][x - 1][3] +
|
||||
output[y - 1][x - 0][3] +
|
||||
output[y - 1][x + 1][3] +
|
||||
output[y - 0][x - 1][3] +
|
||||
output[y - 0][x - 0][3] +
|
||||
output[y - 0][x + 1][3] +
|
||||
output[y + 1][x - 1][3] +
|
||||
output[y + 1][x - 0][3] +
|
||||
output[y + 1][x + 1][3];
|
||||
}
|
||||
tmpData[y][x][0] = output[y][x][0];
|
||||
tmpData[y][x][1] = redSum;
|
||||
tmpData[y][x][2] = greenSum;
|
||||
tmpData[y][x][3] = blueSum;
|
||||
}
|
||||
}
|
||||
|
||||
// getting the new peak value and normalizing the image
|
||||
outputPeak = RAWImageUtil.getPeakValue(tmpData);
|
||||
RAWImageUtil.normalize(output, tmpData, startX, startY, stopX, stopY, ((double)inputPeak)/outputPeak );
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filter;
|
||||
|
||||
import zutil.image.ImageFilterProcessor;
|
||||
import zutil.image.RAWImageUtil;
|
||||
import zutil.math.ZMath;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class BlurFilter extends ImageFilterProcessor{
|
||||
private int blurValue;
|
||||
|
||||
/**
|
||||
* Creates a blur effect on the image
|
||||
* @param img The image to blur
|
||||
*/
|
||||
public BlurFilter(BufferedImage img){
|
||||
this(img, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a blur effect on the image
|
||||
* @param img The image to blur
|
||||
* @param blur The amount to blur
|
||||
*/
|
||||
public BlurFilter(BufferedImage img, int blur){
|
||||
super(img);
|
||||
blurValue = blur;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[][][] process(int[][][] data, int startX, int startY, int stopX, int stopY) {
|
||||
int inputPeak = RAWImageUtil.getPeakValue(data);
|
||||
|
||||
int[][][] tmpData = new int[data.length][data[0].length][4];
|
||||
int[][][] output = RAWImageUtil.copyArray(data);
|
||||
//Perform the convolution one or more times in succession
|
||||
int redSum, greenSum, blueSum, outputPeak;
|
||||
for(int i=0; i<blurValue ;i++){
|
||||
//Iterate on each pixel as a registration point.
|
||||
for(int y=startY; y<stopY ;y++){
|
||||
setProgress(ZMath.percent(0, (blurValue-1)*(stopY-startY-2), i*(stopY-startY-2)+y));
|
||||
for(int x=startX; x<stopX ;x++){
|
||||
if(x == 0 || x == output[0].length-1 || y == 0 || y == output.length-1){
|
||||
redSum = output[y][x][1] * 9;
|
||||
greenSum = output[y][x][2] * 9;
|
||||
blueSum = output[y][x][3] * 9;
|
||||
}
|
||||
else{
|
||||
redSum =
|
||||
output[y - 1][x - 1][1] +
|
||||
output[y - 1][x - 0][1] +
|
||||
output[y - 1][x + 1][1] +
|
||||
output[y - 0][x - 1][1] +
|
||||
output[y - 0][x - 0][1] +
|
||||
output[y - 0][x + 1][1] +
|
||||
output[y + 1][x - 1][1] +
|
||||
output[y + 1][x - 0][1] +
|
||||
output[y + 1][x + 1][1];
|
||||
greenSum =
|
||||
output[y - 1][x - 1][2] +
|
||||
output[y - 1][x - 0][2] +
|
||||
output[y - 1][x + 1][2] +
|
||||
output[y - 0][x - 1][2] +
|
||||
output[y - 0][x - 0][2] +
|
||||
output[y - 0][x + 1][2] +
|
||||
output[y + 1][x - 1][2] +
|
||||
output[y + 1][x - 0][2] +
|
||||
output[y + 1][x + 1][2];
|
||||
blueSum =
|
||||
output[y - 1][x - 1][3] +
|
||||
output[y - 1][x - 0][3] +
|
||||
output[y - 1][x + 1][3] +
|
||||
output[y - 0][x - 1][3] +
|
||||
output[y - 0][x - 0][3] +
|
||||
output[y - 0][x + 1][3] +
|
||||
output[y + 1][x - 1][3] +
|
||||
output[y + 1][x - 0][3] +
|
||||
output[y + 1][x + 1][3];
|
||||
}
|
||||
tmpData[y][x][0] = output[y][x][0];
|
||||
tmpData[y][x][1] = redSum;
|
||||
tmpData[y][x][2] = greenSum;
|
||||
tmpData[y][x][3] = blueSum;
|
||||
}
|
||||
}
|
||||
|
||||
// getting the new peak value and normalizing the image
|
||||
outputPeak = RAWImageUtil.getPeakValue(tmpData);
|
||||
RAWImageUtil.normalize(output, tmpData, startX, startY, stopX, stopY, ((double)inputPeak)/outputPeak );
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
226
src/zutil/image/filters/ColorIntensityFilter.java → src/zutil/image/filter/ColorIntensityFilter.java
Normal file → Executable file
226
src/zutil/image/filters/ColorIntensityFilter.java → src/zutil/image/filter/ColorIntensityFilter.java
Normal file → Executable file
|
|
@ -1,113 +1,113 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filters;
|
||||
|
||||
import zutil.image.ImageFilterProcessor;
|
||||
import zutil.math.ZMath;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class ColorIntensityFilter extends ImageFilterProcessor{
|
||||
private boolean invert;
|
||||
private double redScale;
|
||||
private double greenScale;
|
||||
private double blueScale;
|
||||
|
||||
public ColorIntensityFilter(BufferedImage img){
|
||||
this(img, 0.2, 0.2, 0.2, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ColorIntensityEffect object with the given values
|
||||
* @param img The image data
|
||||
* @param inv If the image color should be inverted
|
||||
*/
|
||||
public ColorIntensityFilter(BufferedImage img, boolean inv){
|
||||
this(img, 0.5, 0.5, 0.5, inv);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ColorIntensityEffect object with the given values
|
||||
* @param img The image data
|
||||
* @param red The scale of red (0-1)
|
||||
* @param green The scale of green (0-1)
|
||||
* @param blue The scale of blue (0-1)
|
||||
*/
|
||||
public ColorIntensityFilter(BufferedImage img, double red, double green, double blue){
|
||||
this(img, red, green, blue, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ColorIntensityEffect object with the given values
|
||||
* @param img The image data
|
||||
* @param red The scale of red (0-1)
|
||||
* @param green The scale of green (0-1)
|
||||
* @param blue The scale of blue (0-1)
|
||||
* @param inv If the image color should be inverted
|
||||
*/
|
||||
public ColorIntensityFilter(BufferedImage img, double red, double green, double blue, boolean inv){
|
||||
super(img);
|
||||
invert = false;
|
||||
redScale = red;
|
||||
greenScale = green;
|
||||
blueScale = blue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[][][] process(int[][][] data, int startX, int startY, int stopX, int stopY) {
|
||||
int[][][] output = new int[data.length][data[0].length][4];
|
||||
// making sure the scales are right
|
||||
if(redScale > 1) redScale = 1;
|
||||
else if(redScale < 0) redScale = 0;
|
||||
|
||||
if(greenScale > 1) greenScale = 1;
|
||||
else if(greenScale < 0) greenScale = 0;
|
||||
|
||||
if(blueScale > 1) blueScale = 1;
|
||||
else if(blueScale < 0) blueScale = 0;
|
||||
|
||||
// Applying the color intensity to the image
|
||||
for(int y=startY; y<stopY ;y++){
|
||||
setProgress(ZMath.percent(0, stopY-startY-1, y));
|
||||
for(int x=startX; x<stopX ;x++){
|
||||
if(!invert){
|
||||
// inversion
|
||||
output[y][x][0] = data[y][x][0];
|
||||
output[y][x][1] = (int)( 255 - data[y][x][1] * redScale );
|
||||
output[y][x][2] = (int)( 255 - data[y][x][2] * greenScale );
|
||||
output[y][x][3] = (int)( 255 - data[y][x][3] * blueScale );
|
||||
}
|
||||
else{
|
||||
output[y][x][0] = data[y][x][0];
|
||||
output[y][x][1] = (int)( data[y][x][1] * redScale );
|
||||
output[y][x][2] = (int)( data[y][x][2] * greenScale );
|
||||
output[y][x][3] = (int)( data[y][x][3] * blueScale );
|
||||
}
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filter;
|
||||
|
||||
import zutil.image.ImageFilterProcessor;
|
||||
import zutil.math.ZMath;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class ColorIntensityFilter extends ImageFilterProcessor{
|
||||
private boolean invert;
|
||||
private double redScale;
|
||||
private double greenScale;
|
||||
private double blueScale;
|
||||
|
||||
public ColorIntensityFilter(BufferedImage img){
|
||||
this(img, 0.2, 0.2, 0.2, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ColorIntensityEffect object with the given values
|
||||
* @param img The image data
|
||||
* @param inv If the image color should be inverted
|
||||
*/
|
||||
public ColorIntensityFilter(BufferedImage img, boolean inv){
|
||||
this(img, 0.5, 0.5, 0.5, inv);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ColorIntensityEffect object with the given values
|
||||
* @param img The image data
|
||||
* @param red The scale of red (0-1)
|
||||
* @param green The scale of green (0-1)
|
||||
* @param blue The scale of blue (0-1)
|
||||
*/
|
||||
public ColorIntensityFilter(BufferedImage img, double red, double green, double blue){
|
||||
this(img, red, green, blue, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ColorIntensityEffect object with the given values
|
||||
* @param img The image data
|
||||
* @param red The scale of red (0-1)
|
||||
* @param green The scale of green (0-1)
|
||||
* @param blue The scale of blue (0-1)
|
||||
* @param inv If the image color should be inverted
|
||||
*/
|
||||
public ColorIntensityFilter(BufferedImage img, double red, double green, double blue, boolean inv){
|
||||
super(img);
|
||||
invert = false;
|
||||
redScale = red;
|
||||
greenScale = green;
|
||||
blueScale = blue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[][][] process(int[][][] data, int startX, int startY, int stopX, int stopY) {
|
||||
int[][][] output = new int[data.length][data[0].length][4];
|
||||
// making sure the scales are right
|
||||
if(redScale > 1) redScale = 1;
|
||||
else if(redScale < 0) redScale = 0;
|
||||
|
||||
if(greenScale > 1) greenScale = 1;
|
||||
else if(greenScale < 0) greenScale = 0;
|
||||
|
||||
if(blueScale > 1) blueScale = 1;
|
||||
else if(blueScale < 0) blueScale = 0;
|
||||
|
||||
// Applying the color intensity to the image
|
||||
for(int y=startY; y<stopY ;y++){
|
||||
setProgress(ZMath.percent(0, stopY-startY-1, y));
|
||||
for(int x=startX; x<stopX ;x++){
|
||||
if(!invert){
|
||||
// inversion
|
||||
output[y][x][0] = data[y][x][0];
|
||||
output[y][x][1] = (int)( 255 - data[y][x][1] * redScale );
|
||||
output[y][x][2] = (int)( 255 - data[y][x][2] * greenScale );
|
||||
output[y][x][3] = (int)( 255 - data[y][x][3] * blueScale );
|
||||
}
|
||||
else{
|
||||
output[y][x][0] = data[y][x][0];
|
||||
output[y][x][1] = (int)( data[y][x][1] * redScale );
|
||||
output[y][x][2] = (int)( data[y][x][2] * greenScale );
|
||||
output[y][x][3] = (int)( data[y][x][3] * blueScale );
|
||||
}
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
142
src/zutil/image/filters/ContrastBrightnessFilter.java → src/zutil/image/filter/ContrastBrightnessFilter.java
Normal file → Executable file
142
src/zutil/image/filters/ContrastBrightnessFilter.java → src/zutil/image/filter/ContrastBrightnessFilter.java
Normal file → Executable file
|
|
@ -1,71 +1,71 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filters;
|
||||
|
||||
import zutil.image.ImageFilterProcessor;
|
||||
import zutil.image.RAWImageUtil;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class ContrastBrightnessFilter extends ImageFilterProcessor{
|
||||
private double contrast;
|
||||
private double brightness;
|
||||
|
||||
/**
|
||||
* Creates a ContrastBrightnessEffect object with the given values
|
||||
* @param img The image to apply the effect to
|
||||
*/
|
||||
public ContrastBrightnessFilter(BufferedImage img){
|
||||
this(img, 3, 1.2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ContrastBrightnessEffect object with the given values
|
||||
* @param img The image to apply the effect to
|
||||
* @param con The contrast to apply
|
||||
* @param brig The brightness to apply
|
||||
*/
|
||||
public ContrastBrightnessFilter(BufferedImage img, double con, double brig){
|
||||
super(img);
|
||||
contrast = con;
|
||||
brightness = brig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[][][] process(int[][][] data, int startX, int startY, int stopX, int stopY) {
|
||||
int mean = RAWImageUtil.getMeanValue(data);
|
||||
|
||||
int[][][] output = RAWImageUtil.copyArray(data);
|
||||
|
||||
RAWImageUtil.addMeanValue(output, startX, startY, stopX, stopY, mean*(-1));
|
||||
RAWImageUtil.scale(output, startX, startY, stopX, stopY, contrast);
|
||||
RAWImageUtil.addMeanValue(output, startX, startY, stopX, stopY, (int)(brightness*mean));
|
||||
|
||||
RAWImageUtil.clip(output, startX, startY, stopX, stopY);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filter;
|
||||
|
||||
import zutil.image.ImageFilterProcessor;
|
||||
import zutil.image.RAWImageUtil;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class ContrastBrightnessFilter extends ImageFilterProcessor{
|
||||
private double contrast;
|
||||
private double brightness;
|
||||
|
||||
/**
|
||||
* Creates a ContrastBrightnessEffect object with the given values
|
||||
* @param img The image to apply the effect to
|
||||
*/
|
||||
public ContrastBrightnessFilter(BufferedImage img){
|
||||
this(img, 3, 1.2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ContrastBrightnessEffect object with the given values
|
||||
* @param img The image to apply the effect to
|
||||
* @param con The contrast to apply
|
||||
* @param brig The brightness to apply
|
||||
*/
|
||||
public ContrastBrightnessFilter(BufferedImage img, double con, double brig){
|
||||
super(img);
|
||||
contrast = con;
|
||||
brightness = brig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[][][] process(int[][][] data, int startX, int startY, int stopX, int stopY) {
|
||||
int mean = RAWImageUtil.getMeanValue(data);
|
||||
|
||||
int[][][] output = RAWImageUtil.copyArray(data);
|
||||
|
||||
RAWImageUtil.addMeanValue(output, startX, startY, stopX, stopY, mean*(-1));
|
||||
RAWImageUtil.scale(output, startX, startY, stopX, stopY, contrast);
|
||||
RAWImageUtil.addMeanValue(output, startX, startY, stopX, stopY, (int)(brightness*mean));
|
||||
|
||||
RAWImageUtil.clip(output, startX, startY, stopX, stopY);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
214
src/zutil/image/filters/ConvolutionFilter.java → src/zutil/image/filter/ConvolutionFilter.java
Normal file → Executable file
214
src/zutil/image/filters/ConvolutionFilter.java → src/zutil/image/filter/ConvolutionFilter.java
Normal file → Executable file
|
|
@ -1,107 +1,107 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filters;
|
||||
|
||||
import zutil.image.ImageFilterProcessor;
|
||||
import zutil.image.RAWImageUtil;
|
||||
import zutil.math.ZMath;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* Applies an Convolution kernel to the specified image
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
public class ConvolutionFilter extends ImageFilterProcessor{
|
||||
private double[][] kernel;
|
||||
|
||||
protected ConvolutionFilter(BufferedImage img) {
|
||||
super(img);
|
||||
}
|
||||
|
||||
public ConvolutionFilter(double[][] kernel) {
|
||||
this(null, kernel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies an Convolution kernel to the specified image
|
||||
*
|
||||
* @param img is the image
|
||||
* @param kernel is the kernel to apply to the image
|
||||
*/
|
||||
public ConvolutionFilter(BufferedImage img, double[][] kernel) {
|
||||
super(img);
|
||||
this.kernel = kernel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[][][] process(int[][][] data, int startX, int startY, int stopX, int stopY) {
|
||||
if(kernel == null) this.kernel = generateKernel();
|
||||
|
||||
int[][][] tmpData = new int[data.length][data[0].length][4];
|
||||
int xk_length = kernel[0].length;
|
||||
int yk_length = kernel.length;
|
||||
|
||||
for(int y=startY; y<stopY ;y++){
|
||||
setProgress(ZMath.percent(0, (stopY-startY), y+1));
|
||||
for(int x=startX; x<stopX ;x++){
|
||||
tmpData[y][x][0] = data[y][x][0]; // alpha
|
||||
|
||||
for(int yk=0; yk<yk_length ;yk++){
|
||||
for(int xk=0; xk<xk_length ;xk++){
|
||||
if(0 <= y-yk_length/2+yk && y-yk_length/2+yk < data.length &&
|
||||
0 <= x-xk_length/2+xk && x-xk_length/2+xk < data[0].length){ // check that its not out of index
|
||||
tmpData[y][x][1] += data[y-yk_length/2+yk][x-xk_length/2+xk][1] * kernel[yk][xk];
|
||||
tmpData[y][x][2] += data[y-yk_length/2+yk][x-xk_length/2+xk][2] * kernel[yk][xk];
|
||||
tmpData[y][x][3] += data[y-yk_length/2+yk][x-xk_length/2+xk][3] * kernel[yk][xk];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RAWImageUtil.clip(tmpData, startX, startY, stopX, stopY);
|
||||
|
||||
return tmpData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the kernel or null if it has not been generated yet.
|
||||
*/
|
||||
public double[][] getKernel(){
|
||||
return kernel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should be overridden by a subclass
|
||||
*
|
||||
* @return an special generated kernel
|
||||
*/
|
||||
protected double[][] generateKernel(){
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filter;
|
||||
|
||||
import zutil.image.ImageFilterProcessor;
|
||||
import zutil.image.RAWImageUtil;
|
||||
import zutil.math.ZMath;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* Applies an Convolution kernel to the specified image
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
public class ConvolutionFilter extends ImageFilterProcessor{
|
||||
private double[][] kernel;
|
||||
|
||||
protected ConvolutionFilter(BufferedImage img) {
|
||||
super(img);
|
||||
}
|
||||
|
||||
public ConvolutionFilter(double[][] kernel) {
|
||||
this(null, kernel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies an Convolution kernel to the specified image
|
||||
*
|
||||
* @param img is the image
|
||||
* @param kernel is the kernel to apply to the image
|
||||
*/
|
||||
public ConvolutionFilter(BufferedImage img, double[][] kernel) {
|
||||
super(img);
|
||||
this.kernel = kernel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[][][] process(int[][][] data, int startX, int startY, int stopX, int stopY) {
|
||||
if(kernel == null) this.kernel = generateKernel();
|
||||
|
||||
int[][][] tmpData = new int[data.length][data[0].length][4];
|
||||
int xk_length = kernel[0].length;
|
||||
int yk_length = kernel.length;
|
||||
|
||||
for(int y=startY; y<stopY ;y++){
|
||||
setProgress(ZMath.percent(0, (stopY-startY), y+1));
|
||||
for(int x=startX; x<stopX ;x++){
|
||||
tmpData[y][x][0] = data[y][x][0]; // alpha
|
||||
|
||||
for(int yk=0; yk<yk_length ;yk++){
|
||||
for(int xk=0; xk<xk_length ;xk++){
|
||||
if(0 <= y-yk_length/2+yk && y-yk_length/2+yk < data.length &&
|
||||
0 <= x-xk_length/2+xk && x-xk_length/2+xk < data[0].length){ // check that its not out of index
|
||||
tmpData[y][x][1] += data[y-yk_length/2+yk][x-xk_length/2+xk][1] * kernel[yk][xk];
|
||||
tmpData[y][x][2] += data[y-yk_length/2+yk][x-xk_length/2+xk][2] * kernel[yk][xk];
|
||||
tmpData[y][x][3] += data[y-yk_length/2+yk][x-xk_length/2+xk][3] * kernel[yk][xk];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RAWImageUtil.clip(tmpData, startX, startY, stopX, stopY);
|
||||
|
||||
return tmpData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the kernel or null if it has not been generated yet.
|
||||
*/
|
||||
public double[][] getKernel(){
|
||||
return kernel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should be overridden by a subclass
|
||||
*
|
||||
* @return an special generated kernel
|
||||
*/
|
||||
protected double[][] generateKernel(){
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
222
src/zutil/image/filters/DitheringFilter.java → src/zutil/image/filter/DitheringFilter.java
Normal file → Executable file
222
src/zutil/image/filters/DitheringFilter.java → src/zutil/image/filter/DitheringFilter.java
Normal file → Executable file
|
|
@ -1,111 +1,111 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filters;
|
||||
|
||||
import zutil.image.ImageFilterProcessor;
|
||||
import zutil.image.RAWImageUtil;
|
||||
import zutil.math.ZMath;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
|
||||
public class DitheringFilter extends ImageFilterProcessor{
|
||||
// default palette is black and white
|
||||
private int[][] palette = {
|
||||
{255,0,0,0},
|
||||
{255,255,255,255}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Sets up a default DitheringEffect
|
||||
*/
|
||||
public DitheringFilter(BufferedImage img){
|
||||
super(img);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Dithering Effect object
|
||||
* @param img The image to apply the effect on
|
||||
* @param palette The palette to use on the image
|
||||
* int[colorCount][4]
|
||||
* 0 -> Alpha data
|
||||
* Red data
|
||||
* Green data
|
||||
* 4 -> Blue data
|
||||
*/
|
||||
public DitheringFilter(BufferedImage img, int[][] palette){
|
||||
super(img);
|
||||
this.palette = palette;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[][][] process(int[][][] data, int startX, int startY, int stopX, int stopY) {
|
||||
int error, index;
|
||||
int[] currentPixel;
|
||||
int[][][] output = RAWImageUtil.copyArray(data);
|
||||
|
||||
for(int y=startY; y<stopY ;y++){
|
||||
setProgress(ZMath.percent(0, stopY-startY-1, y));
|
||||
for(int x=startX; x<stopX ;x++){
|
||||
currentPixel = output[y][x];
|
||||
index = findNearestColor(currentPixel, palette);
|
||||
output[y][x] = palette[index];
|
||||
|
||||
for (int i = 1; i < 4; i++) {
|
||||
error = currentPixel[i] - palette[index][i];
|
||||
if (x + 1 < output[0].length) {
|
||||
output[y+0][x+1][i] = RAWImageUtil.clip( output[y+0][x+1][i] + (error*7)/16 );
|
||||
}
|
||||
if (y + 1 < data.length) {
|
||||
if (x - 1 > 0)
|
||||
output[y+1][x-1][i] = RAWImageUtil.clip( output[y+1][x-1][i] + (error*3)/16 );
|
||||
output[y+1][x+0][i] = RAWImageUtil.clip( output[y+1][x+0][i] + (error*5)/16 );
|
||||
if (x + 1 < data[0].length)
|
||||
output[y+1][x+1][i] = RAWImageUtil.clip( output[y+1][x+1][i] + (error*1)/16 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
private static int findNearestColor(int[] color, int[][] palette) {
|
||||
int minDistanceSquared = 255*255 + 255*255 + 255*255 + 1;
|
||||
int bestIndex = 0;
|
||||
for (byte i = 0; i < palette.length; i++) {
|
||||
int Rdiff = color[1] - palette[i][0];
|
||||
int Gdiff = color[2] - palette[i][1];
|
||||
int Bdiff = color[3] - palette[i][2];
|
||||
int distanceSquared = Rdiff*Rdiff + Gdiff*Gdiff + Bdiff*Bdiff;
|
||||
if (distanceSquared < minDistanceSquared) {
|
||||
minDistanceSquared = distanceSquared;
|
||||
bestIndex = i;
|
||||
}
|
||||
}
|
||||
return bestIndex;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filter;
|
||||
|
||||
import zutil.image.ImageFilterProcessor;
|
||||
import zutil.image.RAWImageUtil;
|
||||
import zutil.math.ZMath;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
|
||||
public class DitheringFilter extends ImageFilterProcessor{
|
||||
// default palette is black and white
|
||||
private int[][] palette = {
|
||||
{255,0,0,0},
|
||||
{255,255,255,255}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Sets up a default DitheringEffect
|
||||
*/
|
||||
public DitheringFilter(BufferedImage img){
|
||||
super(img);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Dithering Effect object
|
||||
* @param img The image to apply the effect on
|
||||
* @param palette The palette to use on the image
|
||||
* int[colorCount][4]
|
||||
* 0 -> Alpha data
|
||||
* Red data
|
||||
* Green data
|
||||
* 4 -> Blue data
|
||||
*/
|
||||
public DitheringFilter(BufferedImage img, int[][] palette){
|
||||
super(img);
|
||||
this.palette = palette;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[][][] process(int[][][] data, int startX, int startY, int stopX, int stopY) {
|
||||
int error, index;
|
||||
int[] currentPixel;
|
||||
int[][][] output = RAWImageUtil.copyArray(data);
|
||||
|
||||
for(int y=startY; y<stopY ;y++){
|
||||
setProgress(ZMath.percent(0, stopY-startY-1, y));
|
||||
for(int x=startX; x<stopX ;x++){
|
||||
currentPixel = output[y][x];
|
||||
index = findNearestColor(currentPixel, palette);
|
||||
output[y][x] = palette[index];
|
||||
|
||||
for (int i = 1; i < 4; i++) {
|
||||
error = currentPixel[i] - palette[index][i];
|
||||
if (x + 1 < output[0].length) {
|
||||
output[y+0][x+1][i] = RAWImageUtil.clip( output[y+0][x+1][i] + (error*7)/16 );
|
||||
}
|
||||
if (y + 1 < data.length) {
|
||||
if (x - 1 > 0)
|
||||
output[y+1][x-1][i] = RAWImageUtil.clip( output[y+1][x-1][i] + (error*3)/16 );
|
||||
output[y+1][x+0][i] = RAWImageUtil.clip( output[y+1][x+0][i] + (error*5)/16 );
|
||||
if (x + 1 < data[0].length)
|
||||
output[y+1][x+1][i] = RAWImageUtil.clip( output[y+1][x+1][i] + (error*1)/16 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
private static int findNearestColor(int[] color, int[][] palette) {
|
||||
int minDistanceSquared = 255*255 + 255*255 + 255*255 + 1;
|
||||
int bestIndex = 0;
|
||||
for (byte i = 0; i < palette.length; i++) {
|
||||
int Rdiff = color[1] - palette[i][0];
|
||||
int Gdiff = color[2] - palette[i][1];
|
||||
int Bdiff = color[3] - palette[i][2];
|
||||
int distanceSquared = Rdiff*Rdiff + Gdiff*Gdiff + Bdiff*Bdiff;
|
||||
if (distanceSquared < minDistanceSquared) {
|
||||
minDistanceSquared = distanceSquared;
|
||||
bestIndex = i;
|
||||
}
|
||||
}
|
||||
return bestIndex;
|
||||
}
|
||||
}
|
||||
142
src/zutil/image/filters/GaussianBlurFilter.java → src/zutil/image/filter/GaussianBlurFilter.java
Normal file → Executable file
142
src/zutil/image/filters/GaussianBlurFilter.java → src/zutil/image/filter/GaussianBlurFilter.java
Normal file → Executable file
|
|
@ -1,71 +1,71 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filters;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* Blurs an image whit the Gaussian blur algorithm
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
public class GaussianBlurFilter extends ConvolutionFilter{
|
||||
private int size;
|
||||
private double sigma;
|
||||
|
||||
public GaussianBlurFilter(BufferedImage img) {
|
||||
this(img, 5, 1.4);
|
||||
}
|
||||
|
||||
public GaussianBlurFilter(BufferedImage img, int size, double sigma) {
|
||||
super(img);
|
||||
this.size = size;
|
||||
this.sigma = sigma;
|
||||
}
|
||||
|
||||
protected double[][] generateKernel(){
|
||||
return gaussianFunction(size, size, sigma);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the kernel from the specified values
|
||||
*/
|
||||
public static double[][] gaussianFunction(int size_x, int size_y, double sigma){
|
||||
double[][] kernel;
|
||||
int center_x = size_x/2;
|
||||
int center_y = size_y/2;
|
||||
|
||||
kernel = new double[size_y][size_x];
|
||||
for(int y=0; y<size_y ;y++){
|
||||
for(int x=0; x<size_x ;x++){
|
||||
double tmp_x = (double)( (x-center_x)*(x-center_x) )/(2*sigma*sigma);
|
||||
double tmp_y = (double)( (y-center_y)*(y-center_y) )/(2*sigma*sigma);
|
||||
kernel[y][x] = 1.0/(2*Math.PI*sigma*sigma) * Math.exp( -(tmp_x + tmp_y) );
|
||||
}
|
||||
}
|
||||
|
||||
return kernel;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filter;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* Blurs an image whit the Gaussian blur algorithm
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
public class GaussianBlurFilter extends ConvolutionFilter{
|
||||
private int size;
|
||||
private double sigma;
|
||||
|
||||
public GaussianBlurFilter(BufferedImage img) {
|
||||
this(img, 5, 1.4);
|
||||
}
|
||||
|
||||
public GaussianBlurFilter(BufferedImage img, int size, double sigma) {
|
||||
super(img);
|
||||
this.size = size;
|
||||
this.sigma = sigma;
|
||||
}
|
||||
|
||||
protected double[][] generateKernel(){
|
||||
return gaussianFunction(size, size, sigma);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the kernel from the specified values
|
||||
*/
|
||||
public static double[][] gaussianFunction(int size_x, int size_y, double sigma){
|
||||
double[][] kernel;
|
||||
int center_x = size_x/2;
|
||||
int center_y = size_y/2;
|
||||
|
||||
kernel = new double[size_y][size_x];
|
||||
for(int y=0; y<size_y ;y++){
|
||||
for(int x=0; x<size_x ;x++){
|
||||
double tmp_x = (double)( (x-center_x)*(x-center_x) )/(2*sigma*sigma);
|
||||
double tmp_y = (double)( (y-center_y)*(y-center_y) )/(2*sigma*sigma);
|
||||
kernel[y][x] = 1.0/(2*Math.PI*sigma*sigma) * Math.exp( -(tmp_x + tmp_y) );
|
||||
}
|
||||
}
|
||||
|
||||
return kernel;
|
||||
}
|
||||
}
|
||||
138
src/zutil/image/filters/MeanBlurFilter.java → src/zutil/image/filter/MeanBlurFilter.java
Normal file → Executable file
138
src/zutil/image/filters/MeanBlurFilter.java → src/zutil/image/filter/MeanBlurFilter.java
Normal file → Executable file
|
|
@ -1,69 +1,69 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filters;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* The MedianFilter is used for noise reduction and things
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
public class MeanBlurFilter extends ConvolutionFilter{
|
||||
private int windowSize;
|
||||
|
||||
/**
|
||||
* Setup a default MedianFilter
|
||||
*
|
||||
* @param img is the image to process
|
||||
*/
|
||||
public MeanBlurFilter(BufferedImage img) {
|
||||
this(img, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup a default MedianFilter
|
||||
*
|
||||
* @param img is the image to process
|
||||
* @param pixels is the size of the window
|
||||
*/
|
||||
public MeanBlurFilter(BufferedImage img, int pixels) {
|
||||
super(img);
|
||||
this.windowSize = pixels;
|
||||
}
|
||||
|
||||
protected double[][] generateKernel(){
|
||||
double[][] kernel = new double[windowSize][windowSize];
|
||||
|
||||
double mean = 1.0/(windowSize*windowSize);
|
||||
for(int y=0; y<windowSize ;y++){
|
||||
for(int x=0; x<windowSize ;x++){
|
||||
kernel[y][x] = mean;
|
||||
}
|
||||
}
|
||||
|
||||
return kernel;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filter;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* The MedianFilter is used for noise reduction and things
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
public class MeanBlurFilter extends ConvolutionFilter{
|
||||
private int windowSize;
|
||||
|
||||
/**
|
||||
* Setup a default MedianFilter
|
||||
*
|
||||
* @param img is the image to process
|
||||
*/
|
||||
public MeanBlurFilter(BufferedImage img) {
|
||||
this(img, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup a default MedianFilter
|
||||
*
|
||||
* @param img is the image to process
|
||||
* @param pixels is the size of the window
|
||||
*/
|
||||
public MeanBlurFilter(BufferedImage img, int pixels) {
|
||||
super(img);
|
||||
this.windowSize = pixels;
|
||||
}
|
||||
|
||||
protected double[][] generateKernel(){
|
||||
double[][] kernel = new double[windowSize][windowSize];
|
||||
|
||||
double mean = 1.0/(windowSize*windowSize);
|
||||
for(int y=0; y<windowSize ;y++){
|
||||
for(int x=0; x<windowSize ;x++){
|
||||
kernel[y][x] = mean;
|
||||
}
|
||||
}
|
||||
|
||||
return kernel;
|
||||
}
|
||||
}
|
||||
388
src/zutil/image/filters/MedianFilter.java → src/zutil/image/filter/MedianFilter.java
Normal file → Executable file
388
src/zutil/image/filters/MedianFilter.java → src/zutil/image/filter/MedianFilter.java
Normal file → Executable file
|
|
@ -1,194 +1,194 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filters;
|
||||
|
||||
import zutil.algo.sort.sortable.SortableDataList;
|
||||
import zutil.image.ImageFilterProcessor;
|
||||
import zutil.image.RAWImageUtil;
|
||||
import zutil.math.ZMath;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* The MedianFilter is used for noise reduction and things
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
public class MedianFilter extends ImageFilterProcessor{
|
||||
private int windowSize;
|
||||
private boolean[] channels;
|
||||
|
||||
/**
|
||||
* Setup a default MedianFilter
|
||||
*
|
||||
* @param img The image to process
|
||||
*/
|
||||
public MedianFilter(BufferedImage img) {
|
||||
this(img, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup a default MedianFilter
|
||||
*
|
||||
* @param img The image to process
|
||||
* @param pixels The size of the window
|
||||
*/
|
||||
public MedianFilter(BufferedImage img, int pixels) {
|
||||
this(img, pixels, new boolean[]{true,true,true,true});
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup a default MedianFilter
|
||||
*
|
||||
* @param img The image to process
|
||||
* @param pixels The size of the window
|
||||
* @param channels Is a 4 element array for witch channels to use the filter on
|
||||
*/
|
||||
public MedianFilter(BufferedImage img, int pixels, boolean[] channels) {
|
||||
super(img);
|
||||
this.windowSize = pixels;
|
||||
this.channels = channels;
|
||||
}
|
||||
|
||||
/*
|
||||
edgex := (window width / 2) rounded down
|
||||
edgey := (window height / 2) rounded down
|
||||
for x from edgex to image width - edgex:
|
||||
for y from edgey to image height - edgey:
|
||||
colorArray[window width][window height];
|
||||
for fx from 0 to window width:
|
||||
for fy from 0 to window height:
|
||||
colorArray[fx][fy] := pixelvalue[x + fx - edgex][y + fy - edgey]
|
||||
Sort colorArray[][];
|
||||
pixelValue[x][y] := colorArray[window width / 2][window height / 2];
|
||||
*/
|
||||
@Override
|
||||
public int[][][] process(int[][][] data, int startX, int startY, int stopX, int stopY) {
|
||||
int[][][] tmpData = RAWImageUtil.copyArray(data);
|
||||
|
||||
int edgeX = windowSize / 2;
|
||||
int edgeY = windowSize / 2;
|
||||
|
||||
int[][] tmpArray = new int[4][256*2];
|
||||
int pixelCount = 0;
|
||||
for(int y=startY; y<stopY ;y++){
|
||||
setProgress(ZMath.percent(0, stopY-startY-1, y));
|
||||
for(int x=startX; x<stopX ;x++){
|
||||
|
||||
pixelCount = 0;
|
||||
for(int fy=0; fy<windowSize ;fy++){
|
||||
for(int fx=0; fx<windowSize ;fx++){
|
||||
if(y+fy-edgeY >= 0 && y+fy-edgeY < data.length && x+fx-edgeX >= 0 && x+fx-edgeX < data[0].length){
|
||||
//colorArray[fx][fy] := pixelvalue[x + fx - edgex][y + fy - edgey]
|
||||
if(channels[0]) tmpArray[0][ getMedianIndex( tmpData[y + fy - edgeY][x + fx - edgeX][0] ) ]++;
|
||||
if(channels[1]) tmpArray[1][ getMedianIndex( tmpData[y + fy - edgeY][x + fx - edgeX][1] ) ]++;
|
||||
if(channels[2]) tmpArray[2][ getMedianIndex( tmpData[y + fy - edgeY][x + fx - edgeX][2] ) ]++;
|
||||
if(channels[3]) tmpArray[3][ getMedianIndex( tmpData[y + fy - edgeY][x + fx - edgeX][3] ) ]++;
|
||||
pixelCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(channels[0]) tmpData[y][x][0] = findMedian(tmpArray[0], pixelCount/2);
|
||||
if(channels[1]) tmpData[y][x][1] = findMedian(tmpArray[1], pixelCount/2);
|
||||
if(channels[2]) tmpData[y][x][2] = findMedian(tmpArray[2], pixelCount/2);
|
||||
if(channels[3]) tmpData[y][x][3] = findMedian(tmpArray[3], pixelCount/2);
|
||||
}
|
||||
}
|
||||
|
||||
return tmpData;
|
||||
}
|
||||
|
||||
private int getMedianIndex(int i){
|
||||
if(i < 0) return Math.abs(i);
|
||||
else return i+256;
|
||||
}
|
||||
|
||||
private int findMedian(int[] median, int medianCount){
|
||||
int sum = 0;
|
||||
int ret = 0;
|
||||
for(int i=0; i<median.length ;i++){
|
||||
sum += median[i];
|
||||
median[i] = 0;
|
||||
if(sum >= medianCount && ret == 0){
|
||||
ret = i-256;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
class SortableARGB implements SortableDataList<Integer>{
|
||||
private int[][][] data;
|
||||
private int cols;
|
||||
private int rows;
|
||||
private int channel;
|
||||
|
||||
public SortableARGB(int[][][] data, int cols, int rows, int channel){
|
||||
this.data = data;
|
||||
this.cols = cols;
|
||||
this.rows = rows;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
public int compare(int a, int b) {
|
||||
return compare(a, data[ getY(b) ][ getX(b) ][ channel ]);
|
||||
}
|
||||
|
||||
public int compare(int a, Integer b) {
|
||||
return ((Integer)data[ getY(a) ][ getX(a) ][ channel ]).compareTo(b);
|
||||
}
|
||||
|
||||
public Integer get(int i) {
|
||||
return data[ getY(i) ][ getX(i) ][ channel ];
|
||||
}
|
||||
|
||||
public void set(int i, Integer o){
|
||||
data[ getY(i) ][ getX(i) ][ channel ] = o;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return cols * rows;
|
||||
}
|
||||
|
||||
public void swap(int a, int b) {
|
||||
int tmp = data[ getY(a) ][ getX(a) ][ channel ];
|
||||
data[ getY(a) ][ getX(a) ][ channel ] = data[ getY(b) ][ getX(b) ][ channel ];
|
||||
data[ getY(b) ][ getX(b) ][ channel ] = tmp;
|
||||
}
|
||||
|
||||
|
||||
private int getX(int a){
|
||||
return a % cols;
|
||||
}
|
||||
|
||||
private int getY(int a){
|
||||
return a / cols;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filter;
|
||||
|
||||
import zutil.algo.sort.sortable.SortableDataList;
|
||||
import zutil.image.ImageFilterProcessor;
|
||||
import zutil.image.RAWImageUtil;
|
||||
import zutil.math.ZMath;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* The MedianFilter is used for noise reduction and things
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
public class MedianFilter extends ImageFilterProcessor{
|
||||
private int windowSize;
|
||||
private boolean[] channels;
|
||||
|
||||
/**
|
||||
* Setup a default MedianFilter
|
||||
*
|
||||
* @param img The image to process
|
||||
*/
|
||||
public MedianFilter(BufferedImage img) {
|
||||
this(img, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup a default MedianFilter
|
||||
*
|
||||
* @param img The image to process
|
||||
* @param pixels The size of the window
|
||||
*/
|
||||
public MedianFilter(BufferedImage img, int pixels) {
|
||||
this(img, pixels, new boolean[]{true,true,true,true});
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup a default MedianFilter
|
||||
*
|
||||
* @param img The image to process
|
||||
* @param pixels The size of the window
|
||||
* @param channels Is a 4 element array for witch channels to use the filter on
|
||||
*/
|
||||
public MedianFilter(BufferedImage img, int pixels, boolean[] channels) {
|
||||
super(img);
|
||||
this.windowSize = pixels;
|
||||
this.channels = channels;
|
||||
}
|
||||
|
||||
/*
|
||||
edgex := (window width / 2) rounded down
|
||||
edgey := (window height / 2) rounded down
|
||||
for x from edgex to image width - edgex:
|
||||
for y from edgey to image height - edgey:
|
||||
colorArray[window width][window height];
|
||||
for fx from 0 to window width:
|
||||
for fy from 0 to window height:
|
||||
colorArray[fx][fy] := pixelvalue[x + fx - edgex][y + fy - edgey]
|
||||
Sort colorArray[][];
|
||||
pixelValue[x][y] := colorArray[window width / 2][window height / 2];
|
||||
*/
|
||||
@Override
|
||||
public int[][][] process(int[][][] data, int startX, int startY, int stopX, int stopY) {
|
||||
int[][][] tmpData = RAWImageUtil.copyArray(data);
|
||||
|
||||
int edgeX = windowSize / 2;
|
||||
int edgeY = windowSize / 2;
|
||||
|
||||
int[][] tmpArray = new int[4][256*2];
|
||||
int pixelCount = 0;
|
||||
for(int y=startY; y<stopY ;y++){
|
||||
setProgress(ZMath.percent(0, stopY-startY-1, y));
|
||||
for(int x=startX; x<stopX ;x++){
|
||||
|
||||
pixelCount = 0;
|
||||
for(int fy=0; fy<windowSize ;fy++){
|
||||
for(int fx=0; fx<windowSize ;fx++){
|
||||
if(y+fy-edgeY >= 0 && y+fy-edgeY < data.length && x+fx-edgeX >= 0 && x+fx-edgeX < data[0].length){
|
||||
//colorArray[fx][fy] := pixelvalue[x + fx - edgex][y + fy - edgey]
|
||||
if(channels[0]) tmpArray[0][ getMedianIndex( tmpData[y + fy - edgeY][x + fx - edgeX][0] ) ]++;
|
||||
if(channels[1]) tmpArray[1][ getMedianIndex( tmpData[y + fy - edgeY][x + fx - edgeX][1] ) ]++;
|
||||
if(channels[2]) tmpArray[2][ getMedianIndex( tmpData[y + fy - edgeY][x + fx - edgeX][2] ) ]++;
|
||||
if(channels[3]) tmpArray[3][ getMedianIndex( tmpData[y + fy - edgeY][x + fx - edgeX][3] ) ]++;
|
||||
pixelCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(channels[0]) tmpData[y][x][0] = findMedian(tmpArray[0], pixelCount/2);
|
||||
if(channels[1]) tmpData[y][x][1] = findMedian(tmpArray[1], pixelCount/2);
|
||||
if(channels[2]) tmpData[y][x][2] = findMedian(tmpArray[2], pixelCount/2);
|
||||
if(channels[3]) tmpData[y][x][3] = findMedian(tmpArray[3], pixelCount/2);
|
||||
}
|
||||
}
|
||||
|
||||
return tmpData;
|
||||
}
|
||||
|
||||
private int getMedianIndex(int i){
|
||||
if(i < 0) return Math.abs(i);
|
||||
else return i+256;
|
||||
}
|
||||
|
||||
private int findMedian(int[] median, int medianCount){
|
||||
int sum = 0;
|
||||
int ret = 0;
|
||||
for(int i=0; i<median.length ;i++){
|
||||
sum += median[i];
|
||||
median[i] = 0;
|
||||
if(sum >= medianCount && ret == 0){
|
||||
ret = i-256;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
class SortableARGB implements SortableDataList<Integer>{
|
||||
private int[][][] data;
|
||||
private int cols;
|
||||
private int rows;
|
||||
private int channel;
|
||||
|
||||
public SortableARGB(int[][][] data, int cols, int rows, int channel){
|
||||
this.data = data;
|
||||
this.cols = cols;
|
||||
this.rows = rows;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
public int compare(int a, int b) {
|
||||
return compare(a, data[ getY(b) ][ getX(b) ][ channel ]);
|
||||
}
|
||||
|
||||
public int compare(int a, Integer b) {
|
||||
return ((Integer)data[ getY(a) ][ getX(a) ][ channel ]).compareTo(b);
|
||||
}
|
||||
|
||||
public Integer get(int i) {
|
||||
return data[ getY(i) ][ getX(i) ][ channel ];
|
||||
}
|
||||
|
||||
public void set(int i, Integer o){
|
||||
data[ getY(i) ][ getX(i) ][ channel ] = o;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return cols * rows;
|
||||
}
|
||||
|
||||
public void swap(int a, int b) {
|
||||
int tmp = data[ getY(a) ][ getX(a) ][ channel ];
|
||||
data[ getY(a) ][ getX(a) ][ channel ] = data[ getY(b) ][ getX(b) ][ channel ];
|
||||
data[ getY(b) ][ getX(b) ][ channel ] = tmp;
|
||||
}
|
||||
|
||||
|
||||
private int getX(int a){
|
||||
return a % cols;
|
||||
}
|
||||
|
||||
private int getY(int a){
|
||||
return a / cols;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
174
src/zutil/image/filters/ResizeImage.java → src/zutil/image/filter/ResizeImage.java
Normal file → Executable file
174
src/zutil/image/filters/ResizeImage.java → src/zutil/image/filter/ResizeImage.java
Normal file → Executable file
|
|
@ -1,87 +1,87 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filters;
|
||||
|
||||
import zutil.image.ImageFilterProcessor;
|
||||
import zutil.math.ZMath;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class ResizeImage extends ImageFilterProcessor{
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
private int[][][] newData;
|
||||
|
||||
/**
|
||||
* Will create a ResizeImage object and fix the height with the aspect
|
||||
* of the width
|
||||
*
|
||||
* @param img The image to resize
|
||||
* @param w The new width
|
||||
*/
|
||||
public ResizeImage(BufferedImage img, int w){
|
||||
this(img, w, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will create a ResizeImage object
|
||||
*
|
||||
* @param img The image to resize
|
||||
* @param w The new width if -1 then it will be scaled whit aspect of the hight
|
||||
* @param h The new height if -1 then it will be scaled whit aspect of the width
|
||||
*/
|
||||
public ResizeImage(BufferedImage img, int w, int h){
|
||||
super(img);
|
||||
width = w;
|
||||
height = h;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[][][] process(final int[][][] data, int startX, int startY, int stopX, int stopY) {
|
||||
if(width < 1){
|
||||
height = (int)(((double)width/(stopX-startX))*(stopY-startY));
|
||||
}
|
||||
else if(height < 1){
|
||||
width = (int)(((double)height/(stopY-startY))*(stopX-startY));
|
||||
}
|
||||
|
||||
newData = new int[height][width][4];
|
||||
double xScale = ((double)(stopX-startX)/width);
|
||||
double yScale = ((double)(stopY-startY)/height);
|
||||
|
||||
for(int y=0; y<width ;y++){
|
||||
setProgress(ZMath.percent(0, width-1, y));
|
||||
for(int x=0; x<height ;x++){
|
||||
newData[y][x][0] = data[(int)(y*yScale)][(int)(x*xScale)][0];
|
||||
newData[y][x][1] = data[(int)(y*yScale)][(int)(x*xScale)][1];
|
||||
newData[y][x][2] = data[(int)(y*yScale)][(int)(x*xScale)][2];
|
||||
newData[y][x][3] = data[(int)(y*yScale)][(int)(x*xScale)][3];
|
||||
}
|
||||
}
|
||||
|
||||
return newData;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filter;
|
||||
|
||||
import zutil.image.ImageFilterProcessor;
|
||||
import zutil.math.ZMath;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class ResizeImage extends ImageFilterProcessor{
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
private int[][][] newData;
|
||||
|
||||
/**
|
||||
* Will create a ResizeImage object and fix the height with the aspect
|
||||
* of the width
|
||||
*
|
||||
* @param img The image to resize
|
||||
* @param w The new width
|
||||
*/
|
||||
public ResizeImage(BufferedImage img, int w){
|
||||
this(img, w, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will create a ResizeImage object
|
||||
*
|
||||
* @param img The image to resize
|
||||
* @param w The new width if -1 then it will be scaled whit aspect of the hight
|
||||
* @param h The new height if -1 then it will be scaled whit aspect of the width
|
||||
*/
|
||||
public ResizeImage(BufferedImage img, int w, int h){
|
||||
super(img);
|
||||
width = w;
|
||||
height = h;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[][][] process(final int[][][] data, int startX, int startY, int stopX, int stopY) {
|
||||
if(width < 1){
|
||||
height = (int)(((double)width/(stopX-startX))*(stopY-startY));
|
||||
}
|
||||
else if(height < 1){
|
||||
width = (int)(((double)height/(stopY-startY))*(stopX-startY));
|
||||
}
|
||||
|
||||
newData = new int[height][width][4];
|
||||
double xScale = ((double)(stopX-startX)/width);
|
||||
double yScale = ((double)(stopY-startY)/height);
|
||||
|
||||
for(int y=0; y<width ;y++){
|
||||
setProgress(ZMath.percent(0, width-1, y));
|
||||
for(int x=0; x<height ;x++){
|
||||
newData[y][x][0] = data[(int)(y*yScale)][(int)(x*xScale)][0];
|
||||
newData[y][x][1] = data[(int)(y*yScale)][(int)(x*xScale)][1];
|
||||
newData[y][x][2] = data[(int)(y*yScale)][(int)(x*xScale)][2];
|
||||
newData[y][x][3] = data[(int)(y*yScale)][(int)(x*xScale)][3];
|
||||
}
|
||||
}
|
||||
|
||||
return newData;
|
||||
}
|
||||
}
|
||||
176
src/zutil/image/filters/SobelEdgeDetectionFilter.java → src/zutil/image/filter/SobelEdgeDetectionFilter.java
Normal file → Executable file
176
src/zutil/image/filters/SobelEdgeDetectionFilter.java → src/zutil/image/filter/SobelEdgeDetectionFilter.java
Normal file → Executable file
|
|
@ -1,88 +1,88 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filters;
|
||||
|
||||
import zutil.image.ImageFilterProcessor;
|
||||
import zutil.math.ZMath;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* Generates an image that contains the edges of the source image
|
||||
*
|
||||
* @author Ziver
|
||||
* INFO: http://en.wikipedia.org/wiki/Sobel_operator
|
||||
*/
|
||||
public class SobelEdgeDetectionFilter extends ImageFilterProcessor{
|
||||
private static final double[][] xG_kernel = new double[][]{
|
||||
{+1, 0, -1},
|
||||
{+2, 0, -2},
|
||||
{+1, 0, -1}
|
||||
};
|
||||
private static final double[][] yG_kernel = new double[][]{
|
||||
{+1, +2, +1},
|
||||
{ 0, 0, 0},
|
||||
{-1, -2, -1}
|
||||
};
|
||||
|
||||
|
||||
public SobelEdgeDetectionFilter(BufferedImage img) {
|
||||
super(img);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[][][] process(int[][][] data, int startX, int startY, int stopX, int stopY) {
|
||||
ConvolutionFilter conv = new ConvolutionFilter(xG_kernel);
|
||||
int[][][] xG = conv.process(data, startX, startY, stopX, stopY);
|
||||
setProgress(33);
|
||||
|
||||
conv = new ConvolutionFilter(yG_kernel);
|
||||
int[][][] yG = conv.process(data, startX, startY, stopX, stopY);
|
||||
setProgress(66);
|
||||
|
||||
int[][][] output = new int[data.length][data[0].length][4];
|
||||
for(int y=startY; y<stopY ;y++){
|
||||
setProgress(66+ZMath.percent(0, (stopY-startY), y+1)/100*34);
|
||||
for(int x=startX; x<stopX ;x++){
|
||||
output[y][x][0] = data[y][x][0];
|
||||
output[y][x][1] = (int)Math.sqrt( xG[y][x][1]*xG[y][x][1] + yG[y][x][1]*yG[y][x][1] );
|
||||
output[y][x][2] = (int)Math.sqrt( xG[y][x][2]*xG[y][x][2] + yG[y][x][2]*yG[y][x][2] );
|
||||
output[y][x][3] = (int)Math.sqrt( xG[y][x][3]*xG[y][x][3] + yG[y][x][3]*yG[y][x][3] );
|
||||
/*
|
||||
output[y][x][1] = Math.abs( xG[y][x][1] ) + Math.abs(yG[y][x][1] );
|
||||
output[y][x][2] = Math.abs( xG[y][x][2] ) + Math.abs(yG[y][x][2] );
|
||||
output[y][x][3] = Math.abs( xG[y][x][3] ) + Math.abs(yG[y][x][3] );
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
// gradient's direction:
|
||||
// 0 = arctan( yG/xG )
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filter;
|
||||
|
||||
import zutil.image.ImageFilterProcessor;
|
||||
import zutil.math.ZMath;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* Generates an image that contains the edges of the source image
|
||||
*
|
||||
* @author Ziver
|
||||
* INFO: http://en.wikipedia.org/wiki/Sobel_operator
|
||||
*/
|
||||
public class SobelEdgeDetectionFilter extends ImageFilterProcessor{
|
||||
private static final double[][] xG_kernel = new double[][]{
|
||||
{+1, 0, -1},
|
||||
{+2, 0, -2},
|
||||
{+1, 0, -1}
|
||||
};
|
||||
private static final double[][] yG_kernel = new double[][]{
|
||||
{+1, +2, +1},
|
||||
{ 0, 0, 0},
|
||||
{-1, -2, -1}
|
||||
};
|
||||
|
||||
|
||||
public SobelEdgeDetectionFilter(BufferedImage img) {
|
||||
super(img);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[][][] process(int[][][] data, int startX, int startY, int stopX, int stopY) {
|
||||
ConvolutionFilter conv = new ConvolutionFilter(xG_kernel);
|
||||
int[][][] xG = conv.process(data, startX, startY, stopX, stopY);
|
||||
setProgress(33);
|
||||
|
||||
conv = new ConvolutionFilter(yG_kernel);
|
||||
int[][][] yG = conv.process(data, startX, startY, stopX, stopY);
|
||||
setProgress(66);
|
||||
|
||||
int[][][] output = new int[data.length][data[0].length][4];
|
||||
for(int y=startY; y<stopY ;y++){
|
||||
setProgress(66+ZMath.percent(0, (stopY-startY), y+1)/100*34);
|
||||
for(int x=startX; x<stopX ;x++){
|
||||
output[y][x][0] = data[y][x][0];
|
||||
output[y][x][1] = (int)Math.sqrt( xG[y][x][1]*xG[y][x][1] + yG[y][x][1]*yG[y][x][1] );
|
||||
output[y][x][2] = (int)Math.sqrt( xG[y][x][2]*xG[y][x][2] + yG[y][x][2]*yG[y][x][2] );
|
||||
output[y][x][3] = (int)Math.sqrt( xG[y][x][3]*xG[y][x][3] + yG[y][x][3]*yG[y][x][3] );
|
||||
/*
|
||||
output[y][x][1] = Math.abs( xG[y][x][1] ) + Math.abs(yG[y][x][1] );
|
||||
output[y][x][2] = Math.abs( xG[y][x][2] ) + Math.abs(yG[y][x][2] );
|
||||
output[y][x][3] = Math.abs( xG[y][x][3] ) + Math.abs(yG[y][x][3] );
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
// gradient's direction:
|
||||
// 0 = arctan( yG/xG )
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
198
src/zutil/image/filters/SpotLightFilter.java → src/zutil/image/filter/SpotLightFilter.java
Normal file → Executable file
198
src/zutil/image/filters/SpotLightFilter.java → src/zutil/image/filter/SpotLightFilter.java
Normal file → Executable file
|
|
@ -1,99 +1,99 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filters;
|
||||
|
||||
import zutil.image.ImageFilterProcessor;
|
||||
import zutil.image.RAWImageUtil;
|
||||
import zutil.math.ZMath;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class SpotLightFilter extends ImageFilterProcessor{
|
||||
private int radius;
|
||||
private int xPos;
|
||||
private int yPos;
|
||||
|
||||
/**
|
||||
* Sets up a default spotlight effect in
|
||||
* the middle of the image
|
||||
*/
|
||||
public SpotLightFilter(BufferedImage img){
|
||||
this(img, 100, -1, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up a custom spotlight
|
||||
* @param r The radius of the spotlight in pixels
|
||||
*/
|
||||
public SpotLightFilter(BufferedImage img, int r){
|
||||
this(img, r, -1, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up a custom spotlight
|
||||
* @param r The radius of the spotlight in pixels
|
||||
* @param x The x position of the spotlight, if -1 then it will be centered
|
||||
* @param y The y position of the spotlight, if -1 then it will be centered
|
||||
*/
|
||||
public SpotLightFilter(BufferedImage img, int r, int x, int y){
|
||||
super(img);
|
||||
radius = r;
|
||||
xPos = x;
|
||||
yPos = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[][][] process(int[][][] data, int startX, int startY, int stopX, int stopY) {
|
||||
if(xPos < 0) xPos = data[0].length/2;
|
||||
if(yPos < 0) yPos = data.length/2;
|
||||
|
||||
int[][][] output = new int[data.length][data[0].length][4];
|
||||
|
||||
double scale, dx, dy, distance;
|
||||
for(int y=startY; y<stopY ;y++){
|
||||
setProgress(ZMath.percent(0, (stopY-startY)-1, y));
|
||||
for(int x=startX; x<stopX ;x++){
|
||||
dx = x-xPos;
|
||||
dy = y-yPos;
|
||||
|
||||
distance = Math.sqrt(dx*dx+dy*dy);
|
||||
|
||||
if(distance > radius){
|
||||
scale = 0;
|
||||
}
|
||||
else{
|
||||
scale = 1-(distance/radius);
|
||||
}
|
||||
|
||||
output[y][x][0] = data[y][x][0];
|
||||
output[y][x][1] = RAWImageUtil.clip((int)(scale * data[y][x][1]));
|
||||
output[y][x][2] = RAWImageUtil.clip((int)(scale * data[y][x][2]));
|
||||
output[y][x][3] = RAWImageUtil.clip((int)(scale * data[y][x][3]));
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.image.filter;
|
||||
|
||||
import zutil.image.ImageFilterProcessor;
|
||||
import zutil.image.RAWImageUtil;
|
||||
import zutil.math.ZMath;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class SpotLightFilter extends ImageFilterProcessor{
|
||||
private int radius;
|
||||
private int xPos;
|
||||
private int yPos;
|
||||
|
||||
/**
|
||||
* Sets up a default spotlight effect in
|
||||
* the middle of the image
|
||||
*/
|
||||
public SpotLightFilter(BufferedImage img){
|
||||
this(img, 100, -1, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up a custom spotlight
|
||||
* @param r The radius of the spotlight in pixels
|
||||
*/
|
||||
public SpotLightFilter(BufferedImage img, int r){
|
||||
this(img, r, -1, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up a custom spotlight
|
||||
* @param r The radius of the spotlight in pixels
|
||||
* @param x The x position of the spotlight, if -1 then it will be centered
|
||||
* @param y The y position of the spotlight, if -1 then it will be centered
|
||||
*/
|
||||
public SpotLightFilter(BufferedImage img, int r, int x, int y){
|
||||
super(img);
|
||||
radius = r;
|
||||
xPos = x;
|
||||
yPos = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[][][] process(int[][][] data, int startX, int startY, int stopX, int stopY) {
|
||||
if(xPos < 0) xPos = data[0].length/2;
|
||||
if(yPos < 0) yPos = data.length/2;
|
||||
|
||||
int[][][] output = new int[data.length][data[0].length][4];
|
||||
|
||||
double scale, dx, dy, distance;
|
||||
for(int y=startY; y<stopY ;y++){
|
||||
setProgress(ZMath.percent(0, (stopY-startY)-1, y));
|
||||
for(int x=startX; x<stopX ;x++){
|
||||
dx = x-xPos;
|
||||
dy = y-yPos;
|
||||
|
||||
distance = Math.sqrt(dx*dx+dy*dy);
|
||||
|
||||
if(distance > radius){
|
||||
scale = 0;
|
||||
}
|
||||
else{
|
||||
scale = 1-(distance/radius);
|
||||
}
|
||||
|
||||
output[y][x][0] = data[y][x][0];
|
||||
output[y][x][1] = RAWImageUtil.clip((int)(scale * data[y][x][1]));
|
||||
output[y][x][2] = RAWImageUtil.clip((int)(scale * data[y][x][2]));
|
||||
output[y][x][3] = RAWImageUtil.clip((int)(scale * data[y][x][3]));
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
package zutil.net.http;
|
||||
|
||||
import zutil.converters.Converter;
|
||||
import zutil.converter.Converter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
package zutil.net.http;
|
||||
|
||||
import zutil.converters.Converter;
|
||||
import zutil.converter.Converter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.net.http.pages;
|
||||
package zutil.net.http.page;
|
||||
|
||||
import zutil.io.IOUtil;
|
||||
import zutil.io.file.FileUtil;
|
||||
2
src/zutil/net/nio/NioNetwork.java
Normal file → Executable file
2
src/zutil/net/nio/NioNetwork.java
Normal file → Executable file
|
|
@ -25,7 +25,7 @@
|
|||
package zutil.net.nio;
|
||||
|
||||
import zutil.Encrypter;
|
||||
import zutil.converters.Converter;
|
||||
import zutil.converter.Converter;
|
||||
import zutil.io.DynamicByteArrayStream;
|
||||
import zutil.io.MultiPrintStream;
|
||||
import zutil.log.LogUtil;
|
||||
|
|
|
|||
78
src/zutil/net/upnp/services/BrowseRetObj.java → src/zutil/net/upnp/service/BrowseRetObj.java
Normal file → Executable file
78
src/zutil/net/upnp/services/BrowseRetObj.java → src/zutil/net/upnp/service/BrowseRetObj.java
Normal file → Executable file
|
|
@ -1,39 +1,39 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.net.upnp.services;
|
||||
|
||||
import zutil.net.ws.WSReturnObject;
|
||||
|
||||
|
||||
public class BrowseRetObj extends WSReturnObject{
|
||||
@WSValueName("Result")
|
||||
public String Result;
|
||||
@WSValueName("NumberReturned")
|
||||
public int NumberReturned;
|
||||
@WSValueName("TotalMatches")
|
||||
public int TotalMatches;
|
||||
@WSValueName("UpdateID")
|
||||
public int UpdateID;
|
||||
}
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.net.upnp.service;
|
||||
|
||||
import zutil.net.ws.WSReturnObject;
|
||||
|
||||
|
||||
public class BrowseRetObj extends WSReturnObject{
|
||||
@WSValueName("Result")
|
||||
public String Result;
|
||||
@WSValueName("NumberReturned")
|
||||
public int NumberReturned;
|
||||
@WSValueName("TotalMatches")
|
||||
public int TotalMatches;
|
||||
@WSValueName("UpdateID")
|
||||
public int UpdateID;
|
||||
}
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.net.upnp.services;
|
||||
package zutil.net.upnp.service;
|
||||
|
||||
import org.dom4j.DocumentException;
|
||||
import zutil.io.file.FileUtil;
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
package zutil.net.ws.rest;
|
||||
|
||||
import zutil.converters.Converter;
|
||||
import zutil.converter.Converter;
|
||||
import zutil.io.StringOutputStream;
|
||||
import zutil.net.http.HttpHeader;
|
||||
import zutil.net.http.HttpPage;
|
||||
|
|
|
|||
|
|
@ -31,9 +31,9 @@ import org.dom4j.Element;
|
|||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
import org.xml.sax.SAXException;
|
||||
import zutil.converters.Converter;
|
||||
import zutil.converter.Converter;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.net.http.HttpHeader;
|
||||
import zutil.net.http.HttpHeader;
|
||||
import zutil.net.http.HttpPage;
|
||||
import zutil.net.http.HttpPrintStream;
|
||||
import zutil.net.ws.*;
|
||||
|
|
@ -113,7 +113,7 @@ public class SOAPHttpPage implements HttpPage{
|
|||
|
||||
|
||||
public void respond(HttpPrintStream out,
|
||||
HttpHeader headers,
|
||||
HttpHeader headers,
|
||||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request) {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
package zutil.parser;
|
||||
|
||||
import zutil.converters.Converter;
|
||||
import zutil.converter.Converter;
|
||||
import zutil.io.DynamicByteArrayStream;
|
||||
|
||||
public class Base64Decoder {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
package zutil.parser;
|
||||
|
||||
import zutil.converters.Converter;
|
||||
import zutil.converter.Converter;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
package zutil.parser.binary;
|
||||
|
||||
import zutil.ByteUtil;
|
||||
import zutil.converters.Converter;
|
||||
import zutil.converter.Converter;
|
||||
import zutil.parser.binary.BinaryStruct.BinaryField;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
|
|
|||
140
src/zutil/ui/wizard/pages/SummaryPage.java → src/zutil/ui/wizard/page/SummaryPage.java
Normal file → Executable file
140
src/zutil/ui/wizard/pages/SummaryPage.java → src/zutil/ui/wizard/page/SummaryPage.java
Normal file → Executable file
|
|
@ -1,70 +1,70 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.ui.wizard.pages;
|
||||
|
||||
import zutil.ui.wizard.WizardPage;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* This class will show a summary of all the values
|
||||
* in the wizard
|
||||
*
|
||||
* @author Ziver
|
||||
*
|
||||
*/
|
||||
public class SummaryPage extends WizardPage{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public SummaryPage(HashMap<String, Object> values){
|
||||
this.setFinalPage( true );
|
||||
|
||||
JTextArea summary = new JTextArea();
|
||||
summary.setEditable(false);
|
||||
summary.setEnabled(false);
|
||||
this.add( summary );
|
||||
|
||||
StringBuffer tmp = new StringBuffer();
|
||||
for(String key : values.keySet()){
|
||||
tmp.append(key);
|
||||
tmp.append(": ");
|
||||
tmp.append(values.get( key ));
|
||||
tmp.append("\n");
|
||||
}
|
||||
summary.setText( tmp.toString() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public WizardPage getNextPage(HashMap<String, Object> values) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPageDescription() {
|
||||
return "Summary";
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.ui.wizard.page;
|
||||
|
||||
import zutil.ui.wizard.WizardPage;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* This class will show a summary of all the values
|
||||
* in the wizard
|
||||
*
|
||||
* @author Ziver
|
||||
*
|
||||
*/
|
||||
public class SummaryPage extends WizardPage{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public SummaryPage(HashMap<String, Object> values){
|
||||
this.setFinalPage( true );
|
||||
|
||||
JTextArea summary = new JTextArea();
|
||||
summary.setEditable(false);
|
||||
summary.setEnabled(false);
|
||||
this.add( summary );
|
||||
|
||||
StringBuffer tmp = new StringBuffer();
|
||||
for(String key : values.keySet()){
|
||||
tmp.append(key);
|
||||
tmp.append(": ");
|
||||
tmp.append(values.get( key ));
|
||||
tmp.append("\n");
|
||||
}
|
||||
summary.setText( tmp.toString() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public WizardPage getNextPage(HashMap<String, Object> values) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPageDescription() {
|
||||
return "Summary";
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue