use of java.awt.image.ColorConvertOp in project jmonkeyengine by jMonkeyEngine.
the class ImageUtils method convertToNormalMapTexture.
/**
* This method converts the given texture into normal-map texture.
*
* @param source
* the source texture
* @param strengthFactor
* the normal strength factor
* @return normal-map texture
*/
public static Image convertToNormalMapTexture(Image source, float strengthFactor) {
BufferedImage sourceImage = ImageToAwt.convert(source, false, false, 0);
BufferedImage heightMap = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
BufferedImage bumpMap = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
ColorConvertOp gscale = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
gscale.filter(sourceImage, heightMap);
Vector3f S = new Vector3f();
Vector3f T = new Vector3f();
Vector3f N = new Vector3f();
for (int x = 0; x < bumpMap.getWidth(); ++x) {
for (int y = 0; y < bumpMap.getHeight(); ++y) {
// generating bump pixel
S.x = 1;
S.y = 0;
S.z = strengthFactor * ImageUtils.getHeight(heightMap, x + 1, y) - strengthFactor * ImageUtils.getHeight(heightMap, x - 1, y);
T.x = 0;
T.y = 1;
T.z = strengthFactor * ImageUtils.getHeight(heightMap, x, y + 1) - strengthFactor * ImageUtils.getHeight(heightMap, x, y - 1);
float den = (float) Math.sqrt(S.z * S.z + T.z * T.z + 1);
N.x = -S.z;
N.y = -T.z;
N.z = 1;
N.divideLocal(den);
// setting thge pixel in the result image
bumpMap.setRGB(x, y, ImageUtils.vectorToColor(N.x, N.y, N.z));
}
}
return ImageUtils.toJmeImage(bumpMap, source.getFormat());
}
use of java.awt.image.ColorConvertOp in project jdk8u_jdk by JetBrains.
the class ColConvCCMTest method testImage.
static boolean testImage(int dataType, int rBits, int gBits, int bBits, int cs, BufferedImage gldImage, double accuracy) {
BufferedImage src = ImageFactory.createCCMImage(cs, dataType);
BufferedImage dst = ImageFactory.createDstImage(BufferedImage.TYPE_INT_RGB);
ColorConvertOp op = new ColorConvertOp(null);
op.filter(src, dst);
ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits, bBits);
boolean result = cmp.compare(gldImage, dst);
if (!result) {
System.err.println(cmp.getStat());
}
return result;
}
use of java.awt.image.ColorConvertOp in project jdk8u_jdk by JetBrains.
the class ColConvCCMTest method testSubImage.
static boolean testSubImage(int x0, int y0, int dx, int dy, int dataType, int rBits, int gBits, int bBits, int cs, BufferedImage gldImage, double accuracy) {
BufferedImage src = ImageFactory.createCCMImage(cs, dataType);
BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
BufferedImage dst = ImageFactory.createDstImage(BufferedImage.TYPE_INT_RGB);
BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);
ColorConvertOp op = new ColorConvertOp(null);
op.filter(subSrc, subDst);
ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits, bBits);
boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
if (!result) {
System.err.println(cmp.getStat());
}
return result;
}
use of java.awt.image.ColorConvertOp in project jdk8u_jdk by JetBrains.
the class ColConvDCMTest method testImage.
static boolean testImage(int type, int rBits, int gBits, int bBits, int cs, BufferedImage gldImage, double accuracy) {
BufferedImage src = ImageFactory.createDCMImage(type, cs);
BufferedImage dst = ImageFactory.createDstImage(BufferedImage.TYPE_INT_RGB);
ColorConvertOp op = new ColorConvertOp(null);
op.filter(src, dst);
ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits, bBits);
boolean result = cmp.compare(gldImage, dst);
if (!result) {
System.err.println(cmp.getStat());
}
return result;
}
use of java.awt.image.ColorConvertOp in project hutool by looly.
the class ImageUtil method gray.
/**
* 彩色转为黑白
*
* @param srcImage 源图像流
* @return {@link Image}灰度后的图片
* @since 3.1.0
*/
public static BufferedImage gray(Image srcImage) {
BufferedImage grayImage = toBufferedImage(srcImage);
final ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
grayImage = op.filter(grayImage, null);
return grayImage;
}
Aggregations