use of java.awt.color.ColorSpace in project android by JetBrains.
the class KMeansColorExtractor method runClustering.
@Override
List<ExtractedColor> runClustering(HashMap<Integer, Integer> labToRgb, List<double[]> clusterInput, Clusterer.ProgressListener listener) {
List<ExtractedColor> extractedColors;
List<List<double[]>> clusters = new KMeansClusterer(myK).cluster(clusterInput.toArray(new double[clusterInput.size()][POINT_DIMENSION]));
extractedColors = new ArrayList<>(clusters.size());
ColorSpace labColorSpace = Colors.getLabColorSpace();
for (List<double[]> cluster : clusters) {
double[] color = cluster.get(0);
float[] rgb = labColorSpace.toRGB(new float[] { (float) color[0], (float) color[1], (float) color[2] });
int rgbInt = Math.round(rgb[0] * 255) << 16 | Math.round(rgb[1] * 255) << 8 | Math.round(rgb[2] * 255);
extractedColors.add(new ExtractedColor(rgbInt, 1, null));
}
return extractedColors;
}
use of java.awt.color.ColorSpace in project intellij-community by JetBrains.
the class MacColorPipette method captureScreen.
@Nullable
static BufferedImage captureScreen(@Nullable Window belowWindow, @NotNull Rectangle rect) {
ID pool = Foundation.invoke("NSAutoreleasePool", "new");
try {
ID windowId = belowWindow != null ? MacUtil.findWindowFromJavaWindow(belowWindow) : null;
Foundation.NSRect nsRect = new Foundation.NSRect(rect.x, rect.y, rect.width, rect.height);
ID cgWindowId = windowId != null ? Foundation.invoke(windowId, "windowNumber") : ID.NIL;
int windowListOptions = cgWindowId != null ? FoundationLibrary.kCGWindowListOptionOnScreenBelowWindow : FoundationLibrary.kCGWindowListOptionAll;
int windowImageOptions = FoundationLibrary.kCGWindowImageNominalResolution;
ID cgImageRef = Foundation.cgWindowListCreateImage(nsRect, windowListOptions, cgWindowId, windowImageOptions);
ID bitmapRep = Foundation.invoke(Foundation.invoke("NSBitmapImageRep", "alloc"), "initWithCGImage:", cgImageRef);
ID nsImage = Foundation.invoke(Foundation.invoke("NSImage", "alloc"), "init");
Foundation.invoke(nsImage, "addRepresentation:", bitmapRep);
ID data = Foundation.invoke(nsImage, "TIFFRepresentation");
ID bytes = Foundation.invoke(data, "bytes");
ID length = Foundation.invoke(data, "length");
ByteBuffer byteBuffer = Native.getDirectByteBuffer(bytes.longValue(), length.longValue());
Foundation.invoke(nsImage, "release");
byte[] b = new byte[byteBuffer.remaining()];
byteBuffer.get(b);
BufferedImage result = ImageIO.read(new ByteArrayInputStream(b));
if (result != null) {
ColorSpace ics = ColorSpace.getInstance(ColorSpace.CS_sRGB);
ColorConvertOp cco = new ColorConvertOp(ics, null);
return cco.filter(result, null);
}
return null;
} catch (Throwable t) {
LOG.error(t);
return null;
} finally {
Foundation.invoke(pool, "release");
}
}
use of java.awt.color.ColorSpace in project jdk8u_jdk by JetBrains.
the class CMMTests method getColorSpace.
protected static ColorSpace getColorSpace(TestEnvironment env) {
ColorSpace cs;
//(Boolean)env.getModifier(usePlatfromProfiles);
Boolean usePlatfrom = true;
int cs_code = env.getIntValue(csList);
if (usePlatfrom) {
cs = ColorSpace.getInstance(cs_code);
} else {
String resource = "profiles/";
switch(cs_code) {
case ColorSpace.CS_CIEXYZ:
resource += "CIEXYZ.pf";
break;
case ColorSpace.CS_GRAY:
resource += "GRAY.pf";
break;
case ColorSpace.CS_LINEAR_RGB:
resource += "LINEAR_RGB.pf";
break;
case ColorSpace.CS_PYCC:
resource += "PYCC.pf";
break;
case ColorSpace.CS_sRGB:
resource += "sRGB.pf";
break;
default:
throw new RuntimeException("Unknown color space: " + cs_code);
}
try {
InputStream is = CMMTests.class.getResourceAsStream(resource);
ICC_Profile p = ICC_Profile.getInstance(is);
cs = new ICC_ColorSpace(p);
} catch (IOException e) {
throw new RuntimeException("Unable load profile from resource " + resource, e);
}
}
return cs;
}
use of java.awt.color.ColorSpace in project jdk8u_jdk by JetBrains.
the class RGBColorConvertTest method main.
public static void main(String[] args) {
BufferedImage src = new BufferedImage(256, 3, BufferedImage.TYPE_INT_RGB);
BufferedImage dst = new BufferedImage(256, 3, BufferedImage.TYPE_INT_RGB);
for (int i = 0; i < 256; i++) {
src.setRGB(i, 0, i);
src.setRGB(i, 1, i << 8);
src.setRGB(i, 2, i << 16);
}
ColorSpace srcColorSpace = src.getColorModel().getColorSpace();
ColorConvertOp op = new ColorConvertOp(srcColorSpace, srcColorSpace, null);
op.filter(src, dst);
int errCount = 0;
for (int i = 0; i < src.getWidth(); i++) {
for (int j = 0; j < src.getHeight(); j++) {
int scol = src.getRGB(i, j);
int dcol = dst.getRGB(i, j);
if (scol != dcol) {
System.err.println("(" + i + "," + j + ") : " + Integer.toHexString(scol) + "!=" + Integer.toHexString(dcol));
errCount++;
}
}
}
if (errCount > 0) {
throw new RuntimeException(errCount + " pixels are changed by " + "transform between the same ICC color " + "spaces");
}
}
use of java.awt.color.ColorSpace in project jdk8u_jdk by JetBrains.
the class ITSDataType method main.
public static void main(String[] args) {
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
int[] bankIndices = new int[] { 1 };
int[] bandOffsets = new int[] { 0 };
// test createBanded()
for (int i = 0; i < dataTypes.length; i++) {
int dataType = dataTypes[i];
try {
ImageTypeSpecifier.createBanded(cs, bankIndices, bandOffsets, dataType, false, false);
} catch (IllegalArgumentException e) {
throw new RuntimeException("createBanded() test failed for " + "dataType = " + dataType);
}
}
// test createInterleaved()
for (int i = 0; i < dataTypes.length; i++) {
int dataType = dataTypes[i];
try {
ImageTypeSpecifier.createInterleaved(cs, bandOffsets, dataType, false, false);
} catch (IllegalArgumentException e) {
throw new RuntimeException("createInterleaved() test failed " + "for dataType = " + dataType);
}
}
}
Aggregations