author | Claus Gittinger <cg@exept.de> |
Fri, 20 Jun 1997 13:19:07 +0200 | |
changeset 426 | 2e3dfa527a07 |
parent 413 | 3d0910d706c9 |
child 429 | f98e6af57214 |
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 |
"/ area := Rectangle left:x top:y width:w height:h. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
164 |
"/ oldClip := self clippingRectangleOrNil. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
165 |
"/ self clippingRectangle:area. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
166 |
|
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
167 |
(magnification = (1@1)) ifTrue:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
168 |
super redrawX:x y:y width:w height:h. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
169 |
"/ self clippingRectangle:oldClip. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
170 |
^ self |
1 | 171 |
]. |
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
172 |
|
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
173 |
"/ self clear. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
174 |
|
1 | 175 |
magnifiedImage notNil ifTrue:[ |
413 | 176 |
self function:#copy. |
177 |
self paint:Black. |
|
178 |
||
179 |
magnifiedImage device ~~ device ifTrue:[ |
|
180 |
"/ 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
|
181 |
|
413 | 182 |
self |
183 |
displayRectangleX:margin y:margin |
|
184 |
width:magnifiedImage width height:magnifiedImage height. |
|
185 |
||
186 |
self withWaitCursorDo:[ |
|
187 |
magnifiedImage := magnifiedImage on:device. |
|
188 |
] |
|
204 | 189 |
]. |
190 |
||
413 | 191 |
self withWaitCursorDo:[ |
192 |
magnifiedImage depth == 1 ifTrue:[ |
|
193 |
self paint:(magnifiedImage colorFromValue:1) |
|
194 |
on:(magnifiedImage colorFromValue:0). |
|
195 |
] ifFalse:[ |
|
196 |
self paint:Black on:White. |
|
197 |
]. |
|
295
6388ebe84be2
fixed display of magnified image with mask.
Claus Gittinger <cg@exept.de>
parents:
294
diff
changeset
|
198 |
|
413 | 199 |
(magnifiedImage depth ~~ 1 |
200 |
and:[magnifiedImage mask notNil]) ifTrue:[ |
|
201 |
self clearRectangleX:x y:y width:w height:h. |
|
202 |
self displayForm:magnifiedImage x:margin y:margin |
|
203 |
] ifFalse:[ |
|
204 |
self displayOpaqueForm:magnifiedImage x:margin y:margin |
|
205 |
]. |
|
295
6388ebe84be2
fixed display of magnified image with mask.
Claus Gittinger <cg@exept.de>
parents:
294
diff
changeset
|
206 |
]. |
6388ebe84be2
fixed display of magnified image with mask.
Claus Gittinger <cg@exept.de>
parents:
294
diff
changeset
|
207 |
|
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
208 |
"/ self clippingRectangle:oldClip. |
203 | 209 |
^ self |
1 | 210 |
]. |
211 |
||
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
212 |
"/ self clear. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
213 |
ih := image height. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
214 |
iw := image width. |
1 | 215 |
dotW := magnification x. |
216 |
dotH := magnification y. |
|
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
217 |
|
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
218 |
minX := x // dotW. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
219 |
minY := y // dotW. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
220 |
maxX := (x + w) // dotW + 1. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
221 |
maxX > iw ifTrue:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
222 |
maxX := iw |
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 |
maxY := (y + h) // dotH + 1. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
225 |
maxY > ih ifTrue:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
226 |
maxY := ih |
1 | 227 |
]. |
228 |
||
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
229 |
lastY := -1. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
230 |
|
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
231 |
x0 := minX. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
232 |
runW := 0. |
204 | 233 |
|
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
234 |
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
|
235 |
y ~~ lastY ifTrue:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
236 |
runW ~~ 0 ifTrue:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
237 |
self fillRectangleX:(x0 * dotW + margin) |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
238 |
y:(lastY * dotH + margin) |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
239 |
width:runW height:dotH. |
203 | 240 |
runW := 0. |
241 |
]. |
|
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
242 |
x0 := x. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
243 |
lastY := y. |
204 | 244 |
]. |
1 | 245 |
|
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
246 |
color ~~ last ifTrue:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
247 |
runW ~~ 0 ifTrue:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
248 |
self fillRectangleX:(x0 * dotW + margin) |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
249 |
y:(y * dotH + margin) |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
250 |
width:runW height:dotH. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
251 |
runW := 0. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
252 |
]. |
204 | 253 |
|
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
254 |
"/ keep colors - otherwise they might get collected & changed |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
255 |
colors notNil ifTrue:[colors add:color]. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
256 |
self paint:color. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
257 |
last := color. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
258 |
runW := 0. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
259 |
x0 := x. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
260 |
]. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
261 |
runW := runW + dotW |
191 | 262 |
]. |
263 |
||
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
264 |
runW ~~ 0 ifTrue:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
265 |
self fillRectangleX:(x0 * dotW + margin) |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
266 |
y:(lastY * dotH + margin) |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
267 |
width:runW height:dotH. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
268 |
runW := 0. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
269 |
]. |
191 | 270 |
|
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
271 |
"/ self clippingRectangle:oldClip |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
272 |
|
413 | 273 |
"Modified: 4.6.1997 / 13:45:53 / cg" |
1 | 274 |
! ! |
275 |
||
161 | 276 |
!ImageEditView methodsFor:'event handling'! |
277 |
||
278 |
buttonMotion:state x:x y:y |
|
279 |
self showColorAtX:x y:y. |
|
280 |
! |
|
281 |
||
167
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
282 |
buttonMultiPress:button x:x y:y |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
283 |
button == 1 ifTrue:[ |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
284 |
|clr| |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
285 |
clr := self getColorAtX:x y:y. |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
286 |
clr inspect. |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
287 |
]. |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
288 |
super buttonMultiPress:button x:x y:y |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
289 |
|
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
290 |
"Created: 8.5.1996 / 00:18:06 / stefan" |
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 |
|
161 | 293 |
buttonPress:button x:x y:y |
294 |
button == 1 ifTrue:[ |
|
295 |
self showColorAtX:x y:y. |
|
296 |
^ self |
|
297 |
]. |
|
298 |
super buttonPress:button x:x y:y |
|
299 |
! |
|
300 |
||
167
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
301 |
getColorAtX:x y:y |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
302 |
|pi| |
161 | 303 |
|
304 |
pi := (x @ y) - margin. |
|
305 |
pi := pi // magnification. |
|
306 |
((0@0 corner:image extent) containsPoint:pi) ifTrue:[ |
|
167
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
307 |
^ image at:pi. |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
308 |
]. |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
309 |
^ nil |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
310 |
|
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
311 |
"Created: 8.5.1996 / 00:15:55 / stefan" |
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 |
|
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
314 |
showColorAtX:x y:y |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
315 |
|clr| |
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 |
clr := self getColorAtX:x y:y. |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
318 |
clr notNil ifTrue:[ |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
319 |
colorPanel notNil ifTrue:[ |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
320 |
colorPanel setColor:clr. |
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
321 |
] ifFalse:[ |
184 | 322 |
Transcript showCR:clr displayString |
167
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
323 |
] |
161 | 324 |
] |
167
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
325 |
|
0d6d90115420
Doubleclick on pixel opens colorInspector.
Stefan Vogel <sv@exept.de>
parents:
161
diff
changeset
|
326 |
"Modified: 8.5.1996 / 00:20:45 / stefan" |
161 | 327 |
! ! |
328 |
||
406 | 329 |
!ImageEditView methodsFor:'image conversion'! |
330 |
||
331 |
convertToColor24 |
|
332 |
(Depth24Image fromImage:image) inspect |
|
333 |
||
334 |
"Modified: 3.6.1997 / 18:34:34 / cg" |
|
335 |
! |
|
336 |
||
337 |
convertToColor4 |
|
338 |
(Depth4Image fromImage:image) inspect |
|
339 |
||
340 |
"Modified: 3.6.1997 / 18:34:45 / cg" |
|
341 |
! |
|
342 |
||
343 |
convertToColor8 |
|
344 |
(Depth8Image fromImage:image) inspect |
|
345 |
||
346 |
"Created: 3.6.1997 / 18:34:08 / cg" |
|
347 |
"Modified: 3.6.1997 / 18:34:51 / cg" |
|
348 |
! |
|
349 |
||
350 |
convertToGray2 |
|
351 |
(image asFloydSteinbergDitheredGrayImageDepth:2) inspect |
|
352 |
||
353 |
"Created: 3.6.1997 / 18:34:02 / cg" |
|
354 |
"Modified: 3.6.1997 / 18:39:23 / cg" |
|
355 |
! |
|
356 |
||
357 |
convertToGray4 |
|
358 |
(image asFloydSteinbergDitheredGrayImageDepth:4) inspect |
|
359 |
||
360 |
"Created: 3.6.1997 / 18:34:04 / cg" |
|
361 |
"Modified: 3.6.1997 / 18:39:20 / cg" |
|
362 |
! |
|
363 |
||
364 |
convertToGray8 |
|
365 |
(image asFloydSteinbergDitheredGrayImageDepth:8) inspect |
|
366 |
||
367 |
"Created: 3.6.1997 / 18:34:05 / cg" |
|
368 |
"Modified: 3.6.1997 / 18:39:16 / cg" |
|
369 |
! |
|
370 |
||
371 |
convertToMono |
|
372 |
(image asFloydSteinbergDitheredGrayImageDepth:1) inspect |
|
373 |
||
374 |
"Created: 3.6.1997 / 18:33:42 / cg" |
|
375 |
"Modified: 3.6.1997 / 18:39:26 / cg" |
|
376 |
! ! |
|
377 |
||
161 | 378 |
!ImageEditView methodsFor:'image processing'! |
379 |
||
380 |
blurr |
|
381 |
self performImageOperation:#blurr withArguments:nil |
|
382 |
! |
|
383 |
||
384 |
flipHorizontal |
|
385 |
self performImageOperation:#flipHorizontal withArguments:nil |
|
386 |
! |
|
387 |
||
388 |
flipVertical |
|
389 |
self performImageOperation:#flipVertical withArguments:nil |
|
390 |
! |
|
391 |
||
426 | 392 |
negative |
393 |
self performImageOperation:#negative withArguments:nil |
|
394 |
||
395 |
"Modified: 20.6.1997 / 13:14:45 / cg" |
|
396 |
! |
|
397 |
||
161 | 398 |
performImageOperation:operation withArguments:args |
399 |
|oldMag| |
|
400 |
||
401 |
windowGroup withCursor:Cursor wait do:[ |
|
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
402 |
oldMag := magnification. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
403 |
magnifiedImage := nil. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
404 |
magnification := 1@1. |
322 | 405 |
image := image perform:operation withArguments:args. |
413 | 406 |
self clear. |
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
407 |
(oldMag isNil or:[oldMag = magnification]) ifTrue:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
408 |
self invalidate |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
409 |
] ifFalse:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
410 |
self magnification:oldMag. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
411 |
] |
161 | 412 |
] |
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
413 |
|
413 | 414 |
"Modified: 4.6.1997 / 13:40:37 / cg" |
322 | 415 |
! |
416 |
||
417 |
rotateCCW |
|
418 |
self performImageOperation:#rotated: withArguments:#(270) |
|
419 |
||
420 |
"Created: 17.3.1997 / 11:56:42 / cg" |
|
421 |
! |
|
422 |
||
423 |
rotateCW |
|
424 |
self performImageOperation:#rotated: withArguments:#(90) |
|
425 |
||
426 |
"Created: 17.3.1997 / 11:56:36 / cg" |
|
161 | 427 |
! ! |
428 |
||
1 | 429 |
!ImageEditView methodsFor:'initialization'! |
430 |
||
161 | 431 |
initialize |
432 |
super initialize. |
|
433 |
magnification := 1@1. |
|
404 | 434 |
antiAlias := false. |
296 | 435 |
colors := nil. |
436 |
||
437 |
self menuHolder:self; menuPerformer:self; menuMessage:#imageMenu. |
|
438 |
||
404 | 439 |
"Modified: 2.6.1997 / 15:49:00 / cg" |
297 | 440 |
! ! |
441 |
||
442 |
!ImageEditView methodsFor:'menu'! |
|
443 |
||
444 |
imageMenu |
|
406 | 445 |
|m convertMenu labels selectors| |
161 | 446 |
|
297 | 447 |
image mask notNil ifTrue:[ |
448 |
labels := #( |
|
449 |
'save as ...' |
|
450 |
'save mask as ...' |
|
451 |
). |
|
452 |
selectors := #( |
|
453 |
saveAs |
|
454 |
saveMaskAs |
|
455 |
). |
|
456 |
magnifiedImage notNil ifTrue:[ |
|
457 |
labels := labels , #( |
|
458 |
'-' |
|
459 |
'save magnified as ...' |
|
460 |
'save magnified mask as ...' |
|
461 |
). |
|
5 | 462 |
|
297 | 463 |
selectors := selectors , #( |
464 |
nil |
|
465 |
saveMagnifiedAs |
|
466 |
saveMagnifiedMaskAs |
|
467 |
). |
|
468 |
] |
|
469 |
] ifFalse:[ |
|
470 |
labels := #( |
|
471 |
'save as ...' |
|
472 |
). |
|
473 |
selectors := #( |
|
474 |
saveAs |
|
475 |
). |
|
476 |
magnifiedImage notNil ifTrue:[ |
|
477 |
labels := labels , #( |
|
478 |
'-' |
|
479 |
'save magnified as ...' |
|
480 |
). |
|
481 |
||
482 |
selectors := selectors , #( |
|
483 |
nil |
|
484 |
saveMagnifiedAs |
|
485 |
). |
|
486 |
] |
|
487 |
]. |
|
488 |
||
489 |
labels := labels , #( |
|
490 |
'-' |
|
362 | 491 |
'print' |
405 | 492 |
'print magnified' |
362 | 493 |
'-' |
297 | 494 |
'magnification' |
404 | 495 |
'magnify & antiAlias' |
26 | 496 |
"/ 'colors' |
297 | 497 |
'effects' |
406 | 498 |
'convert to' |
297 | 499 |
). |
500 |
selectors := selectors , #( |
|
501 |
nil |
|
362 | 502 |
doPrint |
405 | 503 |
doPrintMagnified |
362 | 504 |
nil |
297 | 505 |
changeMagnification |
404 | 506 |
changeMagnificationAndAntiAlias |
26 | 507 |
"/ showColors |
297 | 508 |
effects |
406 | 509 |
convert |
297 | 510 |
). |
511 |
||
512 |
m := PopUpMenu |
|
513 |
labels:(resources array:labels) |
|
514 |
selectors:selectors |
|
515 |
receiver:self |
|
516 |
for:self. |
|
5 | 517 |
|
405 | 518 |
magnification = 1 ifTrue:[ |
519 |
m disable:#doPrintMagnified |
|
520 |
]. |
|
521 |
||
5 | 522 |
m subMenuAt:#effects put:( |
297 | 523 |
PopUpMenu labels:(resources array:#( |
524 |
'flip - vertical' |
|
525 |
'flip - horizontal' |
|
322 | 526 |
'-' |
527 |
'rotate - clockwise' |
|
528 |
'rotate - counter clockwise' |
|
426 | 529 |
'-' |
530 |
'negative' |
|
11 | 531 |
" |
297 | 532 |
'blurr' |
11 | 533 |
" |
297 | 534 |
)) |
535 |
selectors:#( |
|
536 |
flipVertical |
|
537 |
flipHorizontal |
|
322 | 538 |
nil |
539 |
rotateCW |
|
540 |
rotateCCW |
|
426 | 541 |
nil |
542 |
negative |
|
11 | 543 |
" |
297 | 544 |
blurr |
11 | 545 |
" |
297 | 546 |
) |
547 |
receiver:self |
|
548 |
for:self |
|
5 | 549 |
|
550 |
). |
|
1 | 551 |
|
406 | 552 |
m subMenuAt:#convert put:( |
553 |
convertMenu := |
|
554 |
PopUpMenu labels:(resources array:#( |
|
555 |
'monochrome (dither)' |
|
556 |
'-' |
|
557 |
'gray 2-plane (dither)' |
|
558 |
'gray 4-plane (dither) ' |
|
559 |
'gray 8-plane ' |
|
560 |
'-' |
|
561 |
"/ 'color 4-plane (dither)' |
|
562 |
"/ 'color 8-plane (dither)' |
|
563 |
'color 24-plane' |
|
564 |
)) |
|
565 |
selectors:#( |
|
566 |
convertToMono |
|
567 |
nil |
|
568 |
convertToGray2 |
|
569 |
convertToGray4 |
|
570 |
convertToGray8 |
|
571 |
nil |
|
572 |
"/ convertToColor4 |
|
573 |
"/ convertToColor8 |
|
574 |
convertToColor24 |
|
575 |
) |
|
576 |
receiver:self |
|
577 |
for:self |
|
578 |
). |
|
426 | 579 |
|
406 | 580 |
image depth == 1 ifTrue:[ |
581 |
convertMenu disable:#convertToMono |
|
582 |
]. |
|
583 |
image depth == 2 ifTrue:[ |
|
584 |
(image photometric ~~ #palette |
|
585 |
and:[image photometric ~~ #rgb]) ifTrue:[ |
|
586 |
convertMenu disable:#convertToGray2 |
|
587 |
] |
|
588 |
]. |
|
589 |
image depth == 4 ifTrue:[ |
|
590 |
(image photometric ~~ #palette |
|
591 |
and:[image photometric ~~ #rgb]) ifTrue:[ |
|
592 |
convertMenu disable:#convertToGray4 |
|
593 |
] ifFalse:[ |
|
594 |
convertMenu disable:#convertToColor4 |
|
595 |
] |
|
596 |
]. |
|
597 |
image depth == 8 ifTrue:[ |
|
598 |
(image photometric ~~ #palette |
|
599 |
and:[image photometric ~~ #rgb]) ifTrue:[ |
|
600 |
convertMenu disable:#convertToGray8 |
|
601 |
] ifFalse:[ |
|
602 |
convertMenu disable:#convertToColor8 |
|
603 |
] |
|
604 |
]. |
|
605 |
image depth == 24 ifTrue:[ |
|
606 |
image photometric == #rgb ifTrue:[ |
|
607 |
convertMenu disable:#convertToColor24 |
|
608 |
] |
|
609 |
]. |
|
610 |
||
297 | 611 |
^ m |
612 |
||
26 | 613 |
" |
614 |
ImageEditView openOn:'bitmaps/SBrowser.xbm' |
|
615 |
ImageEditView openOn:'bitmaps/garfield.gif' |
|
616 |
" |
|
297 | 617 |
|
618 |
"Created: 20.2.1997 / 18:47:17 / cg" |
|
426 | 619 |
"Modified: 20.6.1997 / 13:18:52 / cg" |
1 | 620 |
! ! |
621 |
||
161 | 622 |
!ImageEditView methodsFor:'menu actions'! |
623 |
||
624 |
changeMagnification |
|
625 |
|b| |
|
1 | 626 |
|
161 | 627 |
b := EnterBox new. |
628 |
b title:'magnification (magX @ magY)'. |
|
629 |
b okText:'apply'. |
|
630 |
b abortText:'abort'. |
|
404 | 631 |
b action:[:string | |
632 |
antiAlias ifTrue:[ |
|
633 |
magnification := nil. |
|
634 |
]. |
|
635 |
antiAlias := false. |
|
636 |
self magnification:(Object readFromString:string)]. |
|
161 | 637 |
b initialText:(magnification printString). |
638 |
b showAtPointer |
|
404 | 639 |
|
640 |
"Modified: 2.6.1997 / 15:49:47 / cg" |
|
641 |
! |
|
642 |
||
643 |
changeMagnificationAndAntiAlias |
|
644 |
|b| |
|
645 |
||
646 |
b := EnterBox new. |
|
647 |
b title:'magnification (magX @ magY)'. |
|
648 |
b okText:'apply'. |
|
649 |
b abortText:'abort'. |
|
650 |
b action:[:string | |
|
651 |
antiAlias ifFalse:[ |
|
652 |
magnification := nil. |
|
653 |
]. |
|
654 |
antiAlias := true. |
|
655 |
self magnification:(Object readFromString:string)]. |
|
656 |
b initialText:(magnification printString). |
|
657 |
b showAtPointer |
|
658 |
||
659 |
"Modified: 2.6.1997 / 15:49:58 / cg" |
|
660 |
"Created: 2.6.1997 / 15:51:01 / cg" |
|
161 | 661 |
! |
662 |
||
362 | 663 |
doPrint |
405 | 664 |
self doPrint:image |
665 |
||
666 |
"Modified: 2.6.1997 / 18:32:11 / cg" |
|
667 |
! |
|
668 |
||
669 |
doPrint:anImage |
|
362 | 670 |
|stream psgc| |
671 |
||
672 |
Printer supportsPostscript ifFalse:[ |
|
673 |
self warn:'need a postscript printer'. |
|
674 |
^ self |
|
675 |
]. |
|
676 |
||
677 |
stream := Printer newNative. |
|
678 |
stream isNil ifTrue:[ |
|
679 |
self warn:'cannot open printer stream'. |
|
680 |
^ nil |
|
681 |
]. |
|
682 |
||
398
7b7255a4db0d
show a wait cursor while printing
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
683 |
self withWaitCursorDo:[ |
7b7255a4db0d
show a wait cursor while printing
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
684 |
psgc := PSGraphicsContext on:stream. "/ extent:(1.0 @ 1.0). |
405 | 685 |
psgc displayForm:anImage x:0 y:0. |
398
7b7255a4db0d
show a wait cursor while printing
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
686 |
psgc close. |
7b7255a4db0d
show a wait cursor while printing
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
687 |
] |
362 | 688 |
|
398
7b7255a4db0d
show a wait cursor while printing
Claus Gittinger <cg@exept.de>
parents:
362
diff
changeset
|
689 |
"Modified: 28.5.1997 / 10:54:11 / cg" |
405 | 690 |
"Created: 2.6.1997 / 18:32:03 / cg" |
691 |
! |
|
692 |
||
693 |
doPrintMagnified |
|
694 |
self doPrint:(magnifiedImage ? image) |
|
695 |
||
696 |
"Modified: 2.6.1997 / 18:31:54 / cg" |
|
362 | 697 |
! |
698 |
||
297 | 699 |
doSaveImageAs:anImage title:aTitle |
161 | 700 |
"save contents into a file |
701 |
- ask user for filename using a fileSelectionBox." |
|
702 |
||
353 | 703 |
|fileName defaultName rdr i txt suffix| |
704 |
||
705 |
defaultName := pathName ? ''. |
|
706 |
||
707 |
pathName isNil ifTrue:[ |
|
708 |
suffix := 'tiff' |
|
709 |
] ifFalse:[ |
|
710 |
suffix := pathName asFilename suffix. |
|
711 |
"/ a supported suffix ? |
|
712 |
((rdr := Image imageReaderClassForSuffix:suffix) isNil |
|
713 |
or:[(rdr canRepresent:anImage) not]) ifTrue:[ |
|
714 |
suffix := 'tiff'. |
|
715 |
defaultName := (pathName asFilename withSuffix:suffix) pathName |
|
716 |
]. |
|
717 |
]. |
|
251 | 718 |
|
161 | 719 |
fileName := Dialog |
297 | 720 |
requestFileName:(resources string:aTitle) |
353 | 721 |
default:defaultName |
251 | 722 |
ok:(resources string:'save') |
723 |
abort:(resources string:'abort') |
|
353 | 724 |
pattern:('*.' , suffix). |
161 | 725 |
|
726 |
fileName notNil ifTrue:[ |
|
297 | 727 |
anImage saveOn:fileName. |
294
479afb39879a
remember last save-name; use as default for saveBox
Claus Gittinger <cg@exept.de>
parents:
256
diff
changeset
|
728 |
pathName := fileName. |
161 | 729 |
]. |
251 | 730 |
|
297 | 731 |
"Created: 20.2.1997 / 18:52:08 / cg" |
353 | 732 |
"Modified: 10.4.1997 / 17:49:58 / cg" |
297 | 733 |
! |
734 |
||
735 |
saveAs |
|
736 |
"save contents into a file |
|
737 |
- ask user for filename using a fileSelectionBox." |
|
738 |
||
739 |
self doSaveImageAs:image title:'save image in:' |
|
740 |
||
741 |
"Modified: 20.2.1997 / 18:52:37 / cg" |
|
742 |
! |
|
743 |
||
744 |
saveMagnifiedAs |
|
745 |
"save contents into a file |
|
746 |
- ask user for filename using a fileSelectionBox." |
|
747 |
||
748 |
self doSaveImageAs:magnifiedImage title:'save magnified image in:' |
|
749 |
||
750 |
"Created: 20.2.1997 / 18:52:53 / cg" |
|
751 |
! |
|
752 |
||
753 |
saveMagnifiedMaskAs |
|
754 |
"save contents into a file |
|
755 |
- ask user for filename using a fileSelectionBox." |
|
756 |
||
757 |
self doSaveImageAs:(magnifiedImage mask) title:'save magnified mask in:' |
|
758 |
||
759 |
"Created: 20.2.1997 / 18:53:31 / cg" |
|
760 |
"Modified: 20.2.1997 / 18:56:48 / cg" |
|
761 |
! |
|
762 |
||
763 |
saveMaskAs |
|
764 |
"save contents into a file |
|
765 |
- ask user for filename using a fileSelectionBox." |
|
766 |
||
767 |
self doSaveImageAs:(image mask) title:'save mask in:' |
|
768 |
||
769 |
"Created: 20.2.1997 / 18:51:06 / cg" |
|
770 |
"Modified: 20.2.1997 / 18:56:54 / cg" |
|
1 | 771 |
! |
772 |
||
161 | 773 |
showColors |
774 |
colorPanel isNil ifTrue:[ |
|
353 | 775 |
colorPanel := ColorPanel new |
1 | 776 |
]. |
161 | 777 |
colorPanel shown ifFalse:[ |
353 | 778 |
colorPanel open |
161 | 779 |
] |
353 | 780 |
|
781 |
"Modified: 10.4.1997 / 17:22:35 / cg" |
|
1 | 782 |
! ! |
783 |
||
161 | 784 |
!ImageEditView methodsFor:'queries'! |
5 | 785 |
|
161 | 786 |
heightOfContents |
787 |
"return the images height" |
|
788 |
||
789 |
image isNil ifTrue:[^ 0]. |
|
790 |
^ (image height * magnification y) rounded |
|
5 | 791 |
! |
792 |
||
161 | 793 |
widthOfContents |
794 |
"return the images width" |
|
5 | 795 |
|
161 | 796 |
image isNil ifTrue:[^ 0]. |
797 |
^ (image width * magnification x) rounded |
|
5 | 798 |
! ! |
799 |
||
1 | 800 |
!ImageEditView methodsFor:'release'! |
801 |
||
802 |
destroy |
|
803 |
colors := nil. |
|
804 |
magnifiedImage := nil. |
|
805 |
colorPanel notNil ifTrue:[ |
|
26 | 806 |
colorPanel destroy. |
807 |
colorPanel := nil. |
|
1 | 808 |
]. |
809 |
super destroy. |
|
810 |
! ! |
|
161 | 811 |
|
255 | 812 |
!ImageEditView class methodsFor:'documentation'! |
161 | 813 |
|
814 |
version |
|
426 | 815 |
^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.42 1997-06-20 11:19:07 cg Exp $' |
161 | 816 |
! ! |