2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / gnu / java / awt / peer / gtk / GtkImagePainter.java
bloba5a8d0959852ff345a46784b1b1be314ce2f0595
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. */
39 package gnu.java.awt.peer.gtk;
41 import java.awt.Color;
42 import java.awt.Rectangle;
43 import java.awt.image.ColorModel;
44 import java.awt.image.ImageConsumer;
45 import java.util.Hashtable;
47 public class GtkImagePainter implements Runnable, ImageConsumer
49 GtkImage image;
50 GdkGraphics gc;
51 int startX, startY;
52 int redBG;
53 int greenBG;
54 int blueBG;
55 double affine[];
56 int width, height;
57 boolean flipX, flipY;
58 Rectangle clip;
59 int s_width, s_height;
61 public
62 GtkImagePainter (GtkImage image, GdkGraphics gc, int x, int y,
63 int width, int height, Color bgcolor)
65 this.image = image;
66 this.gc = (GdkGraphics) gc.create ();
67 startX = x;
68 startY = y;
69 redBG = bgcolor.getRed ();
70 greenBG = bgcolor.getGreen ();
71 blueBG = bgcolor.getBlue ();
72 this.width = width;
73 this.height = height;
74 flipX = flipY = false;
75 s_width = s_height = 0;
76 clip = null;
78 new Thread (this).start ();
81 public
82 GtkImagePainter (GtkImage image, GdkGraphics gc,
83 int dx1, int dy1, int dx2, int dy2,
84 int sx1, int sy1, int sx2, int sy2,
85 Color bgcolor)
87 this.image = image;
88 this.gc = (GdkGraphics) gc.create ();
89 startX = (dx1 < dx2) ? dx1 : dx2;
90 startY = dy1;
91 redBG = bgcolor.getRed ();
92 greenBG = bgcolor.getGreen ();
93 blueBG = bgcolor.getBlue ();
95 this.width = Math.abs (dx2 - dx1);
96 this.height = Math.abs (dy2 - dy1);
98 flipX = ((dx1 > dx2 && sx2 > sx1)
99 || (dx1 < dx2 && sx2 < sx1));
101 flipY = ((dy1 > dy2 && sy2 > sy1)
102 || (dy1 < dy2 && sy2 < sy1));
104 s_width = Math.abs (sx2 - sx1);
105 s_height = Math.abs (sy2 - sy1);
106 clip = new Rectangle (sx1, sy1, s_width, s_height);
108 new Thread (this).start ();
111 public void
112 run ()
114 image.startProduction (this);
115 gc.dispose ();
118 /* Convert pixel data into a format that gdkrgb can understand */
119 static int[]
120 convertPixels (int[] pixels, ColorModel model)
122 if (model.equals (ColorModel.getRGBdefault ()))
123 return pixels;
125 int ret[] = new int[pixels.length];
127 for (int i = 0; i < pixels.length; i++)
128 ret[i] = model.getRGB (pixels[i]);
130 return ret;
133 static int[]
134 convertPixels (byte[] pixels, ColorModel model)
136 int ret[] = new int[pixels.length];
138 for (int i = 0; i < pixels.length; i++)
139 ret[i] = model.getRGB (pixels[i]);
141 return ret;
144 native void
145 drawPixels (GdkGraphics gc, int bg_red, int bg_green, int bg_blue,
146 int x, int y, int width, int height, int[] pixels, int offset,
147 int scansize, double affine[]);
150 public void
151 setPixels (int x, int y, int width, int height, ColorModel model,
152 int[] pixels, int offset, int scansize)
154 if (clip != null)
156 Rectangle r;
157 r = clip.intersection (new Rectangle (x, y, width, height));
158 if (r.width == 0 && r.height == 0)
159 return;
161 offset += r.y * scansize + r.x;
163 r.translate (-Math.abs (clip.x - startX), -Math.abs (clip.y - startY));
165 width = r.width;
166 height = r.height;
167 x = r.x;
168 y = r.y;
171 drawPixels (gc, redBG, greenBG, blueBG,
172 startX + x, startY + y,
173 width, height, convertPixels (pixels, model), offset,
174 scansize, affine);
177 public void
178 setPixels (int x, int y, int width, int height, ColorModel model,
179 byte[] pixels, int offset, int scansize)
181 setPixels (x, y, width, height, model, convertPixels (pixels, model),
182 offset, scansize);
185 public void
186 setDimensions (int width, int height)
188 if (!flipX && !flipY &&
189 ((this.width == -1 && this.height == -1)
190 || (this.width == width && this.height == height)))
191 return;
193 affine = new double[6];
194 affine[1] = affine[2] = affine[4] = affine[5] = 0;
196 if (clip != null)
198 affine[0] = this.width / (double) s_width;
199 affine[3] = this.height / (double) s_height;
201 else
203 affine[0] = this.width / (double) width;
204 affine[3] = this.height / (double) height;
207 if (flipX)
209 affine[0] = -affine[0];
210 affine[4] = this.width;
213 if (flipY)
215 affine[3] = -affine[3];
216 affine[5] = this.height;
219 if (affine[0] == 1 && affine[3] == 1)
220 affine = null;
223 public void
224 setProperties (Hashtable props)
228 public void
229 setColorModel (ColorModel model)
233 public void
234 setHints (int flags)
238 public void
239 imageComplete (int status)