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)
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
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
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
59 int s_width
, s_height
;
62 GtkImagePainter (GtkImage image
, GdkGraphics gc
, int x
, int y
,
63 int width
, int height
, Color bgcolor
)
66 this.gc
= (GdkGraphics
) gc
.create ();
69 redBG
= bgcolor
.getRed ();
70 greenBG
= bgcolor
.getGreen ();
71 blueBG
= bgcolor
.getBlue ();
74 flipX
= flipY
= false;
75 s_width
= s_height
= 0;
78 new Thread (this).start ();
82 GtkImagePainter (GtkImage image
, GdkGraphics gc
,
83 int dx1
, int dy1
, int dx2
, int dy2
,
84 int sx1
, int sy1
, int sx2
, int sy2
,
88 this.gc
= (GdkGraphics
) gc
.create ();
89 startX
= (dx1
< dx2
) ? dx1
: dx2
;
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 ();
114 image
.startProduction (this);
118 /* Convert pixel data into a format that gdkrgb can understand */
120 convertPixels (int[] pixels
, ColorModel model
)
122 if (model
.equals (ColorModel
.getRGBdefault ()))
125 int ret
[] = new int[pixels
.length
];
127 for (int i
= 0; i
< pixels
.length
; i
++)
128 ret
[i
] = model
.getRGB (pixels
[i
]);
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
]);
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
[]);
151 setPixels (int x
, int y
, int width
, int height
, ColorModel model
,
152 int[] pixels
, int offset
, int scansize
)
157 r
= clip
.intersection (new Rectangle (x
, y
, width
, height
));
158 if (r
.width
== 0 && r
.height
== 0)
161 offset
+= r
.y
* scansize
+ r
.x
;
163 r
.translate (-Math
.abs (clip
.x
- startX
), -Math
.abs (clip
.y
- startY
));
171 drawPixels (gc
, redBG
, greenBG
, blueBG
,
172 startX
+ x
, startY
+ y
,
173 width
, height
, convertPixels (pixels
, model
), offset
,
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
),
186 setDimensions (int width
, int height
)
188 if (!flipX
&& !flipY
&&
189 ((this.width
== -1 && this.height
== -1)
190 || (this.width
== width
&& this.height
== height
)))
193 affine
= new double[6];
194 affine
[1] = affine
[2] = affine
[4] = affine
[5] = 0;
198 affine
[0] = this.width
/ (double) s_width
;
199 affine
[3] = this.height
/ (double) s_height
;
203 affine
[0] = this.width
/ (double) width
;
204 affine
[3] = this.height
/ (double) height
;
209 affine
[0] = -affine
[0];
210 affine
[4] = this.width
;
215 affine
[3] = -affine
[3];
216 affine
[5] = this.height
;
219 if (affine
[0] == 1 && affine
[3] == 1)
224 setProperties (Hashtable props
)
229 setColorModel (ColorModel model
)
239 imageComplete (int status
)