Mercurial > hg > Members > you > TreeVNC
view src/test/BlockingUpdateRectangle.java @ 34:32b266967c2c
delete notfound window
author | Yu Taninari <you@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 18 Apr 2012 19:14:17 +0900 |
parents | 74195a7722be |
children |
line wrap: on
line source
package test; import java.io.IOException; import java.nio.ByteBuffer; import java.util.LinkedList; import java.util.zip.Deflater; import org.junit.Test; import treeVnc.RfbProto; public class BlockingUpdateRectangle { int INFLATE_BUFSIZE = 1024*100; @Test public void test() { ByteBuffer input = ByteBuffer.allocate(4096); createUpdateRectangle(input); RfbProto rfb = new RfbProto(); LinkedList<ByteBuffer> output = rfb.BlockingUpdateRectangle(input); fail("Not yet implemented"); } private void createUpdateRectangle(ByteBuffer input) { int x = 512; int y = 512; int count = 1; int bytePixel = 3; int mode = 0; byte[] palette = new byte[count*bytePixel]; input.put((byte)mode); for(byte b: palette) input.put(b); int[] pixel = new int[x*y*bytePixel]; for(int i = 0 ; i < x*y ; i+=bytePixel) { } int[] dst = new int[x*y*bytePixel]; for(int i = 0 ; i < x*y ; i++) { dst[i] = ((pixel[i * 3 + 2] & 0xFF) << 16 | (pixel[i * 3 + 1] & 0xFF) << 8 | (pixel[i * 3] & 0xFF)); } } private LinkedList<ByteBuffer> splitBuffer(LinkedList<ByteBuffer> input) { LinkedList<ByteBuffer> output = new LinkedList<ByteBuffer>(); int high = rectH / 4; //System.out.println(INFLATE_BUFSIZE * (input.size() - 1)+ input.getLast().limit()); int dataLen = 64*64; int temp = 0; int tempDataLen = 0; ByteBuffer buf1 = ByteBuffer.allocate(INFLATE_BUFSIZE); ByteBuffer buf2 = ByteBuffer.allocate(INFLATE_BUFSIZE); buf2 = input.poll(); for (int ty = rectY; ty < rectY + rectH; ty += 64) { int th = Math.min(rectY + rectH - ty, 64); for (int tx = rectX; tx < rectX + rectW; tx += 64) { int tw = Math.min(rectX + rectW - tx, 64); if(buf2.limit()-buf2.position() >= dataLen) { buf2.get(buf1.array(),0,dataLen); temp += dataLen; buf2.position(temp); } else { buf2.get(buf1.array(),0,buf2.remaining()); temp = th*tw - buf2.remaining(); buf2 = input.poll(); buf2.get(buf1.array(), 0, temp); buf2.position(temp); } } } return output; } private void splitData(LinkedList<ByteBuffer> input, ByteBuffer header) throws IOException { // System.out.println(test++); LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>(); LinkedList<ByteBuffer> buf = splitBuffer(input); for (int i = 1; i < 5; i++) { LinkedList<ByteBuffer> tempBuf = new LinkedList<ByteBuffer>(); while (buf.peek() != null) { tempBuf.addLast(buf.poll()); } Deflater nDeflater = deflater; int len2 = zip(nDeflater, tempBuf, 0, bufs); ByteBuffer blen = ByteBuffer.allocate(4); blen.putInt(len2); blen.flip(); bufs.addFirst(blen); // ByteBuffer tempheader = createHeader(header,i); // bufs.addFirst(tempheader); bufs.addFirst(header); multicastqueue.put(bufs); buf.remove(); } } private ByteBuffer createHeader(ByteBuffer header, int count) { ByteBuffer tempheader = header; int h = tempheader.getShort(10); int y = tempheader.getShort(6); int high = h / 4; if (count != 4) y = y + high * count; else y = y + high * count + (h % 4); tempheader.put(10, (byte) high); tempheader.put(6, (byte) y); return tempheader; } }