author | Claus Gittinger <cg@exept.de> |
Tue, 24 Jun 1997 10:01:42 +0200 | |
changeset 430 | 574a94732ece |
parent 429 | f98e6af57214 |
child 477 | 37f12d35c359 |
permissions | -rw-r--r-- |
1 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
26 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
ImageView subclass:#ImageEditView |
|
404 | 14 |
instanceVariableNames:'magnification colors magnifiedImage colorPanel pathName enhance |
15 |
antiAlias' |
|
161 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'Views-Misc' |
|
1 | 19 |
! |
20 |
||
255 | 21 |
!ImageEditView class methodsFor:'documentation'! |
64 | 22 |
|
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
39 |
This View will eventually be able to edit bitmap images. |
|
40 |
For now, it is not. |
|
296 | 41 |
|
42 |
[author:] |
|
43 |
Claus Gittinger |
|
44 |
||
45 |
[see also:] |
|
46 |
Image Form |
|
353 | 47 |
|
48 |
[start with:] |
|
49 |
ImageEditView openOn:'bitmaps/gifImages/garfield.gif' |
|
50 |
ImageEditView openOnImage:(Image fromFile:'bitmaps/gifImages/garfield.gif') |
|
64 | 51 |
" |
1 | 52 |
! ! |
53 |
||
353 | 54 |
!ImageEditView class methodsFor:'startup'! |
55 |
||
56 |
openOn:aFileName |
|
57 |
"startup an image editor on an image read from a file" |
|
58 |
||
59 |
|editView| |
|
60 |
||
61 |
editView := super openOn:aFileName. |
|
62 |
editView pathName:aFileName asFilename pathName. |
|
63 |
||
64 |
^ editView |
|
65 |
||
66 |
" |
|
67 |
ImageEditView openOn:'bitmaps/gifImages/garfield.gif' |
|
68 |
ImageEditView openOn:'bitmaps/xpmBitmaps/BOOK.xpm' |
|
69 |
" |
|
70 |
||
71 |
"Modified: 10.4.1997 / 17:31:17 / cg" |
|
72 |
! ! |
|
73 |
||
7 | 74 |
!ImageEditView methodsFor:'accessing'! |
75 |
||
76 |
image:anImage |
|
295
6388ebe84be2
fixed display of magnified image with mask.
Claus Gittinger <cg@exept.de>
parents:
294
diff
changeset
|
77 |
|oldMag| |
6388ebe84be2
fixed display of magnified image with mask.
Claus Gittinger <cg@exept.de>
parents:
294
diff
changeset
|
78 |
|
6388ebe84be2
fixed display of magnified image with mask.
Claus Gittinger <cg@exept.de>
parents:
294
diff
changeset
|
79 |
oldMag := magnification. |
7 | 80 |
magnification := 1@1. |
81 |
magnifiedImage := nil. |
|
295
6388ebe84be2
fixed display of magnified image with mask.
Claus Gittinger <cg@exept.de>
parents:
294
diff
changeset
|
82 |
super image:anImage. |
6388ebe84be2
fixed display of magnified image with mask.
Claus Gittinger <cg@exept.de>
parents:
294
diff
changeset
|
83 |
self magnification:oldMag |
6388ebe84be2
fixed display of magnified image with mask.
Claus Gittinger <cg@exept.de>
parents:
294
diff
changeset
|
84 |
|
6388ebe84be2
fixed display of magnified image with mask.
Claus Gittinger <cg@exept.de>
parents:
294
diff
changeset
|
85 |
"Modified: 20.2.1997 / 18:29:13 / cg" |
255 | 86 |
! |
87 |
||
88 |
magnification:aMagnificationPoint |
|
413 | 89 |
|nPixel savedImage oldBounds newBounds rects| |
255 | 90 |
|
91 |
magnification ~= aMagnificationPoint ifTrue:[ |
|
92 |
"show wait cursor; although magnification is fast, dithering may take a while" |
|
413 | 93 |
self withWaitCursorDo:[ |
94 |
magnifiedImage isNil ifTrue:[ |
|
95 |
oldBounds := image bounds. |
|
96 |
] ifFalse:[ |
|
97 |
oldBounds := magnifiedImage bounds |
|
98 |
]. |
|
255 | 99 |
|
413 | 100 |
(device visualType == #PseudoColor) ifTrue:[ |
101 |
"release kept colors" |
|
102 |
colors := IdentitySet new. |
|
103 |
]. |
|
104 |
||
105 |
magnification := aMagnificationPoint asPoint. |
|
255 | 106 |
|
413 | 107 |
"use a magnified image, if its size wont be too big" |
108 |
magnifiedImage := nil. |
|
255 | 109 |
|
413 | 110 |
"avoid slow scroll" |
111 |
savedImage := image. |
|
112 |
image := nil. |
|
113 |
self scrollToTopLeft. |
|
114 |
image := savedImage. |
|
255 | 115 |
|
413 | 116 |
magnification ~= (1@1) ifTrue:[ |
117 |
nPixel := image width * image height * magnification x * magnification y. |
|
118 |
nPixel <= (2000 * 2000) ifTrue:[ |
|
119 |
Transcript showCR:'magnifying ..'; endEntry. |
|
120 |
antiAlias ifTrue:[ |
|
121 |
magnifiedImage := image hardAntiAliasedMagnifiedBy:magnification |
|
122 |
] ifFalse:[ |
|
123 |
magnifiedImage := image magnifiedBy:magnification |
|
124 |
] |
|
125 |
]. |
|
126 |
]. |
|
255 | 127 |
|
413 | 128 |
self contentsChanged. |
129 |
||
130 |
magnifiedImage isNil ifTrue:[ |
|
131 |
newBounds := image bounds. |
|
132 |
] ifFalse:[ |
|
133 |
newBounds := magnifiedImage bounds |
|
134 |
]. |
|
135 |
(rects := oldBounds areasOutside:newBounds) notNil ifTrue:[ |
|
136 |
rects do:[:rect | |
|
137 |
self clearRectangle:rect+(1@1). |
|
404 | 138 |
] |
413 | 139 |
] |
255 | 140 |
]. |
141 |
self invalidate. |
|
142 |
] |
|
143 |
||
413 | 144 |
"Modified: 4.6.1997 / 13:38:16 / cg" |
353 | 145 |
! |
146 |
||
147 |
pathName:aPathName |
|
148 |
"set the pathName of the edited image. |
|
149 |
This is used as a default in the save-dialog" |
|
150 |
||
151 |
pathName := aPathName |
|
152 |
||
153 |
"Created: 10.4.1997 / 17:31:54 / cg" |
|
7 | 154 |
! ! |
155 |
||
1 | 156 |
!ImageEditView methodsFor:'drawing'! |
157 |
||
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
158 |
redrawX:x y:y width:w height:h |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
159 |
|area ih iw dotW dotH minX maxX minY maxY color last lastY runW x0 oldClip| |
1 | 160 |
|
161 |
image isNil ifTrue:[^ self]. |
|
162 |
||
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
163 |
(magnification = (1@1)) ifTrue:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
164 |
super redrawX:x y:y width:w height:h. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
165 |
^ self |
1 | 166 |
]. |
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
167 |
|
1 | 168 |
magnifiedImage notNil ifTrue:[ |
413 | 169 |
self function:#copy. |
170 |
self paint:Black. |
|
171 |
||
172 |
magnifiedImage device ~~ device ifTrue:[ |
|
173 |
"/ this may take some time (allocating colors & dithering |
|
205
96f80d06fe5a
oops - care for d1 images colors
Claus Gittinger <cg@exept.de>
parents:
204
diff
changeset
|
174 |
|
413 | 175 |
self |
176 |
displayRectangleX:margin y:margin |
|
177 |
width:magnifiedImage width height:magnifiedImage height. |
|
178 |
||
179 |
self withWaitCursorDo:[ |
|
180 |
magnifiedImage := magnifiedImage on:device. |
|
181 |
] |
|
204 | 182 |
]. |
183 |
||
413 | 184 |
self withWaitCursorDo:[ |
185 |
magnifiedImage depth == 1 ifTrue:[ |
|
186 |
self paint:(magnifiedImage colorFromValue:1) |
|
187 |
on:(magnifiedImage colorFromValue:0). |
|
188 |
] ifFalse:[ |
|
189 |
self paint:Black on:White. |
|
190 |
]. |
|
295
6388ebe84be2
fixed display of magnified image with mask.
Claus Gittinger <cg@exept.de>
parents:
294
diff
changeset
|
191 |
|
413 | 192 |
(magnifiedImage depth ~~ 1 |
193 |
and:[magnifiedImage mask notNil]) ifTrue:[ |
|
194 |
self clearRectangleX:x y:y width:w height:h. |
|
195 |
self displayForm:magnifiedImage x:margin y:margin |
|
196 |
] ifFalse:[ |
|
197 |
self displayOpaqueForm:magnifiedImage x:margin y:margin |
|
198 |
]. |
|
430 | 199 |
|
200 |
"/ right of image ? |
|
201 |
(x + w - 1) > magnifiedImage width ifTrue:[ |
|
202 |
self clearRectangleX:(magnifiedImage width) |
|
203 |
y:y |
|
204 |
width:(x + w - 1 - magnifiedImage width) |
|
205 |
height:h |
|
206 |
]. |
|
207 |
"/ below of image ? |
|
208 |
(y + h - 1) > magnifiedImage height ifTrue:[ |
|
209 |
self clearRectangleX:margin |
|
210 |
y:(magnifiedImage height) |
|
211 |
width:w |
|
212 |
height:(y + h - 1 - magnifiedImage height) |
|
213 |
]. |
|
295
6388ebe84be2
fixed display of magnified image with mask.
Claus Gittinger <cg@exept.de>
parents:
294
diff
changeset
|
214 |
]. |
6388ebe84be2
fixed display of magnified image with mask.
Claus Gittinger <cg@exept.de>
parents:
294
diff
changeset
|
215 |
|
203 | 216 |
^ self |
1 | 217 |
]. |
218 |
||
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
219 |
ih := image height. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
220 |
iw := image width. |
1 | 221 |
dotW := magnification x. |
222 |
dotH := magnification y. |
|
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
223 |
|
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
224 |
minX := x // dotW. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
225 |
minY := y // dotW. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
226 |
maxX := (x + w) // dotW + 1. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
227 |
maxX > iw ifTrue:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
228 |
maxX := iw |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
229 |
]. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
230 |
maxY := (y + h) // dotH + 1. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
231 |
maxY > ih ifTrue:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
232 |
maxY := ih |
1 | 233 |
]. |
234 |
||
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
235 |
lastY := -1. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
236 |
|
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
237 |
x0 := minX. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
238 |
runW := 0. |
204 | 239 |
|
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
240 |
image colorsFromX:minX y:minY toX:maxX-1 y:maxY-1 do:[:x :y :color | |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
241 |
y ~~ lastY ifTrue:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
242 |
runW ~~ 0 ifTrue:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
243 |
self fillRectangleX:(x0 * dotW + margin) |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
244 |
y:(lastY * dotH + margin) |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
245 |
width:runW height:dotH. |
203 | 246 |
runW := 0. |
247 |
]. |
|
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
248 |
x0 := x. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
249 |
lastY := y. |
204 | 250 |
]. |
1 | 251 |
|
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
252 |
color ~~ last ifTrue:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
253 |
runW ~~ 0 ifTrue:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
254 |
self fillRectangleX:(x0 * dotW + margin) |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
255 |
y:(y * dotH + margin) |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
256 |
width:runW height:dotH. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
257 |
runW := 0. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
258 |
]. |
204 | 259 |
|
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
260 |
"/ keep colors - otherwise they might get collected & changed |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
261 |
colors notNil ifTrue:[colors add:color]. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
262 |
self paint:color. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
263 |
last := color. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
264 |
runW := 0. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
265 |
x0 := x. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
266 |
]. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
267 |
runW := runW + dotW |
191 | 268 |
]. |
269 |
||
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
270 |
runW ~~ 0 ifTrue:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
271 |
self fillRectangleX:(x0 * dotW + margin) |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
272 |
y:(lastY * dotH + margin) |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
273 |
width:runW height:dotH. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
274 |
runW := 0. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
275 |
]. |
191 | 276 |
|
430 | 277 |
"Modified: 23.6.1997 / 21:24:40 / cg" |
1 | 278 |
! ! |
279 |
||
161 | 280 |
!ImageEditView methodsFor:'event handling'! |
281 |
||
282 |
buttonMotion:state x:x y:y |
|
283 |
self showColorAtX:x y:y. |
|
284 |
! |
|
285 |
||
167
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
286 |
buttonMultiPress:button x:x y:y |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
287 |
button == 1 ifTrue:[ |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
288 |
|clr| |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
289 |
clr := self getColorAtX:x y:y. |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
290 |
clr inspect. |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
291 |
]. |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
292 |
super buttonMultiPress:button x:x y:y |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
293 |
|
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
294 |
"Created: 8.5.1996 / 00:18:06 / stefan" |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
295 |
! |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
296 |
|
161 | 297 |
buttonPress:button x:x y:y |
298 |
button == 1 ifTrue:[ |
|
299 |
self showColorAtX:x y:y. |
|
300 |
^ self |
|
301 |
]. |
|
302 |
super buttonPress:button x:x y:y |
|
303 |
! |
|
304 |
||
167
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
305 |
getColorAtX:x y:y |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
306 |
|pi| |
161 | 307 |
|
308 |
pi := (x @ y) - margin. |
|
309 |
pi := pi // magnification. |
|
310 |
((0@0 corner:image extent) containsPoint:pi) ifTrue:[ |
|
167
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
311 |
^ image at:pi. |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
312 |
]. |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
313 |
^ nil |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
314 |
|
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
315 |
"Created: 8.5.1996 / 00:15:55 / stefan" |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
316 |
! |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
317 |
|
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
318 |
showColorAtX:x y:y |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
319 |
|clr| |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
320 |
|
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
321 |
clr := self getColorAtX:x y:y. |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
322 |
clr notNil ifTrue:[ |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
323 |
colorPanel notNil ifTrue:[ |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
324 |
colorPanel setColor:clr. |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
325 |
] ifFalse:[ |
184 | 326 |
Transcript showCR:clr displayString |
167
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
327 |
] |
161 | 328 |
] |
167
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
329 |
|
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
330 |
"Modified: 8.5.1996 / 00:20:45 / stefan" |
161 | 331 |
! ! |
332 |
||
406 | 333 |
!ImageEditView methodsFor:'image conversion'! |
334 |
||
335 |
convertToColor24 |
|
336 |
(Depth24Image fromImage:image) inspect |
|
337 |
||
338 |
"Modified: 3.6.1997 / 18:34:34 / cg" |
|
339 |
! |
|
340 |
||
341 |
convertToColor4 |
|
342 |
(Depth4Image fromImage:image) inspect |
|
343 |
||
344 |
"Modified: 3.6.1997 / 18:34:45 / cg" |
|
345 |
! |
|
346 |
||
347 |
convertToColor8 |
|
348 |
(Depth8Image fromImage:image) inspect |
|
349 |
||
350 |
"Created: 3.6.1997 / 18:34:08 / cg" |
|
351 |
"Modified: 3.6.1997 / 18:34:51 / cg" |
|
352 |
! |
|
353 |
||
354 |
convertToGray2 |
|
355 |
(image asFloydSteinbergDitheredGrayImageDepth:2) inspect |
|
356 |
||
357 |
"Created: 3.6.1997 / 18:34:02 / cg" |
|
358 |
"Modified: 3.6.1997 / 18:39:23 / cg" |
|
359 |
! |
|
360 |
||
361 |
convertToGray4 |
|
362 |
(image asFloydSteinbergDitheredGrayImageDepth:4) inspect |
|
363 |
||
364 |
"Created: 3.6.1997 / 18:34:04 / cg" |
|
365 |
"Modified: 3.6.1997 / 18:39:20 / cg" |
|
366 |
! |
|
367 |
||
368 |
convertToGray8 |
|
369 |
(image asFloydSteinbergDitheredGrayImageDepth:8) inspect |
|
370 |
||
371 |
"Created: 3.6.1997 / 18:34:05 / cg" |
|
372 |
"Modified: 3.6.1997 / 18:39:16 / cg" |
|
373 |
! |
|
374 |
||
375 |
convertToMono |
|
376 |
(image asFloydSteinbergDitheredGrayImageDepth:1) inspect |
|
377 |
||
378 |
"Created: 3.6.1997 / 18:33:42 / cg" |
|
379 |
"Modified: 3.6.1997 / 18:39:26 / cg" |
|
380 |
! ! |
|
381 |
||
161 | 382 |
!ImageEditView methodsFor:'image processing'! |
383 |
||
384 |
blurr |
|
385 |
self performImageOperation:#blurr withArguments:nil |
|
386 |
! |
|
387 |
||
388 |
flipHorizontal |
|
389 |
self performImageOperation:#flipHorizontal withArguments:nil |
|
390 |
! |
|
391 |
||
392 |
flipVertical |
|
393 |
self performImageOperation:#flipVertical withArguments:nil |
|
394 |
! |
|
395 |
||
426 | 396 |
negative |
397 |
self performImageOperation:#negative withArguments:nil |
|
398 |
||
399 |
"Modified: 20.6.1997 / 13:14:45 / cg" |
|
400 |
! |
|
401 |
||
161 | 402 |
performImageOperation:operation withArguments:args |
429 | 403 |
|oldMag newImage| |
161 | 404 |
|
405 |
windowGroup withCursor:Cursor wait do:[ |
|
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
406 |
oldMag := magnification. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
407 |
magnifiedImage := nil. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
408 |
magnification := 1@1. |
429 | 409 |
newImage := image perform:operation withArguments:args. |
410 |
newImage isNil ifTrue:[ |
|
411 |
self information:'conversion failed - revert to original'. |
|
412 |
^ self |
|
413 |
]. |
|
414 |
image := newImage. |
|
413 | 415 |
self clear. |
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
416 |
(oldMag isNil or:[oldMag = magnification]) ifTrue:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
417 |
self invalidate |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
418 |
] ifFalse:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
419 |
self magnification:oldMag. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
420 |
] |
161 | 421 |
] |
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
422 |
|
429 | 423 |
"Modified: 23.6.1997 / 09:49:26 / cg" |
322 | 424 |
! |
425 |
||
426 |
rotateCCW |
|
427 |
self performImageOperation:#rotated: withArguments:#(270) |
|
428 |
||
429 |
"Created: 17.3.1997 / 11:56:42 / cg" |
|
430 |
! |
|
431 |
||
432 |
rotateCW |
|
433 |
self performImageOperation:#rotated: withArguments:#(90) |
|
434 |
||
435 |
"Created: 17.3.1997 / 11:56:36 / cg" |
|
161 | 436 |
! ! |
437 |
||
1 | 438 |
!ImageEditView methodsFor:'initialization'! |
439 |
||
161 | 440 |
initialize |
441 |
super initialize. |
|
442 |
magnification := 1@1. |
|
404 | 443 |
antiAlias := false. |
296 | 444 |
colors := nil. |
445 |
||
446 |
self menuHolder:self; menuPerformer:self; menuMessage:#imageMenu. |
|
447 |
||
404 | 448 |
"Modified: 2.6.1997 / 15:49:00 / cg" |
297 | 449 |
! ! |
450 |
||
451 |
!ImageEditView methodsFor:'menu'! |
|
452 |
||
453 |
imageMenu |
|
406 | 454 |
|m convertMenu labels selectors| |
161 | 455 |
|
297 | 456 |
image mask notNil ifTrue:[ |
457 |
labels := #( |
|
458 |
'save as ...' |
|
459 |
'save mask as ...' |
|
460 |
). |
|
461 |
selectors := #( |
|
462 |
saveAs |
|
463 |
saveMaskAs |
|
464 |
). |
|
465 |
magnifiedImage notNil ifTrue:[ |
|
466 |
labels := labels , #( |
|
467 |
'-' |
|
468 |
'save magnified as ...' |
|
469 |
'save magnified mask as ...' |
|
470 |
). |
|
5 | 471 |
|
297 | 472 |
selectors := selectors , #( |
473 |
nil |
|
474 |
saveMagnifiedAs |
|
475 |
saveMagnifiedMaskAs |
|
476 |
). |
|
477 |
] |
|
478 |
] ifFalse:[ |
|
479 |
labels := #( |
|
480 |
'save as ...' |
|
481 |
). |
|
482 |
selectors := #( |
|
483 |
saveAs |
|
484 |
). |
|
485 |
magnifiedImage notNil ifTrue:[ |
|
486 |
labels := labels , #( |
|
487 |
'-' |
|
488 |
'save magnified as ...' |
|
489 |
). |
|
490 |
||
491 |
selectors := selectors , #( |
|
492 |
nil |
|
493 |
saveMagnifiedAs |
|
494 |
). |
|
495 |
] |
|
496 |
]. |
|
497 |
||
498 |
labels := labels , #( |
|
499 |
'-' |
|
362 | 500 |
'print' |
405 | 501 |
'print magnified' |
362 | 502 |
'-' |
297 | 503 |
'magnification' |
404 | 504 |
'magnify & antiAlias' |
26 | 505 |
"/ 'colors' |
297 | 506 |
'effects' |
406 | 507 |
'convert to' |
297 | 508 |
). |
509 |
selectors := selectors , #( |
|
510 |
nil |
|
362 | 511 |
doPrint |
405 | 512 |
doPrintMagnified |
362 | 513 |
nil |
297 | 514 |
changeMagnification |
404 | 515 |
changeMagnificationAndAntiAlias |
26 | 516 |
"/ showColors |
297 | 517 |
effects |
406 | 518 |
convert |
297 | 519 |
). |
520 |
||
521 |
m := PopUpMenu |
|
522 |
labels:(resources array:labels) |
|
523 |
selectors:selectors |
|
524 |
receiver:self |
|
525 |
for:self. |
|
5 | 526 |
|
405 | 527 |
magnification = 1 ifTrue:[ |
528 |
m disable:#doPrintMagnified |
|
529 |
]. |
|
530 |
||
5 | 531 |
m subMenuAt:#effects put:( |
297 | 532 |
PopUpMenu labels:(resources array:#( |
533 |
'flip - vertical' |
|
534 |
'flip - horizontal' |
|
322 | 535 |
'-' |
536 |
'rotate - clockwise' |
|
537 |
'rotate - counter clockwise' |
|
426 | 538 |
'-' |
539 |
'negative' |
|
11 | 540 |
" |
297 | 541 |
'blurr' |
11 | 542 |
" |
297 | 543 |
)) |
544 |
selectors:#( |
|
545 |
flipVertical |
|
546 |
flipHorizontal |
|
322 | 547 |
nil |
548 |
rotateCW |
|
549 |
rotateCCW |
|
426 | 550 |
nil |
551 |
negative |
|
11 | 552 |
" |
297 | 553 |
blurr |
11 | 554 |
" |
297 | 555 |
) |
556 |
receiver:self |
|
557 |
for:self |
|
5 | 558 |
|
559 |
). |
|
1 | 560 |
|
406 | 561 |
m subMenuAt:#convert put:( |
562 |
convertMenu := |
|
563 |
PopUpMenu labels:(resources array:#( |
|
564 |
'monochrome (dither)' |
|
565 |
'-' |
|
566 |
'gray 2-plane (dither)' |
|
567 |
'gray 4-plane (dither) ' |
|
568 |
'gray 8-plane ' |
|
569 |
'-' |
|
570 |
"/ 'color 4-plane (dither)' |
|
571 |
"/ 'color 8-plane (dither)' |
|
572 |
'color 24-plane' |
|
573 |
)) |
|
574 |
selectors:#( |
|
575 |
convertToMono |
|
576 |
nil |
|
577 |
convertToGray2 |
|
578 |
convertToGray4 |
|
579 |
convertToGray8 |
|
580 |
nil |
|
581 |
"/ convertToColor4 |
|
582 |
"/ convertToColor8 |
|
583 |
convertToColor24 |
|
584 |
) |
|
585 |
receiver:self |
|
586 |
for:self |
|
587 |
). |
|
426 | 588 |
|
406 | 589 |
image depth == 1 ifTrue:[ |
590 |
convertMenu disable:#convertToMono |
|
591 |
]. |
|
592 |
image depth == 2 ifTrue:[ |
|
593 |
(image photometric ~~ #palette |
|
594 |
and:[image photometric ~~ #rgb]) ifTrue:[ |
|
595 |
convertMenu disable:#convertToGray2 |
|
596 |
] |
|
597 |
]. |
|
598 |
image depth == 4 ifTrue:[ |
|
599 |
(image photometric ~~ #palette |
|
600 |
and:[image photometric ~~ #rgb]) ifTrue:[ |
|
601 |
convertMenu disable:#convertToGray4 |
|
602 |
] ifFalse:[ |
|
603 |
convertMenu disable:#convertToColor4 |
|
604 |
] |
|
605 |
]. |
|
606 |
image depth == 8 ifTrue:[ |
|
607 |
(image photometric ~~ #palette |
|
608 |
and:[image photometric ~~ #rgb]) ifTrue:[ |
|
609 |
convertMenu disable:#convertToGray8 |
|
610 |
] ifFalse:[ |
|
611 |
convertMenu disable:#convertToColor8 |
|
612 |
] |
|
613 |
]. |
|
614 |
image depth == 24 ifTrue:[ |
|
615 |
image photometric == #rgb ifTrue:[ |
|
616 |
convertMenu disable:#convertToColor24 |
|
617 |
] |
|
618 |
]. |
|
619 |
||
297 | 620 |
^ m |
621 |
||
26 | 622 |
" |
623 |
ImageEditView openOn:'bitmaps/SBrowser.xbm' |
|
624 |
ImageEditView openOn:'bitmaps/garfield.gif' |
|
625 |
" |
|
297 | 626 |
|
627 |
"Created: 20.2.1997 / 18:47:17 / cg" |
|
426 | 628 |
"Modified: 20.6.1997 / 13:18:52 / cg" |
1 | 629 |
! ! |
630 |
||
161 | 631 |
!ImageEditView methodsFor:'menu actions'! |
632 |
||
633 |
changeMagnification |
|
634 |
|b| |
|
1 | 635 |
|
161 | 636 |
b := EnterBox new. |
637 |
b title:'magnification (magX @ magY)'. |
|
638 |
b okText:'apply'. |
|
639 |
b abortText:'abort'. |
|
404 | 640 |
b action:[:string | |
641 |
antiAlias ifTrue:[ |
|
642 |
magnification := nil. |
|
643 |
]. |
|
644 |
antiAlias := false. |
|
645 |
self magnification:(Object readFromString:string)]. |
|
161 | 646 |
b initialText:(magnification printString). |
647 |
b showAtPointer |
|
404 | 648 |
|
649 |
"Modified: 2.6.1997 / 15:49:47 / cg" |
|
650 |
! |
|
651 |
||
652 |
changeMagnificationAndAntiAlias |
|
653 |
|b| |
|
654 |
||
655 |
b := EnterBox new. |
|
656 |
b title:'magnification (magX @ magY)'. |
|
657 |
b okText:'apply'. |
|
658 |
b abortText:'abort'. |
|
659 |
b action:[:string | |
|
660 |
antiAlias ifFalse:[ |
|
661 |
magnification := nil. |
|
662 |
]. |
|
663 |
antiAlias := true. |
|
664 |
self magnification:(Object readFromString:string)]. |
|
665 |
b initialText:(magnification printString). |
|
666 |
b showAtPointer |
|
667 |
||
668 |
"Modified: 2.6.1997 / 15:49:58 / cg" |
|
669 |
"Created: 2.6.1997 / 15:51:01 / cg" |
|
161 | 670 |
! |
671 |
||
362 | 672 |
doPrint |
405 | 673 |
self doPrint:image |
674 |
||
675 |
"Modified: 2.6.1997 / 18:32:11 / cg" |
|
676 |
! |
|
677 |
||
678 |
doPrint:anImage |
|
362 | 679 |
|stream psgc| |
680 |
||
681 |
Printer supportsPostscript ifFalse:[ |
|
682 |
self warn:'need a postscript printer'. |
|
683 |
^ self |
|
684 |
]. |
|
685 |
||
686 |
stream := Printer newNative. |
|
687 |
stream isNil ifTrue:[ |
|
688 |
self warn:'cannot open printer stream'. |
|
689 |
^ nil |
|
690 |
]. |
|
691 |
||
398
7b7255a4db0d
show a wait cursor while printing
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
692 |
self withWaitCursorDo:[ |
7b7255a4db0d
show a wait cursor while printing
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
693 |
psgc := PSGraphicsContext on:stream. "/ extent:(1.0 @ 1.0). |
405 | 694 |
psgc displayForm:anImage x:0 y:0. |
398
7b7255a4db0d
show a wait cursor while printing
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
695 |
psgc close. |
7b7255a4db0d
show a wait cursor while printing
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
696 |
] |
362 | 697 |
|
398
7b7255a4db0d
show a wait cursor while printing
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
698 |
"Modified: 28.5.1997 / 10:54:11 / cg" |
405 | 699 |
"Created: 2.6.1997 / 18:32:03 / cg" |
700 |
! |
|
701 |
||
702 |
doPrintMagnified |
|
703 |
self doPrint:(magnifiedImage ? image) |
|
704 |
||
705 |
"Modified: 2.6.1997 / 18:31:54 / cg" |
|
362 | 706 |
! |
707 |
||
297 | 708 |
doSaveImageAs:anImage title:aTitle |
161 | 709 |
"save contents into a file |
710 |
- ask user for filename using a fileSelectionBox." |
|
711 |
||
353 | 712 |
|fileName defaultName rdr i txt suffix| |
713 |
||
714 |
defaultName := pathName ? ''. |
|
715 |
||
716 |
pathName isNil ifTrue:[ |
|
717 |
suffix := 'tiff' |
|
718 |
] ifFalse:[ |
|
719 |
suffix := pathName asFilename suffix. |
|
720 |
"/ a supported suffix ? |
|
721 |
((rdr := Image imageReaderClassForSuffix:suffix) isNil |
|
722 |
or:[(rdr canRepresent:anImage) not]) ifTrue:[ |
|
723 |
suffix := 'tiff'. |
|
724 |
defaultName := (pathName asFilename withSuffix:suffix) pathName |
|
725 |
]. |
|
726 |
]. |
|
251 | 727 |
|
161 | 728 |
fileName := Dialog |
297 | 729 |
requestFileName:(resources string:aTitle) |
353 | 730 |
default:defaultName |
251 | 731 |
ok:(resources string:'save') |
732 |
abort:(resources string:'abort') |
|
353 | 733 |
pattern:('*.' , suffix). |
161 | 734 |
|
735 |
fileName notNil ifTrue:[ |
|
297 | 736 |
anImage saveOn:fileName. |
294
479afb39879a
remember last save-name; use as default for saveBox
Claus Gittinger <cg@exept.de>
parents:
256
diff
changeset
|
737 |
pathName := fileName. |
161 | 738 |
]. |
251 | 739 |
|
297 | 740 |
"Created: 20.2.1997 / 18:52:08 / cg" |
353 | 741 |
"Modified: 10.4.1997 / 17:49:58 / cg" |
297 | 742 |
! |
743 |
||
744 |
saveAs |
|
745 |
"save contents into a file |
|
746 |
- ask user for filename using a fileSelectionBox." |
|
747 |
||
748 |
self doSaveImageAs:image title:'save image in:' |
|
749 |
||
750 |
"Modified: 20.2.1997 / 18:52:37 / cg" |
|
751 |
! |
|
752 |
||
753 |
saveMagnifiedAs |
|
754 |
"save contents into a file |
|
755 |
- ask user for filename using a fileSelectionBox." |
|
756 |
||
757 |
self doSaveImageAs:magnifiedImage title:'save magnified image in:' |
|
758 |
||
759 |
"Created: 20.2.1997 / 18:52:53 / cg" |
|
760 |
! |
|
761 |
||
762 |
saveMagnifiedMaskAs |
|
763 |
"save contents into a file |
|
764 |
- ask user for filename using a fileSelectionBox." |
|
765 |
||
766 |
self doSaveImageAs:(magnifiedImage mask) title:'save magnified mask in:' |
|
767 |
||
768 |
"Created: 20.2.1997 / 18:53:31 / cg" |
|
769 |
"Modified: 20.2.1997 / 18:56:48 / cg" |
|
770 |
! |
|
771 |
||
772 |
saveMaskAs |
|
773 |
"save contents into a file |
|
774 |
- ask user for filename using a fileSelectionBox." |
|
775 |
||
776 |
self doSaveImageAs:(image mask) title:'save mask in:' |
|
777 |
||
778 |
"Created: 20.2.1997 / 18:51:06 / cg" |
|
779 |
"Modified: 20.2.1997 / 18:56:54 / cg" |
|
1 | 780 |
! |
781 |
||
161 | 782 |
showColors |
783 |
colorPanel isNil ifTrue:[ |
|
353 | 784 |
colorPanel := ColorPanel new |
1 | 785 |
]. |
161 | 786 |
colorPanel shown ifFalse:[ |
353 | 787 |
colorPanel open |
161 | 788 |
] |
353 | 789 |
|
790 |
"Modified: 10.4.1997 / 17:22:35 / cg" |
|
1 | 791 |
! ! |
792 |
||
161 | 793 |
!ImageEditView methodsFor:'queries'! |
5 | 794 |
|
161 | 795 |
heightOfContents |
796 |
"return the images height" |
|
797 |
||
798 |
image isNil ifTrue:[^ 0]. |
|
799 |
^ (image height * magnification y) rounded |
|
5 | 800 |
! |
801 |
||
161 | 802 |
widthOfContents |
803 |
"return the images width" |
|
5 | 804 |
|
161 | 805 |
image isNil ifTrue:[^ 0]. |
806 |
^ (image width * magnification x) rounded |
|
5 | 807 |
! ! |
808 |
||
1 | 809 |
!ImageEditView methodsFor:'release'! |
810 |
||
811 |
destroy |
|
812 |
colors := nil. |
|
813 |
magnifiedImage := nil. |
|
814 |
colorPanel notNil ifTrue:[ |
|
26 | 815 |
colorPanel destroy. |
816 |
colorPanel := nil. |
|
1 | 817 |
]. |
818 |
super destroy. |
|
819 |
! ! |
|
161 | 820 |
|
255 | 821 |
!ImageEditView class methodsFor:'documentation'! |
161 | 822 |
|
823 |
version |
|
430 | 824 |
^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.44 1997-06-24 08:01:42 cg Exp $' |
161 | 825 |
! ! |