001: ///////////////////////////////////////////////////////////////////////////////
002: //
003: // This program is free software; you can redistribute it and/or modify
004: // it under the terms of the GNU General Public License and GNU Library
005: // General Public License as published by the Free Software Foundation;
006: // either version 2, or (at your option) any later version.
007: //
008: // This program is distributed in the hope that it will be useful,
009: // but WITHOUT ANY WARRANTY; without even the implied warranty of
010: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: // GNU General Public License and GNU Library General Public License
012: // for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // and GNU Library General Public License along with this program; if
016: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
017: // MA 02139, USA.
018: //
019: ///////////////////////////////////////////////////////////////////////////////
020:
021: package org.rdesktop.server.rdp;
022:
023: import java.awt.image.BufferedImage;
024:
025: public class RdpRasterOp {
026: private void ropInvert(RdpImage biDst, int[] dest, int width,
027: int x, int y, int cx, int cy, int Bpp) {
028: int mask = RdpOptions.bpp_mask;
029: int pdest = (y * width + x);
030: for (int i = 0; i < cy; i++) {
031: for (int j = 0; j < cx; j++) {
032: if (biDst != null) {
033: int c = biDst.getRGB(x + j, y + i);
034: biDst.setRGB(x + j, y + i, ~c & mask);
035: } else {
036: dest[pdest] = (~dest[pdest]) & mask;
037: }
038:
039: pdest++;
040: }
041:
042: pdest += (width - cx);
043: }
044: }
045:
046: private void ropClear(RdpImage biDst, int width, int x, int y,
047: int cx, int cy, int Bpp) {
048: for (int i = x; i < x + cx; i++) {
049: for (int j = y; j < y + cy; j++) {
050: biDst.setRGB(i, j, 0);
051: }
052: }
053: }
054:
055: private void ropSet(RdpImage biDst, int width, int x, int y,
056: int cx, int cy, int Bpp) {
057: int mask = RdpOptions.bpp_mask;
058:
059: for (int i = x; i < x + cx; i++) {
060: for (int j = y; j < y + cy; j++) {
061: biDst.setRGB(i, j, mask);
062: }
063: }
064: }
065:
066: private void ropCopy(RdpImage biDst, int dstwidth, int x, int y,
067: int cx, int cy, int[] src, int srcwidth, int srcx,
068: int srcy, int Bpp) {
069: if (src == null) {
070: int[] imgSec = null;
071: biDst.getGraphics().copyArea(srcx, srcy, cx, cy, x - srcx,
072: y - srcy);
073: } else {
074: biDst.setRGB(x, y, cx, cy, src, 0, cx);
075: }
076: }
077:
078: private void ropNor(RdpImage biDst, int dstwidth, int x, int y,
079: int cx, int cy, int[] src, int srcwidth, int srcx,
080: int srcy, int Bpp) {
081: // opcode 0x1
082: int mask = RdpOptions.bpp_mask;
083: int psrc = (srcy * srcwidth + srcx);
084:
085: for (int row = 0; row < cy; row++) {
086: for (int col = 0; col < cx; col++) {
087: biDst.setRGB(x + cx, y + cy, (~(biDst.getRGB(x + cx, y
088: + cy) | src[psrc]))
089: & mask);
090: }
091:
092: psrc += (srcwidth - cx);
093: }
094: }
095:
096: private void ropAndInverted(RdpImage biDst, int dstwidth, int x,
097: int y, int cx, int cy, int[] src, int srcwidth, int srcx,
098: int srcy, int Bpp) {
099: // opcode 0x2
100: int mask = RdpOptions.bpp_mask;
101: int psrc = (srcy * srcwidth + srcx);
102: for (int row = 0; row < cy; row++) {
103: for (int col = 0; col < cx; col++) {
104: int c = biDst.getRGB(x + cx, y + cy);
105: biDst.setRGB(x + cx, y + cy, c & ((~src[psrc]) & mask));
106: psrc++;
107: }
108:
109: psrc += (srcwidth - cx);
110: }
111: }
112:
113: private void ropXor(RdpImage biDst, int dstwidth, int x, int y,
114: int cx, int cy, int[] src, int srcwidth, int srcx,
115: int srcy, int Bpp) {
116: // opcode 0x6
117: int mask = RdpOptions.bpp_mask;
118: int psrc = (srcy * srcwidth + srcx);
119: for (int row = 0; row < cy; row++) {
120: for (int col = 0; col < cx; col++) {
121: int c = biDst.getRGB(x + col, y + row);
122: biDst
123: .setRGB(x + col, y + row, c
124: ^ ((src[psrc]) & mask));
125: psrc++;
126: }
127:
128: psrc += (srcwidth - cx);
129: }
130: }
131:
132: private void ropNand(RdpImage biDst, int dstwidth, int x, int y,
133: int cx, int cy, int[] src, int srcwidth, int srcx,
134: int srcy, int Bpp) {
135: // opcode 0x7
136: int mask = RdpOptions.bpp_mask;
137: int psrc = (srcy * srcwidth + srcx);
138: for (int row = 0; row < cy; row++) {
139: for (int col = 0; col < cx; col++) {
140: int c = biDst.getRGB(x + col, y + row);
141: biDst.setRGB(x + col, y + row, (~(c & src[psrc]))
142: & mask);
143: psrc++;
144: }
145:
146: psrc += (srcwidth - cx);
147: }
148: }
149:
150: private void ropAnd(RdpImage biDst, int dstwidth, int x, int y,
151: int cx, int cy, int[] src, int srcwidth, int srcx,
152: int srcy, int Bpp) {
153: // opcode 0x8
154: int mask = RdpOptions.bpp_mask;
155: int psrc = (srcy * srcwidth + srcx);
156: for (int row = 0; row < cy; row++) {
157: for (int col = 0; col < cx; col++) {
158: int c = biDst.getRGB(x + col, y + row);
159: biDst
160: .setRGB(x + col, y + row, c
161: & ((src[psrc]) & mask));
162: psrc++;
163: }
164:
165: psrc += (srcwidth - cx);
166: }
167: }
168:
169: private void ropEquiv(RdpImage biDst, int dstwidth, int x, int y,
170: int cx, int cy, int[] src, int srcwidth, int srcx,
171: int srcy, int Bpp) {
172: // opcode 0x9
173: int mask = RdpOptions.bpp_mask;
174: int psrc = (srcy * srcwidth + srcx);
175: for (int row = 0; row < cy; row++) {
176: for (int col = 0; col < cx; col++) {
177: int c = biDst.getRGB(x + col, y + row);
178: biDst.setRGB(x + col, y + row, c
179: ^ ((~src[psrc]) & mask));
180: psrc++;
181: }
182:
183: psrc += (srcwidth - cx);
184: }
185: }
186:
187: private void ropOrInverted(RdpImage biDst, int dstwidth, int x,
188: int y, int cx, int cy, int[] src, int srcwidth, int srcx,
189: int srcy, int Bpp) {
190: // opcode 0xb
191: int mask = RdpOptions.bpp_mask;
192: int psrc = (srcy * srcwidth + srcx);
193: for (int row = 0; row < cy; row++) {
194: for (int col = 0; col < cx; col++) {
195: int c = biDst.getRGB(x + col, y + row);
196: biDst.setRGB(x + col, y + row, c
197: | ((~src[psrc]) & mask));
198: psrc++;
199: }
200:
201: psrc += (srcwidth - cx);
202: }
203: }
204:
205: private void ropOr(RdpImage biDst, int dstwidth, int x, int y,
206: int cx, int cy, int[] src, int srcwidth, int srcx,
207: int srcy, int Bpp) {
208: // opcode 0xe
209: int mask = RdpOptions.bpp_mask;
210: int psrc = (srcy * srcwidth + srcx);
211: for (int row = 0; row < cy; row++) {
212: for (int col = 0; col < cx; col++) {
213: int c = biDst.getRGB(x + col, y + row);
214: biDst.setRGB(x + col, y + row, c | (src[psrc] & mask));
215: psrc++;
216: }
217:
218: psrc += (srcwidth - cx);
219: }
220: }
221:
222: public void do_array(int opcode, RdpImage biDst, int dstwidth,
223: int x, int y, int cx, int cy, int[] src, int srcwidth,
224: int srcx, int srcy) {
225: int Bpp = RdpOptions.Bpp;
226: switch (opcode) {
227: case 0x0: {
228: ropClear(biDst, dstwidth, x, y, cx, cy, Bpp);
229: break;
230: }
231: case 0x1: {
232: ropNor(biDst, dstwidth, x, y, cx, cy, src, srcwidth, srcx,
233: srcy, Bpp);
234: break;
235: }
236: case 0x2: {
237: ropAndInverted(biDst, dstwidth, x, y, cx, cy, src,
238: srcwidth, srcx, srcy, Bpp);
239: break;
240: }
241: case 0x3: // CopyInverted
242: {
243: ropInvert(biDst, src, srcwidth, srcx, srcy, cx, cy, Bpp);
244: ropCopy(biDst, dstwidth, x, y, cx, cy, src, srcwidth, srcx,
245: srcy, Bpp);
246: break;
247: }
248: case 0x4: // AndReverse
249: {
250: ropInvert(biDst, null, dstwidth, x, y, cx, cy, Bpp);
251: ropAnd(biDst, dstwidth, x, y, cx, cy, src, srcwidth, srcx,
252: srcy, Bpp);
253: break;
254: }
255: case 0x5: {
256: ropInvert(biDst, null, dstwidth, x, y, cx, cy, Bpp);
257: break;
258: }
259: case 0x6: {
260: ropXor(biDst, dstwidth, x, y, cx, cy, src, srcwidth, srcx,
261: srcy, Bpp);
262: break;
263: }
264: case 0x7: {
265: ropNand(biDst, dstwidth, x, y, cx, cy, src, srcwidth, srcx,
266: srcy, Bpp);
267: break;
268: }
269: case 0x8: {
270: ropAnd(biDst, dstwidth, x, y, cx, cy, src, srcwidth, srcx,
271: srcy, Bpp);
272: break;
273: }
274: case 0x9: {
275: ropEquiv(biDst, dstwidth, x, y, cx, cy, src, srcwidth,
276: srcx, srcy, Bpp);
277: break;
278: }
279: case 0xa: // Noop
280: {
281: break;
282: }
283: case 0xb: {
284: ropOrInverted(biDst, dstwidth, x, y, cx, cy, src, srcwidth,
285: srcx, srcy, Bpp);
286: break;
287: }
288: case 0xc: {
289: ropCopy(biDst, dstwidth, x, y, cx, cy, src, srcwidth, srcx,
290: srcy, Bpp);
291: break;
292: }
293: case 0xd: // OrReverse
294: {
295: ropInvert(biDst, null, dstwidth, x, y, cx, cy, Bpp);
296: ropOr(biDst, dstwidth, x, y, cx, cy, src, srcwidth, srcx,
297: srcy, Bpp);
298: break;
299: }
300: case 0xe: {
301: ropOr(biDst, dstwidth, x, y, cx, cy, src, srcwidth, srcx,
302: srcy, Bpp);
303: break;
304: }
305: case 0xf: {
306: ropSet(biDst, dstwidth, x, y, cx, cy, Bpp);
307: break;
308: }
309: default: {
310: break;
311: }
312: }
313: }
314:
315: public void do_pixel(int opcode, RdpImage dst, int x, int y,
316: int color) {
317: int mask = RdpOptions.bpp_mask;
318:
319: if (dst == null) {
320: return;
321: }
322:
323: int c = dst.getRGB(x, y);
324:
325: switch (opcode) {
326: case 0x0: {
327: dst.setRGB(x, y, 0);
328: break;
329: }
330: case 0x1: {
331: dst.setRGB(x, y, (~(c | color)) & mask);
332: break;
333: }
334: case 0x2: {
335: dst.setRGB(x, y, c & ((~color) & mask));
336: break;
337: }
338: case 0x3: {
339: dst.setRGB(x, y, (~color) & mask);
340: break;
341: }
342: case 0x4: {
343: dst.setRGB(x, y, (~c & color) * mask);
344: break;
345: }
346: case 0x5: {
347: dst.setRGB(x, y, (~c) & mask);
348: break;
349: }
350: case 0x6: {
351: dst.setRGB(x, y, c ^ ((color) & mask));
352: break;
353: }
354: case 0x7: {
355: dst.setRGB(x, y, (~c & color) & mask);
356: break;
357: }
358: case 0x8: {
359: dst.setRGB(x, y, c & (color & mask));
360: break;
361: }
362: case 0x9: {
363: dst.setRGB(x, y, c ^ (~color & mask));
364: break;
365: }
366: case 0xa: /* Noop */
367: {
368: break;
369: }
370: case 0xb: {
371: dst.setRGB(x, y, c | (~color & mask));
372: break;
373: }
374: case 0xc: {
375: dst.setRGB(x, y, color);
376: break;
377: }
378: case 0xd: {
379: dst.setRGB(x, y, (~c | color) & mask);
380: break;
381: }
382: case 0xe: {
383: dst.setRGB(x, y, c | (color & mask));
384: break;
385: }
386: case 0xf: {
387: dst.setRGB(x, y, mask);
388: break;
389: }
390: default: {
391: break;
392: }
393: }
394: }
395: }
|