use of org.eclipse.swt.graphics.PaletteData in project tdi-studio-se by Talend.
the class InsertionIndicator method addListeners.
/**
* DOC amaumont Comment method "addListeners".
*/
private void addListeners() {
Listener paintListener = new Listener() {
public void handleEvent(Event event) {
Composite composite = (Composite) event.widget;
Rectangle bounds = composite.getBounds();
// //////////////////////////////////////////////////////////
// draw image filled with transparent pixels
RGB transparentColor = new RGB(0, 255, 0);
PaletteData paletteData = new PaletteData(new RGB[] { transparentColor });
ImageData imageData = new ImageData(bounds.width, bounds.height, 1, paletteData);
int transparentPixelValue = imageData.palette.getPixel(transparentColor);
imageData.transparentPixel = transparentPixelValue;
GC gc = event.gc;
final Image image = new Image(gc.getDevice(), imageData);
gc.drawImage(image, 0, 0);
image.dispose();
// ////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////
// draw left arrow
int yCenter = bounds.height / 2;
int widthExternalArrow = 10;
gc.setBackground(colorIndicator);
gc.setForeground(colorIndicator);
if (composite == leftArrowDraggingIndicator) {
// external left arrow
Point leftCrossPoint = new Point(widthExternalArrow, yCenter);
gc.fillPolygon(new int[] { 0, 0, leftCrossPoint.x, leftCrossPoint.y, 0, bounds.height });
gc.drawLine(leftCrossPoint.x, leftCrossPoint.y, bounds.width, leftCrossPoint.y);
} else {
// external right arrow
Point rightCrossPoint = new Point(bounds.width - widthExternalArrow, yCenter);
gc.fillPolygon(new int[] { bounds.width, 0, rightCrossPoint.x, rightCrossPoint.y, bounds.width, bounds.height });
gc.drawLine(rightCrossPoint.x, rightCrossPoint.y, -bounds.width, rightCrossPoint.y);
}
}
};
leftArrowDraggingIndicator.addListener(SWT.Paint, paintListener);
rightArrowDraggingIndicator.addListener(SWT.Paint, paintListener);
}
use of org.eclipse.swt.graphics.PaletteData in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method createRawInsertModeCaretImage.
private Image createRawInsertModeCaretImage(StyledText styledText) {
PaletteData caretPalette = new PaletteData(new RGB[] { new RGB(0, 0, 0), new RGB(255, 255, 255) });
int width = getCaretWidthPreference();
int widthOffset = width - 1;
// XXX: Filed request to get a caret with auto-height: https://bugs.eclipse.org/bugs/show_bug.cgi?id=118612
ImageData imageData = new ImageData(4 + widthOffset, styledText.getLineHeight(), 1, caretPalette);
Display display = styledText.getDisplay();
Image bracketImage = new Image(display, imageData);
GC gc = new GC(bracketImage);
gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
// NOTE: 0 means width is 1 but with optimized performance
gc.setLineWidth(0);
int height = imageData.height / 3;
// rounded corners.
for (int i = 0; i < width; i++) {
gc.drawLine(i, 0, i, height - 1);
gc.drawLine(i, imageData.height - height, i, imageData.height - 1);
}
gc.dispose();
return bracketImage;
}
use of org.eclipse.swt.graphics.PaletteData in project knime-core by knime.
the class KNIMECTabFolderRenderer method createShadow.
void createShadow(final Display display) {
if (shadowImage != null) {
shadowImage.dispose();
shadowImage = null;
}
ImageData data = new ImageData(60, 60, 32, new PaletteData(0xFF0000, 0xFF00, 0xFF));
Image tmpImage = shadowImage = new Image(display, data);
GC gc = new GC(tmpImage);
if (shadowColor == null) {
shadowColor = gc.getDevice().getSystemColor(SWT.COLOR_GRAY);
}
gc.setBackground(shadowColor);
drawTabBody(gc, new Rectangle(0, 0, 60, 60), SWT.None);
ImageData blured = blur(tmpImage, 5, 25);
shadowImage = new Image(display, blured);
tmpImage.dispose();
}
use of org.eclipse.swt.graphics.PaletteData in project yamcs-studio by yamcs.
the class Colorizer method doColorize.
public void doColorize(ImageData image) {
int[] lineData = new int[image.width];
PaletteData palette = image.palette;
for (int y = 0; y < image.height; y++) {
image.getPixels(0, y, image.width, lineData, 0);
// Analyze each pixel value in the line
for (int x = 0; x < lineData.length; x++) {
int pixelValue = lineData[x];
// Do not set transparent pixel
if (lineData[x] != image.transparentPixel) {
// Get pixel color value if not using direct palette
if (!palette.isDirect) {
pixelValue = palette.getPixel(palette.colors[lineData[x]]);
}
RGB current = palette.getRGB(pixelValue);
if (current.blue == current.green && current.blue == current.red && current.blue < 255) {
Color color = new Color(current.red, current.green, current.blue);
int lum = lum_red_lookup[color.getRed()] + lum_green_lookup[color.getGreen()] + lum_blue_lookup[color.getBlue()];
if (lightness > 0) {
lum = (int) ((double) lum * (100f - lightness) / 100f);
lum += 255f - (100f - lightness) * 255f / 100f;
} else if (lightness < 0) {
lum = (int) (((double) lum * (lightness + 100f)) / 100f);
}
Color final_color = new Color(final_red_lookup[lum], final_green_lookup[lum], final_blue_lookup[lum]);
RGB degraded = new RGB(final_color.getRed(), final_color.getGreen(), final_color.getBlue());
if (palette.isDirect) {
int appliedColor = palette.getPixel(degraded);
image.setPixel(x, y, appliedColor);
} else {
palette.colors[lineData[x]] = degraded;
}
}
}
}
}
}
use of org.eclipse.swt.graphics.PaletteData in project yamcs-studio by yamcs.
the class ImageUtils method oldChangeImageColor2.
// ************************************************************
// Another old method to change image color
// ************************************************************
public static ImageData oldChangeImageColor2(Color color, ImageData originalImageData) {
if (color == null || originalImageData == null || color.getRGB().equals(new RGB(0, 0, 0)))
return originalImageData;
ImageData imageData = ImageUtils.convertToGrayscale(originalImageData);
float[] hsb = new float[3];
java.awt.Color.RGBtoHSB(color.getRGB().red, color.getRGB().green, color.getRGB().blue, hsb);
int[] lineData = new int[imageData.width];
PaletteData palette = imageData.palette;
for (int y = 0; y < imageData.height; y++) {
imageData.getPixels(0, y, imageData.width, lineData, 0);
// Analyze each pixel value in the line
for (int x = 0; x < lineData.length; x++) {
int pixelValue = lineData[x];
// Do not set transparent pixel
if (lineData[x] != imageData.transparentPixel) {
// Get pixel color value if not using direct palette
if (!palette.isDirect) {
pixelValue = palette.getPixel(palette.colors[lineData[x]]);
}
RGB current = palette.getRGB(pixelValue);
if (current.blue == current.green && current.blue == current.red && current.blue < 255) {
float[] pixelHSB = new float[3];
java.awt.Color.RGBtoHSB(current.red, current.green, current.blue, pixelHSB);
int awtRGB = java.awt.Color.HSBtoRGB(hsb[0], hsb[1], 1 - pixelHSB[2]);
java.awt.Color awtColor = new java.awt.Color(awtRGB);
RGB degraded = new RGB(awtColor.getRed(), awtColor.getGreen(), awtColor.getBlue());
if (palette.isDirect) {
int appliedColor = palette.getPixel(degraded);
imageData.setPixel(x, y, appliedColor);
} else {
palette.colors[lineData[x]] = degraded;
}
}
}
}
}
return imageData;
}
Aggregations