diff --git a/common/common-image/src/main/java/com/twelvemonkeys/image/DiffusionDither.java b/common/common-image/src/main/java/com/twelvemonkeys/image/DiffusionDither.java index 363b9542..48664fcc 100755 --- a/common/common-image/src/main/java/com/twelvemonkeys/image/DiffusionDither.java +++ b/common/common-image/src/main/java/com/twelvemonkeys/image/DiffusionDither.java @@ -292,20 +292,20 @@ public class DiffusionDither implements BufferedImageOp, RasterOp { // When reference for column, add 1 to reference as this buffer is // offset from actual column position by one to allow FS to not check // left/right edge conditions - int[][] mCurrErr = new int[width + 2][3]; - int[][] mNextErr = new int[width + 2][3]; + int[][] currErr = new int[width + 2][3]; + int[][] nextErr = new int[width + 2][3]; // Random errors in [-1 .. 1] - for first row for (int i = 0; i < width + 2; i++) { // Note: This is broken for the strange cases where nextInt returns Integer.MIN_VALUE /* - mCurrErr[i][0] = (Math.abs(RANDOM.nextInt()) % (FS_SCALE * 2)) - FS_SCALE; - mCurrErr[i][1] = (Math.abs(RANDOM.nextInt()) % (FS_SCALE * 2)) - FS_SCALE; - mCurrErr[i][2] = (Math.abs(RANDOM.nextInt()) % (FS_SCALE * 2)) - FS_SCALE; + currErr[i][0] = (Math.abs(RANDOM.nextInt()) % (FS_SCALE * 2)) - FS_SCALE; + currErr[i][1] = (Math.abs(RANDOM.nextInt()) % (FS_SCALE * 2)) - FS_SCALE; + currErr[i][2] = (Math.abs(RANDOM.nextInt()) % (FS_SCALE * 2)) - FS_SCALE; */ - mCurrErr[i][0] = RANDOM.nextInt(FS_SCALE * 2) - FS_SCALE; - mCurrErr[i][1] = RANDOM.nextInt(FS_SCALE * 2) - FS_SCALE; - mCurrErr[i][2] = RANDOM.nextInt(FS_SCALE * 2) - FS_SCALE; + currErr[i][0] = RANDOM.nextInt(FS_SCALE * 2) - FS_SCALE; + currErr[i][1] = RANDOM.nextInt(FS_SCALE * 2) - FS_SCALE; + currErr[i][2] = RANDOM.nextInt(FS_SCALE * 2) - FS_SCALE; } // Temp buffers @@ -318,10 +318,10 @@ public class DiffusionDither implements BufferedImageOp, RasterOp { // Loop through image data for (int y = 0; y < height; y++) { // Clear out next error rows for colour errors - for (int i = mNextErr.length; --i >= 0;) { - mNextErr[i][0] = 0; - mNextErr[i][1] = 0; - mNextErr[i][2] = 0; + for (int i = nextErr.length; --i >= 0;) { + nextErr[i][0] = 0; + nextErr[i][1] = 0; + nextErr[i][2] = 0; } // Set up start column and limit @@ -348,7 +348,7 @@ public class DiffusionDither implements BufferedImageOp, RasterOp { for (int i = 0; i < 3; i++) { // Make a 28.4 FP number, add Error (with fraction), // rounding and truncate to int - inRGB[i] = ((inRGB[i] << 4) + mCurrErr[x + 1][i] + 0x08) >> 4; + inRGB[i] = ((inRGB[i] << 4) + currErr[x + 1][i] + 0x08) >> 4; // Clamp if (inRGB[i] > 255) { @@ -384,26 +384,26 @@ public class DiffusionDither implements BufferedImageOp, RasterOp { if (forward) { // Row 1 (y) // Update error in this pixel (x + 1) - mCurrErr[x + 2][0] += diff[0] * 7; - mCurrErr[x + 2][1] += diff[1] * 7; - mCurrErr[x + 2][2] += diff[2] * 7; + currErr[x + 2][0] += diff[0] * 7; + currErr[x + 2][1] += diff[1] * 7; + currErr[x + 2][2] += diff[2] * 7; // Row 2 (y + 1) // Update error in this pixel (x - 1) - mNextErr[x][0] += diff[0] * 3; - mNextErr[x][1] += diff[1] * 3; - mNextErr[x][2] += diff[2] * 3; + nextErr[x][0] += diff[0] * 3; + nextErr[x][1] += diff[1] * 3; + nextErr[x][2] += diff[2] * 3; // Update error in this pixel (x) - mNextErr[x + 1][0] += diff[0] * 5; - mNextErr[x + 1][1] += diff[1] * 5; - mNextErr[x + 1][2] += diff[2] * 5; + nextErr[x + 1][0] += diff[0] * 5; + nextErr[x + 1][1] += diff[1] * 5; + nextErr[x + 1][2] += diff[2] * 5; // Update error in this pixel (x + 1) // TODO: Consider calculating this using // error term = error - sum(error terms 1, 2 and 3) // See Computer Graphics (Foley et al.), p. 573 - mNextErr[x + 2][0] += diff[0]; // * 1; - mNextErr[x + 2][1] += diff[1]; // * 1; - mNextErr[x + 2][2] += diff[2]; // * 1; + nextErr[x + 2][0] += diff[0]; // * 1; + nextErr[x + 2][1] += diff[1]; // * 1; + nextErr[x + 2][2] += diff[2]; // * 1; // Next x++; @@ -417,26 +417,26 @@ public class DiffusionDither implements BufferedImageOp, RasterOp { else { // Row 1 (y) // Update error in this pixel (x - 1) - mCurrErr[x][0] += diff[0] * 7; - mCurrErr[x][1] += diff[1] * 7; - mCurrErr[x][2] += diff[2] * 7; + currErr[x][0] += diff[0] * 7; + currErr[x][1] += diff[1] * 7; + currErr[x][2] += diff[2] * 7; // Row 2 (y + 1) // Update error in this pixel (x + 1) - mNextErr[x + 2][0] += diff[0] * 3; - mNextErr[x + 2][1] += diff[1] * 3; - mNextErr[x + 2][2] += diff[2] * 3; + nextErr[x + 2][0] += diff[0] * 3; + nextErr[x + 2][1] += diff[1] * 3; + nextErr[x + 2][2] += diff[2] * 3; // Update error in this pixel (x) - mNextErr[x + 1][0] += diff[0] * 5; - mNextErr[x + 1][1] += diff[1] * 5; - mNextErr[x + 1][2] += diff[2] * 5; + nextErr[x + 1][0] += diff[0] * 5; + nextErr[x + 1][1] += diff[1] * 5; + nextErr[x + 1][2] += diff[2] * 5; // Update error in this pixel (x - 1) // TODO: Consider calculating this using // error term = error - sum(error terms 1, 2 and 3) // See Computer Graphics (Foley et al.), p. 573 - mNextErr[x][0] += diff[0]; // * 1; - mNextErr[x][1] += diff[1]; // * 1; - mNextErr[x][2] += diff[2]; // * 1; + nextErr[x][0] += diff[0]; // * 1; + nextErr[x][1] += diff[1]; // * 1; + nextErr[x][2] += diff[2]; // * 1; // Previous x--; @@ -450,9 +450,9 @@ public class DiffusionDither implements BufferedImageOp, RasterOp { // Make next error info current for next iteration int[][] temperr; - temperr = mCurrErr; - mCurrErr = mNextErr; - mNextErr = temperr; + temperr = currErr; + currErr = nextErr; + nextErr = temperr; // Toggle direction if (alternateScans) { diff --git a/common/common-image/src/main/java/com/twelvemonkeys/image/ImageUtil.java b/common/common-image/src/main/java/com/twelvemonkeys/image/ImageUtil.java index f9159a9e..721051b9 100644 --- a/common/common-image/src/main/java/com/twelvemonkeys/image/ImageUtil.java +++ b/common/common-image/src/main/java/com/twelvemonkeys/image/ImageUtil.java @@ -39,7 +39,7 @@ import java.util.Hashtable; * * @author Harald Kuhr * @author last modified by $Author: haku $ - * @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/image/ImageUtil.java#3 $ + * @version $Id: common/common-image/src/main/java/com/twelvemonkeys/image/ImageUtil.java#3 $ */ public final class ImageUtil { // TODO: Split palette generation out, into ColorModel classes (?) @@ -845,11 +845,13 @@ public final class ImageUtil { BufferedImage temp = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null); if (cm instanceof IndexColorModel && pHints == Image.SCALE_SMOOTH) { + // TODO: DiffusionDither does not support transparency at the moment, this will create bad results new DiffusionDither((IndexColorModel) cm).filter(scaled, temp); } else { drawOnto(temp, scaled); } + scaled = temp; //long end = System.currentTimeMillis(); //System.out.println("Time: " + (end - start) + " ms"); diff --git a/common/common-image/src/main/java/com/twelvemonkeys/image/IndexImage.java b/common/common-image/src/main/java/com/twelvemonkeys/image/IndexImage.java index ef97bc5c..f7419204 100755 --- a/common/common-image/src/main/java/com/twelvemonkeys/image/IndexImage.java +++ b/common/common-image/src/main/java/com/twelvemonkeys/image/IndexImage.java @@ -96,7 +96,7 @@ import java.util.Iterator; import java.util.List; /** - * This class implements an adaptive pallete generator to reduce images + * This class implements an adaptive palette generator to reduce images * to a variable number of colors. * It can also render images into fixed color pallettes. *

@@ -589,7 +589,7 @@ class IndexImage { /** * Gets an {@code IndexColorModel} from the given image. If the image has an * {@code IndexColorModel}, this will be returned. Otherwise, an {@code IndexColorModel} - * is created, using an adaptive pallete. + * is created, using an adaptive palette. * * @param pImage the image to get {@code IndexColorModel} from * @param pNumberOfColors the number of colors for the {@code IndexColorModel} @@ -637,7 +637,7 @@ class IndexImage { // We now have at least a buffered image, create model from it if (icm == null) { icm = createIndexColorModel(ImageUtil.toBuffered(image), pNumberOfColors, pHints); - } + } else if (!(icm instanceof InverseColorMapIndexColorModel)) { // If possible, use faster code icm = new InverseColorMapIndexColorModel(icm); @@ -648,7 +648,7 @@ class IndexImage { /** * Creates an {@code IndexColorModel} from the given image, using an adaptive - * pallete. + * palette. * * @param pImage the image to get {@code IndexColorModel} from * @param pNumberOfColors the number of colors for the {@code IndexColorModel} @@ -821,7 +821,7 @@ class IndexImage { /** * Converts the input image (must be {@code TYPE_INT_RGB} or * {@code TYPE_INT_ARGB}) to an indexed image. Generating an adaptive - * pallete (8 bit) from the color data in the image, and uses default + * palette (8 bit) from the color data in the image, and uses default * dither. *

* The image returned is a new image, the input image is not modified. @@ -865,7 +865,7 @@ class IndexImage { * Converts the input image (must be {@code TYPE_INT_RGB} or * {@code TYPE_INT_ARGB}) to an indexed image. If the palette image * uses an {@code IndexColorModel}, this will be used. Otherwise, generating an - * adaptive pallete (8 bit) from the given palette image. + * adaptive palette (8 bit) from the given palette image. * Dithering, transparency and color selection is controlled with the * {@code pHints}parameter. *

@@ -875,7 +875,7 @@ class IndexImage { * @param pPalette the Image to read color information from * @param pMatte the background color, used where the original image was * transparent - * @param pHints mHints that control output quality and speed. + * @param pHints hints that control output quality and speed. * @return the indexed BufferedImage. The image will be of type * {@code BufferedImage.TYPE_BYTE_INDEXED} or * {@code BufferedImage.TYPE_BYTE_BINARY}, and use an @@ -900,7 +900,7 @@ class IndexImage { /** * Converts the input image (must be {@code TYPE_INT_RGB} or * {@code TYPE_INT_ARGB}) to an indexed image. Generating an adaptive - * pallete with the given number of colors. + * palette with the given number of colors. * Dithering, transparency and color selection is controlled with the * {@code pHints}parameter. *

@@ -910,7 +910,7 @@ class IndexImage { * @param pNumberOfColors the number of colors for the image * @param pMatte the background color, used where the original image was * transparent - * @param pHints mHints that control output quality and speed. + * @param pHints hints that control output quality and speed. * @return the indexed BufferedImage. The image will be of type * {@code BufferedImage.TYPE_BYTE_INDEXED} or * {@code BufferedImage.TYPE_BYTE_BINARY}, and use an @@ -947,7 +947,7 @@ class IndexImage { /** * Converts the input image (must be {@code TYPE_INT_RGB} or * {@code TYPE_INT_ARGB}) to an indexed image. Using the supplied - * {@code IndexColorModel}'s pallete. + * {@code IndexColorModel}'s palette. * Dithering, transparency and color selection is controlled with the * {@code pHints} parameter. *

@@ -1064,7 +1064,7 @@ class IndexImage { /** * Converts the input image (must be {@code TYPE_INT_RGB} or * {@code TYPE_INT_ARGB}) to an indexed image. Generating an adaptive - * pallete with the given number of colors. + * palette with the given number of colors. * Dithering, transparency and color selection is controlled with the * {@code pHints}parameter. *

@@ -1072,7 +1072,7 @@ class IndexImage { * * @param pImage the BufferedImage to index * @param pNumberOfColors the number of colors for the image - * @param pHints mHints that control output quality and speed. + * @param pHints hints that control output quality and speed. * @return the indexed BufferedImage. The image will be of type * {@code BufferedImage.TYPE_BYTE_INDEXED} or * {@code BufferedImage.TYPE_BYTE_BINARY}, and use an @@ -1094,7 +1094,7 @@ class IndexImage { /** * Converts the input image (must be {@code TYPE_INT_RGB} or * {@code TYPE_INT_ARGB}) to an indexed image. Using the supplied - * {@code IndexColorModel}'s pallete. + * {@code IndexColorModel}'s palette. * Dithering, transparency and color selection is controlled with the * {@code pHints}parameter. *

@@ -1125,7 +1125,7 @@ class IndexImage { * Converts the input image (must be {@code TYPE_INT_RGB} or * {@code TYPE_INT_ARGB}) to an indexed image. If the palette image * uses an {@code IndexColorModel}, this will be used. Otherwise, generating an - * adaptive pallete (8 bit) from the given palette image. + * adaptive palette (8 bit) from the given palette image. * Dithering, transparency and color selection is controlled with the * {@code pHints}parameter. *

@@ -1133,7 +1133,7 @@ class IndexImage { * * @param pImage the BufferedImage to index * @param pPalette the Image to read color information from - * @param pHints mHints that control output quality and speed. + * @param pHints hints that control output quality and speed. * @return the indexed BufferedImage. The image will be of type * {@code BufferedImage.TYPE_BYTE_INDEXED} or * {@code BufferedImage.TYPE_BYTE_BINARY}, and use an @@ -1393,7 +1393,7 @@ class IndexImage { System.exit(5); } - // Create mHints + // Create hints int hints = DITHER_DEFAULT; if ("DIFFUSION".equalsIgnoreCase(dither)) {