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.*;
024: import java.awt.image.*;
025:
026: public class RdpImage {
027: private BufferedImage m_bi;
028: private IndexColorModel m_cm;
029:
030: public RdpImage(int arg0, int arg1, int arg2) {
031: m_bi = new BufferedImage(arg0, arg1, arg2);
032: m_cm = null;
033: }
034:
035: public RdpImage(int arg0, int arg1, int arg2, IndexColorModel cm) {
036: m_bi = new BufferedImage(arg0, arg1, BufferedImage.TYPE_INT_RGB);
037: m_cm = cm;
038: }
039:
040: public void setIndexColorModel(IndexColorModel cm) {
041: m_cm = cm;
042: }
043:
044: public int getWidth() {
045: return m_bi.getWidth();
046: }
047:
048: public int getHeight() {
049: return m_bi.getHeight();
050: }
051:
052: public BufferedImage getBufferedImage() {
053: return m_bi;
054: }
055:
056: public Graphics getGraphics() {
057: return m_bi.getGraphics();
058: }
059:
060: public BufferedImage getSubimage(int x, int y, int width, int height) {
061: return m_bi.getSubimage(x, y, width, height);
062: }
063:
064: public int checkColor(int color) {
065: if (m_cm != null) {
066: return m_cm.getRGB(color);
067: }
068:
069: return color;
070: }
071:
072: public void setRGB(int x, int y, int color) {
073: if (m_cm != null) {
074: color = m_cm.getRGB(color);
075: }
076:
077: m_bi.setRGB(x, y, color);
078: }
079:
080: public void setRGBNoConversion(int x, int y, int cx, int cy,
081: int[] data, int offset, int w) {
082: m_bi.setRGB(x, y, cx, cy, data, offset, w);
083: }
084:
085: public void setRGB(int x, int y, int cx, int cy, int[] data,
086: int offset, int w) {
087: if ((m_cm != null) && (data != null) && (data.length > 0)) {
088: for (int i = 0; i < data.length; i++) {
089: data[i] = m_cm.getRGB(data[i]);
090: }
091: }
092:
093: m_bi.setRGB(x, y, cx, cy, data, offset, w);
094: }
095:
096: public int[] getRGB(int x, int y, int cx, int cy, int[] data,
097: int offset, int width) {
098: return m_bi.getRGB(x, y, cx, cy, data, offset, width);
099: }
100:
101: public int getRGB(int x, int y) {
102: if (m_cm == null) {
103: return m_bi.getRGB(x, y);
104: } else {
105: int pix = m_bi.getRGB(x, y) & 0xFFFFFF;
106: int[] vals = { (pix >> 16) & 0xFF, (pix >> 8) & 0xFF,
107: (pix) & 0xFF };
108: int out = m_cm.getDataElement(vals, 0);
109: return out;
110: }
111: }
112: }
|