Commit 158e38dd by Jonas

Fixed cloning of BufferedImage

1 parent 46a87eae
package org.stegosuite.image.analysis;
import java.awt.Color;
import java.awt.image.BufferedImage;
import org.stegosuite.image.format.ImageFormat;
import org.stegosuite.image.util.ByteUtils;
......@@ -9,7 +10,7 @@ import org.stegosuite.image.util.RgbChannel;
public class LsbVisualization {
public static ImageFormat calculate(ImageFormat image) {
ImageFormat visualizedImage = image.clone();
ImageFormat visualizedImage = image.clone(BufferedImage.TYPE_INT_ARGB);
for (int y = 0; y < visualizedImage.getHeight(); y++) {
for (int x = 0; x < visualizedImage.getWidth(); x++) {
......
......@@ -139,15 +139,19 @@ public abstract class ImageFormat {
return this.file;
}
@Override
public ImageFormat clone() {
public ImageFormat clone(int imageTpye) {
ImageFormat clonedImage = newInstance(this.getClass());
clonedImage.setBufferedImage(ColorUtils.cloneBufferedImage(this.image));
clonedImage.setBufferedImage(ColorUtils.cloneBufferedImage(this.image, imageTpye));
clonedImage.file = this.file;
return clonedImage;
}
@Override
public ImageFormat clone() {
return this.clone(this.image.getType());
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
......
......@@ -3,8 +3,8 @@ package org.stegosuite.image.util;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.WritableRaster;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -153,13 +153,16 @@ public class ColorUtils {
* @return
*/
public static BufferedImage cloneBufferedImage(BufferedImage source, int imageType) {
ColorModel colorModel = source.getColorModel();
boolean isAlphaPremultiplied = colorModel.isAlphaPremultiplied();
if (source.getType() != imageType) {
colorModel = new BufferedImage(source.getWidth(), source.getHeight(), imageType).getColorModel();
if (source.getType() == imageType) {
boolean isAlphaPremultiplied = source.getColorModel().isAlphaPremultiplied();
WritableRaster raster = source.copyData(source.getRaster().createCompatibleWritableRaster());
return new BufferedImage(source.getColorModel(), raster, isAlphaPremultiplied, null);
} else {
BufferedImage copy = new BufferedImage(source.getWidth(), source.getHeight(), imageType);
Graphics2D g2d = copy.createGraphics();
g2d.drawImage(source, 0, 0, null);
g2d.dispose();
return copy;
}
WritableRaster raster = source.copyData(source.getRaster().createCompatibleWritableRaster());
return new BufferedImage(colorModel, raster, isAlphaPremultiplied, null);
}
}
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!