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
|
26
|
14 |
instanceVariableNames:'magnification colors magnifiedImage
|
40
|
15 |
colorPanel'
|
26
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Views-Misc'
|
1
|
19 |
!
|
|
20 |
|
|
21 |
ImageEditView comment:'
|
|
22 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
26
|
23 |
All Rights Reserved
|
1
|
24 |
|
|
25 |
a View to edit images - in construction
|
|
26 |
|
64
|
27 |
$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.13 1995-07-03 02:35:15 claus Exp $
|
1
|
28 |
'!
|
|
29 |
|
64
|
30 |
!ImageEditView class methodsFor:'documentation'!
|
|
31 |
|
|
32 |
copyright
|
|
33 |
"
|
|
34 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
35 |
All Rights Reserved
|
|
36 |
|
|
37 |
This software is furnished under a license and may be used
|
|
38 |
only in accordance with the terms of that license and with the
|
|
39 |
inclusion of the above copyright notice. This software may not
|
|
40 |
be provided or otherwise made available to, or used by, any
|
|
41 |
other person. No title to or ownership of the software is
|
|
42 |
hereby transferred.
|
|
43 |
"
|
|
44 |
!
|
|
45 |
|
|
46 |
documentation
|
|
47 |
"
|
|
48 |
This View will eventually be able to edit bitmap images.
|
|
49 |
For now, it is not.
|
|
50 |
"
|
|
51 |
! !
|
|
52 |
|
1
|
53 |
!ImageEditView methodsFor:'queries'!
|
|
54 |
|
|
55 |
widthOfContents
|
|
56 |
"return the images width"
|
|
57 |
|
|
58 |
image isNil ifTrue:[^ 0].
|
|
59 |
^ (image width * magnification x) rounded
|
|
60 |
!
|
|
61 |
|
|
62 |
heightOfContents
|
|
63 |
"return the images height"
|
|
64 |
|
|
65 |
image isNil ifTrue:[^ 0].
|
|
66 |
^ (image height * magnification y) rounded
|
|
67 |
! !
|
|
68 |
|
7
|
69 |
!ImageEditView methodsFor:'accessing'!
|
|
70 |
|
|
71 |
image:anImage
|
|
72 |
magnification := 1@1.
|
|
73 |
magnifiedImage := nil.
|
|
74 |
super image:anImage
|
|
75 |
! !
|
|
76 |
|
1
|
77 |
!ImageEditView methodsFor:'menu actions'!
|
|
78 |
|
|
79 |
saveAs
|
|
80 |
"save contents into a file
|
|
81 |
- ask user for filename using a fileSelectionBox."
|
|
82 |
|
40
|
83 |
|fileName|
|
|
84 |
|
41
|
85 |
fileName := Dialog
|
40
|
86 |
requestFileName:'save image in:'
|
|
87 |
default:''
|
|
88 |
ok:'save'
|
|
89 |
abort:'abort'
|
|
90 |
pattern:'*.tiff'.
|
|
91 |
|
|
92 |
fileName notNil ifTrue:[
|
|
93 |
image saveOn:fileName
|
1
|
94 |
].
|
|
95 |
!
|
|
96 |
|
|
97 |
showColors
|
|
98 |
colorPanel isNil ifTrue:[
|
26
|
99 |
colorPanel := ColorPanel new
|
1
|
100 |
].
|
|
101 |
colorPanel shown ifFalse:[
|
26
|
102 |
colorPanel realize
|
1
|
103 |
]
|
|
104 |
!
|
|
105 |
|
|
106 |
changeMagnification
|
|
107 |
|b|
|
|
108 |
|
|
109 |
b := EnterBox new.
|
|
110 |
b title:'magnification (magX @ magY)'.
|
|
111 |
b okText:'apply'.
|
|
112 |
b abortText:'abort'.
|
|
113 |
b action:[:string | self magnification:(Object readFromString:string)].
|
|
114 |
b initialText:(magnification printString).
|
|
115 |
b showAtPointer
|
|
116 |
!
|
|
117 |
|
|
118 |
magnification:aMagnificationPoint
|
|
119 |
|nPixel savedImage|
|
|
120 |
|
|
121 |
magnification ~= aMagnificationPoint ifTrue:[
|
26
|
122 |
"show wait cursor; although magnification is fast, dithering may take a while"
|
|
123 |
self cursor:Cursor wait.
|
1
|
124 |
|
26
|
125 |
(device visualType == #PseudoColor) ifTrue:[
|
|
126 |
"keep colors - otherwise they might get collected & changed"
|
|
127 |
colors := IdentitySet new.
|
|
128 |
].
|
1
|
129 |
|
26
|
130 |
magnification := aMagnificationPoint asPoint.
|
1
|
131 |
|
26
|
132 |
"use a magnified image, if its size wont be too big"
|
|
133 |
magnifiedImage := nil.
|
1
|
134 |
|
26
|
135 |
"avoid slow scroll"
|
|
136 |
savedImage := image.
|
|
137 |
image := nil.
|
|
138 |
self scrollToTopLeft.
|
|
139 |
image := savedImage.
|
1
|
140 |
|
26
|
141 |
magnification ~= (1@1) ifTrue:[
|
|
142 |
nPixel := image width * image height * magnification x * magnification y.
|
|
143 |
nPixel <= (device width * device height) ifTrue:[
|
|
144 |
Transcript showCr:'magnifying ..'; endEntry.
|
|
145 |
magnifiedImage := image magnifyBy:magnification
|
|
146 |
].
|
|
147 |
].
|
1
|
148 |
|
26
|
149 |
self contentsChanged.
|
|
150 |
self redraw.
|
|
151 |
self cursor:Cursor normal
|
1
|
152 |
]
|
|
153 |
! !
|
|
154 |
|
|
155 |
!ImageEditView methodsFor:'drawing'!
|
|
156 |
|
|
157 |
redraw
|
|
158 |
|x0 y h w dotW dotH color last runW|
|
|
159 |
|
|
160 |
image isNil ifTrue:[^ self].
|
|
161 |
|
|
162 |
magnification = (1@1) ifTrue:[
|
26
|
163 |
^ super redraw
|
1
|
164 |
].
|
|
165 |
magnifiedImage notNil ifTrue:[
|
26
|
166 |
magnifiedImage := magnifiedImage on:device.
|
|
167 |
self clear.
|
|
168 |
self foreground:Black background:White.
|
|
169 |
self function:#copy.
|
46
|
170 |
self displayOpaqueForm:magnifiedImage x:0 y:0.
|
26
|
171 |
^ self
|
1
|
172 |
].
|
|
173 |
|
|
174 |
self clear.
|
|
175 |
|
|
176 |
h := image height.
|
|
177 |
w := image width.
|
|
178 |
dotW := magnification x.
|
|
179 |
dotH := magnification y.
|
46
|
180 |
((h * dotH > height) or:[w * dotW > width]) ifTrue:[
|
26
|
181 |
^ self redrawX:0 y:0 width:width height:height
|
1
|
182 |
].
|
|
183 |
|
|
184 |
y := 0.
|
|
185 |
0 to:h-1 do:[:row |
|
26
|
186 |
runW := 0.
|
|
187 |
x0 := 0.
|
|
188 |
image atY:row from:0 to:(w-1) do:[:x :color |
|
|
189 |
color ~= last ifTrue:[
|
|
190 |
runW ~~ 0 ifTrue:[
|
|
191 |
self fillRectangleX:x0 y:y width:runW height:dotH.
|
|
192 |
].
|
|
193 |
colors notNil ifTrue:[colors add:color].
|
|
194 |
self paint:color.
|
|
195 |
last := color.
|
|
196 |
x0 := x.
|
|
197 |
runW := 0.
|
|
198 |
].
|
|
199 |
runW := runW + dotW
|
|
200 |
].
|
|
201 |
self fillRectangleX:x0 y:y width:runW height:dotH.
|
|
202 |
y := y + dotH
|
1
|
203 |
]
|
|
204 |
!
|
|
205 |
|
|
206 |
redrawX:x y:y width:w height:h
|
|
207 |
|area dx dy ih iw dotW dotH minX maxX minY maxY color last runW x0|
|
|
208 |
|
|
209 |
image isNil ifTrue:[^ self].
|
|
210 |
|
|
211 |
area := Rectangle left:x top:y width:w height:h.
|
|
212 |
self clippedTo:area do:[
|
26
|
213 |
magnification = (1@1) ifTrue:[
|
|
214 |
self redraw
|
|
215 |
] ifFalse:[
|
|
216 |
magnifiedImage notNil ifTrue:[
|
|
217 |
self redraw
|
|
218 |
] ifFalse:[
|
|
219 |
self clear.
|
|
220 |
ih := image height.
|
|
221 |
iw := image width.
|
|
222 |
dotW := magnification x.
|
|
223 |
dotH := magnification y.
|
1
|
224 |
|
46
|
225 |
minX := x // dotW.
|
|
226 |
minY := y // dotW.
|
|
227 |
maxX := (x + w) // dotW + 1.
|
26
|
228 |
maxX > iw ifTrue:[
|
|
229 |
maxX := iw
|
|
230 |
].
|
46
|
231 |
maxY := (y + h) // dotH + 1.
|
26
|
232 |
maxY > ih ifTrue:[
|
|
233 |
maxY := ih
|
|
234 |
].
|
1
|
235 |
|
46
|
236 |
dy := minY * dotH.
|
26
|
237 |
minY to:maxY-1 do:[:row |
|
46
|
238 |
dx := minX * dotW.
|
26
|
239 |
x0 := dx.
|
|
240 |
runW := 0.
|
|
241 |
image atY:row from:minX to:(maxX-1) do:[:x :color |
|
|
242 |
runW ~~ 0 ifTrue:[
|
|
243 |
self fillRectangleX:x0 y:dy width:runW height:dotH.
|
|
244 |
].
|
|
245 |
color ~= last ifTrue:[
|
|
246 |
colors notNil ifTrue:[colors add:color].
|
|
247 |
self paint:color.
|
|
248 |
last := color.
|
|
249 |
runW := 0.
|
46
|
250 |
x0 := x * dotW.
|
26
|
251 |
].
|
|
252 |
runW := runW + dotW
|
|
253 |
].
|
|
254 |
self fillRectangleX:x0 y:dy width:runW height:dotH.
|
|
255 |
dy := dy + dotH
|
|
256 |
]
|
|
257 |
]
|
|
258 |
]
|
1
|
259 |
]
|
|
260 |
! !
|
|
261 |
|
|
262 |
!ImageEditView methodsFor:'initialization'!
|
|
263 |
|
|
264 |
initializeMiddleButtonMenu
|
5
|
265 |
|m|
|
|
266 |
|
|
267 |
m := (PopUpMenu
|
26
|
268 |
labels:(resources array:
|
|
269 |
#('save as ...'
|
|
270 |
'-'
|
|
271 |
'magnification'
|
|
272 |
"/ 'colors'
|
|
273 |
'effects'
|
|
274 |
))
|
|
275 |
selectors:#(saveAs
|
|
276 |
nil
|
|
277 |
changeMagnification
|
|
278 |
"/ showColors
|
|
279 |
effects
|
|
280 |
)
|
|
281 |
receiver:self
|
|
282 |
for:self).
|
5
|
283 |
self middleButtonMenu:m.
|
|
284 |
|
|
285 |
m subMenuAt:#effects put:(
|
26
|
286 |
PopUpMenu labels:(resources array:#(
|
|
287 |
'flip - vertical'
|
|
288 |
'flip - horizontal'
|
11
|
289 |
"
|
26
|
290 |
'-'
|
|
291 |
'blurr'
|
11
|
292 |
"
|
26
|
293 |
))
|
|
294 |
selectors:#(
|
|
295 |
flipVertical
|
|
296 |
flipHorizontal
|
11
|
297 |
"
|
26
|
298 |
nil
|
|
299 |
blurr
|
11
|
300 |
"
|
26
|
301 |
)
|
|
302 |
receiver:self
|
|
303 |
for:self
|
5
|
304 |
|
|
305 |
).
|
1
|
306 |
|
26
|
307 |
"
|
|
308 |
ImageEditView openOn:'bitmaps/SBrowser.xbm'
|
|
309 |
ImageEditView openOn:'bitmaps/garfield.gif'
|
|
310 |
"
|
1
|
311 |
!
|
|
312 |
|
|
313 |
initialize
|
|
314 |
super initialize.
|
|
315 |
magnification := 1@1.
|
|
316 |
colors := nil
|
|
317 |
! !
|
|
318 |
|
32
|
319 |
!ImageEditView methodsFor:'event handling'!
|
1
|
320 |
|
|
321 |
showColorAtX:x y:y
|
|
322 |
|pi clr|
|
|
323 |
|
46
|
324 |
pi := (x @ y) - margin.
|
42
|
325 |
pi := pi // magnification.
|
|
326 |
((0@0 corner:image extent) containsPoint:pi) ifTrue:[
|
|
327 |
clr := image at:pi.
|
|
328 |
colorPanel notNil ifTrue:[
|
26
|
329 |
colorPanel setColor:clr.
|
42
|
330 |
] ifFalse:[
|
|
331 |
Transcript showCr:clr displayString
|
26
|
332 |
]
|
1
|
333 |
]
|
|
334 |
!
|
|
335 |
|
|
336 |
buttonMotion:state x:x y:y
|
|
337 |
self showColorAtX:x y:y.
|
|
338 |
!
|
|
339 |
|
|
340 |
buttonPress:button x:x y:y
|
|
341 |
button == 1 ifTrue:[
|
26
|
342 |
self showColorAtX:x y:y.
|
|
343 |
^ self
|
1
|
344 |
].
|
|
345 |
super buttonPress:button x:x y:y
|
|
346 |
! !
|
|
347 |
|
5
|
348 |
!ImageEditView methodsFor:'image processing'!
|
|
349 |
|
|
350 |
performImageOperation:operation withArguments:args
|
|
351 |
|oldMag|
|
|
352 |
|
61
|
353 |
windowGroup withCursor:Cursor wait do:[
|
26
|
354 |
oldMag := magnification.
|
|
355 |
magnifiedImage := nil.
|
|
356 |
magnification := 1@1.
|
|
357 |
image perform:operation withArguments:args.
|
|
358 |
(oldMag isNil or:[oldMag = magnification]) ifTrue:[
|
|
359 |
self redraw
|
|
360 |
] ifFalse:[
|
|
361 |
self magnification:oldMag.
|
|
362 |
]
|
5
|
363 |
]
|
|
364 |
!
|
|
365 |
|
|
366 |
flipVertical
|
|
367 |
self performImageOperation:#flipVertical withArguments:nil
|
|
368 |
!
|
|
369 |
|
|
370 |
flipHorizontal
|
|
371 |
self performImageOperation:#flipHorizontal withArguments:nil
|
|
372 |
!
|
|
373 |
|
|
374 |
blurr
|
|
375 |
self performImageOperation:#blurr withArguments:nil
|
|
376 |
! !
|
|
377 |
|
1
|
378 |
!ImageEditView methodsFor:'release'!
|
|
379 |
|
|
380 |
destroy
|
|
381 |
colors := nil.
|
|
382 |
magnifiedImage := nil.
|
|
383 |
colorPanel notNil ifTrue:[
|
26
|
384 |
colorPanel destroy.
|
|
385 |
colorPanel := nil.
|
1
|
386 |
].
|
|
387 |
super destroy.
|
|
388 |
! !
|