FSF GCC merge 02/23/03
[official-gcc.git] / libjava / gnu / java / awt / peer / gtk / GtkImagePainter.java
blob3ea22cd25af7afc47e7414ccb767f6c65f77e3ca
1 /* GtkImagePainter.java
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package gnu.java.awt.peer.gtk;
40 import java.awt.*;
41 import java.awt.image.*;
42 import java.util.*;
44 public class GtkImagePainter implements Runnable, ImageConsumer
46 GtkImage image;
47 GdkGraphics gc;
48 int startX, startY;
49 int redBG;
50 int greenBG;
51 int blueBG;
52 double affine[];
53 int width, height;
54 boolean flipX, flipY;
55 Rectangle clip;
56 int s_width, s_height;
58 public
59 GtkImagePainter (GtkImage image, GdkGraphics gc, int x, int y,
60 int width, int height, Color bgcolor)
62 this.image = image;
63 this.gc = (GdkGraphics) gc.create ();
64 startX = x;
65 startY = y;
66 redBG = bgcolor.getRed ();
67 greenBG = bgcolor.getGreen ();
68 blueBG = bgcolor.getBlue ();
69 this.width = width;
70 this.height = height;
71 flipX = flipY = false;
72 s_width = s_height = 0;
73 clip = null;
75 new Thread (this).start ();
78 public
79 GtkImagePainter (GtkImage image, GdkGraphics gc,
80 int dx1, int dy1, int dx2, int dy2,
81 int sx1, int sy1, int sx2, int sy2,
82 Color bgcolor)
84 this.image = image;
85 this.gc = (GdkGraphics) gc.create ();
86 startX = (dx1 < dx2) ? dx1 : dx2;
87 startY = dy1;
88 redBG = bgcolor.getRed ();
89 greenBG = bgcolor.getGreen ();
90 blueBG = bgcolor.getBlue ();
92 this.width = Math.abs (dx2 - dx1);
93 this.height = Math.abs (dy2 - dy1);
95 flipX = ((dx1 > dx2 && sx2 > sx1)
96 || (dx1 < dx2 && sx2 < sx1));
98 flipY = ((dy1 > dy2 && sy2 > sy1)
99 || (dy1 < dy2 && sy2 < sy1));
101 s_width = Math.abs (sx2 - sx1);
102 s_height = Math.abs (sy2 - sy1);
103 clip = new Rectangle (sx1, sy1, s_width, s_height);
105 new Thread (this).start ();
108 public void
109 run ()
111 image.startProduction (this);
112 gc.dispose ();
115 /* Convert pixel data into a format that gdkrgb can understand */
116 static int[]
117 convertPixels (int[] pixels, ColorModel model)
119 if (model.equals (ColorModel.getRGBdefault ()))
120 return pixels;
122 int ret[] = new int[pixels.length];
124 for (int i = 0; i < pixels.length; i++)
125 ret[i] = model.getRGB (pixels[i]);
127 return ret;
130 static int[]
131 convertPixels (byte[] pixels, ColorModel model)
133 int ret[] = new int[pixels.length];
135 for (int i = 0; i < pixels.length; i++)
136 ret[i] = model.getRGB (pixels[i]);
138 return ret;
141 native void
142 drawPixels (GdkGraphics gc, int bg_red, int bg_green, int bg_blue,
143 int x, int y, int width, int height, int[] pixels, int offset,
144 int scansize, double affine[]);
147 public void
148 setPixels (int x, int y, int width, int height, ColorModel model,
149 int[] pixels, int offset, int scansize)
151 if (clip != null)
153 Rectangle r;
154 r = clip.intersection (new Rectangle (x, y, width, height));
155 if (r.width == 0 && r.height == 0)
156 return;
158 offset += r.y * scansize + r.x;
160 r.translate (-Math.abs (clip.x - startX), -Math.abs (clip.y - startY));
162 width = r.width;
163 height = r.height;
164 x = r.x;
165 y = r.y;
168 drawPixels (gc, redBG, greenBG, blueBG,
169 startX + x, startY + y,
170 width, height, convertPixels (pixels, model), offset,
171 scansize, affine);
174 public void
175 setPixels (int x, int y, int width, int height, ColorModel model,
176 byte[] pixels, int offset, int scansize)
178 setPixels (x, y, width, height, model, convertPixels (pixels, model),
179 offset, scansize);
182 public void
183 setDimensions (int width, int height)
185 if (!flipX && !flipY &&
186 ((this.width == -1 && this.height == -1)
187 || (this.width == width && this.height == height)))
188 return;
190 affine = new double[6];
191 affine[1] = affine[2] = affine[4] = affine[5] = 0;
193 if (clip != null)
195 affine[0] = this.width / (double) s_width;
196 affine[3] = this.height / (double) s_height;
198 else
200 affine[0] = this.width / (double) width;
201 affine[3] = this.height / (double) height;
204 if (flipX)
206 affine[0] = -affine[0];
207 affine[4] = this.width;
210 if (flipY)
212 affine[3] = -affine[3];
213 affine[5] = this.height;
216 if (affine[0] == 1 && affine[3] == 1)
217 affine = null;
220 public void
221 setProperties (Hashtable props)
225 public void
226 setColorModel (ColorModel model)
230 public void
231 setHints (int flags)
235 public void
236 imageComplete (int status)