use of java.awt.image.ColorModel in project BroadleafCommerce by BroadleafCommerce.
the class Crop method filter.
/* (non-Javadoc)
* @see java.awt.image.BufferedImageOp#filter(java.awt.image.BufferedImage, java.awt.image.BufferedImage)
*/
public BufferedImage filter(BufferedImage src, BufferedImage dst) {
if (src == null) {
throw new NullPointerException("src image is null");
}
if (src == dst) {
throw new IllegalArgumentException("src image cannot be the " + "same as the dst image");
}
boolean needToConvert = false;
ColorModel srcCM = src.getColorModel();
ColorModel dstCM;
BufferedImage origDst = dst;
if (srcCM instanceof IndexColorModel) {
IndexColorModel icm = (IndexColorModel) srcCM;
src = icm.convertToIntDiscrete(src.getRaster(), false);
srcCM = src.getColorModel();
}
if (dst == null) {
dst = createCompatibleDestImage(src, null);
dstCM = srcCM;
origDst = dst;
} else {
dstCM = dst.getColorModel();
if (srcCM.getColorSpace().getType() != dstCM.getColorSpace().getType()) {
needToConvert = true;
dst = createCompatibleDestImage(src, null);
dstCM = dst.getColorModel();
} else if (dstCM instanceof IndexColorModel) {
dst = createCompatibleDestImage(src, null);
dstCM = dst.getColorModel();
}
}
java.awt.image.CropImageFilter cropfilter = new java.awt.image.CropImageFilter(region.x, region.y, region.width, region.height);
Image returnImage = Toolkit.getDefaultToolkit().createImage(new java.awt.image.FilteredImageSource(src.getSource(), cropfilter));
dst = ImageConverter.convertImage(returnImage);
origDst = dst;
if (needToConvert) {
ColorConvertOp ccop = new ColorConvertOp(hints);
ccop.filter(dst, origDst);
} else if (origDst != dst) {
java.awt.Graphics2D g2 = origDst.createGraphics();
try {
g2.drawImage(dst, 0, 0, null);
} finally {
g2.dispose();
}
}
return origDst;
}
use of java.awt.image.ColorModel in project BroadleafCommerce by BroadleafCommerce.
the class ImageConverter method getImage.
public static BufferedImage getImage(int[] pixels, int width, int height) {
ColorModel cm = ColorModel.getRGBdefault();
MemoryImageSource imageSource = new MemoryImageSource(width, height, cm, pixels, 0, width);
imageSource.setAnimated(true);
Image temp = Toolkit.getDefaultToolkit().createImage(imageSource);
BufferedImage image = convertImage(temp);
return image;
}
use of java.awt.image.ColorModel in project BroadleafCommerce by BroadleafCommerce.
the class Rotate method filter.
/* (non-Javadoc)
* @see java.awt.image.BufferedImageOp#filter(java.awt.image.BufferedImage, java.awt.image.BufferedImage)
*/
public BufferedImage filter(BufferedImage src, BufferedImage dst) {
if (src == null) {
throw new NullPointerException("src image is null");
}
if (src == dst) {
throw new IllegalArgumentException("src image cannot be the " + "same as the dst image");
}
boolean needToConvert = false;
ColorModel srcCM = src.getColorModel();
ColorModel dstCM;
BufferedImage origDst = dst;
if (srcCM instanceof IndexColorModel) {
IndexColorModel icm = (IndexColorModel) srcCM;
src = icm.convertToIntDiscrete(src.getRaster(), false);
srcCM = src.getColorModel();
}
int neww;
int newh;
int w = src.getWidth();
int h = src.getHeight();
if (dst == null) {
double sin = Math.abs(Math.sin(Math.toRadians(amount))), cos = Math.abs(Math.cos(Math.toRadians(amount)));
neww = (int) Math.floor(w * cos + h * sin);
newh = (int) Math.floor(h * cos + w * sin);
dst = createCompatibleDestImage(src, null, neww, newh);
dstCM = srcCM;
origDst = dst;
} else {
dstCM = dst.getColorModel();
if (srcCM.getColorSpace().getType() != dstCM.getColorSpace().getType()) {
needToConvert = true;
dst = createCompatibleDestImage(src, null);
dstCM = dst.getColorModel();
} else if (dstCM instanceof IndexColorModel) {
dst = createCompatibleDestImage(src, null);
dstCM = dst.getColorModel();
}
neww = dst.getWidth();
newh = dst.getHeight();
}
Graphics2D g = dst.createGraphics();
g.translate((neww - w) / 2, (newh - h) / 2);
g.rotate(Math.toRadians(amount), w / 2, h / 2);
g.drawRenderedImage(src, null);
g.dispose();
origDst = dst;
if (needToConvert) {
ColorConvertOp ccop = new ColorConvertOp(hints);
ccop.filter(dst, origDst);
} else if (origDst != dst) {
Graphics2D g2 = origDst.createGraphics();
try {
g2.drawImage(dst, 0, 0, null);
} finally {
g2.dispose();
}
}
return origDst;
}
use of java.awt.image.ColorModel in project BroadleafCommerce by BroadleafCommerce.
the class UnsharpMask method filter.
/* (non-Javadoc)
* @see java.awt.image.BufferedImageOp#filter(java.awt.image.BufferedImage, java.awt.image.BufferedImage)
*/
public BufferedImage filter(BufferedImage src, BufferedImage dst) {
if (src == null) {
throw new NullPointerException("src image is null");
}
if (src == dst) {
throw new IllegalArgumentException("src image cannot be the " + "same as the dst image");
}
boolean needToConvert = false;
ColorModel srcCM = src.getColorModel();
ColorModel dstCM;
BufferedImage origDst = dst;
if (srcCM instanceof IndexColorModel) {
IndexColorModel icm = (IndexColorModel) srcCM;
src = icm.convertToIntDiscrete(src.getRaster(), false);
srcCM = src.getColorModel();
}
if (dst == null) {
dst = createCompatibleDestImage(src, null);
dstCM = srcCM;
origDst = dst;
} else {
dstCM = dst.getColorModel();
if (srcCM.getColorSpace().getType() != dstCM.getColorSpace().getType()) {
needToConvert = true;
dst = createCompatibleDestImage(src, null);
dstCM = dst.getColorModel();
} else if (dstCM instanceof IndexColorModel) {
dst = createCompatibleDestImage(src, null);
dstCM = dst.getColorModel();
}
}
int[] originalPixels = ImageConverter.getPixels(src);
GaussianBlur blur = new GaussianBlur(radius, 1, hints);
dst = blur.filter(src, null);
int[] uMaskBlur = ImageConverter.getPixels(dst);
int imageWidth = dst.getWidth();
int imageHeight = dst.getHeight();
int index = 0;
for (int y = 0; y < imageHeight; y++) {
for (int x = 0; x < imageWidth; x++) {
int R1 = (originalPixels[index] >> 16) & 0xff;
int G1 = (originalPixels[index] >> 8) & 0xff;
int B1 = (originalPixels[index] >> 0) & 0xff;
int R2 = (uMaskBlur[index] >> 16) & 0xff;
int G2 = (uMaskBlur[index] >> 8) & 0xff;
int B2 = (uMaskBlur[index] >> 0) & 0xff;
int R3 = (int) (value * (float) R1 - (value - 1F) * (float) R2);
int G3 = (int) (value * (float) G1 - (value - 1F) * (float) G2);
int B3 = (int) (value * (float) B1 - (value - 1F) * (float) B2);
// fix overflows
if (R3 > 255)
R3 = 255;
if (R3 < 0)
R3 = 0;
if (G3 > 255)
G3 = 255;
if (G3 < 0)
G3 = 0;
if (B3 > 255)
B3 = 255;
if (B3 < 0)
B3 = 0;
originalPixels[index] = (originalPixels[index] & 0xff000000) | (R3 << 16) | (G3 << 8) | (B3 << 0);
index++;
}
}
dst = ImageConverter.getImage(originalPixels, imageWidth, imageHeight);
if (needToConvert) {
ColorConvertOp ccop = new ColorConvertOp(hints);
ccop.filter(dst, origDst);
} else if (origDst != dst) {
java.awt.Graphics2D g = origDst.createGraphics();
try {
g.drawImage(dst, 0, 0, null);
} finally {
g.dispose();
}
}
return origDst;
}
use of java.awt.image.ColorModel in project freeplane by freeplane.
the class BigBufferedImage method createBigBufferedImage.
private static BufferedImage createBigBufferedImage(File tempDir, int width, int height, int imageType) throws FileNotFoundException, IOException {
FileDataBuffer buffer = new FileDataBuffer(tempDir, width * height, 4);
ColorModel colorModel = null;
BandedSampleModel sampleModel = null;
switch(imageType) {
case TYPE_INT_RGB:
colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] { 8, 8, 8, 0 }, false, false, ComponentColorModel.TRANSLUCENT, DataBuffer.TYPE_BYTE);
sampleModel = new BandedSampleModel(DataBuffer.TYPE_BYTE, width, height, 3);
break;
case TYPE_INT_ARGB:
colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] { 8, 8, 8, 8 }, true, false, ComponentColorModel.TRANSLUCENT, DataBuffer.TYPE_BYTE);
sampleModel = new BandedSampleModel(DataBuffer.TYPE_BYTE, width, height, 4);
break;
default:
throw new IllegalArgumentException("Unsupported image type: " + imageType);
}
SimpleRaster raster = new SimpleRaster(sampleModel, buffer, new Point(0, 0));
BigBufferedImage image = new BigBufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);
return image;
}
Aggregations