public void putRegion( int viewWidth, int viewHeight, int regWidth, int regHeight, int regOffX, int regOffY, int[] regBuffer) { if (image == null) { setPreferredSize(new Dimension(viewWidth, viewHeight)); imageBuffer = new int[viewWidth * viewHeight]; imageSource = new MemoryImageSource(viewWidth, viewHeight, imageBuffer, 0, viewWidth); imageSource.setAnimated(true); image = createImage(imageSource); } int destIndex = regOffX + regOffY * viewWidth; int srcIndex = 0; int extraRowGap = viewWidth - regWidth; for (int j = 0; j < regHeight; j++, destIndex += extraRowGap) for (int i = 0; i < regWidth; i++, srcIndex++, destIndex++) imageBuffer[destIndex] = regBuffer[srcIndex]; imageSource.newPixels(regOffX, regOffY, regWidth, regHeight); repaint(regOffX, regOffY, regWidth, regHeight); }
/** Processes the data and renders it to a component */ public synchronized int process(Buffer buffer) { if (component == null) return BUFFER_PROCESSED_FAILED; Format inf = buffer.getFormat(); if (inf == null) return BUFFER_PROCESSED_FAILED; if (inf != inputFormat || !buffer.getFormat().equals(inputFormat)) { if (setInputFormat(inf) != null) return BUFFER_PROCESSED_FAILED; } Object data = buffer.getData(); if (!(data instanceof int[])) return BUFFER_PROCESSED_FAILED; if (lastBuffer != buffer) { lastBuffer = buffer; newImage(buffer); } sourceImage.newPixels(0, 0, inWidth, inHeight); Graphics g = component.getGraphics(); if (g != null) { if (reqBounds == null) { bounds = component.getBounds(); bounds.x = 0; bounds.y = 0; } else bounds = reqBounds; g.drawImage( destImage, bounds.x, bounds.y, bounds.width, bounds.height, 0, 0, inWidth, inHeight, component); } return BUFFER_PROCESSED_OK; }