public PImage getImpl(int x, int y, int w, int h) { PImage output = new PImage(w, h); output.parent = parent; // oops, the last parameter is the scan size of the *target* buffer // ((BufferedImage) image).getRGB(x, y, w, h, output.pixels, 0, w); WritableRaster raster = ((BufferedImage) (primarySurface ? offscreen : image)).getRaster(); raster.getDataElements(x, y, w, h, output.pixels); return output; }
public void getOverviewShut() { updatePixels(); int[] buffer = new int[pixels.length]; System.arraycopy(pixels, 0, buffer, 0, pixels.length); overviewImage = new PImage(width, height); overviewImage.format = RGB; overviewImage.pixels = buffer; // overviewImage.save("image.tif"); buffer = null; System.out.println("shut for overview"); }
public void preIntroSetup() { try { int bgWidth = env.bgImg.getWidth(env); int bgHeight = env.bgImg.getHeight(env); int[] bgPixels = new int[bgWidth * bgHeight]; for (int i = 0; i < bgPixels.length; i++) if (bgPixels[i] != 0) System.out.print(bgPixels[i]); overlay = new PImage(bgWidth, bgHeight); overlay.format = ARGB; overlay.pixels = bgPixels; runNum = 0; controls.setEnabled(false); /** * get into looping */ afterFirstStreaming = true; /** overview shut */ draw(); /*theCamera.moveToNow(new FVector(0.0f, 0.0f, 1000)); theCamera.lookAtNow(new FVector(0.0f, 1.0f, 0)); */ draw(); ortho(-1500, 800, -800, 800, 1000, 2000); loadPixels(); noStroke(); getOverviewShut(); afterOverviewShot = true; draw(); loop(); /** give the environment the hint to swop the surfaces */ env.addThem(); /** * intro */ theCamera.moveToNow(new FVector(-200.0f, 950.0f, 1000)); theCamera.lookAtNow(new FVector(-200.51917f, 851.8057f, 0)); theCamera.lookAtInter( new FVector(1341.8213f, 757.865f, 0), new Integer(4000), new Integer(3)); Object[] actionObjects = {new FVector(0, 0, -88), new Integer(2000), new Integer(0)}; theCamera.queueAction("lookAtInter", 4000, actionObjects); theCamera.moveToNow(new FVector(-500.51917f, 951.8057f, 200)); theCamera.moveToInter( new FVector(1341.8213f, 857.865f, 200), new Integer(4000), new Integer(3)); Object[] actionObjects2 = { new FVector(0, 800, Camera.maxCameraHeight), new Integer(2000), new Integer(1) }; theCamera.queueAction("moveToInter", 0, actionObjects2); Object[] actionObjects3 = {Boolean.valueOf(true)}; theCamera.queueAction("setControlsEnabled", 3500, actionObjects3); } catch (Exception e) { e.printStackTrace(); env.setErrorDisplay( "Das Applet konnte nicht gestartet werden. Eventuell ist dies ein Speicherproblem. Bitte stoppen sie alle anderen Java-Anwendungen. GGf. muss der Browser neu gestartet werden um den Cache zu leeren."); } }
public void setPImage(PImage node) { if (this._pImage_ != null) { this._pImage_.parent(null); } if (node != null) { if (node.parent() != null) { node.parent().removeChild(node); } node.parent(this); } this._pImage_ = node; }
public Gif(PApplet parent, String filename) { // this creates a fake image so that the first time this // attempts to draw, something happens that's not an exception super(1, 1, ARGB); this.parent = parent; // create the GifDecoder GifDecoder gifDecoder = createDecoder(parent, filename); // fill up the PImage and the delay arrays frames = extractFrames(gifDecoder); delays = extractDelays(gifDecoder); // get the GIFs repeat count repeatSetting = gifDecoder.getLoopCount(); // re-init our PImage with the new size super.init(frames[0].width, frames[0].height, ARGB); jump(0); parent.registerMethod("dispose", this); // and now, make the magic happen runner = new Thread(this); runner.start(); }
public void setup() { size(400, 400); background(255); stroke(0); img = loadImage("http://cseweb.ucsd.edu/~minnes/palmTrees.jpg", "jpg"); img.resize(0, height); image(img, 0, 0); }
public static PImage invert(Matrix H, PImage img, Point dstDimension) { PImage res = new PImage(dstDimension.x, dstDimension.y); // PImage res = new PImage(img.width, img.height); for (int x = 0; x < img.width; x++) { for (int y = 0; y < img.height; y++) { // Point inverse theorique (x0,y0) ? double[][] q_array = {{x}, {y}, {1}}; Matrix P = H.times(new Matrix(q_array)); double x0 = P.get(0, 0) / P.get(2, 0); double y0 = P.get(1, 0) / P.get(2, 0); // S'il est hors de l'image originale, on rend le pixel transparant. if (x0 < 0 || x0 >= img.width || y0 < 0 || y0 >= img.height) res.set(x, y, 0x00000000); else res.set(x, y, img.get((int) x0, (int) y0)); } } return res; }
protected void setImpl(int dx, int dy, int sx, int sy, int sw, int sh, PImage src) { WritableRaster raster = ((BufferedImage) (primarySurface ? offscreen : image)).getRaster(); if ((sx == 0) && (sy == 0) && (sw == src.width) && (sh == src.height)) { raster.setDataElements(dx, dy, src.width, src.height, src.pixels); } else { // TODO Optimize, incredibly inefficient to reallocate this much memory PImage temp = src.get(sx, sy, sw, sh); raster.setDataElements(dx, dy, temp.width, temp.height, temp.pixels); } }
/** Handle renderer-specific image drawing. */ protected void imageImpl( PImage who, float x1, float y1, float x2, float y2, int u1, int v1, int u2, int v2) { // Image not ready yet, or an error if (who.width <= 0 || who.height <= 0) return; if (who.getCache(this) == null) { // System.out.println("making new image cache"); who.setCache(this, new ImageCache(who)); who.updatePixels(); // mark the whole thing for update who.modified = true; } ImageCache cash = (ImageCache) who.getCache(this); // if image previously was tinted, or the color changed // or the image was tinted, and tint is now disabled if ((tint && !cash.tinted) || (tint && (cash.tintedColor != tintColor)) || (!tint && cash.tinted)) { // for tint change, mark all pixels as needing update who.updatePixels(); } if (who.modified) { cash.update(tint, tintColor); who.modified = false; } g2.drawImage( ((ImageCache) who.getCache(this)).image, (int) x1, (int) y1, (int) x2, (int) y2, u1, v1, u2, v2, null); }
// Takes a PImage and compresses it into a JPEG byte stream // Adapted from Dan Shiffman's UDP Sender code public byte[] compressImage(PImage img) { // We need a buffered image to do the JPG encoding BufferedImage bimg = new BufferedImage(img.width, img.height, BufferedImage.TYPE_INT_RGB); img.loadPixels(); bimg.setRGB(0, 0, img.width, img.height, img.pixels, 0, img.width); // Need these output streams to get image as bytes for UDP communication ByteArrayOutputStream baStream = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(baStream); // Turn the BufferedImage into a JPG and put it in the BufferedOutputStream // Requires try/catch try { ImageIO.write(bimg, "jpg", bos); } catch (IOException e) { e.printStackTrace(); } // Get the byte array, which we will send out via UDP! return baStream.toByteArray(); }
public void draw() { Date date = new Date(); // given date Calendar calendar = GregorianCalendar.getInstance(); // creates a new calendar instance calendar.setTime(date); // assigns calendar to given date calendar.get(Calendar.HOUR_OF_DAY); // gets hour in 24h format calendar.get(Calendar.HOUR); // gets hour in 12h format calendar.get(Calendar.MONTH); backgroundImg.resize(0, height); image(backgroundImg, 0, 0); int r = 0; int g = 0; int b = 0; int hour = (calendar.get(Calendar.HOUR_OF_DAY)); int second = (calendar.get(Calendar.SECOND)); switch (second % 5) { case 0: fill(255, 0, 0); break; case 1: fill(0, 255, 0); break; case 2: fill(0, 0, 255); break; case 3: fill(227, 227, 0); break; case 4: fill(227, 0, 227); break; default: fill(0, 227, 227); break; } ellipse(width / 4, height / 6, width / 5, height / 5); }