mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-03 03:25:28 -04:00
TMI-XXX: New code style + minor housekeeping changes.
This commit is contained in:
parent
f666610184
commit
00f47e81a4
@ -175,10 +175,6 @@ public final class ImageUtil {
|
|||||||
|
|
||||||
/** Our static image tracker */
|
/** Our static image tracker */
|
||||||
private static MediaTracker sTracker = new MediaTracker(NULL_COMPONENT);
|
private static MediaTracker sTracker = new MediaTracker(NULL_COMPONENT);
|
||||||
//private static Object sTrackerMutex = new Object();
|
|
||||||
|
|
||||||
/** Image id used by the image tracker */
|
|
||||||
//private static int sTrackerId = 0;
|
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
protected static final AffineTransform IDENTITY_TRANSFORM = new AffineTransform();
|
protected static final AffineTransform IDENTITY_TRANSFORM = new AffineTransform();
|
||||||
@ -1140,26 +1136,26 @@ public final class ImageUtil {
|
|||||||
* Sharpens an image using a convolution matrix.
|
* Sharpens an image using a convolution matrix.
|
||||||
* The sharpen kernel used, is defined by the following 3 by 3 matrix:
|
* The sharpen kernel used, is defined by the following 3 by 3 matrix:
|
||||||
* <TABLE border="1" cellspacing="0">
|
* <TABLE border="1" cellspacing="0">
|
||||||
* <TR><TD>0.0</TD><TD>-{@code pAmmount}</TD><TD>0.0</TD></TR>
|
* <TR><TD>0.0</TD><TD>-{@code pAmount}</TD><TD>0.0</TD></TR>
|
||||||
* <TR><TD>-{@code pAmmount}</TD>
|
* <TR><TD>-{@code pAmount}</TD>
|
||||||
* <TD>4.0 * {@code pAmmount} + 1.0</TD>
|
* <TD>4.0 * {@code pAmount} + 1.0</TD>
|
||||||
* <TD>-{@code pAmmount}</TD></TR>
|
* <TD>-{@code pAmount}</TD></TR>
|
||||||
* <TR><TD>0.0</TD><TD>-{@code pAmmount}</TD><TD>0.0</TD></TR>
|
* <TR><TD>0.0</TD><TD>-{@code pAmount}</TD><TD>0.0</TD></TR>
|
||||||
* </TABLE>
|
* </TABLE>
|
||||||
*
|
*
|
||||||
* @param pOriginal the BufferedImage to sharpen
|
* @param pOriginal the BufferedImage to sharpen
|
||||||
* @param pAmmount the ammount of sharpening
|
* @param pAmount the amount of sharpening
|
||||||
*
|
*
|
||||||
* @return a BufferedImage, containing the sharpened image.
|
* @return a BufferedImage, containing the sharpened image.
|
||||||
*/
|
*/
|
||||||
public static BufferedImage sharpen(BufferedImage pOriginal, float pAmmount) {
|
public static BufferedImage sharpen(BufferedImage pOriginal, float pAmount) {
|
||||||
if (pAmmount == 0f) {
|
if (pAmount == 0f) {
|
||||||
return pOriginal;
|
return pOriginal;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the convolution matrix
|
// Create the convolution matrix
|
||||||
float[] data = new float[] {
|
float[] data = new float[] {
|
||||||
0.0f, -pAmmount, 0.0f, -pAmmount, 4f * pAmmount + 1f, -pAmmount, 0.0f, -pAmmount, 0.0f
|
0.0f, -pAmount, 0.0f, -pAmount, 4f * pAmount + 1f, -pAmount, 0.0f, -pAmount, 0.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
// Do the filtering
|
// Do the filtering
|
||||||
@ -1185,7 +1181,7 @@ public final class ImageUtil {
|
|||||||
* Creates a blurred version of the given image.
|
* Creates a blurred version of the given image.
|
||||||
*
|
*
|
||||||
* @param pOriginal the original image
|
* @param pOriginal the original image
|
||||||
* @param pRadius the ammount to blur
|
* @param pRadius the amount to blur
|
||||||
*
|
*
|
||||||
* @return a new {@code BufferedImage} with a blurred version of the given image
|
* @return a new {@code BufferedImage} with a blurred version of the given image
|
||||||
*/
|
*/
|
||||||
@ -1198,18 +1194,18 @@ public final class ImageUtil {
|
|||||||
// See: http://en.wikipedia.org/wiki/Gaussian_blur#Implementation
|
// See: http://en.wikipedia.org/wiki/Gaussian_blur#Implementation
|
||||||
// Also see http://www.jhlabs.com/ip/blurring.html
|
// Also see http://www.jhlabs.com/ip/blurring.html
|
||||||
|
|
||||||
// TODO: Rethink... Fixed ammount and scale matrix instead?
|
// TODO: Rethink... Fixed amount and scale matrix instead?
|
||||||
// pAmmount = 1f - pAmmount;
|
// pAmount = 1f - pAmount;
|
||||||
// float pAmmount = 1f - pRadius;
|
// float pAmount = 1f - pRadius;
|
||||||
//
|
//
|
||||||
// // Normalize ammount
|
// // Normalize amount
|
||||||
// float normAmt = (1f - pAmmount) / 24;
|
// float normAmt = (1f - pAmount) / 24;
|
||||||
//
|
//
|
||||||
// // Create the convolution matrix
|
// // Create the convolution matrix
|
||||||
// float[] data = new float[] {
|
// float[] data = new float[] {
|
||||||
// normAmt / 2, normAmt, normAmt, normAmt, normAmt / 2,
|
// normAmt / 2, normAmt, normAmt, normAmt, normAmt / 2,
|
||||||
// normAmt, normAmt, normAmt * 2, normAmt, normAmt,
|
// normAmt, normAmt, normAmt * 2, normAmt, normAmt,
|
||||||
// normAmt, normAmt * 2, pAmmount, normAmt * 2, normAmt,
|
// normAmt, normAmt * 2, pAmount, normAmt * 2, normAmt,
|
||||||
// normAmt, normAmt, normAmt * 2, normAmt, normAmt,
|
// normAmt, normAmt, normAmt * 2, normAmt, normAmt,
|
||||||
// normAmt / 2, normAmt, normAmt, normAmt, normAmt / 2
|
// normAmt / 2, normAmt, normAmt, normAmt, normAmt / 2
|
||||||
// };
|
// };
|
||||||
@ -1391,18 +1387,18 @@ public final class ImageUtil {
|
|||||||
* Changes the contrast of the image
|
* Changes the contrast of the image
|
||||||
*
|
*
|
||||||
* @param pOriginal the {@code Image} to change
|
* @param pOriginal the {@code Image} to change
|
||||||
* @param pAmmount the ammount of contrast in the range [-1.0..1.0].
|
* @param pAmount the amount of contrast in the range [-1.0..1.0].
|
||||||
*
|
*
|
||||||
* @return an {@code Image}, containing the contrasted image.
|
* @return an {@code Image}, containing the contrasted image.
|
||||||
*/
|
*/
|
||||||
public static Image contrast(Image pOriginal, float pAmmount) {
|
public static Image contrast(Image pOriginal, float pAmount) {
|
||||||
// No change, return original
|
// No change, return original
|
||||||
if (pAmmount == 0f) {
|
if (pAmount == 0f) {
|
||||||
return pOriginal;
|
return pOriginal;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create filter
|
// Create filter
|
||||||
RGBImageFilter filter = new BrightnessContrastFilter(0f, pAmmount);
|
RGBImageFilter filter = new BrightnessContrastFilter(0f, pAmount);
|
||||||
|
|
||||||
// Return contrast adjusted image
|
// Return contrast adjusted image
|
||||||
return filter(pOriginal, filter);
|
return filter(pOriginal, filter);
|
||||||
@ -1413,18 +1409,18 @@ public final class ImageUtil {
|
|||||||
* Changes the brightness of the original image.
|
* Changes the brightness of the original image.
|
||||||
*
|
*
|
||||||
* @param pOriginal the {@code Image} to change
|
* @param pOriginal the {@code Image} to change
|
||||||
* @param pAmmount the ammount of brightness in the range [-2.0..2.0].
|
* @param pAmount the amount of brightness in the range [-2.0..2.0].
|
||||||
*
|
*
|
||||||
* @return an {@code Image}
|
* @return an {@code Image}
|
||||||
*/
|
*/
|
||||||
public static Image brightness(Image pOriginal, float pAmmount) {
|
public static Image brightness(Image pOriginal, float pAmount) {
|
||||||
// No change, return original
|
// No change, return original
|
||||||
if (pAmmount == 0f) {
|
if (pAmount == 0f) {
|
||||||
return pOriginal;
|
return pOriginal;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create filter
|
// Create filter
|
||||||
RGBImageFilter filter = new BrightnessContrastFilter(pAmmount, 0f);
|
RGBImageFilter filter = new BrightnessContrastFilter(pAmount, 0f);
|
||||||
|
|
||||||
// Return brightness adjusted image
|
// Return brightness adjusted image
|
||||||
return filter(pOriginal, filter);
|
return filter(pOriginal, filter);
|
||||||
@ -1465,7 +1461,7 @@ public final class ImageUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to use H/W-accellerated code for an image for display purposes.
|
* Tries to use H/W-accelerated code for an image for display purposes.
|
||||||
* Note that transparent parts of the image might be replaced by solid
|
* Note that transparent parts of the image might be replaced by solid
|
||||||
* color. Additional image information not used by the current diplay
|
* color. Additional image information not used by the current diplay
|
||||||
* hardware may be discarded, like extra bith depth etc.
|
* hardware may be discarded, like extra bith depth etc.
|
||||||
@ -1478,7 +1474,7 @@ public final class ImageUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to use H/W-accellerated code for an image for display purposes.
|
* Tries to use H/W-accelerated code for an image for display purposes.
|
||||||
* Note that transparent parts of the image might be replaced by solid
|
* Note that transparent parts of the image might be replaced by solid
|
||||||
* color. Additional image information not used by the current diplay
|
* color. Additional image information not used by the current diplay
|
||||||
* hardware may be discarded, like extra bith depth etc.
|
* hardware may be discarded, like extra bith depth etc.
|
||||||
@ -1494,7 +1490,7 @@ public final class ImageUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to use H/W-accellerated code for an image for display purposes.
|
* Tries to use H/W-accelerated code for an image for display purposes.
|
||||||
* Note that transparent parts of the image will be replaced by solid
|
* Note that transparent parts of the image will be replaced by solid
|
||||||
* color. Additional image information not used by the current diplay
|
* color. Additional image information not used by the current diplay
|
||||||
* hardware may be discarded, like extra bith depth etc.
|
* hardware may be discarded, like extra bith depth etc.
|
||||||
@ -1825,13 +1821,6 @@ public final class ImageUtil {
|
|||||||
// Create a local id for use with the mediatracker
|
// Create a local id for use with the mediatracker
|
||||||
int imageId;
|
int imageId;
|
||||||
|
|
||||||
// NOTE: The synchronization throws IllegalMonitorStateException if
|
|
||||||
// using JIT on J2SE 1.2 (tested version Sun JRE 1.2.2_017).
|
|
||||||
// Works perfectly interpreted... Hmmm...
|
|
||||||
//synchronized (sTrackerMutex) {
|
|
||||||
//imageId = ++sTrackerId;
|
|
||||||
//}
|
|
||||||
|
|
||||||
// NOTE: This is very experimental...
|
// NOTE: This is very experimental...
|
||||||
imageId = pImages.length == 1 ? System.identityHashCode(pImages[0]) : System.identityHashCode(pImages);
|
imageId = pImages.length == 1 ? System.identityHashCode(pImages[0]) : System.identityHashCode(pImages);
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ public abstract class AbstractTokenIterator implements TokenIterator {
|
|||||||
public void remove() {
|
public void remove() {
|
||||||
// TODO: This is not difficult:
|
// TODO: This is not difficult:
|
||||||
// - Convert String to StringBuilder in constructor
|
// - Convert String to StringBuilder in constructor
|
||||||
// - delete(pos, mNext.lenght())
|
// - delete(pos, next.lenght())
|
||||||
// - Add toString() method
|
// - Add toString() method
|
||||||
// BUT: Would it ever be useful? :-)
|
// BUT: Would it ever be useful? :-)
|
||||||
|
|
||||||
|
@ -205,6 +205,7 @@ public class LRUHashMap<K, V> extends LinkedHashMap<K, V> implements ExpiringMap
|
|||||||
*/
|
*/
|
||||||
public void removeLRU() {
|
public void removeLRU() {
|
||||||
int removeCount = (int) Math.max((size() * trimFactor), 1);
|
int removeCount = (int) Math.max((size() * trimFactor), 1);
|
||||||
|
|
||||||
Iterator<Map.Entry<K, V>> entries = entrySet().iterator();
|
Iterator<Map.Entry<K, V>> entries = entrySet().iterator();
|
||||||
while ((removeCount--) > 0 && entries.hasNext()) {
|
while ((removeCount--) > 0 && entries.hasNext()) {
|
||||||
entries.next();
|
entries.next();
|
||||||
|
@ -45,7 +45,7 @@ import java.util.Map;
|
|||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/util/LRUMap.java#1 $
|
* @version $Id: com/twelvemonkeys/util/LRUMap.java#1 $
|
||||||
*/
|
*/
|
||||||
public class LRUMap<K, V> extends LinkedMap<K, V> implements ExpiringMap<K, V> {
|
public class LRUMap<K, V> extends LinkedMap<K, V> implements ExpiringMap<K, V> {
|
||||||
|
|
||||||
@ -222,8 +222,9 @@ public class LRUMap<K, V> extends LinkedMap<K, V> implements ExpiringMap<K, V> {
|
|||||||
*/
|
*/
|
||||||
public void removeLRU() {
|
public void removeLRU() {
|
||||||
int removeCount = (int) Math.max((size() * trimFactor), 1);
|
int removeCount = (int) Math.max((size() * trimFactor), 1);
|
||||||
|
|
||||||
while ((removeCount--) > 0) {
|
while ((removeCount--) > 0) {
|
||||||
removeEntry(head.mNext);
|
removeEntry(head.next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,19 +181,19 @@ public class LinkedMap<K, V> extends AbstractDecoratedMap<K, V> implements Seria
|
|||||||
return "head";
|
return "head";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
head.mPrevious = head.mNext = head;
|
head.previous = head.next = head;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsValue(Object pValue) {
|
public boolean containsValue(Object pValue) {
|
||||||
// Overridden to take advantage of faster iterator
|
// Overridden to take advantage of faster iterator
|
||||||
if (pValue == null) {
|
if (pValue == null) {
|
||||||
for (LinkedEntry e = head.mNext; e != head; e = e.mNext) {
|
for (LinkedEntry e = head.next; e != head; e = e.next) {
|
||||||
if (e.mValue == null) {
|
if (e.mValue == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (LinkedEntry e = head.mNext; e != head; e = e.mNext) {
|
for (LinkedEntry e = head.next; e != head; e = e.next) {
|
||||||
if (pValue.equals(e.mValue)) {
|
if (pValue.equals(e.mValue)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -215,7 +215,7 @@ public class LinkedMap<K, V> extends AbstractDecoratedMap<K, V> implements Seria
|
|||||||
}
|
}
|
||||||
|
|
||||||
private abstract class LinkedMapIterator<E> implements Iterator<E> {
|
private abstract class LinkedMapIterator<E> implements Iterator<E> {
|
||||||
LinkedEntry<K, V> mNextEntry = head.mNext;
|
LinkedEntry<K, V> mNextEntry = head.next;
|
||||||
LinkedEntry<K, V> mLastReturned = null;
|
LinkedEntry<K, V> mLastReturned = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -254,7 +254,7 @@ public class LinkedMap<K, V> extends AbstractDecoratedMap<K, V> implements Seria
|
|||||||
}
|
}
|
||||||
|
|
||||||
LinkedEntry<K, V> e = mLastReturned = mNextEntry;
|
LinkedEntry<K, V> e = mLastReturned = mNextEntry;
|
||||||
mNextEntry = e.mNext;
|
mNextEntry = e.next;
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
@ -309,7 +309,7 @@ public class LinkedMap<K, V> extends AbstractDecoratedMap<K, V> implements Seria
|
|||||||
oldValue = null;
|
oldValue = null;
|
||||||
|
|
||||||
// Remove eldest entry if instructed, else grow capacity if appropriate
|
// Remove eldest entry if instructed, else grow capacity if appropriate
|
||||||
LinkedEntry<K, V> eldest = head.mNext;
|
LinkedEntry<K, V> eldest = head.next;
|
||||||
if (removeEldestEntry(eldest)) {
|
if (removeEldestEntry(eldest)) {
|
||||||
removeEntry(eldest);
|
removeEntry(eldest);
|
||||||
}
|
}
|
||||||
@ -407,13 +407,13 @@ public class LinkedMap<K, V> extends AbstractDecoratedMap<K, V> implements Seria
|
|||||||
* Linked list implementation of {@code Map.Entry}.
|
* Linked list implementation of {@code Map.Entry}.
|
||||||
*/
|
*/
|
||||||
protected static class LinkedEntry<K, V> extends BasicEntry<K, V> implements Serializable {
|
protected static class LinkedEntry<K, V> extends BasicEntry<K, V> implements Serializable {
|
||||||
LinkedEntry<K, V> mPrevious;
|
LinkedEntry<K, V> previous;
|
||||||
LinkedEntry<K, V> mNext;
|
LinkedEntry<K, V> next;
|
||||||
|
|
||||||
LinkedEntry(K pKey, V pValue, LinkedEntry<K, V> pNext) {
|
LinkedEntry(K pKey, V pValue, LinkedEntry<K, V> pNext) {
|
||||||
super(pKey, pValue);
|
super(pKey, pValue);
|
||||||
|
|
||||||
mNext = pNext;
|
next = pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -423,19 +423,19 @@ public class LinkedMap<K, V> extends AbstractDecoratedMap<K, V> implements Seria
|
|||||||
* @param pExisting the entry to add before
|
* @param pExisting the entry to add before
|
||||||
*/
|
*/
|
||||||
void addBefore(LinkedEntry<K, V> pExisting) {
|
void addBefore(LinkedEntry<K, V> pExisting) {
|
||||||
mNext = pExisting;
|
next = pExisting;
|
||||||
mPrevious = pExisting.mPrevious;
|
previous = pExisting.previous;
|
||||||
|
|
||||||
mPrevious.mNext = this;
|
previous.next = this;
|
||||||
mNext.mPrevious = this;
|
next.previous = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes this entry from the linked list.
|
* Removes this entry from the linked list.
|
||||||
*/
|
*/
|
||||||
void remove() {
|
void remove() {
|
||||||
mPrevious.mNext = mNext;
|
previous.next = next;
|
||||||
mNext.mPrevious = mPrevious;
|
next.previous = previous;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -456,7 +456,7 @@ public class LinkedMap<K, V> extends AbstractDecoratedMap<K, V> implements Seria
|
|||||||
/**
|
/**
|
||||||
* Removes this entry from the linked list.
|
* Removes this entry from the linked list.
|
||||||
*
|
*
|
||||||
* @param pMap the map to record remoal from
|
* @param pMap the map to record removal from
|
||||||
*/
|
*/
|
||||||
protected void recordRemoval(Map<K, V> pMap) {
|
protected void recordRemoval(Map<K, V> pMap) {
|
||||||
// TODO: Is this REALLY correct?
|
// TODO: Is this REALLY correct?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user