use of java.awt.image.PixelGrabber in project openchemlib by Actelion.
the class WMFGraphics method drawImage.
@Override
public boolean drawImage(Image image, int leftD, int topD, int rightD, int bottomD, int leftS, int topS, int rightS, int bottomS, Color color, ImageObserver imageobserver) {
restore();
int imagewidth = image.getWidth(imageobserver);
int imageheight = image.getHeight(imageobserver);
int[] pixbuffer = new int[imagewidth * imageheight];
PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, imagewidth, imageheight, pixbuffer, 0, imagewidth);
try {
pixelgrabber.grabPixels();
} catch (InterruptedException _ex) {
return false;
}
if ((pixelgrabber.status() & 0x80) != 0) {
return false;
}
int diffx = rightD - leftD;
int diffy = bottomD - topD;
int sourcediffx = rightS - leftS;
int sourcediffy = bottomS - topS;
int k3 = bottomS;
bottomS = imageheight - topS;
topS = imageheight - k3;
if ((diffx < 0) != (sourcediffx < 0)) {
flipHorizontal(pixbuffer, imagewidth, imageheight);
if (sourcediffx < 0) {
leftS = imagewidth - leftS;
} else {
leftS = imagewidth - rightS;
}
}
if (diffx < 0) {
leftD = rightD;
if (sourcediffx < 0) {
leftS = rightS;
}
diffx = -diffx;
}
if (sourcediffx < 0) {
sourcediffx = -sourcediffx;
}
if ((diffy < 0) != (sourcediffy < 0)) {
flipVertical(pixbuffer, imagewidth, imageheight);
if (sourcediffy < 0) {
topS = imageheight - topS;
} else {
topS = imageheight - bottomS;
}
}
if (diffy < 0) {
topD = bottomD;
if (sourcediffy < 0) {
topS = bottomS;
}
diffy = -diffy;
}
if (sourcediffy < 0) {
sourcediffy = -sourcediffy;
}
int l3 = color.getRGB();
for (int i4 = 0; i4 < pixbuffer.length; i4++) if ((pixbuffer[i4] & 0xff000000) == 0) {
pixbuffer[i4] = l3;
}
wmf.stretchBlt(leftD, topD, diffx, diffy, leftS, topS, sourcediffx, sourcediffy, SRC_COPY, pixbuffer, imagewidth, imageheight);
return true;
}
use of java.awt.image.PixelGrabber in project openchemlib by Actelion.
the class WMFGraphics method drawImage.
@Override
public boolean drawImage(Image image, int leftD, int topD, int rightD, int bottomD, int leftS, int topS, int rightS, int bottomS, ImageObserver imageobserver) {
restore();
int imagewidth = image.getWidth(imageobserver);
int imageheight = image.getHeight(imageobserver);
int[] pixarray = new int[imagewidth * imageheight];
PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, imagewidth, imageheight, pixarray, 0, imagewidth);
try {
pixelgrabber.grabPixels();
} catch (InterruptedException _ex) {
return false;
}
if ((pixelgrabber.status() & 0x80) != 0) {
return false;
}
int ddiffx = rightD - leftD;
int ddiffy = bottomD - topD;
int sdiffx = rightS - leftS;
int sdiffy = bottomS - topS;
bottomS = imageheight - topS;
topS = imageheight - bottomS;
if ((ddiffx < 0) != (sdiffx < 0)) {
flipHorizontal(pixarray, imagewidth, imageheight);
if (sdiffx < 0) {
leftS = imagewidth - leftS;
} else {
leftS = imagewidth - rightS;
}
}
if (ddiffx < 0) {
leftD = rightD;
if (sdiffx < 0) {
leftS = rightS;
}
ddiffx = -ddiffx;
}
if (sdiffx < 0) {
sdiffx = -sdiffx;
}
if ((ddiffy < 0) != (sdiffy < 0)) {
flipVertical(pixarray, imagewidth, imageheight);
if (sdiffy < 0) {
topS = imageheight - topS;
} else {
topS = imageheight - bottomS;
}
}
if (ddiffy < 0) {
topD = bottomD;
if (sdiffy < 0) {
topS = bottomS;
}
ddiffy = -ddiffy;
}
if (sdiffy < 0) {
sdiffy = -sdiffy;
}
int[] ai1 = new int[pixarray.length];
boolean flag = false;
for (int l3 = 0; l3 < pixarray.length; l3++) if ((pixarray[l3] & 0xff000000) == 0) {
ai1[l3] = -1;
pixarray[l3] = 0;
flag = true;
} else {
ai1[l3] = 0;
}
if (flag) {
wmf.stretchBlt(leftD, topD, ddiffx, ddiffy, leftS, topS, sdiffx, sdiffy, SRC_AND, ai1, imagewidth, imageheight);
wmf.stretchBlt(leftD, topD, ddiffx, ddiffy, leftS, topS, sdiffx, sdiffy, SRC_PAINT, pixarray, imagewidth, imageheight);
} else {
wmf.stretchBlt(leftD, topD, ddiffx, ddiffy, leftS, topS, sdiffx, sdiffy, SRC_COPY, pixarray, imagewidth, imageheight);
}
return true;
}
use of java.awt.image.PixelGrabber in project gephi by gephi.
the class JImagePanel method setPreferredBackground.
protected void setPreferredBackground() {
int[] pixels = new int[1];
PixelGrabber pg = null;
switch(imageAlign) {
case (SwingConstants.TOP):
pg = new PixelGrabber(image, 0, image.getHeight(null) - 1, 1, 1, pixels, 0, 1);
break;
case (SwingConstants.BOTTOM):
pg = new PixelGrabber(image, 0, 0, 1, 1, pixels, 0, 1);
break;
default:
pg = new PixelGrabber(image, 0, image.getHeight(null) - 1, 1, 1, pixels, 0, 1);
}
try {
if ((pg != null) && pg.grabPixels()) {
setBackground(new Color(pixels[0]));
}
} catch (InterruptedException e) {
}
}
use of java.awt.image.PixelGrabber in project gephi by gephi.
the class UIUtils method getGTKProfilerResultsBackground.
private static Color getGTKProfilerResultsBackground() {
int[] pixels = new int[1];
pixels[0] = -1;
// Prepare textarea to grab the color from
JTextArea textArea = new JTextArea();
textArea.setSize(new Dimension(10, 10));
textArea.doLayout();
// Print the textarea to an image
Image image = new BufferedImage(textArea.getSize().width, textArea.getSize().height, BufferedImage.TYPE_INT_RGB);
textArea.printAll(image.getGraphics());
// Grab appropriate pixels to get the color
PixelGrabber pixelGrabber = new PixelGrabber(image, 5, 5, 1, 1, pixels, 0, 1);
try {
pixelGrabber.grabPixels();
if (pixels[0] == -1) {
// System background not customized
return Color.WHITE;
}
} catch (InterruptedException e) {
return getNonGTKProfilerResultsBackground();
}
return pixels[0] != -1 ? new Color(pixels[0]) : getNonGTKProfilerResultsBackground();
}
use of java.awt.image.PixelGrabber in project jivejdon by banq.
the class ImageUtils method hasAlpha.
/**
* Determines if the image has transparent pixels.
*
* @param image The image to check for transparent pixel.s
* @return <code>true</code> of <code>false</code>, according to the result
*/
public static boolean hasAlpha(Image image) {
try {
PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
pg.grabPixels();
return pg.getColorModel().hasAlpha();
} catch (InterruptedException e) {
return false;
}
}
Aggregations