enikey | 00e0dbf | 2008-12-08 10:59:59 +0000 | [diff] [blame] | 1 | package com.tightvnc.decoder; |
| 2 | |
enikey | 2f811b8 | 2008-12-19 04:45:15 +0000 | [diff] [blame] | 3 | import com.tightvnc.vncviewer.RecordInterface; |
| 4 | import com.tightvnc.vncviewer.RfbInputStream; |
| 5 | import java.awt.Graphics; |
| 6 | import java.awt.Image; |
| 7 | import java.awt.image.ColorModel; |
| 8 | import java.awt.image.DirectColorModel; |
| 9 | import java.awt.image.MemoryImageSource; |
| 10 | import java.awt.Color; |
| 11 | |
enikey | b3e19f7 | 2008-12-19 04:54:49 +0000 | [diff] [blame^] | 12 | // |
| 13 | // This is base decoder class. |
| 14 | // Other classes will be childs of RawDecoder. |
| 15 | // |
enikey | 00e0dbf | 2008-12-08 10:59:59 +0000 | [diff] [blame] | 16 | public class RawDecoder { |
| 17 | |
enikey | 2f811b8 | 2008-12-19 04:45:15 +0000 | [diff] [blame] | 18 | public RawDecoder(Graphics g, RfbInputStream is) { |
| 19 | setGraphics(g); |
| 20 | setRfbInputStream(is); |
enikey | b3e19f7 | 2008-12-19 04:54:49 +0000 | [diff] [blame^] | 21 | // FIXME: cm24 created in getColorModel24. |
| 22 | // Remove if no bugs |
enikey | 2f811b8 | 2008-12-19 04:45:15 +0000 | [diff] [blame] | 23 | 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); |
enikey | b3e19f7 | 2008-12-19 04:54:49 +0000 | [diff] [blame^] | 31 | // FIXME: cm24 created in getColorModel24. |
| 32 | // Remove if no bugs |
enikey | 2f811b8 | 2008-12-19 04:45:15 +0000 | [diff] [blame] | 33 | 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 | |
enikey | b3e19f7 | 2008-12-19 04:54:49 +0000 | [diff] [blame^] | 48 | // |
| 49 | // FIXME: This method may be useless in future, remove if so |
| 50 | // |
| 51 | |
enikey | 2f811b8 | 2008-12-19 04:45:15 +0000 | [diff] [blame] | 52 | public int getBPP() { |
| 53 | return bytesPerPixel; |
| 54 | } |
| 55 | |
| 56 | public void setFrameBufferSize(int w, int h) { |
| 57 | framebufferWidth = w; |
| 58 | framebufferHeight = h; |
| 59 | } |
| 60 | |
enikey | b3e19f7 | 2008-12-19 04:54:49 +0000 | [diff] [blame^] | 61 | // |
| 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 | // |
enikey | 2f811b8 | 2008-12-19 04:45:15 +0000 | [diff] [blame] | 91 | 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 | |
enikey | b3e19f7 | 2008-12-19 04:54:49 +0000 | [diff] [blame^] | 98 | // |
| 99 | // This data must be shared between decoders |
| 100 | // |
enikey | 2f811b8 | 2008-12-19 04:45:15 +0000 | [diff] [blame] | 101 | protected static byte []pixels8 = null; |
| 102 | protected static int []pixels24 = null; |
| 103 | protected static MemoryImageSource pixelsSource = null; |
| 104 | protected static Image rawPixelsImage = null; |
| 105 | |
enikey | b3e19f7 | 2008-12-19 04:54:49 +0000 | [diff] [blame^] | 106 | // |
| 107 | // Access to this static members only though protected methods |
| 108 | // |
enikey | 2f811b8 | 2008-12-19 04:45:15 +0000 | [diff] [blame] | 109 | private static ColorModel cm8 = null; |
| 110 | private static ColorModel cm24 = null; |
| 111 | private static Color []color256 = null; |
enikey | 00e0dbf | 2008-12-08 10:59:59 +0000 | [diff] [blame] | 112 | } |