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
.awt
.image
.ImageObserver
;
46 import java
.util
.Hashtable
;
48 public class GtkImagePainter
implements Runnable
, ImageConsumer
60 int s_width
, s_height
;
61 ImageObserver observer
;
64 GtkImagePainter (GtkImage image
, GdkGraphics gc
, int x
, int y
,
65 int width
, int height
, Color bgcolor
, ImageObserver o
)
68 this.gc
= (GdkGraphics
) gc
.create ();
71 redBG
= bgcolor
.getRed ();
72 greenBG
= bgcolor
.getGreen ();
73 blueBG
= bgcolor
.getBlue ();
76 flipX
= flipY
= false;
77 s_width
= s_height
= 0;
85 GtkImagePainter (GtkImage image
, GdkGraphics gc
,
86 int dx1
, int dy1
, int dx2
, int dy2
,
87 int sx1
, int sy1
, int sx2
, int sy2
,
88 Color bgcolor
, ImageObserver o
)
91 this.gc
= (GdkGraphics
) gc
.create ();
92 startX
= (dx1
< dx2
) ? dx1
: dx2
;
94 redBG
= bgcolor
.getRed ();
95 greenBG
= bgcolor
.getGreen ();
96 blueBG
= bgcolor
.getBlue ();
99 this.width
= Math
.abs (dx2
- dx1
);
100 this.height
= Math
.abs (dy2
- dy1
);
102 flipX
= ((dx1
> dx2
&& sx2
> sx1
)
103 || (dx1
< dx2
&& sx2
< sx1
));
105 flipY
= ((dy1
> dy2
&& sy2
> sy1
)
106 || (dy1
< dy2
&& sy2
< sy1
));
108 s_width
= Math
.abs (sx2
- sx1
);
109 s_height
= Math
.abs (sy2
- sy1
);
110 clip
= new Rectangle (sx1
, sy1
, s_width
, s_height
);
118 image
.startProduction (this);
122 /* Convert pixel data into a format that gdkrgb can understand */
124 convertPixels (int[] pixels
, ColorModel model
)
126 if (pixels
== null || model
== null)
131 if (model
.equals (ColorModel
.getRGBdefault ()))
134 int ret
[] = new int[pixels
.length
];
136 for (int i
= 0; i
< pixels
.length
; i
++)
137 ret
[i
] = model
.getRGB (pixels
[i
]);
143 convertPixels (byte[] pixels
, ColorModel model
)
145 if (pixels
== null || model
== null)
150 int ret
[] = new int[pixels
.length
];
152 for (int i
= 0; i
< pixels
.length
; i
++)
153 ret
[i
] = model
.getRGB (pixels
[i
]);
159 drawPixels (GdkGraphics gc
, int bg_red
, int bg_green
, int bg_blue
,
160 int x
, int y
, int width
, int height
, int[] pixels
, int offset
,
161 int scansize
, double affine
[]);
165 setPixels (int x
, int y
, int width
, int height
, ColorModel model
,
166 int[] pixels
, int offset
, int scansize
)
171 r
= clip
.intersection (new Rectangle (x
, y
, width
, height
));
172 if (r
.width
== 0 && r
.height
== 0)
175 offset
+= r
.y
* scansize
+ r
.x
;
183 drawPixels (gc
, redBG
, greenBG
, blueBG
,
184 startX
+ x
, startY
+ y
,
185 width
, height
, convertPixels (pixels
, model
), offset
,
188 if (observer
!= null)
189 observer
.imageUpdate (image
,
190 ImageObserver
.SOMEBITS
,
191 x
, y
, width
, height
);
195 setPixels (int x
, int y
, int width
, int height
, ColorModel model
,
196 byte[] pixels
, int offset
, int scansize
)
198 setPixels (x
, y
, width
, height
, ColorModel
.getRGBdefault(),
199 convertPixels (pixels
, model
), offset
, scansize
);
203 setDimensions (int width
, int height
)
205 if (!flipX
&& !flipY
&&
206 ((this.width
== -1 && this.height
== -1)
207 || (this.width
== width
&& this.height
== height
)))
210 affine
= new double[6];
211 affine
[1] = affine
[2] = affine
[4] = affine
[5] = 0;
215 affine
[0] = this.width
/ (double) s_width
;
216 affine
[3] = this.height
/ (double) s_height
;
220 affine
[0] = this.width
/ (double) width
;
221 affine
[3] = this.height
/ (double) height
;
226 affine
[0] = -affine
[0];
227 affine
[4] = this.width
;
232 affine
[3] = -affine
[3];
233 affine
[5] = this.height
;
236 if (affine
[0] == 1 && affine
[3] == 1)
241 setProperties (Hashtable props
)
246 setColorModel (ColorModel model
)
256 imageComplete (int status
)
258 image
.imageComplete(status
);
260 if (observer
!= null)
262 if (status
== ImageConsumer
.IMAGEERROR
)
263 observer
.imageUpdate (null,
267 observer
.imageUpdate (null,
268 ImageObserver
.ALLBITS
,