Java Code Examples for processing.core.PImage#updatePixels()

The following examples show how to use processing.core.PImage#updatePixels() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConstellationPointMarker.java    From constellation with Apache License 2.0 6 votes vote down vote up
private void createImages() {
    try {
        final File templateImageFile = ConstellationInstalledFileLocator.locate(
                "modules/ext/data/" + TEMPLATE_IMAGE_PATH,
                "au.gov.asd.tac.constellation.views.mapview",
                false, ConstellationPointMarker.class.getProtectionDomain());
        final BufferedImage templateImage = ImageIO.read(templateImageFile);
        TEMPLATE_IMAGE = new PImage(templateImage.getWidth(), templateImage.getHeight(), PConstants.ARGB);
        TEMPLATE_IMAGE.loadPixels();
        templateImage.getRGB(0, 0, TEMPLATE_IMAGE.width, TEMPLATE_IMAGE.height, TEMPLATE_IMAGE.pixels, 0, TEMPLATE_IMAGE.width);
        TEMPLATE_IMAGE.updatePixels();

        POINT_X_OFFSET = TEMPLATE_IMAGE.width / 2;
        POINT_Y_OFFSET = TEMPLATE_IMAGE.height;
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example 2
Source File: Utility.java    From Project-16x16 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Scales a PImage object by a given amount.
 *
 * @param pBuffer Image to scale.
 * @param scaling Times to scale.
 * @return new PImage object transformed.
 */
public static PImage scale(PImage pBuffer, int scaling) {
	PImage originalImage = pBuffer;
	PImage tempImage = applet.createImage(PApplet.parseInt(originalImage.width * scaling),
			PApplet.parseInt(originalImage.height * scaling), PConstants.ARGB);
	tempImage.loadPixels();
	originalImage.loadPixels();
	for (int i = 0; i < originalImage.pixels.length; i++) {
		tempImage.pixels[i * scaling] = originalImage.pixels[i];
		tempImage.pixels[i * scaling + 1] = originalImage.pixels[i];
		tempImage.pixels[i * scaling + originalImage.width] = originalImage.pixels[i];
		tempImage.pixels[i * scaling + originalImage.width + 1] = originalImage.pixels[i];
	}
	tempImage.updatePixels();
	return pg(tempImage).get();
}
 
Example 3
Source File: DwUtils.java    From PixelFlow with MIT License 6 votes vote down vote up
static public PImage createSprite(PApplet papplet, int size, float exp1, float exp2, float mult){
  PImage pimg = papplet.createImage(size, size, PConstants.ARGB);
  pimg.loadPixels();
  for(int y = 0; y < size; y++){
    for(int x = 0; x < size; x++){
      int pid = y * size + x;
      
      float xn = ((x + 0.5f) / (float)size) * 2f - 1f;
      float yn = ((y + 0.5f) / (float)size) * 2f - 1f;
      float dd = (float) Math.sqrt(xn*xn + yn*yn);
      
      dd = clamp(dd, 0, 1);
      dd = (float) Math.pow(dd, exp1);
      dd = 1.0f - dd;
      dd = (float) Math.pow(dd, exp2);
      dd *= mult;
      dd = clamp(dd, 0, 1);
      pimg.pixels[pid] = ((int)(dd * 255)) << 24 | 0x00FFFFFF;
    }
  }
  pimg.updatePixels();
  return pimg;
}
 
Example 4
Source File: ImageUtils.java    From PapARt with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void createAnaglyph(PImage imgL, PImage imgR, PImage imgOut) {
    imgL.loadPixels();
    imgR.loadPixels();
    imgOut.loadPixels();
    int[] pL = imgL.pixels;
    int[] pR = imgR.pixels;
    int[] pO = imgOut.pixels;
    for (int i = 0; i < pL.length; i++) {
        pO[i] = (pR[i] >> 16) << 16 | (pL[i] >> 8) & 255 << 8 | pL[i] & 255;
        //            pO[i] = pL[i];
    }
    imgOut.updatePixels();
    //        imgL.updatePixels();
}
 
Example 5
Source File: ImageUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static PImage getReversePImageFast( PImage image ) {
	PImage reverse = new PImage( image.width, image.height );
	reverse.loadPixels();
	for (int i = 0; i < image.width; i++) {
		for (int j = 0; j < image.height; j++) { 
			reverse.pixels[j*image.width+i] = image.pixels[(image.width - i - 1) + j*image.width]; // Reversing x to mirror the image
		}
	}
	reverse.updatePixels();
	return reverse;
}
 
Example 6
Source File: ImageUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static PImage bufferedToPImage(BufferedImage bimg) {
	try {
		PImage img = new PImage(bimg.getWidth(), bimg.getHeight(), PConstants.ARGB);
		bimg.getRGB(0, 0, img.width, img.height, img.pixels, 0, img.width);
		img.updatePixels();
		return img;
	}
	catch(Exception e) {
		System.err.println("Can't create image from buffer");
		e.printStackTrace();
	}
	return null;
}
 
Example 7
Source File: ImageUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static void copyBufferedToPImagePixels(BufferedImage buffImg, PImage pimg) {
		// get pixels from BufferedImage
//		int pixels[] = ((DataBufferInt) buffImg.getRaster().getDataBuffer()).getData();
		// Copy array to PImage and update
		buffImg.getRGB(0, 0, pimg.width, pimg.height, pimg.pixels, 0, pimg.width);
		pimg.updatePixels();
	}
 
Example 8
Source File: Spout.java    From haxademic with MIT License 5 votes vote down vote up
/**
 * Receive into an image texture.
 * 
 * @param img - the image to be used and returned
 * @return true if a texture was returned
 */
public PImage receiveTexture(PImage img) {

	// If no sender, keep looking
	if(!bReceiverInitialized) {
		createReceiver("");
		return img;
	}

	boolean bInvert = false; // default for this function
	if(invertMode >= 0) bInvert = (invertMode == 1);

	if(dim[0] != img.width || dim[1] != img.height && dim[0] > 0 && dim[1] > 0) {
		img.resize(dim[0], dim[1]);
	}
	else {
		Texture tex = pgl.getTexture(img);
		if(!JNISpout.receiveTexture(dim, tex.glName, tex.glTarget, bInvert, spoutPtr)) {
			JNISpout.releaseReceiver(spoutPtr);
			senderName = "";
			img.updatePixels();
			bReceiverInitialized = false;
		}
	}    

	return img;
}
 
Example 9
Source File: Spout.java    From haxademic with MIT License 5 votes vote down vote up
/**
 * Receive into image pixels.
 * 
 * @param img - the image to be used and returned
 * @return true if pixels were returned
 */
public PImage receivePixels(PImage img) {

	// If no sender, keep looking
	if(!bReceiverInitialized) {
		createReceiver("");
		return img;
	}

	boolean bInvert = false; // default for this function
	if(invertMode >= 0) bInvert = (invertMode == 1);

	if(dim[0] != img.width || dim[1] != img.height && dim[0] > 0 && dim[1] > 0) {
		img.resize(dim[0], dim[1]);
	}
	else {
		img.loadPixels();
		if(!JNISpout.receivePixels(dim, img.pixels, spoutPtr)) {
			JNISpout.releaseReceiver(spoutPtr);
			senderName = "";
			bReceiverInitialized = false;
		}
	    img.updatePixels();
	}

	return img;
}
 
Example 10
Source File: Utility.java    From Project-16x16 with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Blurs the input PImage, producing a copy [the orignal is untouched] (much
 * faster than using {@link processing.core.PApplet#filter(int) filter(BLUR)}).
 * 
 * @param in         source PImage
 * @param radius     radius of blur effect
 * @param iterations the number of times to perform the blur; i.e. to increase
 *                   quality
 * @return PImage blurred PImage object
 */
public static PImage blurImage(PImage in, int radius, int iterations) {
	PImage out = new PImage(in.width, in.height);
	out.loadPixels();
	out.pixels = blur(in.pixels, in.width, in.height, radius, iterations);
	out.updatePixels();
	return out;
}