blob: 8272d3b4b8d6dd7d1cf840d05d88a0c04f72a480 [file] [log] [blame]
enikey00e0dbf2008-12-08 10:59:59 +00001package com.tightvnc.decoder;
2
enikey2f811b82008-12-19 04:45:15 +00003import com.tightvnc.vncviewer.RecordInterface;
4import com.tightvnc.vncviewer.RfbInputStream;
5import java.awt.Graphics;
6import java.awt.Image;
7import java.awt.image.ColorModel;
8import java.awt.image.DirectColorModel;
9import java.awt.image.MemoryImageSource;
10import java.awt.Color;
11
enikeyb3e19f72008-12-19 04:54:49 +000012//
13// This is base decoder class.
14// Other classes will be childs of RawDecoder.
15//
enikey00e0dbf2008-12-08 10:59:59 +000016public class RawDecoder {
17
enikey2f811b82008-12-19 04:45:15 +000018 public RawDecoder(Graphics g, RfbInputStream is) {
19 setGraphics(g);
20 setRfbInputStream(is);
enikeyb3e19f72008-12-19 04:54:49 +000021 // FIXME: cm24 created in getColorModel24.
22 // Remove if no bugs
enikey2f811b82008-12-19 04:45:15 +000023 cm24 = new DirectColorModel(24, 0xFF0000, 0x00FF00, 0x0000FF);
24 }
25
26 public RawDecoder(Graphics g, RfbInputStream is, int frameBufferW,
27 int frameBufferH) {
28 setGraphics(g);
29 setRfbInputStream(is);
30 setFrameBufferSize(frameBufferW, frameBufferH);
enikeyb3e19f72008-12-19 04:54:49 +000031 // FIXME: cm24 created in getColorModel24.
32 // Remove if no bugs
enikey2f811b82008-12-19 04:45:15 +000033 cm24 = new DirectColorModel(24, 0xFF0000, 0x00FF00, 0x0000FF);
34 }
35
36 public void setRfbInputStream(RfbInputStream is) {
37 rfbis = is;
38 }
39
40 public void setGraphics(Graphics g) {
41 graphics = g;
42 }
43
44 public void setBPP(int bpp) {
45 bytesPerPixel = bpp;
46 }
47
enikeyb3e19f72008-12-19 04:54:49 +000048 //
49 // FIXME: This method may be useless in future, remove if so
50 //
51
enikey2f811b82008-12-19 04:45:15 +000052 public int getBPP() {
53 return bytesPerPixel;
54 }
55
56 public void setFrameBufferSize(int w, int h) {
57 framebufferWidth = w;
58 framebufferHeight = h;
59 }
60
enikeyb3e19f72008-12-19 04:54:49 +000061 //
62 // Private static members access methdos
63 //
64
65 protected ColorModel getColorModel8() {
66 if (cm8 == null) {
67 cm8 = cm8 = new DirectColorModel(8, 7, (7 << 3), (3 << 6));
68 }
69 return cm8;
70 }
71
72 protected ColorModel getColorModel24() {
73 if (cm24 == null) {
74 cm24 = new DirectColorModel(24, 0xFF0000, 0x00FF00, 0x0000FF);
75 }
76 return cm24;
77 }
78
79 protected Color[]getColor256() {
80 if (color256 == null) {
81 color256 = new Color[256];
82 for (int i = 0; i < 256; i++)
83 color256[i] = new Color(cm8.getRGB(i));
84 }
85 return color256;
86 }
87
88 //
89 // Unique data for every decoder (? maybe not ?)
90 //
enikey2f811b82008-12-19 04:45:15 +000091 protected int bytesPerPixel = 4;
92 protected int framebufferWidth = 0;
93 protected int framebufferHeight = 0;
94 protected RfbInputStream rfbis = null;
95 protected Graphics graphics = null;
96 protected RecordInterface rec = null;
97
enikeyb3e19f72008-12-19 04:54:49 +000098 //
99 // This data must be shared between decoders
100 //
enikey2f811b82008-12-19 04:45:15 +0000101 protected static byte []pixels8 = null;
102 protected static int []pixels24 = null;
103 protected static MemoryImageSource pixelsSource = null;
104 protected static Image rawPixelsImage = null;
105
enikeyb3e19f72008-12-19 04:54:49 +0000106 //
107 // Access to this static members only though protected methods
108 //
enikey2f811b82008-12-19 04:45:15 +0000109 private static ColorModel cm8 = null;
110 private static ColorModel cm24 = null;
111 private static Color []color256 = null;
enikey00e0dbf2008-12-08 10:59:59 +0000112}