Commit 3a6bb33e authored by Thomas Krex's avatar Thomas Krex

paint funktioniert, aber langsam

parent 33a8627e
......@@ -5,6 +5,7 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
......@@ -13,6 +14,7 @@ public class MySurfaceView extends SurfaceView implements
private final SurfaceHolder sh;
private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
Canvas canvas;
public MySurfaceView(Context context) {
super(context);
......@@ -44,8 +46,10 @@ public class MySurfaceView extends SurfaceView implements
}
public void drawRec() {
Canvas canvas = sh.lockCanvas();
public void drawRec(int x, int y, int w, int h, Paint p) {
canvas = sh.lockCanvas();
canvas.drawRect(new Rect(x, y, x + w, y + h), p);
sh.unlockCanvasAndPost(canvas);
}
......
......@@ -34,7 +34,6 @@ public class PlayerActivity extends Activity {
fileName = getIntent().getStringExtra(DownloadService.FILE_NAME);
filePath = getIntent().getStringExtra(DownloadService.FILE_PATH);
GraphicsContext graphicsContext = new GraphicsContext(imgV);
File file = new File(filePath + "/" + fileName + ".ttt");
playButton = (Button) findViewById(R.id.play_btn);
stopButton = (Button) findViewById(R.id.stop_btn);
......@@ -52,33 +51,16 @@ public class PlayerActivity extends Activity {
@Override
public void onClick(View v) {
recording.stop();
;
recording.pause();
}
});
// bitmap = Bitmap.createBitmap(1280, 768, Config.ARGB_8888);
// final int[] pixels = new int[1280 * 768];
// for (int i = 10 * 1280; i < 11 * 1280; i++) {
// pixels[i] = Color.BLUE;
//
// }
// imgV.setImageBitmap(bitmap);
//
// Thread t = new Thread(new Runnable() {
//
// @Override
// public void run() {
// handleUpdatedPixels(pixels, 0, 10, 1280, 1);
//
// }
// });
// t.start();
try {
recording = new Recording(file, graphicsContext);
recording = new Recording(file);
GraphicsContext graphicsContext = new GraphicsContext(imgV,
recording);
} catch (IOException e) {
// TODO Auto-generated catch block
......@@ -86,12 +68,4 @@ public class PlayerActivity extends Activity {
}
}
public void handleUpdatedPixels(int[] pixels, int x, int y, int w, int h) {
// System.out.println("handleUpdatedPixels("+x+","+y+","+w+","+h+")");
// drawingScreen.updateBitmap(pixels,prefs.framebufferWidth,
// prefs.framebufferHeight);
bitmap.setPixels(pixels, x + y * 1280, 1280, x, y, w, h);
imgV.setImageBitmap(bitmap);
}
}
......@@ -34,7 +34,6 @@ import java.util.Random;
import tttclient.ttt.Constants;
import tttclient.ttt.GraphicsContext;
import android.graphics.Color;
import android.util.Log;
public class HextileMessage extends FramebufferUpdateMessage {
......@@ -87,19 +86,9 @@ public class HextileMessage extends FramebufferUpdateMessage {
try {
byteArrayInputStream.reset();
// if(TTT.debug){
// int intensity = 255*getTimestamp()/(100*60000);
// graphicsContext.memGraphics.setColor(new
// Color(intensity,intensity,intensity));
// graphicsContext.memGraphics.fillRect(x, y, width, height);
// }else
handleHextileRect(graphicsContext, is, null, x, y, width, height,
updateFlag);
// if(TTT.debug){
// graphicsContext.memGraphics.setColor(new
// Color(random.nextInt(256),random.nextInt(256),random.nextInt(256)));
// graphicsContext.memGraphics.fillRect(x, y, width, height);
// }
} catch (IOException e) {
e.printStackTrace();
......@@ -158,7 +147,8 @@ public class HextileMessage extends FramebufferUpdateMessage {
DataInputStream is, DataOutputStream os, int tx, int ty, int tw,
int th, boolean updateFlag) throws IOException {
Log.d("HextileMessage", "" + tx + " , " + ty + " , " + tw + " , " + th);
// Log.d("HextileMessage", "" + tx + " , " + ty + " , " + tw + " , " +
// th);
int subencoding = is.readUnsignedByte();
// buffering
......@@ -312,7 +302,7 @@ public class HextileMessage extends FramebufferUpdateMessage {
// TODO: to call or not to call???
// NOTE: raw mode calls update for whole rectangle, not for
// subrectangles
graphicsContext.handleUpdatedPixels(x, y, w, h);
// graphicsContext.handleUpdatedPixels(x, y, w, h);
}
// paint sub-reactangle
......@@ -320,27 +310,30 @@ public class HextileMessage extends FramebufferUpdateMessage {
int w, int h, byte[] colorField, boolean updateFlag) {
int color = graphicsContext.decodeColor(colorField);
Log.d("HextileMessage", " fill Rec : " + x + " , " + y + " , " + w
+ " , " + h);
// set color of pixels
for (int j = 0; j < h; j++) {
for (int i = x + j * y * graphicsContext.prefs.framebufferWidth; i < x
+ j * y * graphicsContext.prefs.framebufferWidth + w; i++) {
graphicsContext.pixels[i] = Color.RED;
}
}
// Paint paint = new Paint(color);
Log.d("color", "color = " + color);
// Paint paint = new Paint(color);
// if (y > 100) {
// Log.d("HextileMessage", " fill Rec : " + x + " , " + y + " , " + w
// + " , " + h);
// }
// graphicsContext.canvas.drawRect(x, y, x + w, y + h, paint);
// graphicsContext.canvas.dr
// graphicsContext.updateView();
for (int i = y; i < y + h; i++) {
int offset = i * graphicsContext.prefs.framebufferWidth + x;
for (int j = 0; j < w; j++) {
// TODO: add 8bit support
graphicsContext.pixels[offset + j] = color;
}
}
graphicsContext.handleUpdatedPixels(x, y, w, h);
// graphicsContext.canvas.drawBitmap(graphicsContext.bitmap, null,
// paint);
// graphicsContext.updateView();
}
// static Color getGrayscale(Color color) {
// int argb = color.getRGB();
// int argb = color.a;
// int a = argb >> 24 & 0xff;
// int r = argb >> 16 & 0xff;
// int g = argb >> 8 & 0xff;
......@@ -354,5 +347,4 @@ public class HextileMessage extends FramebufferUpdateMessage {
// color = Color.getHSBColor(hsb[0], hsb[1], hsb[2] * 0.95f);
// return new Color(color.getRed(), color.getGreen(), color.getBlue(), a);
// }
}
......@@ -33,6 +33,7 @@ import java.io.IOException;
import tttclient.ttt.Constants;
import tttclient.ttt.GraphicsContext;
import android.util.Log;
public class RawMessage extends FramebufferUpdateMessage {
// TODO: this is untested
......@@ -109,6 +110,9 @@ public class RawMessage extends FramebufferUpdateMessage {
DataInputStream is, DataOutputStream os, int x, int y, int w, int h)
throws IOException {
Log.d("RawMessage", "handleRaw Rect: " + x + " , " + y + " , " + w
+ " , " + h);
switch (graphicsContext.prefs.bytesPerPixel) {
// case 1:
// for (int dy = y; dy < y + h; dy++) {
......
......@@ -2,21 +2,27 @@ package tttclient.ttt;
import tttclient.messages.Message;
import tttclient.messages.MessageConsumer;
import tttclient.messages.MessageProducer;
import tttclient.utils.BitmapContainer;
import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Handler;
import android.util.Log;
import android.widget.ImageView;
@SuppressLint("NewApi")
public class GraphicsContext implements MessageConsumer {
public Canvas canvas;
public Canvas scaledCanvas;
public Bitmap bitmap;
public BitmapContainer bitmapContainer;
public Bitmap scaledBitmap;
public ImageView imgView;
boolean refreshEnabled;
public MessageProducer producer;
public ProtocolPreferences prefs;
public int screenWidth = 1280;
public int screenHeight = 768;
......@@ -25,16 +31,28 @@ public class GraphicsContext implements MessageConsumer {
public byte[] hextile_fg_encoded;
public int[] pixels;
public GraphicsContext(ImageView imgV) {
public GraphicsContext(ImageView imgV, Recording record) {
this.imgView = imgV;
this.prefs = new ProtocolPreferences();
this.bitmap = Bitmap.createBitmap(screenWidth, screenHeight,
Config.ARGB_8888);
this.pixels = new int[prefs.framebufferWidth * prefs.framebufferHeight];
updateView(bitmap);
this.canvas = new Canvas(bitmap);
bitmap.getHeight();
bitmap.getWidth();
this.producer = record;
producer.addMessageConsumer(this);
this.prefs = record.getProtocolPreferences();
Log.d("GraphicContext", "framebuffer size: " + prefs.framebufferWidth
+ " , " + prefs.framebufferHeight);
this.bitmapContainer = new BitmapContainer(Bitmap.createBitmap(
prefs.framebufferWidth, prefs.framebufferHeight,
Config.ARGB_8888));
this.canvas = new Canvas(bitmapContainer.getBimap());
this.pixels = bitmapContainer.getPixels();
Log.d("Bitmap", "size: " + bitmapContainer.getBimap().getHeight()
+ bitmapContainer.getBimap().getWidth());
Log.d("ImageView", " ScaleX " + imgView.getScaleX() + " , ScaleY "
+ imgView.getScaleY());
updateView(bitmapContainer.getBimap());
uiThreadHandler = new Handler();
hextile_bg_encoded = new byte[prefs.bytesPerPixel];
......@@ -57,15 +75,18 @@ public class GraphicsContext implements MessageConsumer {
}
public void updateView(final Bitmap bitmap) {
Thread t = new Thread(new Runnable() {
new Thread(new Runnable() {
@Override
public void run() {
imgView.setImageBitmap(bitmap);
imgView.post(new Runnable() {
@Override
public void run() {
imgView.setImageBitmap(bitmap);
imgView.invalidate();
}
});
}
});
t.start();
}).start();
}
......@@ -92,6 +113,41 @@ public class GraphicsContext implements MessageConsumer {
}
// public Color decodeColor(byte[] colorField) {
// int color = 0;
// for (int i = 0, shift = 0; i < prefs.bytesPerPixel; i++, shift += 8) {
// color += (colorField[i] & 0xFF) << shift;
// }
//
// switch (prefs.bitsPerPixel) {
// case 16:
// if (prefs.bigEndian)
// // 16 bit big endian: swap bytes
// color = (color & 0xFF) << 8 | ((color & 0xFF00) >> 8);
// case 8:
// // use color table
// return colors[color];
// default:
// // use default color
// if (prefs.bigEndian) {
// // 24 bit big endian: swap bytes
// color = (color & 0xFF) << 24 | (color >> 8 & 0xFF) << 16
// | (color >> 16 & 0xFF) << 8 | color >> 24 & 0xFF;
// }
// return new Color(color);
// }
// }
public void setForeground(byte[] color, int offset) {
System.arraycopy(color, offset, hextile_fg_encoded, 0,
prefs.bytesPerPixel);
}
public void setBackground(byte[] color, int offset) {
System.arraycopy(color, offset, hextile_bg_encoded, 0,
prefs.bytesPerPixel);
}
// if (refreshEnabled)
// repaint((int) (x * scaleFactor), (int) (y * scaleFactor),
// (int) (width * scaleFactor + 1),
......@@ -107,21 +163,45 @@ public class GraphicsContext implements MessageConsumer {
message.paint(this);
}
public void setForeground(byte[] color, int offset) {
System.arraycopy(color, offset, hextile_fg_encoded, 0,
prefs.bytesPerPixel);
}
public void setBackground(byte[] color, int offset) {
System.arraycopy(color, offset, hextile_bg_encoded, 0,
prefs.bytesPerPixel);
}
// public void setForeground(byte[] color, int offset) {
// System.arraycopy(color, offset, hextile_fg_encoded, 0,
// prefs.bytesPerPixel);
// }
//
// public void setBackground(byte[] color, int offset) {
// System.arraycopy(color, offset, hextile_bg_encoded, 0,
// prefs.bytesPerPixel);
// }
public void handleUpdatedPixels(int x, int y, int w, int h) {
// TODO
bitmap.setPixels(pixels, x + y * prefs.framebufferWidth,
prefs.framebufferWidth, x, y, w, h);
updateView(bitmap);
bitmapContainer.getBimap().setPixels(pixels,
x + y * prefs.framebufferWidth, prefs.framebufferWidth, x, y,
w, h);
updateView(bitmapContainer.getBimap());
}
}
public int getEncodedColor(byte[] colorField) {
int color = 0;
for (int i = 0, shift = 0; i < prefs.bytesPerPixel; i++, shift += 8) {
color += (colorField[i] & 0xFF) << shift;
}
switch (prefs.bitsPerPixel) {
case 16:
if (prefs.bigEndian)
// 16 bit big endian: swap bytes
color = (color & 0xFF) << 8 | ((color & 0xFF00) >> 8);
case 8:
break;
default:
// use default color
if (prefs.bigEndian) {
// 24 bit big endian: swap bytes
color = (color & 0xFF) << 24 | (color >> 8 & 0xFF) << 16
| (color >> 16 & 0xFF) << 8 | color >> 24 & 0xFF;
}
}
return color;
}
}
\ No newline at end of file
......@@ -63,13 +63,10 @@ public class Recording extends MessageProducerAdapter implements Runnable {
messages.setmessages(list);
}
public Recording(File file, GraphicsContext context) throws IOException {
public Recording(File file) throws IOException {
// read
read(file);
graphicsContext = context;
this.addMessageConsumer(graphicsContext);
// Note: keyframes are computed dynamically during random access
// TODO: add keyframes if dynamic computation is too slow - e.g. if
// border stays unchanged over long periods
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment