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. */
38 package gnu
.java
.awt
.peer
.gtk
;
41 import java
.awt
.image
.*;
44 public class GtkImagePainter
implements Runnable
, ImageConsumer
56 int s_width
, s_height
;
59 GtkImagePainter (GtkImage image
, GdkGraphics gc
, int x
, int y
,
60 int width
, int height
, Color bgcolor
)
63 this.gc
= (GdkGraphics
) gc
.create ();
66 redBG
= bgcolor
.getRed ();
67 greenBG
= bgcolor
.getGreen ();
68 blueBG
= bgcolor
.getBlue ();
71 flipX
= flipY
= false;
72 s_width
= s_height
= 0;
75 new Thread (this).start ();
79 GtkImagePainter (GtkImage image
, GdkGraphics gc
,
80 int dx1
, int dy1
, int dx2
, int dy2
,
81 int sx1
, int sy1
, int sx2
, int sy2
,
85 this.gc
= (GdkGraphics
) gc
.create ();
86 startX
= (dx1
< dx2
) ? dx1
: dx2
;
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 ();
111 image
.startProduction (this);
115 /* Convert pixel data into a format that gdkrgb can understand */
117 convertPixels (int[] pixels
, ColorModel model
)
119 if (model
.equals (ColorModel
.getRGBdefault ()))
122 int ret
[] = new int[pixels
.length
];
124 for (int i
= 0; i
< pixels
.length
; i
++)
125 ret
[i
] = model
.getRGB (pixels
[i
]);
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
]);
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
[]);
148 setPixels (int x
, int y
, int width
, int height
, ColorModel model
,
149 int[] pixels
, int offset
, int scansize
)
154 r
= clip
.intersection (new Rectangle (x
, y
, width
, height
));
155 if (r
.width
== 0 && r
.height
== 0)
158 offset
+= r
.y
* scansize
+ r
.x
;
160 r
.translate (-Math
.abs (clip
.x
- startX
), -Math
.abs (clip
.y
- startY
));
168 drawPixels (gc
, redBG
, greenBG
, blueBG
,
169 startX
+ x
, startY
+ y
,
170 width
, height
, convertPixels (pixels
, model
), offset
,
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
),
183 setDimensions (int width
, int height
)
185 if (!flipX
&& !flipY
&&
186 ((this.width
== -1 && this.height
== -1)
187 || (this.width
== width
&& this.height
== height
)))
190 affine
= new double[6];
191 affine
[1] = affine
[2] = affine
[4] = affine
[5] = 0;
195 affine
[0] = this.width
/ (double) s_width
;
196 affine
[3] = this.height
/ (double) s_height
;
200 affine
[0] = this.width
/ (double) width
;
201 affine
[3] = this.height
/ (double) height
;
206 affine
[0] = -affine
[0];
207 affine
[4] = this.width
;
212 affine
[3] = -affine
[3];
213 affine
[5] = this.height
;
216 if (affine
[0] == 1 && affine
[3] == 1)
221 setProperties (Hashtable props
)
226 setColorModel (ColorModel model
)
236 imageComplete (int status
)