Mercurial > hg > Applications > TightVNC_orginal
diff src/main/java/com/glavsoft/drawing/Renderer.java @ 30:0c08cdc4b572
Create AbstractRenderer.java
and
Renderer change to Interface
author | one |
---|---|
date | Sat, 01 Sep 2012 20:33:48 +0900 |
parents | 4689cc86d6cb |
children | f70008073a03 |
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/drawing/Renderer.java Sat Sep 01 20:08:03 2012 +0900 +++ b/src/main/java/com/glavsoft/drawing/Renderer.java Sat Sep 01 20:33:48 2012 +0900 @@ -36,293 +36,53 @@ * * @author dime @ tightvnc.com */ -public abstract class Renderer { - - protected Reader reader; - - public abstract void drawJpegImage(byte[] bytes, int offset, - int jpegBufferLength, FramebufferUpdateRectangle rect); +public interface Renderer { - protected int width; - protected int height; - protected int bytesPerPixel; - protected int bytesPerPixelSignificant; - protected int[] pixels; - protected SoftCursor cursor; - protected PixelFormat pixelFormat; - private ColorDecoder colorDecoder; - - protected void init(Reader reader, int width, int height, PixelFormat pixelFormat) { - this.reader = reader; - this.width = width; - this.height = height; - initPixelFormat(pixelFormat); - pixels = new int[width * height]; - Arrays.fill(pixels, 0); - } + void copyRect(int srcX, int srcY, FramebufferUpdateRectangle rect); - public synchronized void initPixelFormat(PixelFormat pixelFormat) { - this.pixelFormat = pixelFormat; - bytesPerPixel = pixelFormat.bitsPerPixel / 8; - bytesPerPixelSignificant = - 24 == pixelFormat.depth && 32 == pixelFormat.bitsPerPixel ? 3 : bytesPerPixel; - colorDecoder = new ColorDecoder(pixelFormat); - } + int readPixelColor(Reader reader) throws TransportException; - /** - * Draw byte array bitmap data - * - * @param bytes bitmap data - * @param x bitmap x position - * @param y bitmap y position - * @param width bitmap width - * @param height bitmap height - */ - public void drawBytes(byte[] bytes, int x, int y, int width, int height) { - int i = 0; - for (int ly = y; ly < y + height; ++ly) { - int end = ly * this.width + x + width; - for (int pixelsOffset = ly * this.width + x; pixelsOffset < end; ++pixelsOffset) { - pixels[pixelsOffset] = getPixelColor(bytes, i); - i += bytesPerPixel; - } - } - } + void fillRect(int i, int tileX, int tileY, int tileWidth, int tileHeight); + + int getBytesPerPixel(); - /** - * Draw byte array bitmap data (for ZRLE) - */ - public synchronized int drawCompactBytes(byte[] bytes, int offset, int x, int y, int width, int height) { - int i = offset; - for (int ly = y; ly < y + height; ++ly) { - int end = ly * this.width + x + width; - for (int pixelsOffset = ly * this.width + x; pixelsOffset < end; ++pixelsOffset) { - pixels[pixelsOffset] = getCompactPixelColor(bytes, i); - i += bytesPerPixelSignificant; - } - } - return i - offset; - } + void drawBytes(byte[] bytes, int x, int y, int width, int height); - /** - * Draw int (colors) array bitmap data (for ZRLE) - */ - public synchronized void drawColoredBitmap(int[] colors, int x, int y, int width, int height) { - int i = 0; - for (int ly = y; ly < y + height; ++ly) { - int end = ly * this.width + x + width; - for (int pixelsOffset = ly * this.width + x; pixelsOffset < end; ++pixelsOffset) { - pixels[pixelsOffset] = colors[i++]; - } - } - } + int getPixelColor(byte[] buffer, int i); + + void createCursor(int[] cursorPixels, FramebufferUpdateRectangle rect) throws TransportException; - /** - * Draw byte array bitmap data (for Tight) - */ - public synchronized int drawTightBytes(byte[] bytes, int offset, int x, int y, int width, int height) { - int i = offset; - for (int ly = y; ly < y + height; ++ly) { - int end = ly * this.width + x + width; - for (int pixelsOffset = ly * this.width + x; pixelsOffset < end; ++pixelsOffset) { - pixels[pixelsOffset] = colorDecoder.getTightColor(bytes, i); - i += bytesPerPixelSignificant; - } - } - return i - offset; - } + void fillRect(int color, FramebufferUpdateRectangle rect); - /** - * Draw byte array bitmap data (from array with plain RGB color components. Assumed: rrrrrrrr gggggggg bbbbbbbb) - */ - public synchronized void drawUncaliberedRGBLine(byte[] bytes, int x, int y, int width) { - int end = y * this.width + x + width; - for (int i=3, pixelsOffset = y * this.width + x; pixelsOffset < end; ++pixelsOffset) { - pixels[pixelsOffset] = -// (0xff & bytes[i++]) << 16 | -// (0xff & bytes[i++]) << 8 | -// 0xff & bytes[i++]; - (0xff & 255 * (colorDecoder.redMax & bytes[i++]) / colorDecoder.redMax) << 16 | - (0xff & 255 * (colorDecoder.greenMax & bytes[i++]) / colorDecoder.greenMax) << 8 | - 0xff & 255 * (colorDecoder.blueMax & bytes[i++]) / colorDecoder.blueMax; - } - } + int getBytesPerPixelSignificant(); - /** - * Draw paletted byte array bitmap data - * - * @param buffer bitmap data - * @param rect bitmap location and dimensions - * @param palette colour palette - */ - public synchronized void drawBytesWithPalette(byte[] buffer, FramebufferUpdateRectangle rect, - int[] palette) { - // 2 colors - if (palette.length == 2) { - int dx, dy, n; - int i = rect.y * this.width + rect.x; - int rowBytes = (rect.width + 7) / 8; - byte b; + int readTightPixelColor(Reader reader) throws TransportException; - for (dy = 0; dy < rect.height; dy++) { - for (dx = 0; dx < rect.width / 8; dx++) { - b = buffer[dy * rowBytes + dx]; - for (n = 7; n >= 0; n--) { - pixels[i++] = palette[b >> n & 1]; - } - } - for (n = 7; n >= 8 - rect.width % 8; n--) { - pixels[i++] = palette[buffer[dy * rowBytes + dx] >> n & 1]; - } - i += this.width- rect.width; - } - } else { - // 3..255 colors (assuming bytesPixel == 4). - int i = 0; - for (int ly = rect.y; ly < rect.y + rect.height; ++ly) { - for (int lx = rect.x; lx < rect.x + rect.width; ++lx) { - int pixelsOffset = ly * this.width + lx; - pixels[pixelsOffset] = palette[buffer[i++] & 0xFF]; - } - } - } + int drawTightBytes(byte[] buffer, int i, int x, int y, int width, + int height); - } + void drawBytesWithPalette(byte[] buffer, FramebufferUpdateRectangle rect, + int[] palette); - /** - * Copy rectangle region from one position to another. Regions may be overlapped. - * - * @param srcX source rectangle x position - * @param srcY source rectangle y position - * @param dstRect destination rectangle - */ - public synchronized void copyRect(int srcX, int srcY, FramebufferUpdateRectangle dstRect) { - int startSrcY, endSrcY, dstY, deltaY; - if (srcY > dstRect.y) { - startSrcY = srcY; - endSrcY = srcY + dstRect.height; - dstY = dstRect.y; - deltaY = +1; - } else { - startSrcY = srcY + dstRect.height - 1; - endSrcY = srcY -1; - dstY = dstRect.y + dstRect.height - 1; - deltaY = -1; - } - for (int y = startSrcY; y != endSrcY; y += deltaY) { - System.arraycopy(pixels, y * width + srcX, - pixels, dstY * width + dstRect.x, dstRect.width); - dstY += deltaY; - } - } + ColorDecoder getColorDecoder(); - /** - * Fill rectangle region with specified colour - * - * @param color colour to fill with - * @param rect rectangle region posions and dimensions - */ - public void fillRect(int color, FramebufferUpdateRectangle rect) { - fillRect(color, rect.x, rect.y, rect.width, rect.height); - } + void drawUncaliberedRGBLine(byte[] thisRow, int x, int i, int width); - /** - * Fill rectangle region with specified colour - * - * @param color colour to fill with - * @param x rectangle x position - * @param y rectangle y position - * @param width rectangle width - * @param height rectangle height - */ - public synchronized void fillRect(int color, int x, int y, int width, int height) { - int sy = y * this.width + x; - int ey = sy + height * this.width; - for (int i = sy; i < ey; i += this.width) { - Arrays.fill(pixels, i, i + width, color); - } - } + void drawJpegImage(byte[] bytes, int i, int jpegBufferLength, + FramebufferUpdateRectangle rect); - /** - * Reads color bytes (PIXEL) from reader, returns int combined RGB - * value consisting of the red component in bits 16-23, the green component - * in bits 8-15, and the blue component in bits 0-7. May be used directly for - * creation awt.Color object - */ - public int readPixelColor(Reader reader) throws TransportException { - return colorDecoder.readColor(reader); - } - - public int readTightPixelColor(Reader reader) throws TransportException { - return colorDecoder.readTightColor(reader); - } - - public ColorDecoder getColorDecoder() { - return colorDecoder; - } + int getCompactPixelColor(byte[] bytes, int index); - public int getCompactPixelColor(byte[] bytes, int offset) { - return colorDecoder.getCompactColor(bytes, offset); - } - - public int getPixelColor(byte[] bytes, int offset) { - return colorDecoder.getColor(bytes, offset); - } - - public int getBytesPerPixel() { - return bytesPerPixel; - } - - public int getBytesPerPixelSignificant() { - return bytesPerPixelSignificant; - } - - public void fillColorBitmapWithColor(int[] bitmapData, int decodedOffset, int rlength, int color) { - while (rlength-- > 0) { - bitmapData[decodedOffset++] = color; - } - } + void fillColorBitmapWithColor(int[] decodedBitmap, int decodedOffset, + int rlength, int color); - /** - * Width of rendered image - * - * @return width - */ - public int getWidth() { - return width; - } - - /** - * Height of rendered image - * - * @return height - */ - public int getHeight() { - return height; - } + void drawColoredBitmap(int[] decodedBitmap, int tileX, int tileY, + int tileWidth, int tileHeight); - /** - * Read and decode cursor image - * - * @param rect new cursor hot point position and cursor dimensions - * @throws TransportException - */ - public void createCursor(int[] cursorPixels, FramebufferUpdateRectangle rect) - throws TransportException { - synchronized (cursor) { - cursor.createCursor(cursorPixels, rect.x, rect.y, rect.width, rect.height); - } - } + int drawCompactBytes(byte[] bytes, int offset, int tileX, int tileY, + int tileWidth, int tileHeight); - /** - * Read and decode new cursor position - * - * @param rect cursor position - */ - public void decodeCursorPosition(FramebufferUpdateRectangle rect) { - synchronized (cursor) { - cursor.updatePosition(rect.x, rect.y); - } - } + void decodeCursorPosition(FramebufferUpdateRectangle rect); + } \ No newline at end of file