Mercurial > hg > Applications > tvnjviewer
comparison src/main/java/com/glavsoft/rfb/encoding/PixelFormat.java @ 0:daa24f8a557b
TightVNC original
author | YU |
---|---|
date | Thu, 11 Sep 2014 07:30:03 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:daa24f8a557b |
---|---|
1 // Copyright (C) 2010, 2011, 2012, 2013 GlavSoft LLC. | |
2 // All rights reserved. | |
3 // | |
4 //------------------------------------------------------------------------- | |
5 // This file is part of the TightVNC software. Please visit our Web site: | |
6 // | |
7 // http://www.tightvnc.com/ | |
8 // | |
9 // This program is free software; you can redistribute it and/or modify | |
10 // it under the terms of the GNU General Public License as published by | |
11 // the Free Software Foundation; either version 2 of the License, or | |
12 // (at your option) any later version. | |
13 // | |
14 // This program is distributed in the hope that it will be useful, | |
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 // GNU General Public License for more details. | |
18 // | |
19 // You should have received a copy of the GNU General Public License along | |
20 // with this program; if not, write to the Free Software Foundation, Inc., | |
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
22 //------------------------------------------------------------------------- | |
23 // | |
24 | |
25 package com.glavsoft.rfb.encoding; | |
26 | |
27 import com.glavsoft.exceptions.TransportException; | |
28 import com.glavsoft.transport.Reader; | |
29 import com.glavsoft.transport.Writer; | |
30 | |
31 /** | |
32 * Pixel Format: | |
33 * 1 - U8 - bits-per-pixel | |
34 * 1 - U8 - depth | |
35 * 1 - U8 - big-endian-flag | |
36 * 1 - U8 - true-color-flag | |
37 * 2 - U16 - red-max | |
38 * 2 - U16 - green-max | |
39 * 2 - U16 - blue-max | |
40 * 1 - U8 - red-shift | |
41 * 1 - U8 - green-shift | |
42 * 1 - U8 - blue-shift | |
43 * 3 - - padding | |
44 */ | |
45 public class PixelFormat { | |
46 public byte bitsPerPixel; | |
47 public byte depth; | |
48 public byte bigEndianFlag; | |
49 public byte trueColourFlag; | |
50 public short redMax; | |
51 public short greenMax; | |
52 public short blueMax; | |
53 public byte redShift; | |
54 public byte greenShift; | |
55 public byte blueShift; | |
56 | |
57 public void fill(Reader reader) throws TransportException { | |
58 bitsPerPixel = reader.readByte(); | |
59 depth = reader.readByte(); | |
60 bigEndianFlag = reader.readByte(); | |
61 trueColourFlag = reader.readByte(); | |
62 redMax = reader.readInt16(); | |
63 greenMax = reader.readInt16(); | |
64 blueMax = reader.readInt16(); | |
65 redShift = reader.readByte(); | |
66 greenShift = reader.readByte(); | |
67 blueShift = reader.readByte(); | |
68 reader.readBytes(3); // skip padding bytes | |
69 } | |
70 | |
71 public void send(Writer writer) throws TransportException { | |
72 writer.write(bitsPerPixel); | |
73 writer.write(depth); | |
74 writer.write(bigEndianFlag); | |
75 writer.write(trueColourFlag); | |
76 writer.write(redMax); | |
77 writer.write(greenMax); | |
78 writer.write(blueMax); | |
79 writer.write(redShift); | |
80 writer.write(greenShift); | |
81 writer.write(blueShift); | |
82 writer.writeInt16(0); // padding bytes | |
83 writer.writeByte(0); // padding bytes | |
84 } | |
85 | |
86 public static PixelFormat create24bitColorDepthPixelFormat(int bigEndianFlag) { | |
87 final PixelFormat pixelFormat = new PixelFormat(); | |
88 pixelFormat.bigEndianFlag = (byte) bigEndianFlag; | |
89 pixelFormat.bitsPerPixel = 32; | |
90 pixelFormat.blueMax = 255; | |
91 pixelFormat.blueShift = 0; | |
92 pixelFormat.greenMax = 255; | |
93 pixelFormat.greenShift = 8; | |
94 pixelFormat.redMax = 255; | |
95 pixelFormat.redShift = 16; | |
96 pixelFormat.depth = 24; | |
97 pixelFormat.trueColourFlag = 1; | |
98 return pixelFormat; | |
99 } | |
100 | |
101 /** | |
102 * specifies 65536 colors, 5bit per Red, 6bit per Green, 5bit per Blue | |
103 */ | |
104 public static PixelFormat create16bitColorDepthPixelFormat(int bigEndianFlag) { | |
105 final PixelFormat pixelFormat = new PixelFormat(); | |
106 pixelFormat.bigEndianFlag = (byte) bigEndianFlag; | |
107 pixelFormat.bitsPerPixel = 16; | |
108 pixelFormat.blueMax = 31; | |
109 pixelFormat.blueShift = 0; | |
110 pixelFormat.greenMax = 63; | |
111 pixelFormat.greenShift = 5; | |
112 pixelFormat.redMax = 31; | |
113 pixelFormat.redShift = 11; | |
114 pixelFormat.depth = 16; | |
115 pixelFormat.trueColourFlag = 1; | |
116 return pixelFormat; | |
117 } | |
118 | |
119 /** | |
120 * specifies 256 colors, 2bit per Blue, 3bit per Green & Red | |
121 */ | |
122 public static PixelFormat create8bitColorDepthBGRPixelFormat(int bigEndianFlag) { | |
123 final PixelFormat pixelFormat = new PixelFormat(); | |
124 pixelFormat.bigEndianFlag = (byte) bigEndianFlag; | |
125 pixelFormat.bitsPerPixel = 8; | |
126 pixelFormat.redMax = 7; | |
127 pixelFormat.redShift = 0; | |
128 pixelFormat.greenMax = 7; | |
129 pixelFormat.greenShift = 3; | |
130 pixelFormat.blueMax = 3; | |
131 pixelFormat.blueShift = 6; | |
132 pixelFormat.depth = 8; | |
133 pixelFormat.trueColourFlag = 1; | |
134 return pixelFormat; | |
135 } | |
136 | |
137 /** | |
138 * specifies 64 colors, 2bit per Red, Green & Blue | |
139 */ | |
140 public static PixelFormat create6bitColorDepthPixelFormat(int bigEndianFlag) { | |
141 final PixelFormat pixelFormat = new PixelFormat(); | |
142 pixelFormat.bigEndianFlag = (byte) bigEndianFlag; | |
143 pixelFormat.bitsPerPixel = 8; | |
144 pixelFormat.blueMax = 3; | |
145 pixelFormat.blueShift = 0; | |
146 pixelFormat.greenMax = 3; | |
147 pixelFormat.greenShift = 2; | |
148 pixelFormat.redMax = 3; | |
149 pixelFormat.redShift = 4; | |
150 pixelFormat.depth = 6; | |
151 pixelFormat.trueColourFlag = 1; | |
152 return pixelFormat; | |
153 } | |
154 | |
155 /** | |
156 * specifies 8 colors, 1bit per Red, Green & Blue | |
157 */ | |
158 public static PixelFormat create3bppPixelFormat(int bigEndianFlag) { | |
159 final PixelFormat pixelFormat = new PixelFormat(); | |
160 pixelFormat.bigEndianFlag = (byte) bigEndianFlag; | |
161 pixelFormat.bitsPerPixel = 8; | |
162 pixelFormat.blueMax = 1; | |
163 pixelFormat.blueShift = 0; | |
164 pixelFormat.greenMax = 1; | |
165 pixelFormat.greenShift = 1; | |
166 pixelFormat.redMax = 1; | |
167 pixelFormat.redShift = 2; | |
168 pixelFormat.depth = 3; | |
169 pixelFormat.trueColourFlag = 1; | |
170 return pixelFormat; | |
171 } | |
172 | |
173 @Override | |
174 public String toString() { | |
175 return "PixelFormat: [bits-per-pixel: " + String.valueOf(0xff & bitsPerPixel) + | |
176 ", depth: " + String.valueOf(0xff & depth) + | |
177 ", big-endian-flag: " + String.valueOf(0xff & bigEndianFlag) + | |
178 ", true-color-flag: " + String.valueOf(0xff & trueColourFlag) + | |
179 ", red-max: " + String.valueOf(0xffff & redMax) + | |
180 ", green-max: " + String.valueOf(0xffff & greenMax) + | |
181 ", blue-max: " + String.valueOf(0xffff & blueMax) + | |
182 ", red-shift: " + String.valueOf(0xff & redShift) + | |
183 ", green-shift: " + String.valueOf(0xff & greenShift) + | |
184 ", blue-shift: " + String.valueOf(0xff & blueShift) + | |
185 "]"; | |
186 } | |
187 } |