author | Claus Gittinger <cg@exept.de> |
Tue, 16 Jan 2018 18:19:16 +0100 | |
changeset 5671 | 511ca27ab8d6 |
parent 5669 | bd36e715726a |
child 5695 | 0e68bf885fa0 |
permissions | -rw-r--r-- |
5656 | 1 |
"{ Encoding: utf8 }" |
2 |
||
636 | 3 |
" |
704 | 4 |
COPYRIGHT (c) 1997 by eXept Software AG |
1116
441ff42c1472
fixes to allow 24bit images to be (at least) displayed
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
5 |
All Rights Reserved |
636 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
1763
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1706
diff
changeset
|
14 |
"{ Package: 'stx:libwidg2' }" |
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1706
diff
changeset
|
15 |
|
4714 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
1 | 18 |
ImageView subclass:#ImageEditView |
4041 | 19 |
instanceVariableNames:'readOnly magnification imageReaderClass resourceClass |
5499 | 20 |
resourceSelector mouseKeyColorMode undoImages originalImage |
21 |
modifiedHolder editMode lastPastePoint imageInfoHolder |
|
22 |
activityInfoHolder pickedColorHolder drawingColors drawingPixels |
|
23 |
drawingColorHolders drawingPixelHolders clickInfoCallBack |
|
24 |
penWidth sprayProcess sprayPosition spraySpot drawingAlpha |
|
25 |
floodFillMaxHueError floodFillMaxLightError |
|
26 |
userAllowedToChangeDrawingColor' |
|
5618 | 27 |
classVariableNames:'Clipboard ClipboardMagnified ClipboardImage |
28 |
ClipboardImageMagnified LastMagnification GridMagnificationLimit |
|
29 |
MaxUndos LastSaveDirectory LastSaveClass EditModePoint |
|
30 |
EditModeBox EditModeFilledBox EditModeFill EditModeCopy |
|
31 |
EditModePasteUnder EditModePaste EditModePasteWithMask |
|
32 |
EditModeSpecialOperation EditModeSpray EditModeCircle |
|
33 |
EditModeSmooth EditModeFilledCircle |
|
5491 | 34 |
EditModeSpecialOperationCropSubImage EditModeMaskOutsideRect |
35 |
EditModeMaskOutsideCircle' |
|
1035 | 36 |
poolDictionaries:'' |
1706 | 37 |
category:'Views-Misc' |
1 | 38 |
! |
39 |
||
636 | 40 |
!ImageEditView class methodsFor:'documentation'! |
41 |
||
42 |
copyright |
|
43 |
" |
|
704 | 44 |
COPYRIGHT (c) 1997 by eXept Software AG |
1116
441ff42c1472
fixes to allow 24bit images to be (at least) displayed
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
45 |
All Rights Reserved |
636 | 46 |
|
47 |
This software is furnished under a license and may be used |
|
48 |
only in accordance with the terms of that license and with the |
|
49 |
inclusion of the above copyright notice. This software may not |
|
50 |
be provided or otherwise made available to, or used by, any |
|
51 |
other person. No title to or ownership of the software is |
|
52 |
hereby transferred. |
|
53 |
" |
|
54 |
! |
|
55 |
||
56 |
documentation |
|
57 |
" |
|
2747 | 58 |
An ImageEditView is a view which can be used by applications |
59 |
like the Image Editor for editing or inspecting (bitmap-) images. |
|
636 | 60 |
|
61 |
[see also:] |
|
2747 | 62 |
ImageEditor Image |
636 | 63 |
|
64 |
[author:] |
|
2747 | 65 |
Thomas Zwick |
636 | 66 |
" |
67 |
! ! |
|
353 | 68 |
|
1245 | 69 |
!ImageEditView class methodsFor:'initialization'! |
70 |
||
71 |
initialize |
|
2915 | 72 |
MaxUndos := 10. |
5413 | 73 |
GridMagnificationLimit := 6 @ 6. |
1245 | 74 |
|
2889 | 75 |
EditModePoint := #point. |
76 |
EditModeBox := #box. |
|
3476 | 77 |
EditModeCircle := #circle. |
2889 | 78 |
EditModePaste := #paste. |
79 |
EditModePasteUnder := #pasteUnder. |
|
80 |
EditModePasteWithMask := #pasteWithMask. |
|
81 |
EditModeFilledBox := #filledBox. |
|
5491 | 82 |
EditModeFilledCircle := #filledCircle. |
2889 | 83 |
EditModeFill := #fill. |
84 |
EditModeCopy := #copy. |
|
3476 | 85 |
EditModeSpray := #spray. |
4715 | 86 |
EditModeSmooth := #smooth. |
5491 | 87 |
EditModeMaskOutsideRect := #maskOutsideRect. |
88 |
EditModeMaskOutsideCircle := #maskOutsideCircle. |
|
89 |
EditModeSpecialOperation := #specialOperation. |
|
90 |
EditModeSpecialOperationCropSubImage := #specialOperationCropSubImage. |
|
2889 | 91 |
|
1245 | 92 |
" |
93 |
self initialize |
|
94 |
" |
|
5491 | 95 |
|
96 |
"Modified: / 20-02-2017 / 16:54:11 / cg" |
|
1245 | 97 |
! ! |
98 |
||
1706 | 99 |
!ImageEditView class methodsFor:'accessing'! |
100 |
||
2889 | 101 |
editModeBox |
102 |
^ EditModeBox |
|
103 |
! |
|
104 |
||
105 |
editModeCopy |
|
106 |
^ EditModeCopy |
|
107 |
! |
|
108 |
||
109 |
editModeFill |
|
110 |
^ EditModeFill |
|
111 |
! |
|
112 |
||
113 |
editModeFilledBox |
|
114 |
^ EditModeFilledBox |
|
115 |
! |
|
116 |
||
117 |
editModePaste |
|
118 |
^ EditModePaste |
|
119 |
! |
|
120 |
||
121 |
editModePasteUnder |
|
122 |
^ EditModePasteUnder |
|
123 |
! |
|
124 |
||
125 |
editModePasteWithMask |
|
126 |
^ EditModePasteWithMask |
|
127 |
! |
|
128 |
||
129 |
editModePoint |
|
130 |
^ EditModePoint |
|
131 |
! |
|
132 |
||
4715 | 133 |
editModeSmooth |
134 |
^ EditModeSmooth |
|
135 |
! |
|
136 |
||
2889 | 137 |
editModeSpecialOperation |
138 |
^ EditModeSpecialOperation |
|
139 |
! |
|
140 |
||
1706 | 141 |
gridMagnificationLimit |
142 |
^ GridMagnificationLimit |
|
143 |
! |
|
144 |
||
145 |
gridMagnificationLimit:anInteger |
|
146 |
GridMagnificationLimit := anInteger |
|
3980 | 147 |
! |
148 |
||
149 |
lastSaveDirectory |
|
150 |
^ LastSaveDirectory |
|
151 |
||
152 |
"Created: / 14-12-2010 / 14:49:01 / cg" |
|
153 |
! |
|
154 |
||
155 |
lastSaveDirectory:aStringOrFilename |
|
156 |
LastSaveDirectory := aStringOrFilename |
|
157 |
||
158 |
"Created: / 14-12-2010 / 14:49:18 / cg" |
|
1706 | 159 |
! ! |
160 |
||
2480 | 161 |
!ImageEditView class methodsFor:'helpers'! |
162 |
||
163 |
copyImageToClipboard:copiedImage |
|
5618 | 164 |
ClipboardImageMagnified := nil. |
165 |
ClipboardImage := copiedImage. |
|
166 |
||
167 |
"Modified: / 08-10-2017 / 08:55:10 / cg" |
|
2480 | 168 |
! ! |
169 |
||
2634 | 170 |
!ImageEditView class methodsFor:'resources'! |
171 |
||
172 |
classResources |
|
173 |
^ ImageEditor classResources |
|
174 |
! ! |
|
175 |
||
7 | 176 |
!ImageEditView methodsFor:'accessing'! |
177 |
||
1031
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
178 |
activityInfoHolder |
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
179 |
"return the value of the instance variable 'activityInfoHolder' (automatically generated)" |
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
180 |
|
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
181 |
^ activityInfoHolder |
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
182 |
|
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
183 |
"Created: / 29.7.1998 / 18:49:39 / cg" |
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
184 |
! |
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
185 |
|
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
186 |
activityInfoHolder:something |
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
187 |
"set the value of the instance variable 'activityInfoHolder' (automatically generated)" |
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
188 |
|
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
189 |
activityInfoHolder := something. |
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
190 |
|
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
191 |
"Created: / 29.7.1998 / 18:49:39 / cg" |
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
192 |
! |
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
193 |
|
2590
b811d560e00a
modified flag after edit operations
Claus Gittinger <cg@exept.de>
parents:
2589
diff
changeset
|
194 |
clearModified |
2915 | 195 |
self modified:false |
2590
b811d560e00a
modified flag after edit operations
Claus Gittinger <cg@exept.de>
parents:
2589
diff
changeset
|
196 |
! |
b811d560e00a
modified flag after edit operations
Claus Gittinger <cg@exept.de>
parents:
2589
diff
changeset
|
197 |
|
1693 | 198 |
clickInfoCallBack:aTwoArgBlock |
199 |
clickInfoCallBack := aTwoArgBlock |
|
200 |
||
201 |
"Created: / 10.2.2000 / 23:07:14 / cg" |
|
202 |
! |
|
203 |
||
2440 | 204 |
clipBoard |
5413 | 205 |
|clipboardObject| |
206 |
||
207 |
clipboardObject := self getClipboardObject. |
|
208 |
clipboardObject isImage ifTrue:[ |
|
209 |
^ clipboardObject |
|
210 |
]. |
|
5618 | 211 |
^ ClipboardImage. |
212 |
||
213 |
"Modified: / 08-10-2017 / 08:52:27 / cg" |
|
214 |
! |
|
215 |
||
216 |
clipBoardImage |
|
217 |
"if there is one in the clobal clipboard, |
|
218 |
return that (an thus support copy-paste from another smalltalk application). |
|
219 |
Otherwise return the local clipboardImage from a classVar to support copy-paste |
|
220 |
within this smalltalk session." |
|
221 |
||
222 |
|clipboardObject| |
|
223 |
||
224 |
clipboardObject := self getClipboardObject. |
|
225 |
clipboardObject isImage ifTrue:[ |
|
226 |
^ clipboardObject |
|
227 |
]. |
|
228 |
^ ClipboardImage. |
|
229 |
||
230 |
"Created: / 08-10-2017 / 08:55:59 / cg" |
|
2440 | 231 |
! |
232 |
||
5593 | 233 |
drawingAlpha |
234 |
"return the alpha value for drawing; |
|
235 |
if the current drawing color is nil, ONLY the alpha value will be changed" |
|
236 |
||
237 |
^ drawingAlpha ? 100 |
|
238 |
||
239 |
"Created: / 05-09-2017 / 09:11:32 / cg" |
|
5594 | 240 |
"Modified: / 05-09-2017 / 10:47:18 / cg" |
5593 | 241 |
! |
242 |
||
243 |
drawingAlpha:anAlphaValue |
|
244 |
"set the alpha value for drawing; |
|
245 |
if the current drawing color is nil, ONLY the alpha value will be changed" |
|
246 |
||
247 |
drawingAlpha := anAlphaValue |
|
248 |
||
249 |
"Created: / 05-09-2017 / 09:11:26 / cg" |
|
250 |
! |
|
251 |
||
3610
11e215de80a0
color selection when undoing
Claus Gittinger <cg@exept.de>
parents:
3564
diff
changeset
|
252 |
drawingColorHolders |
5499 | 253 |
drawingColorHolders isNil ifTrue:[ |
254 |
drawingColorHolders := Array with:(nil asValue) with:(nil asValue). "/ left/right mouse colors |
|
255 |
]. |
|
3610
11e215de80a0
color selection when undoing
Claus Gittinger <cg@exept.de>
parents:
3564
diff
changeset
|
256 |
^ drawingColorHolders |
5499 | 257 |
|
258 |
"Modified: / 23-02-2017 / 10:14:49 / cg" |
|
3610
11e215de80a0
color selection when undoing
Claus Gittinger <cg@exept.de>
parents:
3564
diff
changeset
|
259 |
! |
11e215de80a0
color selection when undoing
Claus Gittinger <cg@exept.de>
parents:
3564
diff
changeset
|
260 |
|
11e215de80a0
color selection when undoing
Claus Gittinger <cg@exept.de>
parents:
3564
diff
changeset
|
261 |
drawingColors |
5593 | 262 |
"return the two colors in which I will draw (left / right mouse button colors)" |
263 |
||
3610
11e215de80a0
color selection when undoing
Claus Gittinger <cg@exept.de>
parents:
3564
diff
changeset
|
264 |
^ drawingColorHolders collect:[:each | each value]. |
5499 | 265 |
|
266 |
"Modified: / 23-02-2017 / 10:17:14 / cg" |
|
5593 | 267 |
"Modified (comment): / 05-09-2017 / 09:12:14 / cg" |
3610
11e215de80a0
color selection when undoing
Claus Gittinger <cg@exept.de>
parents:
3564
diff
changeset
|
268 |
! |
11e215de80a0
color selection when undoing
Claus Gittinger <cg@exept.de>
parents:
3564
diff
changeset
|
269 |
|
2009
4f556ff9fec5
pick with SHIFT-click in the mag-view
Claus Gittinger <cg@exept.de>
parents:
2007
diff
changeset
|
270 |
drawingColors:anArrayTwoColors |
5593 | 271 |
"set the two colors in which I will draw (left / right mouse button colors)" |
272 |
||
2009
4f556ff9fec5
pick with SHIFT-click in the mag-view
Claus Gittinger <cg@exept.de>
parents:
2007
diff
changeset
|
273 |
(drawingColorHolders at:1) value:(anArrayTwoColors at:1). |
4f556ff9fec5
pick with SHIFT-click in the mag-view
Claus Gittinger <cg@exept.de>
parents:
2007
diff
changeset
|
274 |
(drawingColorHolders at:2) value:(anArrayTwoColors at:2). |
5499 | 275 |
|
276 |
"Modified: / 23-02-2017 / 10:17:21 / cg" |
|
5593 | 277 |
"Modified (comment): / 05-09-2017 / 09:12:07 / cg" |
2009
4f556ff9fec5
pick with SHIFT-click in the mag-view
Claus Gittinger <cg@exept.de>
parents:
2007
diff
changeset
|
278 |
! |
4f556ff9fec5
pick with SHIFT-click in the mag-view
Claus Gittinger <cg@exept.de>
parents:
2007
diff
changeset
|
279 |
|
5485 | 280 |
editMode |
281 |
"is one of the edit modes: |
|
282 |
||
283 |
EditModePoint |
|
284 |
EditModeBox |
|
285 |
EditModePaste |
|
286 |
EditModePasteUnder |
|
287 |
EditModePasteWithMask |
|
288 |
EditModeFilledBox |
|
289 |
EditModeFill |
|
290 |
EditModeCopy |
|
291 |
EditModeSpecialOperation |
|
292 |
EditModeSpray |
|
293 |
EditModeCircle |
|
294 |
EditModeSmooth |
|
295 |
" |
|
296 |
||
297 |
^editMode |
|
298 |
! |
|
299 |
||
300 |
editMode: anEditModeSymbol |
|
301 |
"must be one of the edit modes: |
|
302 |
||
303 |
EditModePoint |
|
304 |
EditModeBox |
|
305 |
EditModePaste |
|
306 |
EditModePasteUnder |
|
307 |
EditModePasteWithMask |
|
308 |
EditModeFilledBox |
|
309 |
EditModeFill |
|
310 |
EditModeCopy |
|
311 |
EditModeSpecialOperation |
|
312 |
EditModeSpray |
|
313 |
EditModeCircle |
|
314 |
EditModeSmooth |
|
315 |
" |
|
316 |
||
317 |
editMode := anEditModeSymbol |
|
318 |
! |
|
319 |
||
5483 | 320 |
floodFillMaxHueError:aFraction |
321 |
floodFillMaxHueError := aFraction. |
|
322 |
||
323 |
"Modified (format): / 17-02-2017 / 15:26:59 / cg" |
|
324 |
! |
|
325 |
||
326 |
floodFillMaxLightError:aFraction |
|
327 |
floodFillMaxLightError := aFraction. |
|
328 |
||
329 |
"Modified (format): / 17-02-2017 / 15:27:03 / cg" |
|
330 |
! |
|
331 |
||
2915 | 332 |
image:anImage scroll:doScroll |
3706 | 333 |
self image:anImage scroll:doScroll invalidate:true |
334 |
! |
|
335 |
||
336 |
image:anImage scroll:doScroll invalidate:doInvalidate |
|
2915 | 337 |
|retVal fileName| |
338 |
||
339 |
anImage isImage ifTrue:[ |
|
340 |
true "(image isNil or: [self checkModified])" ifTrue: [ |
|
341 |
image notNil ifTrue: [ |
|
342 |
fileName := image fileName. |
|
343 |
anImage fileName isNil ifTrue: [anImage fileName: fileName]. |
|
344 |
]. |
|
3706 | 345 |
super image:anImage scroll:doScroll invalidate:doInvalidate. |
2915 | 346 |
retVal := self. |
347 |
]. |
|
348 |
] ifFalse: [ |
|
3706 | 349 |
super image:nil scroll:true invalidate:doInvalidate. |
2915 | 350 |
]. |
3706 | 351 |
|
2915 | 352 |
"/ self changed:#image. |
353 |
image isNil ifTrue:[ |
|
354 |
self clearModified. |
|
355 |
] ifFalse:[ |
|
356 |
self setModified. |
|
357 |
]. |
|
358 |
self updateImageInfo: self imageInfoString. |
|
359 |
^ retVal |
|
360 |
||
361 |
"Modified: / 10.2.2000 / 23:33:12 / cg" |
|
362 |
! |
|
363 |
||
1031
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
364 |
imageInfoHolder |
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
365 |
^ imageInfoHolder |
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
366 |
|
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
367 |
"Created: / 29.7.1998 / 18:29:50 / cg" |
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
368 |
! |
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
369 |
|
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
370 |
imageInfoHolder:something |
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
371 |
imageInfoHolder := something. |
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
372 |
|
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
373 |
"Created: / 29.7.1998 / 18:29:50 / cg" |
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
374 |
! |
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
375 |
|
624 | 376 |
magnification |
377 |
||
378 |
^magnification |
|
379 |
||
255 | 380 |
! |
381 |
||
636 | 382 |
magnification: aPoint |
1037 | 383 |
|oldOrg| |
255 | 384 |
|
627 | 385 |
magnification ~= aPoint |
624 | 386 |
ifTrue: |
387 |
[ |
|
5618 | 388 |
oldOrg := self viewOrigin / magnification. |
389 |
magnification := aPoint asPoint. |
|
390 |
||
391 |
self scrollTo:(oldOrg * magnification) rounded redraw:false. |
|
1037 | 392 |
"/ self scrollToTopLeft. |
5618 | 393 |
self contentsChanged. |
394 |
self invalidate. |
|
395 |
ClipboardImageMagnified := nil. |
|
686 | 396 |
] |
1037 | 397 |
|
5618 | 398 |
"Modified: / 08-10-2017 / 08:54:54 / cg" |
624 | 399 |
! |
255 | 400 |
|
2913 | 401 |
modified |
402 |
^ modifiedHolder value |
|
403 |
! |
|
404 |
||
2747 | 405 |
modified:aBoolean |
406 |
modifiedHolder value:aBoolean |
|
407 |
! |
|
408 |
||
409 |
modifiedHolder |
|
410 |
^ modifiedHolder |
|
411 |
! |
|
412 |
||
5485 | 413 |
mouseKeyColorMode |
414 |
||
415 |
^mouseKeyColorMode printString |
|
416 |
! |
|
417 |
||
418 |
mouseKeyColorMode:aMode |
|
419 |
||
420 |
mouseKeyColorMode := aMode |
|
421 |
! |
|
422 |
||
3265 | 423 |
penWidth |
424 |
^ penWidth ? 1 |
|
425 |
||
426 |
"Created: / 01-11-2007 / 23:34:49 / cg" |
|
427 |
! |
|
428 |
||
5405 | 429 |
penWidth:anInteger |
430 |
penWidth := anInteger |
|
3265 | 431 |
|
432 |
"Created: / 01-11-2007 / 23:34:56 / cg" |
|
433 |
! |
|
434 |
||
4041 | 435 |
readOnly |
436 |
^ readOnly |
|
437 |
! |
|
438 |
||
5405 | 439 |
readOnly:aBoolean |
440 |
readOnly := aBoolean. |
|
4041 | 441 |
! |
442 |
||
2915 | 443 |
removelastUndo |
444 |
undoImages removeLast |
|
445 |
! |
|
446 |
||
627 | 447 |
resourceClass |
2915 | 448 |
^ resourceClass |
627 | 449 |
! |
450 |
||
2915 | 451 |
resourceClass: aClassOrClassNameString |
452 |
"support for names will vanish - obsolete left over from tz" |
|
453 |
||
454 |
resourceClass := aClassOrClassNameString. |
|
455 |
resourceClass notNil ifTrue:[ |
|
456 |
resourceClass isBehavior ifFalse: [ |
|
457 |
resourceClass := Smalltalk classNamed:aClassOrClassNameString |
|
458 |
] |
|
459 |
] |
|
2908
a759fa87d598
some code cleanup (resourceClass was actually its name)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
460 |
! |
a759fa87d598
some code cleanup (resourceClass was actually its name)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
461 |
|
a759fa87d598
some code cleanup (resourceClass was actually its name)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
462 |
resourceClassName |
a759fa87d598
some code cleanup (resourceClass was actually its name)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
463 |
resourceClass isNil ifTrue:[^ '']. |
a759fa87d598
some code cleanup (resourceClass was actually its name)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
464 |
^ resourceClass name |
627 | 465 |
! |
466 |
||
467 |
resourceMessage |
|
2909 | 468 |
(resourceClass isNil or:[resourceSelector isNil]) ifTrue:[^ '']. |
2908
a759fa87d598
some code cleanup (resourceClass was actually its name)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
469 |
^ resourceClass name, ' ', resourceSelector |
627 | 470 |
! |
471 |
||
472 |
resourceSelector |
|
2915 | 473 |
^ resourceSelector |
627 | 474 |
! |
475 |
||
476 |
resourceSelector: aStringOrSymbol |
|
2909 | 477 |
aStringOrSymbol isNil ifTrue:[ |
478 |
resourceSelector := nil |
|
479 |
] ifFalse:[ |
|
480 |
resourceSelector := aStringOrSymbol asSymbol |
|
481 |
] |
|
627 | 482 |
! |
483 |
||
5480 | 484 |
selectMaskForDrawing |
5483 | 485 |
image mask isNil ifTrue:[ |
486 |
Logger warning:'image has no mask'. |
|
487 |
^ self. |
|
488 |
]. |
|
5484 | 489 |
"/ self selectedColorIndex:1. |
490 |
self selectedColor:(Color noColor). |
|
491 |
self selectedColorIndex:nil. |
|
5480 | 492 |
|
493 |
"Created: / 16-02-2017 / 09:57:40 / cg" |
|
5484 | 494 |
"Modified: / 17-02-2017 / 16:30:50 / cg" |
5480 | 495 |
! |
496 |
||
627 | 497 |
selectedColor |
3730 | 498 |
|clr| |
499 |
||
500 |
clr := (drawingColorHolders at:mouseKeyColorMode) value. |
|
3931 | 501 |
clr isNil ifTrue:[ clr := Color black ]. |
5593 | 502 |
|
3730 | 503 |
image hasAlphaChannel ifTrue:[ |
5594 | 504 |
clr isPseudoColor ifTrue:[ |
505 |
"/ the mask is selected - return a pseudoColor holding ONLY the alpha value |
|
506 |
"/ will be detected in the drawing operations to change the alpha value only |
|
507 |
^ TranslucentColor new |
|
508 |
alpha:((drawingAlpha ? 100) / 100) |
|
509 |
]. |
|
510 |
||
3730 | 511 |
^ (TranslucentColor |
512 |
scaledRed:clr scaledRed |
|
513 |
scaledGreen:clr scaledGreen |
|
514 |
scaledBlue:clr scaledBlue) |
|
5594 | 515 |
alpha:((drawingAlpha ? 100) / 100) |
3730 | 516 |
]. |
517 |
^ clr |
|
3931 | 518 |
|
5594 | 519 |
"Modified (format): / 05-09-2017 / 12:21:53 / cg" |
1246 | 520 |
! |
521 |
||
522 |
selectedColor: aColor |
|
4853 | 523 |
(drawingColorHolders at:(mouseKeyColorMode min:drawingColorHolders size)) value:aColor |
5499 | 524 |
|
525 |
"Modified: / 23-02-2017 / 10:17:02 / cg" |
|
627 | 526 |
! |
527 |
||
1246 | 528 |
selectedColorIndex |
2915 | 529 |
^ (drawingPixelHolders at:mouseKeyColorMode) value |
1246 | 530 |
! |
531 |
||
532 |
selectedColorIndex: aPixelIndex |
|
4853 | 533 |
(drawingPixelHolders at:(mouseKeyColorMode min:drawingPixelHolders size)) value: aPixelIndex |
995 | 534 |
! |
535 |
||
2590
b811d560e00a
modified flag after edit operations
Claus Gittinger <cg@exept.de>
parents:
2589
diff
changeset
|
536 |
setModified |
5497 | 537 |
"remember being modified (to ask about saving, when closing)" |
538 |
||
2915 | 539 |
self modified:true |
5497 | 540 |
|
541 |
"Modified (comment): / 22-02-2017 / 22:24:34 / cg" |
|
2590
b811d560e00a
modified flag after edit operations
Claus Gittinger <cg@exept.de>
parents:
2589
diff
changeset
|
542 |
! |
b811d560e00a
modified flag after edit operations
Claus Gittinger <cg@exept.de>
parents:
2589
diff
changeset
|
543 |
|
4111 | 544 |
spraySpot |
545 |
^ spraySpot |
|
546 |
||
547 |
"Created: / 15-02-2012 / 22:38:04 / cg" |
|
548 |
! |
|
549 |
||
3476 | 550 |
spraySpot:something |
551 |
spraySpot := something. |
|
552 |
! |
|
553 |
||
995 | 554 |
undoImages |
2915 | 555 |
^ undoImages |
5484 | 556 |
! |
557 |
||
558 |
userAllowedToChangeDrawingColor:aBoolean |
|
559 |
"for special applications, whre user is only allowed to draw |
|
560 |
in the predefined color (eg. expecco)" |
|
561 |
||
562 |
userAllowedToChangeDrawingColor := aBoolean |
|
563 |
||
564 |
"Created: / 17-02-2017 / 16:24:37 / cg" |
|
627 | 565 |
! ! |
566 |
||
567 |
!ImageEditView methodsFor:'drawing'! |
|
568 |
||
1036 | 569 |
drawFrame |
5413 | 570 |
"draws a black frame around the image's bounds" |
571 |
||
5432 | 572 |
gc paint:self blackColor. |
573 |
gc lineWidth: (magnification x//3 min: 3). |
|
574 |
gc displayRectangle: ((0@0) extent:(image extent * magnification) + margin). |
|
575 |
gc lineWidth:1. |
|
1036 | 576 |
! |
577 |
||
578 |
drawFramesIn: aRectangle |
|
5413 | 579 |
"draws the pixel frame grid" |
580 |
||
581 |
|origin lineStartingPoint lineEndingPoint oldColor mX mY| |
|
582 |
||
583 |
magnification >= GridMagnificationLimit ifTrue: [ |
|
584 |
mX := magnification x. |
|
585 |
mY := magnification y. |
|
586 |
||
1706 | 587 |
origin := aRectangle origin - 1. |
5413 | 588 |
lineStartingPoint := origin + (0 @ mY). |
1706 | 589 |
lineEndingPoint := lineStartingPoint + (aRectangle width@0). |
5413 | 590 |
|
5432 | 591 |
oldColor := gc paint. |
5584 | 592 |
gc paint:Color gray. |
593 |
"/ gc xoring:[ |
|
5432 | 594 |
gc displayLineFrom: lineStartingPoint to: lineEndingPoint. |
5413 | 595 |
lineStartingPoint x to: lineStartingPoint x + aRectangle width - mX by: mX |
596 |
do:[:x| |
|
5432 | 597 |
gc displayLineFrom: x@(origin y) to: x@(origin y + mY) |
1706 | 598 |
]. |
5584 | 599 |
"/ ]. |
5432 | 600 |
gc paint: oldColor. |
1036 | 601 |
] |
5584 | 602 |
|
603 |
"Modified: / 29-08-2017 / 21:58:07 / cg" |
|
1036 | 604 |
! |
605 |
||
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
606 |
drawPasteRectangleAt: aPoint |
2889 | 607 |
|currentPoint gridCorrection extent| |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
608 |
|
1706 | 609 |
magnification >= GridMagnificationLimit ifFalse: [gridCorrection := 0] ifTrue: [gridCorrection := 1]. |
1449 | 610 |
currentPoint := aPoint // magnification*magnification + margin. |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
611 |
|
2085 | 612 |
self repairDamage. |
613 |
||
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
614 |
currentPoint ~= lastPastePoint ifTrue:[ |
5618 | 615 |
ClipboardImageMagnified isNil ifTrue:[ |
616 |
ClipboardImageMagnified := (ClipboardImage magnifiedBy: magnification) onDevice:device |
|
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
617 |
]. |
5618 | 618 |
extent := ClipboardImageMagnified extent. |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
619 |
|
1967 | 620 |
"/ currentPoint := currentPoint - self viewOrigin. |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
621 |
|
2085 | 622 |
self redraw: (((lastPastePoint ? currentPoint)"-self viewOrigin") extent: extent). |
3267 | 623 |
"/ self repairDamage. |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
624 |
|
2085 | 625 |
false " (extent x > 400 or: [extent y > 400])" ifTrue:[ |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
626 |
self xoring: [ |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
627 |
self fillRectangle: (currentPoint extent: extent) |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
628 |
] |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
629 |
] ifFalse:[ |
5618 | 630 |
ClipboardImageMagnified notNil ifTrue:[ |
631 |
self displayDeviceForm: ClipboardImageMagnified |
|
2089 | 632 |
x: currentPoint x - self viewOrigin x |
633 |
y: currentPoint y - self viewOrigin y. |
|
634 |
]. |
|
2889 | 635 |
editMode == EditModePastUnder ifTrue:[ |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
636 |
self redrawImageX:currentPoint x y:currentPoint y width:extent x height:extent y unmaskedOnly:true |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
637 |
] |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
638 |
] |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
639 |
]. |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
640 |
lastPastePoint := currentPoint. |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
641 |
|
5618 | 642 |
"Modified: / 08-10-2017 / 08:54:49 / cg" |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
643 |
! |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
644 |
|
662 | 645 |
fillFramedRectangle: aRectangle |
646 |
||
647 |
self fillRectangle: aRectangle. |
|
648 |
self drawFramesIn: aRectangle |
|
649 |
! |
|
650 |
||
1449 | 651 |
redraw:aRectangle |
2838
8525a35121d2
changeHLS fixed dfor depth24-images;
Claus Gittinger <cg@exept.de>
parents:
2824
diff
changeset
|
652 |
self |
8525a35121d2
changeHLS fixed dfor depth24-images;
Claus Gittinger <cg@exept.de>
parents:
2824
diff
changeset
|
653 |
invalidate:(aRectangle origin "+ self viewOrigin" extent:aRectangle extent) |
8525a35121d2
changeHLS fixed dfor depth24-images;
Claus Gittinger <cg@exept.de>
parents:
2824
diff
changeset
|
654 |
repairNow:true. |
1449 | 655 |
|
2053
5c19fe5b2db3
invalidate rather than redraw
Claus Gittinger <cg@exept.de>
parents:
2034
diff
changeset
|
656 |
"Modified: / 15.11.2001 / 16:43:53 / cg" |
1449 | 657 |
! |
658 |
||
627 | 659 |
redrawImageX:x y:y width:w height:h |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
660 |
self redrawImageX:x y:y width:w height:h unmaskedOnly:false |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
661 |
|
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
662 |
"Modified: / 18.5.1999 / 20:14:03 / cg" |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
663 |
! |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
664 |
|
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
665 |
redrawImageX:x y:y width:w height:h unmaskedOnly:unmaskedOnly |
3319 | 666 |
"redraw the magnified (editing) view of the image" |
636 | 667 |
|
5413 | 668 |
self |
669 |
redrawImageX:x y:y width:w height:h |
|
670 |
unmaskedOnly:unmaskedOnly processColorsWith:[:colorIn | colorIn]. |
|
671 |
||
672 |
"Created: / 18.5.1999 / 20:13:39 / cg" |
|
673 |
"Modified: / 18.5.1999 / 20:36:20 / cg" |
|
674 |
! |
|
675 |
||
676 |
redrawImageX:x y:y width:w height:h unmaskedOnly:unmaskedOnly processColorsWith:aColorBlock |
|
677 |
"redraw the magnified (editing) view of the image" |
|
678 |
||
5591 | 679 |
|ih iw magX magY minX maxX minY maxY lastColor lastY runW x0 |
680 |
isMasked mask photometric |
|
681 |
lastPixelColor |
|
682 |
sizeOfMaskPoint offsetOfMaskPoint |
|
683 |
useNearestColor isRGBA isRGBLike drawPixel |
|
684 |
showPixelValue pixelValueFont savedFont ascent| |
|
1180 | 685 |
|
4999 | 686 |
useNearestColor := device visualType == #PseudoColor. |
627 | 687 |
|
1037 | 688 |
mask := image mask. |
5591 | 689 |
photometric := image photometric. |
690 |
isRGBA := photometric == #rgba. |
|
691 |
isRGBLike := #(rgb rgba argb) includes:photometric. |
|
627 | 692 |
ih := image height. |
693 |
iw := image width. |
|
662 | 694 |
magX := magnification x. |
695 |
magY := magnification y. |
|
627 | 696 |
|
662 | 697 |
minX := (x // magX - 1) max: 0. |
725 | 698 |
minX >= iw ifTrue:[minX := (iw - 1) max: 0]. |
662 | 699 |
minY := (y // magY - 1) max: 0. |
725 | 700 |
minY >= ih ifTrue:[minY := (ih - 1) max: 0]. |
662 | 701 |
maxX := (x + w) // magX + 1. |
627 | 702 |
maxX > iw ifTrue:[maxX := iw]. |
662 | 703 |
maxY := (y + h) // magY + 1. |
627 | 704 |
maxY > ih ifTrue:[maxY := ih]. |
705 |
||
5591 | 706 |
showPixelValue := "(image depth <= 12) and:["(magX > 32) and:[magY > 32]"]". |
707 |
showPixelValue ifTrue:[ |
|
708 |
pixelValueFont := TextView defaultFont asSize:(magY // 6). |
|
709 |
pixelValueFont := pixelValueFont onDevice:gc device. |
|
710 |
savedFont := gc font. |
|
711 |
gc font:pixelValueFont. |
|
712 |
ascent := pixelValueFont ascent + 2. |
|
713 |
]. |
|
714 |
||
715 |
drawPixel := |
|
716 |
[:x :y :clr | |
|
717 |
|origin pixelColor pixelValue s| |
|
718 |
||
719 |
origin := (x * magX + margin)@(y * magY + margin). |
|
720 |
(unmaskedOnly and:[isMasked]) ifFalse:[ |
|
721 |
self fillFramedRectangle: (origin extent: runW@magY). |
|
722 |
isMasked ifTrue:[ |
|
723 |
gc xoring:[ |
|
724 |
gc fillRectangle: (origin + offsetOfMaskPoint extent: sizeOfMaskPoint) |
|
725 |
] |
|
726 |
] ifFalse:[ |
|
727 |
pixelValueFont notNil ifTrue:[ |
|
728 |
pixelColor := gc paint. |
|
729 |
gc paint:(pixelColor contrastingColorFor:pixelColor). |
|
730 |
pixelValue := image pixelAtX:x y:y. |
|
731 |
isRGBLike ifTrue:[ |
|
732 |
s := pixelValue hexPrintString. |
|
733 |
] ifFalse:[ |
|
734 |
s := pixelValue printString. |
|
735 |
]. |
|
736 |
gc displayString:s x:(origin x + 1) y:(origin y + ascent). |
|
737 |
]. |
|
738 |
]. |
|
739 |
] |
|
740 |
]. |
|
741 |
||
627 | 742 |
lastY := -1. |
743 |
x0 := minX. |
|
744 |
runW := 0. |
|
5591 | 745 |
isMasked := false. |
746 |
sizeOfMaskPoint := (magnification//3) min:8. |
|
747 |
offsetOfMaskPoint := (magnification - sizeOfMaskPoint) // 2. |
|
748 |
||
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
749 |
image |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
750 |
colorsFromX:minX y:minY toX:maxX-1 y:maxY-1 |
5413 | 751 |
do:[:xx :yy :colorIn| |
752 |
|color| |
|
753 |
||
754 |
color := aColorBlock value:colorIn. |
|
755 |
||
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
756 |
shown ifFalse:[^ self]. |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
757 |
|
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
758 |
yy ~~ lastY ifTrue:[ |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
759 |
runW ~~ 0 ifTrue:[ |
5591 | 760 |
drawPixel value:x0 value:lastY value:lastColor. |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
761 |
runW := 0. |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
762 |
]. |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
763 |
x0 := xx. |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
764 |
lastY := yy. |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
765 |
]. |
1160 | 766 |
|
5591 | 767 |
(color ~= lastColor or:[showPixelValue]) ifTrue:[ |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
768 |
runW ~~ 0 ifTrue:[ |
5591 | 769 |
drawPixel value:x0 value:yy value:lastColor. |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
770 |
runW := 0. |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
771 |
]. |
5591 | 772 |
|
773 |
lastColor := lastPixelColor := color. |
|
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
774 |
useNearestColor ifTrue:[ |
4999 | 775 |
lastColor := lastColor nearestOn:device |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
776 |
]. |
5432 | 777 |
gc paint:lastColor. |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
778 |
mask notNil ifTrue:[ |
5591 | 779 |
isMasked := false. |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
780 |
(mask pixelAtX:xx y:yy) == 0 ifTrue:[ |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
781 |
unmaskedOnly ifFalse:[ |
5432 | 782 |
gc paint: (lastColor := self viewBackground). |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
783 |
]. |
5591 | 784 |
isMasked := true. |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
785 |
]. |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
786 |
lastColor := nil. |
5485 | 787 |
] ifFalse:[ |
788 |
isRGBA ifTrue:[ |
|
5591 | 789 |
isMasked := false. |
5485 | 790 |
colorIn alphaByte == 0 ifTrue:[ |
791 |
unmaskedOnly ifFalse:[ |
|
792 |
gc paint: (lastColor := self viewBackground). |
|
793 |
]. |
|
5591 | 794 |
isMasked := true. |
5485 | 795 |
] ifFalse:[ |
796 |
]. |
|
797 |
lastColor := nil. |
|
798 |
] |
|
799 |
]. |
|
1160 | 800 |
runW := 0. |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
801 |
x0 := xx. |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
802 |
]. |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
803 |
runW := runW + magX |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
804 |
]. |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
805 |
|
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
806 |
runW ~~ 0 ifTrue:[ |
5591 | 807 |
drawPixel value:x0 value:lastY value:lastColor. |
808 |
]. |
|
809 |
||
810 |
savedFont notNil ifTrue:[ |
|
811 |
gc font:savedFont. |
|
627 | 812 |
]. |
1037 | 813 |
|
5485 | 814 |
"Created: / 18-05-1999 / 20:13:39 / cg" |
5591 | 815 |
"Modified: / 01-09-2017 / 11:39:09 / cg" |
627 | 816 |
! |
817 |
||
818 |
redrawX:x y:y width:w height:h |
|
636 | 819 |
|
5413 | 820 |
|xI yI devImage imgWidth imgHeight mX mY magnifiedWidth magnifiedHeight| |
627 | 821 |
|
1037 | 822 |
image isNil ifTrue:[^self]. |
662 | 823 |
|
1037 | 824 |
magnification = (1@1) ifTrue: [ |
4212 | 825 |
Error handle:[:ex | |
2092 | 826 |
Transcript showCR:'cannot convert image: ', ex description. |
1510
fd0cd6065dc6
catch image conversion errors.
Claus Gittinger <cg@exept.de>
parents:
1449
diff
changeset
|
827 |
] do:[ |
4999 | 828 |
devImage := image onDevice:device. |
1763
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1706
diff
changeset
|
829 |
devImage ~~ image ifTrue:[ |
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1706
diff
changeset
|
830 |
image := devImage. |
1764 | 831 |
self changed:#image. |
1763
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1706
diff
changeset
|
832 |
]. |
1510
fd0cd6065dc6
catch image conversion errors.
Claus Gittinger <cg@exept.de>
parents:
1449
diff
changeset
|
833 |
]. |
4999 | 834 |
image device == device ifTrue:[ |
5413 | 835 |
super redrawX:x y:y width:w height:h. |
836 |
self drawFrame. |
|
837 |
^ self. |
|
1510
fd0cd6065dc6
catch image conversion errors.
Claus Gittinger <cg@exept.de>
parents:
1449
diff
changeset
|
838 |
]. |
1037 | 839 |
]. |
627 | 840 |
|
3476 | 841 |
"/ self clippingRectangle: (x@y extent:w@h). |
5413 | 842 |
"/ draw the image itself |
627 | 843 |
self redrawImageX:x y:y width:w height:h. |
844 |
||
4233 | 845 |
imgWidth := image width. |
846 |
imgHeight := image height. |
|
847 |
||
3476 | 848 |
"/ beyond of image ? |
5413 | 849 |
adjust == #center ifTrue:[ |
4233 | 850 |
xI := (width - imgWidth) // 2 - margin. |
851 |
yI := (height - imgHeight) // 2 - margin. |
|
5413 | 852 |
] ifFalse:[ |
1449 | 853 |
xI := yI := margin |
627 | 854 |
]. |
1967 | 855 |
|
5413 | 856 |
mX := magnification x. |
857 |
mY := magnification y. |
|
858 |
magnifiedWidth := mX * imgWidth. |
|
859 |
magnifiedHeight := mY * imgHeight. |
|
860 |
||
861 |
"/ draw the rest to the right and at the bottom |
|
862 |
(x + w - 1) > (xI + magnifiedWidth) ifTrue:[ |
|
863 |
self |
|
864 |
clearRectangleX:(xI + magnifiedWidth) y:y |
|
865 |
width:(x + w - magnifiedWidth - xI) height:h |
|
627 | 866 |
]. |
5413 | 867 |
(y + h - 1) > (yI + magnifiedHeight) ifTrue:[ |
868 |
self |
|
869 |
clearRectangleX:margin y:(yI + magnifiedHeight) |
|
870 |
width:w height:(y + h - magnifiedHeight - yI) |
|
627 | 871 |
]. |
872 |
self drawFrame. |
|
5413 | 873 |
self clippingBounds: nil. |
1037 | 874 |
|
875 |
"Modified: / 31.7.1998 / 02:22:45 / cg" |
|
3476 | 876 |
! |
877 |
||
878 |
startSpray |
|
879 |
spraySpot isNil ifTrue:[ |
|
880 |
spraySpot := 8 |
|
881 |
]. |
|
882 |
||
883 |
sprayProcess isNil ifTrue:[ |
|
884 |
sprayProcess := [ |
|
885 |
|p rnd norm sprayPoint dly angle x y dist| |
|
886 |
||
887 |
rnd := Random new. |
|
3477 | 888 |
Distributions::NormalDistribution notNil ifTrue:[ |
889 |
norm := Distributions::NormalDistribution mean:0 deviation:0.5. |
|
890 |
]. |
|
3487 | 891 |
dly := Delay forMilliseconds:20. |
3476 | 892 |
[true] whileTrue:[ |
893 |
10 timesRepeat:[ |
|
894 |
p := sprayPosition. |
|
895 |
p notNil ifTrue:[ |
|
896 |
angle := rnd next * 359.999. "/ the angle is uniformly ditributed |
|
3477 | 897 |
norm notNil ifTrue:[ |
898 |
dist := norm next * spraySpot. "/ the distance is a normalDistribution |
|
899 |
] ifFalse:[ |
|
900 |
dist := (rnd nextBetween:-1 and:1) * spraySpot. |
|
901 |
]. |
|
3476 | 902 |
sprayPoint := (Point r:dist degrees:angle)*magnification. |
903 |
||
904 |
x := p x + sprayPoint x truncated. |
|
905 |
y := p y + sprayPoint y truncated. |
|
4111 | 906 |
self pointAt:(x@y) width:1. |
3476 | 907 |
]. |
908 |
]. |
|
909 |
dly wait. |
|
910 |
]. |
|
911 |
] fork. |
|
912 |
] |
|
913 |
||
4111 | 914 |
"Modified: / 15-02-2012 / 22:44:54 / cg" |
3476 | 915 |
! |
916 |
||
917 |
stopSpray |
|
918 |
sprayProcess notNil ifTrue:[ |
|
919 |
sprayProcess terminate. |
|
920 |
sprayProcess := nil |
|
921 |
]. |
|
627 | 922 |
! ! |
923 |
||
924 |
!ImageEditView methodsFor:'event handling'! |
|
925 |
||
926 |
buttonMotion:state x:x y:y |
|
1693 | 927 |
|p| |
928 |
||
2072
abd4e246f393
care for negative pos in buttonMotion (win32 klusge)
Claus Gittinger <cg@exept.de>
parents:
2053
diff
changeset
|
929 |
(x < 0 or:[y < 0]) ifTrue:[ |
abd4e246f393
care for negative pos in buttonMotion (win32 klusge)
Claus Gittinger <cg@exept.de>
parents:
2053
diff
changeset
|
930 |
^ self |
abd4e246f393
care for negative pos in buttonMotion (win32 klusge)
Claus Gittinger <cg@exept.de>
parents:
2053
diff
changeset
|
931 |
]. |
5413 | 932 |
"/ readOnly ifTrue:[^ self]. |
2072
abd4e246f393
care for negative pos in buttonMotion (win32 klusge)
Claus Gittinger <cg@exept.de>
parents:
2053
diff
changeset
|
933 |
|
1693 | 934 |
p := x@y. |
935 |
||
936 |
state ~~ 0 ifTrue:[ |
|
3476 | 937 |
"/ button down |
938 |
||
939 |
"/ self selectedColor notNil ifTrue:[ |
|
940 |
(self imageContainsPoint:p) ifTrue:[ |
|
941 |
(editMode == EditModePoint) ifTrue:[ |
|
942 |
self pointAt:p. |
|
943 |
^ self |
|
944 |
]. |
|
4715 | 945 |
(editMode == EditModeSmooth) ifTrue:[ |
946 |
self smoothAt:p. |
|
947 |
^ self |
|
948 |
]. |
|
3476 | 949 |
sprayProcess notNil ifTrue:[ |
950 |
sprayPosition := p. |
|
5481 | 951 |
^ self |
3476 | 952 |
]. |
1246 | 953 |
]. |
1693 | 954 |
self drawCursorAt:p. |
3476 | 955 |
^ self |
956 |
]. |
|
957 |
||
5413 | 958 |
"/ button is up (care for paste-mode, dragging the pasted image) |
3476 | 959 |
self drawCursorAt:p. |
5481 | 960 |
|
961 |
"/ if in pastemode, highlight the affected rectangle (image to be pasted is in ClipBoard) |
|
5618 | 962 |
(self inPasteMode and:[ ClipboardImage notNil ]) ifTrue: [ |
5481 | 963 |
"/ with shift, paste is offset by pasted image's size |
964 |
"/ (i.e. click-point will be corner of pasted rectangle) |
|
3476 | 965 |
self sensor shiftDown ifTrue:[ |
5655 | 966 |
p := p - (ClipboardImage extent * magnification) |
3476 | 967 |
]. |
5481 | 968 |
(self imageContainsPastePoint:p) ifTrue:[ |
969 |
(self sensor hasButtonMotionEventFor:self) ifFalse:[ |
|
970 |
self drawPasteRectangleAt:p |
|
971 |
] |
|
972 |
] ifFalse: [ |
|
973 |
self cursor:Cursor stop. |
|
974 |
self releasePasteDrawing |
|
975 |
] |
|
686 | 976 |
] |
1019
e68414752bc9
only change the cursor for myself.
Claus Gittinger <cg@exept.de>
parents:
1013
diff
changeset
|
977 |
|
5655 | 978 |
"Modified: / 07-12-2017 / 17:53:35 / cg" |
624 | 979 |
! |
255 | 980 |
|
627 | 981 |
buttonPress:button x:x y:y |
2889 | 982 |
|p clr masked| |
627 | 983 |
|
1693 | 984 |
p := x@y. |
985 |
||
5481 | 986 |
"/ with shift, paste is offset by pasted image's size |
987 |
"/ (i.e. click-point will be corner of pasted rectangle) |
|
5618 | 988 |
(self inPasteMode and:[ ClipboardImage notNil ]) ifTrue:[ |
3278 | 989 |
self sensor shiftDown ifTrue:[ |
5655 | 990 |
p := p - (ClipboardImage extent * magnification) |
3278 | 991 |
] |
992 |
]. |
|
993 |
||
1693 | 994 |
self drawCursorAt:p. |
1011
325d334e93c8
added paste-under (only paste where pixel ~= current selected)
Claus Gittinger <cg@exept.de>
parents:
1006
diff
changeset
|
995 |
|
5481 | 996 |
(self imageContainsPoint:p) ifTrue:[ |
5480 | 997 |
"/ shift click: select the pixel-color |
5481 | 998 |
(self inPasteMode not and:[self sensor shiftDown]) ifTrue:[ |
5484 | 999 |
userAllowedToChangeDrawingColor ifTrue:[ |
1000 |
(image maskAt:(p // magnification)) == 0 ifTrue:[ |
|
1001 |
masked := true. |
|
1002 |
] ifFalse:[ |
|
1003 |
masked := false. |
|
1004 |
clr := image colorAt:(p // magnification). |
|
1005 |
]. |
|
1006 |
pickedColorHolder notNil ifTrue:[ |
|
1007 |
pickedColorHolder value:clr. |
|
1008 |
]. |
|
1009 |
self selectedColor:clr. |
|
1010 |
masked ifTrue:[self selectedColorIndex:nil]. |
|
1011 |
self changed:#selectedColor with:clr. |
|
1012 |
]. |
|
1246 | 1013 |
] ifFalse:[ |
5480 | 1014 |
"/ normal click: |
5413 | 1015 |
(readOnly not |
1016 |
or:[editMode == EditModeCopy |
|
1017 |
or:[editMode == EditModeSpecialOperation]] |
|
1018 |
) ifTrue:[ |
|
4853 | 1019 |
(button between:1 and:2) ifTrue:[ |
1020 |
mouseKeyColorMode := button. |
|
1021 |
self makeUndo. |
|
1022 |
||
1023 |
clickInfoCallBack notNil ifTrue:[ |
|
1024 |
"/ still a kludge, but less ugly ... |
|
1025 |
clickInfoCallBack value:button value:p |
|
1026 |
]. |
|
1027 |
"/ editMode is something like #point, #rectangle etc. |
|
5480 | 1028 |
"/ so we call pointAt: / rectAt: / filledBoxAt: etc. here |
4853 | 1029 |
[ |
1030 |
self perform: (editMode, 'At:') asSymbol with:p |
|
1031 |
] on:Error do:[:ex | |
|
1032 |
(Dialog confirm:('Error during operation: ', ex description,'\\Debug ?') withCRs ) |
|
1033 |
ifTrue:[ |
|
1034 |
ex reject |
|
1035 |
]. |
|
4041 | 1036 |
]. |
2889 | 1037 |
]. |
1038 |
]. |
|
1246 | 1039 |
] |
686 | 1040 |
] |
995 | 1041 |
|
5655 | 1042 |
"Modified: / 07-12-2017 / 17:53:23 / cg" |
632 | 1043 |
! |
1044 |
||
994
5727c2484ecd
bugs fixed in undo/mask and point painting/preview and pasting
tz
parents:
877
diff
changeset
|
1045 |
buttonRelease:button x:x y:y |
5727c2484ecd
bugs fixed in undo/mask and point painting/preview and pasting
tz
parents:
877
diff
changeset
|
1046 |
|
5727c2484ecd
bugs fixed in undo/mask and point painting/preview and pasting
tz
parents:
877
diff
changeset
|
1047 |
self drawCursorAt: x@y. |
4041 | 1048 |
readOnly ifTrue:[^ self]. |
1246 | 1049 |
|
5481 | 1050 |
(self imageContainsPoint: x@y) ifTrue: [ |
3476 | 1051 |
sprayProcess notNil ifTrue:[ |
1052 |
self stopSpray |
|
1053 |
]. |
|
1054 |
||
1763
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1706
diff
changeset
|
1055 |
image release. |
1011
325d334e93c8
added paste-under (only paste where pixel ~= current selected)
Claus Gittinger <cg@exept.de>
parents:
1006
diff
changeset
|
1056 |
|
5481 | 1057 |
"/ "/ cg: what a kludge - please change to use a valueHolder, |
1058 |
"/ "/ which gets the information ... |
|
1059 |
"/ masterApplication imagePreView invalidate. |
|
1693 | 1060 |
|
1061 |
"/ cg: still a kludge - but less ugly |
|
1062 |
self changed:#subImageIn with:(image bounds). |
|
994
5727c2484ecd
bugs fixed in undo/mask and point painting/preview and pasting
tz
parents:
877
diff
changeset
|
1063 |
] |
1116
441ff42c1472
fixes to allow 24bit images to be (at least) displayed
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1064 |
|
5481 | 1065 |
"Modified: / 16-02-2017 / 16:57:24 / cg" |
994
5727c2484ecd
bugs fixed in undo/mask and point painting/preview and pasting
tz
parents:
877
diff
changeset
|
1066 |
! |
5727c2484ecd
bugs fixed in undo/mask and point painting/preview and pasting
tz
parents:
877
diff
changeset
|
1067 |
|
2508 | 1068 |
inPasteMode |
2889 | 1069 |
^ (editMode notNil and:[editMode startsWith:#paste]) |
2508 | 1070 |
! |
1071 |
||
5669 | 1072 |
keyboardZoom:largerBoolean |
5671 | 1073 |
"CTRL+/- zoom action" |
1074 |
||
1075 |
self magnification:( |
|
1076 |
largerBoolean |
|
1077 |
ifTrue:[(magnification + 1) min:63] |
|
1078 |
ifFalse:[(magnification - 1) max:1]) |
|
5277 | 1079 |
! |
1080 |
||
686 | 1081 |
pointerLeave:state |
1082 |
||
688 | 1083 |
super pointerLeave: state. |
686 | 1084 |
|
1031
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
1085 |
self updateImageInfo: self imageInfoString. |
1019
e68414752bc9
only change the cursor for myself.
Claus Gittinger <cg@exept.de>
parents:
1013
diff
changeset
|
1086 |
self cursor:Cursor normal. |
995 | 1087 |
|
2508 | 1088 |
self inPasteMode ifTrue: [ |
1246 | 1089 |
self releasePasteDrawing |
1090 |
] |
|
995 | 1091 |
|
1031
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
1092 |
"Modified: / 29.7.1998 / 18:27:42 / cg" |
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
1093 |
! ! |
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
1094 |
|
636 | 1095 |
!ImageEditView methodsFor:'image editing'! |
627 | 1096 |
|
5491 | 1097 |
askForSpecialOperation |
1098 |
"let user ask for which special operation to apply to the selected imageBox, |
|
1099 |
then perform it." |
|
1100 |
||
5497 | 1101 |
|listOfOpSpecs listOfOpNames listOfOpSelectors operation| |
1102 |
||
1103 |
listOfOpSpecs := OrderedCollection new. |
|
5491 | 1104 |
|
5497 | 1105 |
listOfOpSpecs addAll: |
5491 | 1106 |
#( |
5497 | 1107 |
('edit separately' editIcon #edit) |
1108 |
('extract subimage' cropSubImageIcon #editSubImage) |
|
5491 | 1109 |
). |
1110 |
||
1111 |
self readOnly ifFalse:[ |
|
5497 | 1112 |
listOfOpSpecs addAll: |
1113 |
#( |
|
1114 |
('-' nil nil) |
|
1115 |
('flip vertical' flipVerticalIcon flipVertical) |
|
1116 |
('flip horizontal' flipHorizontalIcon flipHorizontal) |
|
1117 |
('-' nil nil) |
|
1118 |
('slightly brightened' slightlyBrighterIcon slightlyBrightened) |
|
1119 |
('slightly darkened' slightlyDarkerIcon slightlyDarkened) |
|
1120 |
('brightened' brighterIcon brightened) |
|
1121 |
('darkened' darkerIcon darkened) |
|
1122 |
('-' nil nil) |
|
1123 |
('make grey' nil makeGrey) |
|
1124 |
('greyed' nil greyed) |
|
1125 |
('grey pattern' nil greyPattern) |
|
1126 |
('grey pattern (unmasked)' nil unmaskedGreyPattern) |
|
1127 |
('-' nil nil) |
|
1128 |
('reversed' nil reversed) |
|
1129 |
('-' nil nil) |
|
1130 |
('change hue' nil changeHue) |
|
1131 |
('colorize' nil colorize) |
|
1132 |
('-' nil nil) |
|
1133 |
('gradient fill horizontal' fillHorizontalGradientRectIcon gradientFillHorizontal) |
|
1134 |
('gradient fill vertical' fillVerticalGradientRectIcon gradientFillVertical) |
|
5499 | 1135 |
"/ unfinished |
1136 |
"/ ('gradient fill diagonal' fillDiagonalGradientRectIcon gradientFillDiagonal) |
|
5497 | 1137 |
('-' nil nil) |
1138 |
('auto gradient fill horizontal' fillHorizontalGradientRectIcon autoGradientFillHorizontal) |
|
1139 |
('auto gradient fill vertical' fillVerticalGradientRectIcon autoGradientFillVertical) |
|
5499 | 1140 |
"/ unfinished |
1141 |
"/ ('auto gradient fill diagonal' fillDiagonalGradientRectIcon autoGradientFillDiagonal) |
|
5497 | 1142 |
). |
5491 | 1143 |
]. |
1144 |
||
5497 | 1145 |
listOfOpNames := listOfOpSpecs collect:[:entry | |
1146 |
|name iconSelector icon| |
|
1147 |
name := entry first. |
|
1148 |
iconSelector := entry second. |
|
1149 |
iconSelector notNil ifTrue:[ |
|
1150 |
icon := self class perform:iconSelector ifNotUnderstood:[ImageEditor perform:iconSelector]. |
|
1151 |
LabelAndIcon label:name icon:icon |
|
1152 |
] ifFalse:[ |
|
1153 |
name |
|
1154 |
]. |
|
1155 |
]. |
|
1156 |
||
1157 |
listOfOpSelectors := listOfOpSpecs collect:#third. |
|
1158 |
||
5491 | 1159 |
operation := Dialog |
1160 |
choose:(resources string:'Which Operation:') |
|
1161 |
fromList:listOfOpNames |
|
1162 |
values:listOfOpSelectors |
|
5497 | 1163 |
lines:20 |
5491 | 1164 |
cancel:nil. |
1165 |
||
1166 |
^ operation |
|
1167 |
||
1168 |
"Created: / 20-02-2017 / 17:37:23 / cg" |
|
5499 | 1169 |
"Modified: / 23-02-2017 / 15:54:42 / cg" |
5491 | 1170 |
! |
1171 |
||
5492 | 1172 |
autoCropLeft:doLeft right:doRight top:doTop bottom:doBottom |
1173 |
|yMinNew yMaxNew xMinNew xMaxNew |
|
1174 |
pix stillCropping xMax yMax| |
|
1175 |
||
5531 | 1176 |
image isNil ifTrue:[^ self]. |
1177 |
||
5492 | 1178 |
xMax := image width - 1. |
1179 |
yMax := image height - 1. |
|
1180 |
||
1181 |
xMinNew := 0. |
|
1182 |
doLeft ifTrue:[ |
|
1183 |
pix := image pixelAtX:xMinNew y:0. |
|
1184 |
stillCropping := true. |
|
1185 |
[stillCropping] whileTrue:[ |
|
1186 |
0 to:yMax do:[:y | |
|
5531 | 1187 |
(image pixelAtX:xMinNew y:y) ~= pix ifTrue:[ |
5492 | 1188 |
stillCropping := false |
1189 |
] |
|
1190 |
]. |
|
1191 |
stillCropping ifTrue:[ |
|
1192 |
xMinNew := xMinNew + 1. |
|
1193 |
xMinNew >= image width ifTrue:[ |
|
1194 |
self warn:(resources string:'Image is all the same color - no crop.'). |
|
1195 |
^ self |
|
1196 |
] |
|
1197 |
]. |
|
1198 |
]. |
|
1199 |
]. |
|
1200 |
||
1201 |
xMaxNew := xMax. |
|
1202 |
doRight ifTrue:[ |
|
1203 |
stillCropping := true. |
|
1204 |
pix := image pixelAtX:xMaxNew y:0. |
|
1205 |
[stillCropping] whileTrue:[ |
|
1206 |
0 to:yMax do:[:y | |
|
5531 | 1207 |
(image pixelAtX:xMaxNew y:y) ~= pix ifTrue:[ |
5492 | 1208 |
stillCropping := false |
1209 |
] |
|
1210 |
]. |
|
1211 |
stillCropping ifTrue:[ |
|
1212 |
xMaxNew := xMaxNew - 1. |
|
1213 |
]. |
|
1214 |
]. |
|
1215 |
]. |
|
1216 |
||
1217 |
yMinNew := 0. |
|
1218 |
doTop ifTrue:[ |
|
1219 |
pix := image pixelAtX:xMinNew y:yMinNew. |
|
1220 |
stillCropping := true. |
|
1221 |
[stillCropping] whileTrue:[ |
|
1222 |
xMinNew to:xMaxNew do:[:x | |
|
5531 | 1223 |
(image pixelAtX:x y:yMinNew) ~= pix ifTrue:[ |
5492 | 1224 |
stillCropping := false |
1225 |
] |
|
1226 |
]. |
|
1227 |
stillCropping ifTrue:[ |
|
1228 |
yMinNew := yMinNew + 1. |
|
1229 |
]. |
|
1230 |
]. |
|
1231 |
]. |
|
1232 |
||
1233 |
yMaxNew := yMax. |
|
5531 | 1234 |
doBottom ifTrue:[ |
5492 | 1235 |
stillCropping := true. |
1236 |
pix := image pixelAtX:xMaxNew y:yMaxNew. |
|
1237 |
[stillCropping] whileTrue:[ |
|
1238 |
xMinNew to:xMaxNew do:[:x | |
|
5531 | 1239 |
(image pixelAtX:x y:yMaxNew) ~= pix ifTrue:[ |
5492 | 1240 |
stillCropping := false |
1241 |
] |
|
1242 |
]. |
|
1243 |
stillCropping ifTrue:[ |
|
1244 |
yMaxNew := yMaxNew - 1. |
|
1245 |
]. |
|
1246 |
]. |
|
1247 |
]. |
|
1248 |
||
1249 |
(xMinNew == 0 |
|
1250 |
and:[xMaxNew == (image width - 1) |
|
1251 |
and:[yMinNew == 0 |
|
1252 |
and:[yMaxNew == (image height - 1)]]]) ifTrue:[ |
|
1253 |
self warn:(resources string:'No border found - no crob.'). |
|
1254 |
^ self |
|
1255 |
]. |
|
1256 |
||
1257 |
"/ self warn:'extract subImage ' |
|
1258 |
"/ , (xMinNew @ yMinNew) printString |
|
1259 |
"/ , ' -> ' |
|
1260 |
"/ , (xMaxNew @ yMaxNew) printString. |
|
1261 |
||
1262 |
self makeUndo. |
|
1263 |
self |
|
1264 |
makeSubImageX:xMinNew y:yMinNew |
|
1265 |
width:(xMaxNew - xMinNew + 1) |
|
1266 |
height:(yMaxNew - yMinNew + 1) |
|
1267 |
||
1268 |
"Created: / 20-02-2017 / 17:59:05 / cg" |
|
5531 | 1269 |
"Modified: / 12-04-2017 / 09:33:08 / cg" |
5492 | 1270 |
! |
1271 |
||
2480 | 1272 |
copyImageToClipboard |
5531 | 1273 |
image isNil ifTrue:[^ self]. |
1274 |
||
2480 | 1275 |
self class copyImageToClipboard:image. |
4264 | 1276 |
self setClipboardObject:image. |
5531 | 1277 |
|
1278 |
"Modified: / 12-04-2017 / 09:27:07 / cg" |
|
2480 | 1279 |
! |
1280 |
||
1228 | 1281 |
cropLeft:doLeft right:doRight top:doTop bottom:doBottom |
5531 | 1282 |
<resource: #obsolete> |
1283 |
||
1284 |
self autoCropLeft:doLeft right:doRight top:doTop bottom:doBottom |
|
1285 |
||
1286 |
"Created: / 07-09-1998 / 14:25:52 / cg" |
|
1287 |
"Modified: / 12-04-2017 / 09:31:04 / cg" |
|
1121 | 1288 |
! |
1289 |
||
5435 | 1290 |
drawingColorOrNil |
1291 |
|cmap| |
|
1292 |
||
1293 |
cmap := image colorMap. |
|
1294 |
(cmap isNil or:[cmap isFixedPalette or:[cmap isMappedPalette]]) ifTrue:[ |
|
1295 |
^ self selectedColor. |
|
1296 |
]. |
|
1297 |
^ nil |
|
1298 |
||
1299 |
"Created: / 03-02-2017 / 21:58:01 / cg" |
|
5594 | 1300 |
"Modified: / 05-09-2017 / 10:49:34 / cg" |
5435 | 1301 |
! |
1302 |
||
1303 |
drawingPixelOrNil |
|
1304 |
|cmap| |
|
1305 |
||
1306 |
cmap := image colorMap. |
|
1307 |
(cmap isNil or:[cmap isFixedPalette or:[cmap isMappedPalette]]) ifTrue:[ |
|
1308 |
^ nil. |
|
1309 |
]. |
|
1310 |
^ self selectedColorIndex. |
|
1311 |
||
1312 |
"Created: / 03-02-2017 / 21:58:28 / cg" |
|
1313 |
! |
|
1314 |
||
4032 | 1315 |
flipSubImage:how in:imageBox |
1316 |
"/ now, do it |
|
4624 | 1317 |
"/ caveat: this should go into image class |
4032 | 1318 |
|
1319 |
|x0 y0 x1 y1 image t| |
|
1320 |
||
4623 | 1321 |
self makeUndo. |
1322 |
||
4032 | 1323 |
x0 := imageBox left. |
1324 |
y0 := imageBox top. |
|
1325 |
x1 := imageBox right-1. |
|
1326 |
y1 := imageBox bottom-1. |
|
1327 |
||
1328 |
image := self image. |
|
1329 |
||
1330 |
how == #vertical ifTrue:[ |
|
1331 |
0 to:((y1-y0)//2) do:[:dy | |
|
1332 |
x0 to:x1 do:[:x | |
|
1333 |
t := image pixelAtX:x y:(y0+dy). |
|
1334 |
image pixelAtX:x y:(y0+dy) put:(image pixelAtX:x y:(y1-dy)). |
|
1335 |
image pixelAtX:x y:(y1-dy) put:t. |
|
4624 | 1336 |
image mask notNil ifTrue:[ |
1337 |
t := image maskAtX:x y:(y0+dy). |
|
1338 |
image maskAtX:x y:(y0+dy) put:(image maskAtX:x y:(y1-dy)). |
|
1339 |
image maskAtX:x y:(y1-dy) put:t. |
|
1340 |
]. |
|
4032 | 1341 |
]. |
1342 |
] |
|
1343 |
] ifFalse:[ |
|
1344 |
0 to:((x1-x0)//2) do:[:dx | |
|
1345 |
y0 to:y1 do:[:y | |
|
1346 |
t := image pixelAtX:(x0+dx) y:y. |
|
1347 |
image pixelAtX:(x0+dx) y:y put:(image pixelAtX:(x1-dx) y:y). |
|
1348 |
image pixelAtX:(x1-dx) y:y put:t. |
|
4623 | 1349 |
|
4624 | 1350 |
image mask notNil ifTrue:[ |
1351 |
t := image maskAtX:(x0+dx) y:y. |
|
1352 |
image maskAtX:(x0+dx) y:y put:(image maskAtX:(x1-dx) y:y). |
|
1353 |
image maskAtX:(x1-dx) y:y put:t. |
|
1354 |
]. |
|
4032 | 1355 |
]. |
1356 |
] |
|
1357 |
]. |
|
1358 |
||
1359 |
self setModified. |
|
1360 |
||
1361 |
"Created: / 07-04-2011 / 09:34:23 / cg" |
|
1362 |
! |
|
1363 |
||
5497 | 1364 |
gradientFillIn:imageBox orientation:orientation auto:auto |
5499 | 1365 |
"/ with auto, pick 2 bounding pixels and do a gradient fill with those; |
1366 |
"/ (don't know what diagonal should do, yet) |
|
5497 | 1367 |
"/ if auto is false, use color1/color2 for the fill |
1368 |
||
1369 |
|x0 y0 x1 y1 image n color1 color2 |
|
5499 | 1370 |
r0 g0 b0 dR dG dB i cX cY A B qAB a b pD1x pD1y pD2x pD2y |
1371 |
dxH dyH hX hY dH dP f | |
|
5497 | 1372 |
|
1373 |
self makeUndo. |
|
1374 |
||
1375 |
x0 := imageBox left. |
|
1376 |
y0 := imageBox top. |
|
1377 |
x1 := imageBox right-1. |
|
1378 |
y1 := imageBox bottom-1. |
|
1379 |
image := self image. |
|
1380 |
||
1381 |
self setModified. |
|
1382 |
||
1383 |
auto ifTrue:[ |
|
1384 |
orientation == #vertical ifTrue:[ |
|
1385 |
n := y1-y0-1. |
|
1386 |
n = 0 ifTrue:[^ self]. |
|
1387 |
x0 to:x1 do:[:x | |
|
1388 |
color1 := image colorAtX:x y:y0. |
|
1389 |
color2 := image colorAtX:x y:y1. |
|
1390 |
r0 := color1 red. |
|
1391 |
g0 := color1 green. |
|
1392 |
b0 := color1 blue. |
|
1393 |
dR := (color2 red - color1 red) / n. |
|
1394 |
dG := (color2 green - color1 green) / n. |
|
1395 |
dB := (color2 blue - color1 blue) / n. |
|
1396 |
i := 1. |
|
1397 |
y0+1 to:y1-1 do:[:y | |
|
1398 |
|clr| |
|
1399 |
clr := Color red:(r0 + (i*dR)) green:(g0 + (i*dG)) blue:(b0 + (i*dB)). |
|
1400 |
image colorAtX:x y:y put:clr. |
|
1401 |
i := i+1. |
|
1402 |
]. |
|
1403 |
]. |
|
1404 |
^ self. |
|
1405 |
]. |
|
1406 |
||
1407 |
orientation == #horizontal ifTrue:[ |
|
1408 |
n := x1-x0-1. |
|
1409 |
n = 0 ifTrue:[^ self]. |
|
1410 |
y0 to:y1 do:[:y | |
|
1411 |
color1 := image colorAtX:x0 y:y. |
|
1412 |
color2 := image colorAtX:x1 y:y. |
|
1413 |
r0 := color1 red. |
|
1414 |
g0 := color1 green. |
|
1415 |
b0 := color1 blue. |
|
1416 |
dR := (color2 red - color1 red) / n. |
|
1417 |
dG := (color2 green - color1 green) / n. |
|
1418 |
dB := (color2 blue - color1 blue) / n. |
|
1419 |
i := 1. |
|
1420 |
x0+1 to:x1-1 do:[:x | |
|
1421 |
|clr| |
|
1422 |
clr := Color red:(r0 + (i*dR)) green:(g0 + (i*dG)) blue:(b0 + (i*dB)). |
|
1423 |
image colorAtX:x y:y put:clr. |
|
1424 |
i := i+1. |
|
1425 |
]. |
|
1426 |
]. |
|
1427 |
^ self. |
|
1428 |
]. |
|
1429 |
^ self. |
|
1430 |
]. |
|
1431 |
||
5499 | 1432 |
color1 := (self drawingColorHolders at:1) value. |
5497 | 1433 |
color1 isNil ifTrue:[ color1 := Color black ]. |
5499 | 1434 |
color2 := (self drawingColorHolders at:2) value. |
5497 | 1435 |
color2 isNil ifTrue:[ color2 := Color white ]. |
1436 |
||
1437 |
r0 := color1 red. |
|
1438 |
g0 := color1 green. |
|
1439 |
b0 := color1 blue. |
|
1440 |
||
1441 |
orientation == #vertical ifTrue:[ |
|
1442 |
n := y1-y0. |
|
1443 |
n = 0 ifTrue:[^ self]. |
|
1444 |
||
5499 | 1445 |
dR := (color2 red - r0) / n. |
1446 |
dG := (color2 green - g0) / n. |
|
1447 |
dB := (color2 blue - b0) / n. |
|
5497 | 1448 |
|
1449 |
x0 to:x1 do:[:x | |
|
1450 |
i := 0. |
|
1451 |
y0 to:y1 do:[:y | |
|
1452 |
|clr| |
|
1453 |
clr := Color red:(r0 + (i*dR)) green:(g0 + (i*dG)) blue:(b0 + (i*dB)). |
|
1454 |
image colorAtX:x y:y put:clr. |
|
1455 |
i := i+1. |
|
1456 |
]. |
|
1457 |
]. |
|
1458 |
^ self. |
|
1459 |
]. |
|
1460 |
orientation == #horizontal ifTrue:[ |
|
1461 |
n := x1-x0. |
|
1462 |
n = 0 ifTrue:[^ self ]. |
|
1463 |
||
5499 | 1464 |
dR := (color2 red - r0) / n. |
1465 |
dG := (color2 green - g0) / n. |
|
1466 |
dB := (color2 blue - b0) / n. |
|
5497 | 1467 |
|
1468 |
y0 to:y1 do:[:y | |
|
1469 |
i := 1. |
|
1470 |
x0+1 to:x1-1 do:[:x | |
|
1471 |
|clr| |
|
1472 |
clr := Color red:(r0 + (i*dR)) green:(g0 + (i*dG)) blue:(b0 + (i*dB)). |
|
1473 |
image colorAtX:x y:y put:clr. |
|
1474 |
i := i+1. |
|
1475 |
]. |
|
1476 |
]. |
|
1477 |
^ self. |
|
1478 |
]. |
|
1479 |
||
1480 |
orientation == #diagonal ifTrue:[ |
|
5499 | 1481 |
cX := (x1+1 + x0) / 2. |
1482 |
cY := (y1+1 + y0) / 2. |
|
1483 |
A := cY-y0. |
|
1484 |
B := cX-x0. |
|
1485 |
(A=0 or:[B=0]) ifTrue:[^ self]. |
|
1486 |
||
1487 |
qAB := A/B. |
|
5497 | 1488 |
|
5499 | 1489 |
"/ {(cX-10) rounded . (cX-5) rounded . cX rounded . (cX+5)rounded . (cX+10)rounded } |
1490 |
x0 to:x1 |
|
1491 |
do:[:x | |
|
1492 |
b := cX-x. |
|
1493 |
b = 0 ifTrue:[ |
|
1494 |
pD1x := pD2x := cX. |
|
1495 |
pD1y := pD2y := cY. |
|
1496 |
] ifFalse:[ |
|
1497 |
"/ (A/B) = (a/b) -> a = (A/B)*b |
|
1498 |
a := qAB*b. |
|
1499 |
pD1x := ((cX-b) max:x0) min:x1. |
|
1500 |
pD1y := ((cY+a) max:y0) min:y1. |
|
1501 |
pD2x := ((cX-b) max:x0) min:x1. |
|
1502 |
pD2y := ((cY-a) max:y0) min:y1. |
|
1503 |
]. |
|
1504 |
"/ {(cY-10)rounded . (cY-5)rounded . cY rounded. (cY+5)rounded. (cY+10)rounded } |
|
1505 |
y0 to:y1 |
|
1506 |
do:[:y | |
|
1507 |
"/ the edge-point to interpolate against... |
|
1508 |
"/ take a line from C through x/y and compute where it hits the edge H |
|
1509 |
a := y-cY. |
|
1510 |
b := x-cX. |
|
1511 |
(a = 0) ifTrue:[ |
|
1512 |
"/ exactly in the middle |
|
1513 |
hX := (x < cX) ifTrue:[x0] ifFalse:[x1]. |
|
1514 |
hY := cY. |
|
5497 | 1515 |
] ifFalse:[ |
5499 | 1516 |
(b = 0) ifTrue:[ |
1517 |
hX := cX. |
|
1518 |
hY := (y < cY) ifTrue:[y0] ifFalse:[y1]. |
|
1519 |
] ifFalse:[ |
|
1520 |
"/ (dH/A) = (b/a) -> dH = (b/a)*A |
|
1521 |
y <= pD1y ifTrue:[ |
|
1522 |
"/ in left-upper half |
|
1523 |
(y <= pD2y) ifTrue:[ |
|
1524 |
"/ in upper quadrant |
|
1525 |
dxH := (b/a)*A. |
|
1526 |
hX := cX-dxH. |
|
1527 |
hY := y0. |
|
1528 |
] ifFalse:[ |
|
1529 |
"/ in left quadrant |
|
1530 |
dyH := (a/b)*B negated. |
|
1531 |
hY := cY+dyH. |
|
1532 |
hX := x0. |
|
1533 |
]. |
|
1534 |
] ifFalse:[ |
|
1535 |
"/ in right-lower half |
|
1536 |
y >= pD2y ifTrue:[ |
|
1537 |
"/ in lower quadrant |
|
1538 |
dxH := (b/a)*A negated. |
|
1539 |
hX := cX-dxH. |
|
1540 |
hY := y1. |
|
1541 |
] ifFalse:[ |
|
1542 |
"/ in right quadrant |
|
1543 |
dyH := (a/b)*B. |
|
1544 |
hY := cY+dyH. |
|
1545 |
hX := x1. |
|
1546 |
]. |
|
1547 |
]. |
|
1548 |
]. |
|
1549 |
hX := hX min:x1. |
|
1550 |
hY := hY min:y1. |
|
5497 | 1551 |
]. |
5499 | 1552 |
|
1553 |
"/ the color at H |
|
1554 |
color2 := image colorAtX:hX rounded y:hY rounded. |
|
1555 |
||
1556 |
"/ the distance between H and C |
|
1557 |
dH := (hX@hY) dist:(cX@cY). |
|
1558 |
"/ the distance between P and C |
|
1559 |
dP := (x@y) dist:(cX@cY). |
|
1560 |
"/ the fraction (0 at H; 1 at C) |
|
1561 |
f := 1 - (dP / dH). |
|
1562 |
self assert:(f between:0 and:1). |
|
1563 |
||
1564 |
"/ the new color |
|
1565 |
dR := color2 red + ((r0-color2 red ) * f). |
|
1566 |
dG := color2 green + ((g0-color2 green) * f). |
|
1567 |
dB := color2 blue + ((b0-color2 blue) * f). |
|
1568 |
image colorAtX:x y:y put:(Color red:dR green:dG blue:dB). |
|
1569 |
||
1570 |
"/ y <= pD1y ifTrue:[ |
|
1571 |
"/ "/ in left-upper half |
|
1572 |
"/ (y <= pD2y) ifTrue:[ |
|
1573 |
"/ "/ in upper quadrant |
|
1574 |
"/ image colorAtX:x y:y put:Color red. |
|
1575 |
"/ ] ifFalse:[ |
|
1576 |
"/ "/ in left quadrant |
|
1577 |
"/ image colorAtX:x y:y put:Color green. |
|
1578 |
"/ ]. |
|
1579 |
"/ ] ifFalse:[ |
|
1580 |
"/ "/ in right-lower half |
|
1581 |
"/ y >= pD2y ifTrue:[ |
|
1582 |
"/ "/ in lower quadrant |
|
1583 |
"/ image colorAtX:x y:y put:Color blue. |
|
1584 |
"/ ] ifFalse:[ |
|
1585 |
"/ "/ in right quadrant |
|
1586 |
"/ image colorAtX:x y:y put:Color yellow. |
|
1587 |
"/ ]. |
|
1588 |
"/ |
|
1589 |
"/ ]. |
|
1590 |
]. |
|
5497 | 1591 |
]. |
5499 | 1592 |
"/ image colorAtX:cX rounded y:cY rounded put:Color magenta. |
1593 |
||
1594 |
"/ clr2 := image colorAtX:p2X y:p2Y. |
|
1595 |
"/ |
|
1596 |
"/ cTop := image colorAtX:x y:y0. |
|
1597 |
"/ cBot := image colorAtX:x y:y1. |
|
1598 |
"/ "/ point on diagonal |
|
1599 |
"/ xD := x. |
|
1600 |
"/ yD := (y1-y0)/(x1-x0)*x. |
|
1601 |
"/ "/ color at point on diagonal |
|
1602 |
"/ "/ cDiag := image colorAtX:xD rounded y:yD rounded. |
|
1603 |
"/ "/ the distance of the diagonal point from the origin |
|
1604 |
"/ dd := ((x-x0) squared + (yD-y0) squared) sqrt. |
|
1605 |
"/ "/ desired color at point on diagonal |
|
1606 |
"/ cDiag := Color red:(color1 red + (dd*dR)) green:(color1 green + (dd*dG)) blue:(color1 blue + (dd*dB)). |
|
1607 |
"/"/ image colorAtX:xD rounded y:yD rounded put:cDiag. |
|
1608 |
"/ |
|
1609 |
"/ n1 := yD-y0+1. "/ num points between top at x and diagonalPoint at x |
|
1610 |
"/ n2 := y1-yD+1. "/ num points between diagonalPoint at x and bottom at x |
|
1611 |
"/ y0 to:y1 do:[:y | |
|
1612 |
"/ |clr d dR2 dG2 dB2| |
|
1613 |
"/ |
|
1614 |
"/ y < yD ifTrue:[ |
|
1615 |
"/ "/ gradient from top-color at x to diagonal point at x |
|
1616 |
"/ d := y-y0. |
|
1617 |
"/ dR2 := (cDiag red - cTop red) / n1. |
|
1618 |
"/ dG2 := (cDiag green - cTop green) / n1. |
|
1619 |
"/ dB2 := (cDiag blue - cTop blue) / n1. |
|
1620 |
"/ clr := Color red:(cTop red + (d*dR2)) green:(cTop green + (d*dG2)) blue:(cTop blue + (d*dB2)). |
|
1621 |
"/ image colorAtX:x y:y put:clr. |
|
1622 |
"/ ] ifFalse:[ |
|
1623 |
"/ "/ gradient from diagonal point at x to bottom point at x |
|
1624 |
"/ d := y-yD. |
|
1625 |
"/ dR2 := (cBot red - cDiag red) / n2. |
|
1626 |
"/ dG2 := (cBot green - cDiag green) / n2. |
|
1627 |
"/ dB2 := (cBot blue - cDiag blue) / n2. |
|
1628 |
"/ clr := Color red:(cDiag red + (d*dR2)) green:(cDiag green + (d*dG2)) blue:(cDiag blue + (d*dB2)). |
|
1629 |
"/ "/ clr := image colorAtX:x y:y. |
|
1630 |
"/ image colorAtX:x y:y put:clr. |
|
1631 |
"/ ]. |
|
1632 |
"/ ] |
|
1633 |
"/ ]. |
|
5497 | 1634 |
^ self. |
1635 |
]. |
|
1636 |
||
1637 |
"Created: / 22-02-2017 / 21:00:01 / cg" |
|
5499 | 1638 |
"Modified: / 23-02-2017 / 15:41:23 / cg" |
5497 | 1639 |
! |
1640 |
||
4723 | 1641 |
magnifyAntiAliasedImageTo:newSize |
4730 | 1642 |
self newImageWithUndo: (image hardAntiAliasedMagnifiedBy: newSize/image extent). |
4723 | 1643 |
! |
1644 |
||
1706 | 1645 |
magnifyImageTo:newSize |
4730 | 1646 |
self newImageWithUndo: (image magnifiedBy: newSize/image extent). |
636 | 1647 |
! |
1648 |
||
5586 | 1649 |
magnifySmoothingBy:scale |
1650 |
self newImageWithUndo: (image hardSmoothingMagnifiedBy:scale). |
|
1651 |
||
1652 |
"Created: / 30-08-2017 / 15:35:15 / cg" |
|
1653 |
! |
|
1654 |
||
5587 | 1655 |
magnifySmoothingTo:newSize |
1656 |
self newImageWithUndo: (image hardSmoothingMagnifiedBy: newSize/image extent). |
|
1657 |
||
1658 |
"Created: / 30-08-2017 / 15:46:46 / cg" |
|
1659 |
! |
|
1660 |
||
2168 | 1661 |
makeNewColorMapByMapping:functionOfColor |
5589 | 1662 |
"wrong name: no longer needs a colormap - can also process the pixels |
1663 |
||
1664 |
undoable make a new image by processing colors with a function. |
|
1665 |
If the image is a true-color image (rgb), the function is applied |
|
1666 |
to every pixel's color and a new pixel-array is created (this is slow). |
|
1667 |
Currently not done (why?): |
|
1668 |
If the image is a palette image, |
|
1669 |
the function is applied to the colormap only and a new colormap is |
|
1670 |
created (i.e. this is very fast). |
|
1671 |
||
1672 |
This is the internal low level function to brighten, darken |
|
1673 |
or hue-shift the image. |
|
1674 |
Returns true, if there was any change." |
|
1675 |
||
2566
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1676 |
|xMax yMax map revMap anyChange |
5589 | 1677 |
newColors newColorArray newImage pixelAction |
1678 |
prevRGBIn prevRGBOut| |
|
2168 | 1679 |
|
1886 | 1680 |
anyChange := false. |
1681 |
||
1682 |
xMax := image width - 1. |
|
1683 |
yMax := image height - 1. |
|
1684 |
||
1685 |
newImage := image class width:image width height:image height depth:image depth. |
|
5589 | 1686 |
|
1886 | 1687 |
newImage photometric:image photometric. |
1688 |
newImage bits:(ByteArray new:(image bits size)). |
|
1689 |
newImage mask:(image mask copy). |
|
1690 |
||
2566
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1691 |
image colorMap notNil ifTrue:[ |
5589 | 1692 |
"/ huh - what is going on here??? |
1693 |
"/ whx not just collect over the colormap??? |
|
1694 |
||
2566
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1695 |
newColors := Set new. |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1696 |
newColorArray := OrderedCollection new. |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1697 |
map := Array new:256. |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1698 |
revMap := OrderedCollection new. |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1699 |
|
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1700 |
pixelAction := |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1701 |
[:x :y | |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1702 |
|pix n_pix clr n_clr| |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1703 |
|
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1704 |
pix := image pixelAtX:x y:y. |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1705 |
(n_pix := map at:pix+1) isNil ifTrue:[ |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1706 |
clr := image colorAtX:x y:y. |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1707 |
n_clr := functionOfColor value:clr. |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1708 |
(newColors includes:n_clr) ifFalse:[ |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1709 |
newColors add:n_clr. |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1710 |
newColorArray add:n_clr. |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1711 |
revMap add:pix. |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1712 |
map at:pix+1 put:(n_pix := revMap size - 1). |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1713 |
] ifTrue:[ |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1714 |
"/ mhmh - multiple pixels mapped to the same color |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1715 |
n_pix := (newColorArray indexOf:n_clr) - 1. |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1716 |
map at:pix+1 put:n_pix. |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1717 |
] |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1718 |
]. |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1719 |
newImage pixelAtX:x y:y put:n_pix. |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1720 |
]. |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1721 |
] ifFalse:[ |
5589 | 1722 |
((image depth == 24) and:[image photometric == #rgb]) ifTrue:[ |
1723 |
pixelAction := |
|
1724 |
[:x :y | |
|
1725 |
|rgb clr n_rgb| |
|
1726 |
||
1727 |
rgb := image pixelAtX:x y:y. |
|
1728 |
rgb == prevRGBIn ifTrue:[ |
|
1729 |
n_rgb := prevRGBOut |
|
1730 |
] ifFalse:[ |
|
1731 |
clr := Color rgbValue:rgb. |
|
1732 |
n_rgb := (functionOfColor value:clr) rgbValue. |
|
1733 |
prevRGBIn := rgb. |
|
1734 |
prevRGBOut := n_rgb. |
|
1735 |
]. |
|
1736 |
newImage pixelAtX:x y:y put:n_rgb. |
|
1737 |
]. |
|
1738 |
] ifFalse:[ |
|
1739 |
pixelAction := |
|
1740 |
[:x :y | |
|
1741 |
|clr n_clr| |
|
1742 |
||
1743 |
||
1744 |
clr := image colorAtX:x y:y. |
|
1745 |
n_clr := functionOfColor value:clr. |
|
1746 |
newImage colorAtX:x y:y put:n_clr. |
|
1747 |
]. |
|
1748 |
]. |
|
2566
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1749 |
]. |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1750 |
|
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1751 |
0 to:yMax do:[:y | |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1752 |
0 to:xMax do:[:x | |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1753 |
pixelAction value:x value:y |
1886 | 1754 |
] |
1755 |
]. |
|
1756 |
||
2566
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1757 |
image colorMap notNil ifTrue:[ |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1758 |
newImage colorMap:(MappedPalette withColors:newColorArray). |
d0894c5f6d4d
allow image processing of trueColor images
Claus Gittinger <cg@exept.de>
parents:
2556
diff
changeset
|
1759 |
]. |
4730 | 1760 |
self newImageWithUndo:newImage. |
5589 | 1761 |
|
1762 |
"/ for now, always return true |
|
1763 |
"/ (do not check if functionOfColor returns somthing different) |
|
1886 | 1764 |
^ true |
5589 | 1765 |
|
1766 |
"Modified (comment): / 31-08-2017 / 12:11:25 / cg" |
|
1886 | 1767 |
! |
1768 |
||
1121 | 1769 |
makeSubImageX:oldX y:oldY width:newWidth height:newHeight |
3706 | 1770 |
|oldWidth oldHeight newImage newMaskImage needRedraw redrawRect1 redrawRect2 | |
1771 |
||
1772 |
oldWidth := image width. |
|
1773 |
oldHeight := image height. |
|
1774 |
self assert:(newWidth <= oldWidth). |
|
1775 |
self assert:(newHeight <= oldHeight). |
|
1121 | 1776 |
|
1777 |
newImage := image class width:newWidth height:newHeight depth:image depth. |
|
1778 |
newImage photometric:image photometric. |
|
5468 | 1779 |
image photometric == #palette ifTrue:[ |
1780 |
newImage colorMap:image colorMap copy. |
|
1781 |
]. |
|
1121 | 1782 |
newImage bits:(ByteArray new:(newImage bytesPerRow * newHeight)). |
1783 |
||
3706 | 1784 |
image mask notNil ifTrue:[ |
1121 | 1785 |
newMaskImage := Depth1Image width:newWidth height:newHeight. |
1786 |
newMaskImage photometric: image mask photometric. |
|
1787 |
newMaskImage colorMap: image mask colorMap copy. |
|
1788 |
newMaskImage bits:(ByteArray new: newMaskImage bytesPerRow * newHeight). |
|
1789 |
newImage mask: newMaskImage |
|
1790 |
]. |
|
1791 |
||
1792 |
newImage copyFrom:image x:oldX y:oldY toX:0 y:0 width:newWidth height:newHeight. |
|
3706 | 1793 |
|
1794 |
needRedraw := true. |
|
1795 |
(oldX == 0 and:[oldY == 0]) ifTrue:[ |
|
1796 |
needRedraw := false. |
|
5332 | 1797 |
redrawRect1 := ((newWidth@0) * magnification) corner:(((oldWidth@oldHeight)+1) * magnification). |
1798 |
redrawRect2 := ((0@newHeight) * magnification) corner:(((oldWidth@oldHeight)+1) * magnification). |
|
3706 | 1799 |
]. |
1800 |
self image:newImage scroll:false invalidate:needRedraw. |
|
1801 |
redrawRect1 notNil ifTrue:[ |
|
1802 |
self invalidateRectangle:redrawRect1 repairNow:false. |
|
1803 |
]. |
|
1804 |
redrawRect2 notNil ifTrue:[ |
|
1805 |
self invalidateRectangle:redrawRect2 repairNow:false. |
|
1806 |
]. |
|
2590
b811d560e00a
modified flag after edit operations
Claus Gittinger <cg@exept.de>
parents:
2589
diff
changeset
|
1807 |
self setModified. |
1121 | 1808 |
|
5332 | 1809 |
"Created: / 07-09-1998 / 13:00:16 / cg" |
5468 | 1810 |
"Modified: / 13-02-2017 / 14:48:46 / cg" |
1121 | 1811 |
! |
1812 |
||
2915 | 1813 |
makeUndo |
5499 | 1814 |
|theCopy| |
1815 |
||
1816 |
image notNil ifTrue:[ |
|
3278 | 1817 |
[undoImages size >= MaxUndos] whileTrue:[ |
2915 | 1818 |
undoImages removeFirst. |
1819 |
]. |
|
5499 | 1820 |
theCopy := image copy. |
1821 |
undoImages add:theCopy. |
|
1822 |
originalImage isNil ifTrue:[ originalImage := theCopy ]. |
|
2915 | 1823 |
] |
3278 | 1824 |
|
5499 | 1825 |
"Modified: / 23-02-2017 / 15:43:55 / cg" |
2915 | 1826 |
! |
1827 |
||
2135 | 1828 |
pasteAt: aPoint mode:modeSymbol |
5480 | 1829 |
"called from button-press/button motion while in paste mode: |
1830 |
paste the image in the clipboard at aPoint" |
|
636 | 1831 |
|
2838
8525a35121d2
changeHLS fixed dfor depth24-images;
Claus Gittinger <cg@exept.de>
parents:
2824
diff
changeset
|
1832 |
|answer anyColorMissing choosenBox imagePoint imgX imgY copiedImage imageBox newColorMap |
2764 | 1833 |
existingColors newColors allColors currentColorMap newColormap anyColorAdded oldColorMap| |
1888 | 1834 |
|
4203 | 1835 |
Error handle:[:ex| |
1836 |
ex creator == Image unrepresentableColorSignal ifFalse:[ |
|
1246 | 1837 |
ex reject |
1838 |
]. |
|
1839 |
self undo. |
|
5061 | 1840 |
self warn:(resources stringWithCRs:'Paste failed !!\Increasing the images depth might help.'). |
1823 | 1841 |
] do: [ |
1246 | 1842 |
windowGroup withExecuteCursorDo:[ |
2838
8525a35121d2
changeHLS fixed dfor depth24-images;
Claus Gittinger <cg@exept.de>
parents:
2824
diff
changeset
|
1843 |
choosenBox := self dragRectangleStartingAt: aPoint emphasis: #inverseFilledBox. |
8525a35121d2
changeHLS fixed dfor depth24-images;
Claus Gittinger <cg@exept.de>
parents:
2824
diff
changeset
|
1844 |
choosenBox isNil ifTrue:[ ^ self ]. |
8525a35121d2
changeHLS fixed dfor depth24-images;
Claus Gittinger <cg@exept.de>
parents:
2824
diff
changeset
|
1845 |
|
8525a35121d2
changeHLS fixed dfor depth24-images;
Claus Gittinger <cg@exept.de>
parents:
2824
diff
changeset
|
1846 |
imagePoint := choosenBox origin//magnification. |
1011
325d334e93c8
added paste-under (only paste where pixel ~= current selected)
Claus Gittinger <cg@exept.de>
parents:
1006
diff
changeset
|
1847 |
|
5618 | 1848 |
copiedImage := ClipboardImage copy. |
5417 | 1849 |
copiedImage isNil ifTrue:[^ self]. |
1850 |
||
2440 | 1851 |
true "/ image photometric == #palette |
1888 | 1852 |
ifTrue:[ |
1246 | 1853 |
"/ for all colors in the pasted image, |
5472 | 1854 |
"/ check, if it's in the colormap of the |
1246 | 1855 |
"/ target image. |
995 | 1856 |
|
2764 | 1857 |
anyColorMissing := anyColorAdded := false. |
1858 |
oldColorMap := image colorMap. |
|
5434 | 1859 |
(oldColorMap notNil and:[image photometric == #palette]) ifTrue:[ |
2764 | 1860 |
newColorMap := oldColorMap asOrderedCollection. |
1957
9a4347986d96
paste with non-colormap image (i.e. truecolor).
Claus Gittinger <cg@exept.de>
parents:
1903
diff
changeset
|
1861 |
copiedImage usedValues do:[:pixel | |
2764 | 1862 |
|pastedColor | |
1116
441ff42c1472
fixes to allow 24bit images to be (at least) displayed
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1863 |
|
1957
9a4347986d96
paste with non-colormap image (i.e. truecolor).
Claus Gittinger <cg@exept.de>
parents:
1903
diff
changeset
|
1864 |
pastedColor := copiedImage colorFromValue:pixel. |
2764 | 1865 |
|
3762 | 1866 |
(newColorMap includes:pastedColor) ifFalse:[ |
2764 | 1867 |
newColorMap size < (1 bitShift:image depth) ifTrue:[ |
1957
9a4347986d96
paste with non-colormap image (i.e. truecolor).
Claus Gittinger <cg@exept.de>
parents:
1903
diff
changeset
|
1868 |
"/ add to colormap |
9a4347986d96
paste with non-colormap image (i.e. truecolor).
Claus Gittinger <cg@exept.de>
parents:
1903
diff
changeset
|
1869 |
newColorMap add:pastedColor. |
2764 | 1870 |
anyColorAdded := true. |
1957
9a4347986d96
paste with non-colormap image (i.e. truecolor).
Claus Gittinger <cg@exept.de>
parents:
1903
diff
changeset
|
1871 |
"/ Transcript showCR:'adding color:' , pastedColor displayString , ' to targets colorMap'. |
9a4347986d96
paste with non-colormap image (i.e. truecolor).
Claus Gittinger <cg@exept.de>
parents:
1903
diff
changeset
|
1872 |
] ifFalse:[ |
9a4347986d96
paste with non-colormap image (i.e. truecolor).
Claus Gittinger <cg@exept.de>
parents:
1903
diff
changeset
|
1873 |
"/ Transcript showCR:'color:' , pastedColor displayString , ' not found in targets colorMap'. |
1987 | 1874 |
"/ copiedImage colorMap notNil ifTrue:[ |
1875 |
"/ copiedImage colorMap at: pixel+1 put: Color black. |
|
1876 |
"/ ]. |
|
1957
9a4347986d96
paste with non-colormap image (i.e. truecolor).
Claus Gittinger <cg@exept.de>
parents:
1903
diff
changeset
|
1877 |
anyColorMissing := true. |
9a4347986d96
paste with non-colormap image (i.e. truecolor).
Claus Gittinger <cg@exept.de>
parents:
1903
diff
changeset
|
1878 |
] |
1246 | 1879 |
] |
1957
9a4347986d96
paste with non-colormap image (i.e. truecolor).
Claus Gittinger <cg@exept.de>
parents:
1903
diff
changeset
|
1880 |
]. |
1246 | 1881 |
]. |
2764 | 1882 |
|
1888 | 1883 |
anyColorMissing ifTrue:[ |
1884 |
answer := Dialog |
|
5061 | 1885 |
confirmWithCancel:(resources stringWithCRs:'Some color(s) cannot be represented (colorMap full).\Use nearest or compute colorMap ?') |
2172
737d8733fb01
brightemed, darkened, reverse etc. added to operations.
Claus Gittinger <cg@exept.de>
parents:
2168
diff
changeset
|
1886 |
labels:#( 'Cancel' 'New ColorMap' 'Use Nearest' ) |
737d8733fb01
brightemed, darkened, reverse etc. added to operations.
Claus Gittinger <cg@exept.de>
parents:
2168
diff
changeset
|
1887 |
values:#( nil new nearest) |
737d8733fb01
brightemed, darkened, reverse etc. added to operations.
Claus Gittinger <cg@exept.de>
parents:
2168
diff
changeset
|
1888 |
default:3. |
1888 | 1889 |
|
1890 |
answer isNil ifTrue:[^ self]. |
|
1986
630db3277f10
support pasing 24bit rgb image into an 8-bit palette image
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1891 |
|
630db3277f10
support pasing 24bit rgb image into an 8-bit palette image
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1892 |
currentColorMap := image colorMap. |
1987 | 1893 |
imgX := imagePoint x. |
1894 |
imgY := imagePoint y. |
|
1986
630db3277f10
support pasing 24bit rgb image into an 8-bit palette image
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1895 |
|
1888 | 1896 |
answer == #nearest ifTrue:[ |
1897 |
0 to:copiedImage height-1 do:[:y | |
|
1898 |
0 to:copiedImage width-1 do:[:x | |
|
1899 |
|clr n_clr| |
|
1900 |
||
1987 | 1901 |
(copiedImage maskAtX:x y:y) == 0 ifTrue:[ |
1902 |
image mask isNil ifTrue:[ |
|
1903 |
image createMask. |
|
1904 |
]. |
|
1905 |
image maskAtX:imgX+x y:imgY+y put:0. |
|
1906 |
] ifFalse:[ |
|
2582 | 1907 |
clr := copiedImage colorAtX:x y:y. |
1987 | 1908 |
n_clr := clr nearestIn:currentColorMap. |
2582 | 1909 |
image colorAtX:imgX+x y:imgY+y put:n_clr |
1987 | 1910 |
] |
1888 | 1911 |
] |
1912 |
]. |
|
1987 | 1913 |
image restored. |
5618 | 1914 |
self redraw: (imageBox := (imagePoint * magnification extent: (ClipboardImage extent * magnification)) expandedBy: 1@1). |
2590
b811d560e00a
modified flag after edit operations
Claus Gittinger <cg@exept.de>
parents:
2589
diff
changeset
|
1915 |
self setModified. |
1987 | 1916 |
^ self. |
2135 | 1917 |
]. |
1918 |
answer == #new ifTrue:[ |
|
1919 |
existingColors := image usedValues asIdentitySet. |
|
1920 |
newColors := copiedImage usedValues. |
|
1921 |
allColors := existingColors addAll:newColors. |
|
1922 |
allColors size > (1 bitShift:image depth) ifTrue:[ |
|
5061 | 1923 |
self warn:(resources string:'Sorry: too many colors - unimplemented function'). |
2135 | 1924 |
self undo. |
1986
630db3277f10
support pasing 24bit rgb image into an 8-bit palette image
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1925 |
^ self. |
630db3277f10
support pasing 24bit rgb image into an 8-bit palette image
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1926 |
]. |
2135 | 1927 |
|
1928 |
newColormap := OrderedCollection new. |
|
1929 |
newColormap addAll:image usedColors. |
|
1930 |
newColormap addAll:copiedImage usedColors. |
|
1931 |
"/ translate image to use new colorMap... |
|
1932 |
||
1933 |
"/ translate image to use new colors ... |
|
1934 |
0 to:image height-1 do:[:y | |
|
1935 |
0 to:image width-1 do:[:x | |
|
1936 |
|clr n_idx| |
|
1937 |
||
1938 |
(image maskAtX:x y:y) == 1 ifTrue:[ |
|
2582 | 1939 |
clr := image colorAtX:x y:y. |
2135 | 1940 |
n_idx := newColormap indexOf:clr. |
1941 |
image pixelAtX:x y:y put:n_idx-1. |
|
1942 |
] |
|
1943 |
] |
|
1944 |
]. |
|
1945 |
image colorMap:newColormap. |
|
1946 |
currentColorMap := newColormap. |
|
1947 |
||
1948 |
"/ paste new image... |
|
1949 |
0 to:copiedImage height-1 do:[:y | |
|
1950 |
0 to:copiedImage width-1 do:[:x | |
|
1951 |
|clr idx| |
|
1952 |
||
1953 |
(copiedImage maskAtX:x y:y) == 1 |
|
1954 |
ifTrue:[ |
|
2582 | 1955 |
clr := copiedImage colorAtX:x y:y. |
2135 | 1956 |
idx := currentColorMap indexOf:clr. |
1957 |
idx == 0 ifTrue:[ |
|
1958 |
currentColorMap add:clr. |
|
1959 |
idx := currentColorMap size. |
|
1960 |
idx > (1 bitShift:image depth) ifTrue:[ |
|
5061 | 1961 |
self warn:(resources string:'Sorry: too many colors'). |
2135 | 1962 |
self undo. |
1963 |
^ self. |
|
1964 |
]. |
|
1965 |
]. |
|
1966 |
image pixelAtX:imgX+x y:imgY+y put:idx-1. |
|
1967 |
image maskAtX:imgX+x y:imgY+y put:1. |
|
1968 |
] |
|
1969 |
] |
|
1970 |
]. |
|
1971 |
image restored. |
|
5618 | 1972 |
self redraw: (imageBox := (imagePoint * magnification extent: (ClipboardImage extent * magnification)) expandedBy: 1@1). |
2590
b811d560e00a
modified flag after edit operations
Claus Gittinger <cg@exept.de>
parents:
2589
diff
changeset
|
1973 |
self setModified. |
1888 | 1974 |
^ self. |
1975 |
]. |
|
5061 | 1976 |
self warn:(resources string:'Sorry: unimplemented function'). |
2135 | 1977 |
self undo. |
1978 |
^ self. |
|
1888 | 1979 |
]. |
2764 | 1980 |
anyColorAdded ifTrue:[ |
2490
62230519175a
slowly getting rid of the Colormap class
Claus Gittinger <cg@exept.de>
parents:
2489
diff
changeset
|
1981 |
image colorMap:(MappedPalette withColors:newColorMap). |
1246 | 1982 |
]. |
1983 |
]. |
|
1011
325d334e93c8
added paste-under (only paste where pixel ~= current selected)
Claus Gittinger <cg@exept.de>
parents:
1006
diff
changeset
|
1984 |
|
1246 | 1985 |
copiedImage := image class fromImage: copiedImage. |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
1986 |
(newColorMap isNil |
2135 | 1987 |
and:[modeSymbol isNil |
1987 | 1988 |
and:[copiedImage mask isNil] ]) ifTrue:[ |
5654 | 1989 |
"/ use image's copy functionality |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
1990 |
"/ however, this copies the mask as well, |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
1991 |
"/ which is not useful here |
1246 | 1992 |
image copyFrom: copiedImage x:0 y:0 toX: imagePoint x y: imagePoint y width: copiedImage width height: copiedImage height. |
1993 |
] ifFalse:[ |
|
1994 |
imgX := imagePoint x. |
|
1995 |
imgY := imagePoint y. |
|
1028
4dfe1c6cbc48
fixed paste-drag display (when scrolled)
Claus Gittinger <cg@exept.de>
parents:
1027
diff
changeset
|
1996 |
|
1246 | 1997 |
0 to:copiedImage height-1 do:[:y | |
1998 |
0 to:copiedImage width-1 do:[:x | |
|
1999 |
|wasMasked newMasked dstX dstY oldColor| |
|
1011
325d334e93c8
added paste-under (only paste where pixel ~= current selected)
Claus Gittinger <cg@exept.de>
parents:
1006
diff
changeset
|
2000 |
|
1246 | 2001 |
dstX := imgX + x. |
2002 |
dstY := imgY + y. |
|
2003 |
wasMasked := (image maskAtX:dstX y:dstY) == 0. |
|
2004 |
newMasked := (copiedImage maskAtX:x y:y) == 0. |
|
994
5727c2484ecd
bugs fixed in undo/mask and point painting/preview and pasting
tz
parents:
877
diff
changeset
|
2005 |
|
1246 | 2006 |
"/ with modeUnder, |
5654 | 2007 |
"/ only replace, if its masked, |
2008 |
((modeSymbol isNil or:[modeSymbol == #withMask]) |
|
2009 |
or:[wasMasked] |
|
2010 |
) ifTrue:[ |
|
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
2011 |
newMasked ifFalse:[ |
2764 | 2012 |
image colorAtX:dstX y:dstY put:(copiedImage colorAtX:x y:y). |
1823 | 2013 |
wasMasked ifTrue:[ |
5654 | 2014 |
"/ wasMasked before; no longer masked now |
2015 |
(modeSymbol == #withMask or:[modeSymbol == #under]) ifTrue:[ |
|
2016 |
image maskAtX:dstX y:dstY put:1 |
|
2017 |
]. |
|
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
2018 |
]. |
1823 | 2019 |
] ifTrue:[ |
2020 |
wasMasked ifFalse:[ |
|
5654 | 2021 |
"/ masked now; was not masked before |
2135 | 2022 |
modeSymbol == #withMask ifTrue:[ |
2023 |
image maskAtX:dstX y:dstY put:0 |
|
2024 |
] |
|
1823 | 2025 |
] |
2026 |
]. |
|
1987 | 2027 |
]. |
2028 |
||
1246 | 2029 |
] |
2030 |
]. |
|
2031 |
]. |
|
2032 |
image restored. |
|
5618 | 2033 |
self redraw: (imageBox := (imagePoint * magnification extent: (ClipboardImage extent * magnification)) expandedBy: 1@1). |
1028
4dfe1c6cbc48
fixed paste-drag display (when scrolled)
Claus Gittinger <cg@exept.de>
parents:
1027
diff
changeset
|
2034 |
"/ masterApplication imagePreView redraw: (imageBox expandedBy: 1). |
2590
b811d560e00a
modified flag after edit operations
Claus Gittinger <cg@exept.de>
parents:
2589
diff
changeset
|
2035 |
self setModified. |
1246 | 2036 |
] |
1028
4dfe1c6cbc48
fixed paste-drag display (when scrolled)
Claus Gittinger <cg@exept.de>
parents:
1027
diff
changeset
|
2037 |
] |
4dfe1c6cbc48
fixed paste-drag display (when scrolled)
Claus Gittinger <cg@exept.de>
parents:
1027
diff
changeset
|
2038 |
|
5654 | 2039 |
"Modified: / 07-12-2017 / 15:56:42 / cg" |
636 | 2040 |
! |
2041 |
||
2086 | 2042 |
shiftImageHorizontal:shiftH vertical:shiftV |
2489 | 2043 |
self shiftImageHorizontal:shiftH vertical:shiftV wrap:false |
2044 |
! |
|
2045 |
||
2046 |
shiftImageHorizontal:shiftH vertical:shiftV wrap:doWrap |
|
2047 |
"shift the pixels; |
|
2048 |
shift<0 is left-shift/up-shift; shift>0 is right-shift/down-shift; |
|
2049 |
doWrap controls if shifted-out pixels are to be shifted in at the opposite side. |
|
2050 |
i.e.: |
|
2051 |
0123456789 -> 3456789789 (shift: -3) 0123456789 -> 0120123456 (shift:3) |
|
2052 |
or, with wrap: |
|
2053 |
0123456789 -> 3456789012 (shift: -3) 0123456789 -> 7890123456 (shift:3) |
|
2054 |
" |
|
2055 |
||
2056 |
|newImage| |
|
2057 |
||
2058 |
newImage := self shifted:image horizontal:shiftH vertical:shiftV wrap:doWrap. |
|
2059 |
self image:newImage. |
|
2590
b811d560e00a
modified flag after edit operations
Claus Gittinger <cg@exept.de>
parents:
2589
diff
changeset
|
2060 |
self setModified. |
2489 | 2061 |
! |
2062 |
||
2063 |
shifted:image horizontal:shiftH vertical:shiftV wrap:doWrap |
|
2064 |
"shift the pixels; |
|
2065 |
shift<0 is left-shift/up-shift; shift>0 is right-shift/down-shift; |
|
2066 |
doWrap controls if shifted-out pixels are to be shifted in at the opposite side. |
|
2067 |
i.e.: |
|
2068 |
0123456789 -> 3456789789 (shift: -3) 0123456789 -> 0120123456 (shift:3) |
|
2069 |
or, with wrap: |
|
2070 |
0123456789 -> 3456789012 (shift: -3) 0123456789 -> 7890123456 (shift:3) |
|
2071 |
" |
|
2072 |
||
2086 | 2073 |
|w h srcX srcY dstX dstY newImage| |
2074 |
||
2489 | 2075 |
doWrap ifTrue:[ |
2076 |
"/ if wrapping, split into two operations to make wrap-code below simpler. |
|
2077 |
||
2078 |
shiftH ~~ 0 ifTrue:[ |
|
2079 |
shiftV ~~ 0 ifTrue:[ |
|
2080 |
newImage := self shifted:image horizontal:shiftH vertical:0 wrap:doWrap. |
|
2081 |
newImage := self shifted:newImage horizontal:0 vertical:shiftV wrap:doWrap. |
|
2082 |
^ newImage |
|
2083 |
]. |
|
2084 |
]. |
|
2085 |
]. |
|
2086 |
(shiftV == 0 and:[shiftH == 0]) ifTrue:[ |
|
2087 |
^ image |
|
2088 |
]. |
|
2089 |
||
2086 | 2090 |
w := image width. |
2091 |
h := image height. |
|
2092 |
||
2093 |
newImage := image copy. |
|
2094 |
||
2095 |
srcX := srcY := dstX := dstY := 0. |
|
2096 |
shiftH < 0 ifTrue:[ |
|
2097 |
srcX := shiftH negated |
|
2098 |
] ifFalse:[ |
|
2099 |
dstX := shiftH |
|
2100 |
]. |
|
2101 |
shiftV < 0 ifTrue:[ |
|
2102 |
srcY := shiftV negated |
|
2103 |
] ifFalse:[ |
|
2104 |
dstY := shiftV |
|
2105 |
]. |
|
2106 |
||
2107 |
newImage copyFrom:image x:srcX y:srcY toX:dstX y:dstY width:w-shiftH abs height:h-shiftV abs. |
|
2108 |
||
2489 | 2109 |
doWrap ifTrue:[ |
2110 |
srcX := srcY := dstX := dstY := 0. |
|
2111 |
||
2112 |
"/ already simplified - see above |
|
2113 |
shiftH ~~ 0 ifTrue:[ |
|
2114 |
"/ shiftV known to be 0 |
|
2115 |
shiftH < 0 ifTrue:[ |
|
2116 |
dstX := w-1-shiftH negated |
|
2117 |
] ifFalse:[ |
|
2118 |
srcX := w-1-shiftH |
|
2119 |
]. |
|
2120 |
w := shiftH abs. |
|
2121 |
] ifFalse:[ |
|
2122 |
"/ shiftH known to be 0 |
|
2123 |
shiftV < 0 ifTrue:[ |
|
2124 |
dstY := h-1-shiftV negated |
|
2125 |
] ifFalse:[ |
|
2126 |
srcY := h-1-shiftV |
|
2127 |
]. |
|
2128 |
h := shiftV abs. |
|
2129 |
]. |
|
2130 |
newImage copyFrom:image x:srcX y:srcY toX:dstX y:dstY width:w height:h. |
|
2131 |
^ newImage |
|
2132 |
]. |
|
2133 |
||
2134 |
^ newImage. |
|
2086 | 2135 |
|
2136 |
"Created: / 7.9.1998 / 13:00:16 / cg" |
|
2137 |
"Modified: / 7.9.1998 / 14:15:32 / cg" |
|
2138 |
! |
|
2139 |
||
5491 | 2140 |
specialOperation:operation on:imageBox withColor:clr |
5497 | 2141 |
"ask for and perform one of the special operations on the previously selected imageBox; |
5491 | 2142 |
then redraw as required" |
2143 |
||
2144 |
self invalidate. |
|
2145 |
self windowGroup processExposeEvents. |
|
2146 |
||
2147 |
operation isNil ifTrue:[^ false]. |
|
2148 |
||
2149 |
(self performSpecialOperation:operation on:imageBox withColor:self selectedColor) ifFalse:[ |
|
2150 |
^ false |
|
2151 |
]. |
|
2152 |
||
2153 |
image restored. |
|
2154 |
self invalidate. "/ : (choosedBox expandedBy: 1). |
|
2155 |
||
2156 |
"/ self redraw: (choosedBox expandedBy: 1). |
|
2157 |
||
2158 |
"/ "/ cg: what a kludge - please change to use a valueHolder, |
|
2159 |
"/ "/ which gets the information ... |
|
2160 |
"/ masterApplication imagePreView redraw: (imageBox expandedBy: 1). |
|
2161 |
||
2162 |
"/ cg: still a kludge - but less ugly |
|
2163 |
self changed:#subImageIn with:(imageBox expandedBy: 1). |
|
2164 |
self setModified. |
|
2165 |
^ true |
|
2166 |
||
2167 |
"Created: / 20-02-2017 / 17:35:33 / cg" |
|
5497 | 2168 |
"Modified (comment): / 22-02-2017 / 19:56:47 / cg" |
5491 | 2169 |
! |
2170 |
||
5485 | 2171 |
text:aString at:aPoint |
2172 |
"draw a character" |
|
2173 |
||
2174 |
|tempForm| |
|
2175 |
||
2176 |
tempForm := Form extent:(image extent) depth:1 onDevice:device. |
|
2177 |
tempForm clear. |
|
2178 |
tempForm paint:(Color colorId:1). |
|
2179 |
tempForm displayString:aString at:aPoint. |
|
2180 |
0 to:image extent x - 1 do:[:x | |
|
2181 |
0 to:image extent y - 1 do:[:y | |
|
2182 |
(tempForm valueAt:(x@y)) == 1 ifTrue:[ |
|
2183 |
self pointAt:(x@y) width:1 |
|
2184 |
]. |
|
2185 |
] |
|
2186 |
]. |
|
2187 |
||
2188 |
"Modified: / 15-02-2012 / 22:47:44 / cg" |
|
2189 |
! |
|
2190 |
||
2191 |
undo |
|
5499 | 2192 |
|newImage| |
2193 |
||
2194 |
undoImages notEmpty ifTrue:[ |
|
2195 |
newImage := undoImages removeLast. |
|
2196 |
] ifFalse:[ |
|
2197 |
(Dialog confirm:(resources string:'No more undo images remembered. Back to the initial image?')) |
|
2198 |
ifFalse:[^ self]. |
|
2199 |
newImage := originalImage copy |
|
2200 |
]. |
|
2201 |
||
2202 |
windowGroup withExecuteCursorDo:[ |
|
2203 |
|oldImage| |
|
2204 |
||
2205 |
oldImage := self image. |
|
2206 |
self clearModified. |
|
2207 |
self image:newImage scroll:(newImage extent ~= oldImage extent). |
|
5485 | 2208 |
] |
2209 |
||
5499 | 2210 |
"Modified: / 23-02-2017 / 15:47:15 / cg" |
5485 | 2211 |
! ! |
2212 |
||
2213 |
!ImageEditView methodsFor:'image editing-editmode button actions'! |
|
2214 |
||
2215 |
boxAt: aPoint |
|
2216 |
"called from button-press/button motion while in box-drawing mode: |
|
2217 |
drag a rectangular outline, |
|
2218 |
when released, draw a rectangle with the currently selected color" |
|
2219 |
||
2220 |
self |
|
2221 |
commonBoxOperation:[:box :colorOrPixel | |
|
5653 | 2222 |
colorOrPixel isColor ifTrue:[ |
5485 | 2223 |
image drawRectangle:box withColor:colorOrPixel. |
2224 |
] ifFalse:[ |
|
2225 |
image drawRectangle:box withValue:colorOrPixel. |
|
2226 |
]. |
|
2227 |
] |
|
2228 |
at:aPoint |
|
2229 |
||
5653 | 2230 |
"Modified: / 07-12-2017 / 14:52:17 / cg" |
5485 | 2231 |
! |
2232 |
||
2233 |
circleAt: aPoint |
|
2234 |
"called from button-press/button motion while in circle-drawing mode: |
|
2235 |
drag an ellipse, |
|
2236 |
when released, draw an ellipse with the currently selected color" |
|
2237 |
||
2238 |
self |
|
2239 |
commonBoxOperation:[:box :colorOrPixel | |
|
5653 | 2240 |
colorOrPixel isColor ifTrue:[ |
5506 | 2241 |
image drawEllipse:box withColor:colorOrPixel lineWidth:penWidth. |
5485 | 2242 |
] ifFalse:[ |
5506 | 2243 |
image drawEllipse:box withValue:colorOrPixel lineWidth:penWidth. |
5485 | 2244 |
]. |
2245 |
] |
|
2246 |
at:aPoint |
|
2247 |
||
5653 | 2248 |
"Modified: / 07-12-2017 / 14:53:34 / cg" |
5485 | 2249 |
! |
2250 |
||
2251 |
commonBoxOperation:action at:aPoint |
|
2252 |
"common code for filling/drawing." |
|
2253 |
||
2254 |
|choosenBox imageBox clr pix| |
|
2255 |
||
2256 |
(clr := self selectedColor) notNil ifTrue:[ |
|
2257 |
choosenBox := self dragRectangleStartingAt: aPoint emphasis: #box. |
|
2258 |
choosenBox notNil ifTrue:[ |
|
2259 |
imageBox := choosenBox origin//magnification extent: (choosenBox extent//magnification). |
|
2260 |
(clr := self drawingColorOrNil) notNil ifTrue:[ |
|
2261 |
action value:imageBox value:clr. |
|
2262 |
] ifFalse:[ |
|
5653 | 2263 |
pix := self drawingPixelOrNil. |
2264 |
true "pix notNil" ifTrue:[ "/ nil is valid here, and means: masked |
|
5485 | 2265 |
action value:imageBox value:pix. |
2266 |
]. |
|
2267 |
]. |
|
2268 |
image restored. |
|
2269 |
self redraw: (choosenBox expandedBy: 1). |
|
2270 |
||
2271 |
"/ cg: still a kludge - but less ugly |
|
2272 |
self changed:#subImageIn with:(imageBox expandedBy: 1). |
|
2273 |
||
2274 |
self setModified. |
|
2275 |
]. |
|
2276 |
]. |
|
2277 |
||
2278 |
"Created: / 16-02-2017 / 11:20:49 / cg" |
|
5653 | 2279 |
"Modified: / 07-12-2017 / 14:51:37 / cg" |
5485 | 2280 |
! |
2281 |
||
2282 |
copyAt: aPoint |
|
2283 |
"called from button-press/button motion while in copy-drawing mode: |
|
2284 |
drag a filled box, |
|
2285 |
when released, copy the selected rectangle to the clipboard" |
|
2286 |
||
2287 |
|choosenBox box copiedImage| |
|
2288 |
||
2289 |
choosenBox := self dragRectangleStartingAt: aPoint emphasis: #inverseFilledBox. |
|
2290 |
choosenBox notNil ifTrue:[ |
|
2291 |
box := choosenBox origin // magnification extent: (choosenBox extent // magnification). |
|
2292 |
copiedImage := image subImageIn: box. |
|
2293 |
||
2294 |
self class copyImageToClipboard:copiedImage. |
|
2295 |
||
2296 |
self redraw:(choosenBox expandedBy:1) |
|
2297 |
] |
|
2298 |
||
2299 |
"Modified: / 21-08-1998 / 20:16:41 / cg" |
|
2300 |
"Modified (comment): / 16-02-2017 / 11:15:09 / cg" |
|
2301 |
! |
|
2302 |
||
5491 | 2303 |
cropSubImageAt: aPoint |
2304 |
"called from button-press/button motion while in crop-subImage mode: |
|
2305 |
drag a filled box, |
|
2306 |
when released, change the image to the new bounds" |
|
2307 |
||
2308 |
|choosenBox imageBox| |
|
2309 |
||
2310 |
choosenBox := self dragRectangleStartingAt: aPoint emphasis: #inverseFilledBox. |
|
2311 |
choosenBox notNil ifTrue:[ |
|
2312 |
imageBox := choosenBox origin//magnification extent: (choosenBox extent//magnification). |
|
2313 |
self specialOperation:#editSubImage on:imageBox withColor:nil. |
|
2314 |
] |
|
2315 |
||
2316 |
"Created: / 20-02-2017 / 17:27:50 / cg" |
|
2317 |
! |
|
2318 |
||
5485 | 2319 |
fillAt: aPoint |
2320 |
"called from button-press motion while in floo-fill drawing mode: |
|
2321 |
perform a flood-fill with the currently selected color" |
|
2322 |
||
2323 |
windowGroup withExecuteCursorDo:[ |
|
2324 |
|filledPoints clr| |
|
2325 |
||
2326 |
(clr := self selectedColor) notNil ifTrue:[ |
|
2327 |
self updateActivity:'Flood filling - press CTRL-y to abort ...'. |
|
2328 |
[ |
|
2329 |
|pix| |
|
2330 |
||
2331 |
(clr := self drawingColorOrNil) notNil ifTrue:[ |
|
2332 |
pix := image valueFromColor:clr. |
|
2333 |
] ifFalse:[ |
|
2334 |
pix := self drawingPixelOrNil. |
|
2335 |
]. |
|
2336 |
image floodFillAt:aPoint//magnification withValue:pix |
|
2337 |
maxDeviationInLight:floodFillMaxLightError |
|
2338 |
maxDeviationInHue:floodFillMaxHueError. |
|
2339 |
||
2340 |
image restored. |
|
2341 |
||
2342 |
self invalidate. |
|
2343 |
self changed:#subImageIn with:(image bounds). |
|
2344 |
||
2345 |
self setModified. |
|
2346 |
] ifCurtailed:[ |
|
2347 |
self updateActivity:'Flood fill aborted.' |
|
2348 |
]. |
|
2349 |
]. |
|
2350 |
self updateActivity:'' |
|
2351 |
] |
|
2352 |
||
2353 |
"Modified: / 17-02-2017 / 15:30:38 / cg" |
|
2354 |
! |
|
2355 |
||
2356 |
filledBoxAt: aPoint |
|
2357 |
"called from button-press/button motion while in filled rectangle-drawing mode: |
|
2358 |
drag a filled box, |
|
2359 |
when released, fill a rectangular area with the currently selected color" |
|
2360 |
||
2361 |
self |
|
2362 |
commonBoxOperation:[:box :colorOrPixel | |
|
5594 | 2363 |
image fillRectangle:box with:colorOrPixel. |
5485 | 2364 |
] |
2365 |
at:aPoint |
|
2366 |
||
5594 | 2367 |
"Modified: / 05-09-2017 / 14:50:51 / cg" |
5485 | 2368 |
! |
2369 |
||
2370 |
filledCircleAt: aPoint |
|
2371 |
"called from button-press/button motion while in filled circle-drawing mode: |
|
2372 |
drag a filled ellipse, |
|
2373 |
when released, fill an ellipse with the currently selected color" |
|
2374 |
||
2375 |
self |
|
2376 |
commonBoxOperation:[:box :colorOrPixel | |
|
5653 | 2377 |
colorOrPixel isColor ifTrue:[ |
5485 | 2378 |
image fillEllipse:box withColor:colorOrPixel. |
2379 |
] ifFalse:[ |
|
2380 |
image fillEllipse:box withValue:colorOrPixel. |
|
2381 |
]. |
|
2382 |
] |
|
2383 |
at:aPoint |
|
2384 |
||
2385 |
"Created: / 16-02-2017 / 11:10:17 / cg" |
|
5653 | 2386 |
"Modified: / 07-12-2017 / 14:53:59 / cg" |
5485 | 2387 |
! |
2388 |
||
2389 |
maskOutsideCircleAt: aPoint |
|
2390 |
"called from button-press/button motion while in filled rectangle-drawing mode: |
|
2391 |
drag a box, |
|
2392 |
when released, mask everything outside the rectangular area" |
|
2393 |
||
2394 |
self |
|
2395 |
commonBoxOperation:[:box :colorOrPixel | |
|
2396 |
|newForm oldForm| |
|
2397 |
||
2398 |
newForm := Form extent:image extent depth:1 onDevice:Screen current. |
|
2399 |
newForm paint:(Color colorId:0). |
|
2400 |
newForm fillRectangle:(newForm bounds). |
|
2401 |
newForm paint:(Color colorId:1). |
|
2402 |
newForm fillCircleIn:box. |
|
2403 |
oldForm := image mask asFormOn:Screen current. |
|
2404 |
newForm function:#and. |
|
2405 |
newForm paint:(Color colorId:1) on:(Color colorId:0). |
|
2406 |
newForm copyFrom:oldForm x:0 y:0 toX:0 y:0 width:image width height:image height. |
|
2407 |
image mask:(ImageMask fromForm:newForm). |
|
2408 |
||
2409 |
"/ wrong: does not preserve already masked pixels... |
|
2410 |
"/ image mask fillRectangle:(image bounds) withValue:0. |
|
2411 |
"/ image mask fillEllipse:box withValue:1. |
|
2412 |
] |
|
2413 |
at:aPoint. |
|
2414 |
||
2415 |
image restored. |
|
2416 |
self invalidate. |
|
2417 |
||
2418 |
"Created: / 16-02-2017 / 12:33:25 / cg" |
|
2419 |
"Modified: / 17-02-2017 / 16:47:47 / cg" |
|
2420 |
! |
|
2421 |
||
2422 |
maskOutsideRectAt: aPoint |
|
2423 |
"called from button-press/button motion while in filled rectangle-drawing mode: |
|
2424 |
drag a box, |
|
2425 |
when released, mask everything outside the rectangular area" |
|
2426 |
||
2427 |
self |
|
2428 |
commonBoxOperation:[:box :colorOrPixel | |
|
2429 |
|newForm oldForm| |
|
2430 |
||
2431 |
newForm := Form extent:image extent depth:1 onDevice:Screen current. |
|
2432 |
newForm paint:(Color colorId:0). |
|
2433 |
newForm fillRectangle:(newForm bounds). |
|
2434 |
newForm paint:(Color colorId:1). |
|
2435 |
newForm fillRectangle:box. |
|
2436 |
oldForm := image mask asFormOn:Screen current. |
|
2437 |
newForm function:#and. |
|
2438 |
newForm paint:(Color colorId:1) on:(Color colorId:0). |
|
2439 |
newForm copyFrom:oldForm x:0 y:0 toX:0 y:0 width:image width height:image height. |
|
2440 |
image mask:(ImageMask fromForm:newForm). |
|
2441 |
||
2442 |
"/ wrong: does not preserve already masked pixels... |
|
2443 |
"/image mask fillRectangle:(image bounds) withValue:0. |
|
2444 |
"/image mask fillRectangle:box withValue:1. |
|
2445 |
] |
|
2446 |
at:aPoint. |
|
2447 |
||
2448 |
image restored. |
|
2449 |
self invalidate. |
|
2450 |
||
2451 |
"Created: / 16-02-2017 / 12:33:06 / cg" |
|
2452 |
"Modified: / 17-02-2017 / 17:23:57 / cg" |
|
2453 |
! |
|
2454 |
||
2455 |
pasteAt: aPoint |
|
2456 |
"called from button-press/button motion while in paste mode: |
|
2457 |
paste the image in the clipboard at aPoint" |
|
2458 |
||
2459 |
self pasteAt:aPoint mode:nil. |
|
2460 |
||
2461 |
"Modified (comment): / 16-02-2017 / 11:13:54 / cg" |
|
2462 |
! |
|
2463 |
||
2464 |
pasteUnderAt: aPoint |
|
2465 |
"called from button-press/button motion while in paste mode: |
|
2466 |
pasteUnder the image in the clipboard at aPoint. |
|
2467 |
In this mode, only pixels which are not equal to |
|
2468 |
the current color or masked are pasted." |
|
2469 |
||
2470 |
self pasteAt:aPoint mode:#under. |
|
2471 |
||
2472 |
"Modified (comment): / 16-02-2017 / 11:14:04 / cg" |
|
2473 |
! |
|
2474 |
||
2475 |
pasteWithMaskAt: aPoint |
|
2476 |
"called from button-press/button motion while in paste mode: |
|
2477 |
paste the image in the clipboard at aPoint. |
|
2478 |
In this mode, both the mask and the image pixel are pasted" |
|
2479 |
||
2480 |
||
2481 |
self pasteAt:aPoint mode:#withMask. |
|
2482 |
||
2483 |
"Modified (comment): / 16-02-2017 / 11:14:08 / cg" |
|
2484 |
! |
|
2485 |
||
2486 |
pointAt:aPoint |
|
2487 |
"called from button-press/button motion while in point-drawing mode: |
|
2488 |
draw a single pixel with the currently selected color" |
|
2489 |
||
5652 | 2490 |
self pointAt:aPoint width:(self penWidth). |
5485 | 2491 |
|
2492 |
"Modified: / 15-02-2012 / 22:47:30 / cg" |
|
5652 | 2493 |
"Modified (format): / 07-12-2017 / 14:46:17 / cg" |
5485 | 2494 |
! |
2495 |
||
5604 | 2496 |
pointAt:aPoint width:pw |
2497 |
"called from button-press/button motion while in point-drawing mode: |
|
2498 |
draw a single pixel (or dot of width pw) with the currently selected color" |
|
2499 |
||
2500 |
|draw imagePoint clr pix oldColor newColor| |
|
2501 |
||
2502 |
imagePoint := aPoint // magnification. |
|
2503 |
(imagePoint x between:0 and:image width-1) ifFalse:[^ self]. |
|
2504 |
(imagePoint y between:0 and:image height-1) ifFalse:[^ self]. |
|
2505 |
||
2506 |
draw := |
|
2507 |
[:point | |
|
2508 |
(clr := self drawingColorOrNil) notNil ifTrue:[ |
|
2509 |
clr isPseudoColor ifTrue:[ |
|
2510 |
"/ only set the alpha value |
|
2511 |
newColor := (image colorAt:point) alpha:clr alpha. |
|
2512 |
] ifFalse:[ |
|
2513 |
newColor := clr. |
|
2514 |
"/ clr alpha = 1 ifTrue:[ |
|
2515 |
"/ newColor := clr. |
|
2516 |
"/ ] ifFalse:[ |
|
2517 |
"/ clr alpha = 0 ifTrue:[ |
|
2518 |
"/ newColor := clr. |
|
2519 |
"/ ] ifFalse:[ |
|
2520 |
"/ oldColor := image colorAt:point. |
|
2521 |
"/ newColor := clr alphaMixed:clr alpha with:oldColor. |
|
2522 |
"/ ]. |
|
2523 |
"/ ]. |
|
2524 |
]. |
|
2525 |
image atImageAndMask:point put:newColor |
|
2526 |
] ifFalse:[ |
|
5652 | 2527 |
pix := self drawingPixelOrNil. "/ nil is valid here, and means: masked |
2528 |
image atImageAndMask:point putValue:pix. |
|
5604 | 2529 |
]. |
2530 |
self invalidate:((point * magnification extent: magnification) expandedBy:1). |
|
2531 |
]. |
|
2532 |
||
2533 |
draw value:imagePoint. |
|
2534 |
||
2535 |
pw > 1 ifTrue:[ |
|
2536 |
"/ draw with a wide pen |
|
2537 |
(pw//2) negated to:(pw-(pw//2)-1) do:[:xOffs | |
|
2538 |
(pw//2) negated to:(pw-(pw//2)-1) do:[:yOffs | |
|
2539 |
imagePoint x + xOffs >= 0 ifTrue:[ |
|
2540 |
imagePoint y + yOffs >= 0 ifTrue:[ |
|
2541 |
draw value:(imagePoint + (xOffs@yOffs)). |
|
2542 |
]. |
|
2543 |
]. |
|
2544 |
]. |
|
2545 |
]. |
|
2546 |
]. |
|
2547 |
self setModified. |
|
2548 |
||
2549 |
"Created: / 15-02-2012 / 22:47:08 / cg" |
|
5652 | 2550 |
"Modified: / 07-12-2017 / 14:49:48 / cg" |
5604 | 2551 |
! |
2552 |
||
4715 | 2553 |
smoothAt:aPoint |
5480 | 2554 |
"called from button-press/button motion while in smoothing mode: |
2555 |
smoth (average) a single pixel with pixels around" |
|
4715 | 2556 |
|
2557 |
|draw imagePoint x y w h| |
|
2558 |
||
2559 |
imagePoint := aPoint // magnification. |
|
2560 |
w := image width. |
|
2561 |
h := image height. |
|
2562 |
((x := imagePoint x) between:0 and:w-1) ifFalse:[^ self]. |
|
2563 |
((y := imagePoint y) between:0 and:h-1) ifFalse:[^ self]. |
|
2564 |
||
2565 |
draw := |
|
2566 |
[:point | |
|
2567 |
|sumRed sumGreen sumBlue newClr| |
|
2568 |
||
2569 |
sumRed := sumGreen := sumBlue := 0. |
|
2570 |
-1 to:1 do:[:dx | |
|
2571 |
-1 to:1 do:[:dy | |
|
2572 |
|clr| |
|
2573 |
||
2574 |
((x + dx) between:0 and:w-1) ifTrue:[ |
|
2575 |
((y + dy) between:0 and:h-1) ifTrue:[ |
|
2576 |
clr := image colorAtX:(x + dx) y:(y + dy). |
|
2577 |
sumRed := sumRed + clr redByte. |
|
2578 |
sumGreen := sumGreen + clr greenByte. |
|
2579 |
sumBlue := sumBlue + clr blueByte. |
|
2580 |
] |
|
2581 |
]. |
|
2582 |
] |
|
2583 |
]. |
|
2584 |
newClr := Color |
|
2585 |
redByte:(sumRed / 9) rounded |
|
2586 |
greenByte:(sumGreen / 9) rounded |
|
2587 |
blueByte:(sumBlue / 9) rounded. |
|
5480 | 2588 |
|
4715 | 2589 |
image colorMap isNil ifTrue:[ |
5480 | 2590 |
"/ Transcript |
2591 |
"/ show:(image colorAt:point); |
|
2592 |
"/ show:' -> '; |
|
2593 |
"/ showCR:newClr. |
|
4715 | 2594 |
image atImageAndMask:point put:newClr. |
2595 |
] ifFalse:[ |
|
2596 |
image atImageAndMask:point put:(image colorMap colorNearestTo:newClr). |
|
2597 |
]. |
|
2598 |
self invalidate:((point * magnification extent: magnification) expandedBy:1). |
|
2599 |
]. |
|
2600 |
||
2601 |
draw value:imagePoint. |
|
2602 |
self setModified. |
|
5480 | 2603 |
|
2604 |
"Modified: / 16-02-2017 / 12:34:41 / cg" |
|
4715 | 2605 |
! |
2606 |
||
1858 | 2607 |
specialOperationAt: aPoint |
2608 |
"special operation on a rectangular area" |
|
2609 |
||
5491 | 2610 |
|choosenBox operation imageBox| |
2838
8525a35121d2
changeHLS fixed dfor depth24-images;
Claus Gittinger <cg@exept.de>
parents:
2824
diff
changeset
|
2611 |
|
5413 | 2612 |
choosenBox := self dragRectangleStartingAt: aPoint emphasis:#inverseFilledBox. |
2838
8525a35121d2
changeHLS fixed dfor depth24-images;
Claus Gittinger <cg@exept.de>
parents:
2824
diff
changeset
|
2613 |
choosenBox isNil ifTrue:[ ^ self ]. |
8525a35121d2
changeHLS fixed dfor depth24-images;
Claus Gittinger <cg@exept.de>
parents:
2824
diff
changeset
|
2614 |
|
5491 | 2615 |
operation := self askForSpecialOperation. |
2616 |
operation isNil ifTrue:[^ self]. |
|
2617 |
||
2838
8525a35121d2
changeHLS fixed dfor depth24-images;
Claus Gittinger <cg@exept.de>
parents:
2824
diff
changeset
|
2618 |
imageBox := choosenBox origin//magnification extent: (choosenBox extent//magnification). |
5491 | 2619 |
self specialOperation:operation on:imageBox withColor:self selectedColor. |
2620 |
||
2621 |
"Modified: / 20-02-2017 / 17:38:32 / cg" |
|
1858 | 2622 |
! |
2623 |
||
3476 | 2624 |
sprayAt: aPoint |
5480 | 2625 |
"called from button-press/button motion while in spray mode: |
2626 |
start spraying with the currently selected color" |
|
3476 | 2627 |
|
2628 |
|clr| |
|
2629 |
||
2630 |
(clr := self selectedColor) notNil ifTrue:[ |
|
2631 |
sprayPosition := aPoint. |
|
2632 |
self startSpray. |
|
2633 |
]. |
|
5480 | 2634 |
|
2635 |
"Modified (comment): / 16-02-2017 / 11:12:28 / cg" |
|
627 | 2636 |
! ! |
2637 |
||
2839 | 2638 |
!ImageEditView methodsFor:'image manipulation'! |
2639 |
||
2640 |
brightenImage |
|
5589 | 2641 |
"make the image brighter" |
2642 |
||
2643 |
image photometric == #palette ifTrue:[ |
|
2644 |
self makeNewColorMapByMapping:[:clr | clr lightened]. |
|
2645 |
] ifFalse:[ |
|
2646 |
self newImageWithUndo: (image copy lightened). |
|
2647 |
]. |
|
2648 |
||
2649 |
"Modified: / 31-08-2017 / 12:09:39 / cg" |
|
2839 | 2650 |
! |
2651 |
||
2652 |
darkenImage |
|
5589 | 2653 |
"make the image darker" |
2654 |
||
2655 |
image photometric == #palette ifTrue:[ |
|
2656 |
self makeNewColorMapByMapping:[:clr | clr darkened]. |
|
2657 |
] ifFalse:[ |
|
2658 |
self newImageWithUndo: (image copy darkened). |
|
2659 |
]. |
|
2660 |
||
2661 |
"Modified: / 31-08-2017 / 12:09:23 / cg" |
|
2839 | 2662 |
! |
2663 |
||
2664 |
flipHorizontal |
|
2665 |
||
5589 | 2666 |
self newImageWithUndo:(image copy flipHorizontal). |
2667 |
||
2668 |
"Modified (format): / 31-08-2017 / 12:13:03 / cg" |
|
2839 | 2669 |
! |
2670 |
||
2671 |
flipVertical |
|
5589 | 2672 |
self newImageWithUndo:(image copy flipVertical). |
2673 |
||
2674 |
"Modified: / 31-08-2017 / 12:13:11 / cg" |
|
2839 | 2675 |
! |
2676 |
||
2677 |
makeBorderedImageX:newX y:newY width:newWidth height:newHeight |
|
2678 |
|newImage oldWidth oldHeight| |
|
2679 |
||
2680 |
oldWidth := image width. |
|
2681 |
oldHeight := image height. |
|
2682 |
||
2683 |
newImage := image class width:newWidth height:newHeight depth:image depth. |
|
2684 |
newImage photometric:image photometric. |
|
2685 |
newImage colorMap:image colorMap copy. |
|
2686 |
newImage bits:(ByteArray new:(newImage bytesPerRow * newHeight)). |
|
2687 |
||
2842 | 2688 |
image mask notNil ifTrue:[ |
2839 | 2689 |
|newMaskImage| |
2690 |
||
2691 |
newMaskImage := Depth1Image width:newWidth height:newHeight. |
|
2692 |
newMaskImage photometric: image mask photometric. |
|
2693 |
newMaskImage colorMap: image mask colorMap copy. |
|
2694 |
newMaskImage bits:(ByteArray new: newMaskImage bytesPerRow * newHeight). |
|
2695 |
newImage mask: newMaskImage |
|
2696 |
]. |
|
2697 |
||
2698 |
newImage copyFrom:image x:0 y:0 toX:newX y:newY width:oldWidth height:oldHeight. |
|
4730 | 2699 |
self newImageWithUndo:newImage. |
2839 | 2700 |
|
2701 |
"Created: / 7.9.1998 / 13:00:16 / cg" |
|
2702 |
"Modified: / 7.9.1998 / 14:15:32 / cg" |
|
2703 |
! |
|
2704 |
||
2705 |
makeBrighter |
|
5589 | 2706 |
"make the image brighter (obsolete, backward compatible entry)" |
2707 |
||
2708 |
self brightenImage |
|
2709 |
||
2710 |
"Modified: / 31-08-2017 / 12:12:38 / cg" |
|
2839 | 2711 |
! |
2712 |
||
2713 |
makeDarker |
|
5589 | 2714 |
"make the image darker (obsolete, backward compatible entry)" |
2715 |
||
2716 |
self darkenImage |
|
2717 |
||
2718 |
"Modified: / 31-08-2017 / 12:12:41 / cg" |
|
2839 | 2719 |
! |
2720 |
||
2841 | 2721 |
makeGrayScaleImage |
5589 | 2722 |
self makeNewColorMapByMapping: |
4730 | 2723 |
[:clr | Color brightness:(clr brightness)]. |
5589 | 2724 |
|
2725 |
"Modified: / 31-08-2017 / 12:12:30 / cg" |
|
2839 | 2726 |
! |
2727 |
||
2728 |
makeInverse |
|
5589 | 2729 |
self makeNewColorMapByMapping: |
4730 | 2730 |
[:clr | |
5589 | 2731 |
Color |
2732 |
redByte:(255-clr redByte) |
|
2733 |
greenByte:(255-clr greenByte) |
|
2734 |
blueByte:(255-clr blueByte) |
|
4730 | 2735 |
]. |
5589 | 2736 |
|
2737 |
"Modified: / 31-08-2017 / 12:47:20 / cg" |
|
2738 |
! |
|
2739 |
||
2740 |
makeInvertedBits |
|
2741 |
"invert the pixels |
|
2742 |
for palette images, this will lead to funny results; |
|
2743 |
for all others, this makes it a negative" |
|
2744 |
||
2745 |
|newImage| |
|
2746 |
||
2747 |
newImage := image copy. |
|
2748 |
newImage bits invert. |
|
2749 |
self newImageWithUndo:newImage. |
|
2750 |
||
2751 |
"Created: / 31-08-2017 / 12:48:33 / cg" |
|
2752 |
"Modified (comment): / 31-08-2017 / 14:02:28 / cg" |
|
2753 |
! |
|
2754 |
||
2755 |
makeNegative |
|
2756 |
"make a real negative. |
|
2757 |
For non-palette images, this is done by inverting the pixels; |
|
2758 |
for palette images, we need new colors." |
|
2759 |
||
2760 |
image photometric ~~ #palette ifTrue:[ |
|
2761 |
self makeInvertedBits. |
|
2762 |
^ self. |
|
2763 |
]. |
|
2764 |
||
2765 |
self makeNewColorMapByMapping: |
|
2766 |
[:clr | |
|
2767 |
Color |
|
2768 |
redByte:(255-clr redByte) |
|
2769 |
greenByte:(255-clr greenByte) |
|
2770 |
blueByte:(255-clr blueByte) |
|
2771 |
]. |
|
2772 |
||
2773 |
"Created: / 31-08-2017 / 13:50:39 / cg" |
|
2839 | 2774 |
! |
2775 |
||
3971 | 2776 |
makeSlightlyBrighter |
5589 | 2777 |
self makeNewColorMapByMapping: |
4730 | 2778 |
[:clr | |
2779 |
clr brightness > Color lightGray brightness |
|
5163 | 2780 |
ifTrue:[ clr blendWith:self whiteColor ] |
4730 | 2781 |
ifFalse:[ clr blendWith:Color lightGray ] |
2782 |
]. |
|
3971 | 2783 |
|
2784 |
"Created: / 24-11-2010 / 11:08:18 / cg" |
|
5589 | 2785 |
"Modified: / 31-08-2017 / 12:11:34 / cg" |
3971 | 2786 |
! |
2787 |
||
2788 |
makeSlightlyDarker |
|
5589 | 2789 |
self makeNewColorMapByMapping: |
4730 | 2790 |
[:clr | |
2791 |
clr brightness < Color darkGray brightness |
|
2792 |
ifTrue:[ clr blendWith:Color black ] |
|
2793 |
ifFalse:[ clr blendWith:Color darkGray ] |
|
2794 |
]. |
|
3971 | 2795 |
|
2796 |
"Created: / 24-11-2010 / 11:08:08 / cg" |
|
5589 | 2797 |
"Modified: / 31-08-2017 / 12:11:39 / cg" |
3971 | 2798 |
! |
2799 |
||
4730 | 2800 |
newImageWithUndo:newImage |
5589 | 2801 |
"undoable set a new image (after processing)" |
2802 |
||
2839 | 2803 |
self makeUndo. |
4730 | 2804 |
self image: newImage. |
2839 | 2805 |
self setModified. |
5589 | 2806 |
|
2807 |
"Modified (comment): / 31-08-2017 / 12:09:11 / cg" |
|
2839 | 2808 |
! |
2809 |
||
5491 | 2810 |
performSpecialOperation:operation on:imageBox withColor:clr |
2811 |
"actually perform one of the special operations on the previously selected imageBox" |
|
2812 |
||
2813 |
|x0 y0 x1 y1 pixelAction requiredColors missingColors answer hue| |
|
2814 |
||
2815 |
x0 := imageBox left. |
|
2816 |
y0 := imageBox top. |
|
2817 |
x1 := imageBox right - 1. |
|
2818 |
y1 := imageBox bottom -1 . |
|
2819 |
||
2820 |
operation == #edit ifTrue:[ |
|
2821 |
(self image subImageIn:imageBox) edit. |
|
2822 |
^ false. |
|
2823 |
]. |
|
2824 |
operation == #editSubImage ifTrue:[ |
|
2825 |
self makeUndo. |
|
2826 |
self image:(self image subImageIn:imageBox). |
|
2827 |
^ false. |
|
2828 |
]. |
|
2829 |
operation == #flipVertical ifTrue:[ |
|
2830 |
self flipSubImage:#vertical in:imageBox. |
|
2831 |
^ true. |
|
2832 |
]. |
|
2833 |
operation == #flipHorizontal ifTrue:[ |
|
2834 |
self flipSubImage:#horizontal in:imageBox. |
|
2835 |
^ true. |
|
2836 |
]. |
|
5497 | 2837 |
operation == #autoGradientFillVertical ifTrue:[ |
2838 |
self gradientFillIn:imageBox orientation:#vertical auto:true. |
|
2839 |
^ true. |
|
2840 |
]. |
|
2841 |
operation == #autoGradientFillHorizontal ifTrue:[ |
|
2842 |
self gradientFillIn:imageBox orientation:#horizontal auto:true. |
|
2843 |
^ true. |
|
2844 |
]. |
|
2845 |
operation == #autoGradientFillDiagonal ifTrue:[ |
|
2846 |
self gradientFillIn:imageBox orientation:#diagonal auto:true. |
|
2847 |
^ true. |
|
2848 |
]. |
|
2849 |
operation == #gradientFillVertical ifTrue:[ |
|
2850 |
self gradientFillIn:imageBox orientation:#vertical auto:false. |
|
2851 |
^ true. |
|
2852 |
]. |
|
2853 |
operation == #gradientFillHorizontal ifTrue:[ |
|
2854 |
self gradientFillIn:imageBox orientation:#horizontal auto:false. |
|
2855 |
^ true. |
|
2856 |
]. |
|
2857 |
operation == #gradientFillDiagonal ifTrue:[ |
|
2858 |
self gradientFillIn:imageBox orientation:#diagonal auto:false. |
|
2859 |
^ true. |
|
2860 |
]. |
|
5491 | 2861 |
|
2862 |
operation == #slightlyBrightened ifTrue:[ |
|
2863 |
pixelAction := [:x :y :clr | clr slightlyLightened]. |
|
2864 |
]. |
|
2865 |
operation == #slightlyDarkened ifTrue:[ |
|
2866 |
pixelAction := [:x :y :clr | clr slightlyDarkened]. |
|
2867 |
]. |
|
2868 |
operation == #brightened ifTrue:[ |
|
2869 |
pixelAction := [:x :y :clr | clr lightened]. |
|
2870 |
]. |
|
2871 |
operation == #darkened ifTrue:[ |
|
2872 |
pixelAction := [:x :y :clr | clr darkened]. |
|
2873 |
]. |
|
2874 |
operation == #reversed ifTrue:[ |
|
2875 |
pixelAction := [:x :y :clr | Color red:(100-clr red) green:(100-clr green) blue:(100-clr blue) ]. |
|
2876 |
]. |
|
2877 |
operation == #makeGrey ifTrue:[ |
|
2878 |
pixelAction := [:x :y :clr | Color grey:(clr greyIntensity)]. |
|
2879 |
]. |
|
2880 |
operation == #greyed ifTrue:[ |
|
2881 |
pixelAction := [:x :y :clr | clr blendWith:Color gray]. |
|
2882 |
]. |
|
2883 |
operation == #greyPattern ifTrue:[ |
|
2884 |
pixelAction := [:x :y :clr | x odd == y even |
|
2885 |
ifTrue:[Color gray] |
|
2886 |
ifFalse:[clr]]. |
|
2887 |
]. |
|
2888 |
operation == #unmaskedGreyPattern ifTrue:[ |
|
2889 |
pixelAction := [:x :y :clr | x odd == y even |
|
2890 |
ifTrue:[self image maskAtX:x y:y put:1. Color gray] |
|
2891 |
ifFalse:[clr]]. |
|
2892 |
]. |
|
2893 |
||
2894 |
operation == #changeHue ifTrue:[ |
|
2895 |
hue := Dialog request:'Hue (0..360)\red->yellow->green->blue->red' withCRs. |
|
2896 |
hue := Number readFrom:hue onError:nil. |
|
2897 |
hue isNil ifTrue:[^ false]. |
|
2898 |
pixelAction := [:x :y :clr | Color hue:(hue+(clr hue?0)) light:clr light saturation:clr saturation]. |
|
2899 |
]. |
|
2900 |
operation == #colorize ifTrue:[ |
|
2901 |
hue := Dialog request:'Hue (0..360)\red->yellow->green->blue->red' withCRs. |
|
2902 |
hue := Number readFrom:hue onError:nil. |
|
2903 |
hue isNil ifTrue:[^ false]. |
|
2904 |
pixelAction := [:x :y :clr | Color hue:hue light:clr light saturation:100] |
|
2905 |
]. |
|
2906 |
||
2907 |
pixelAction isNil ifTrue:[ |
|
5497 | 2908 |
Dialog warn:(resources string:'Sorry - unimplemented pixelAction: ',operation asString). |
5491 | 2909 |
^ false |
2910 |
]. |
|
2911 |
||
2912 |
image colorMap notNil ifTrue:[ |
|
2913 |
"/ compute required colors ... |
|
2914 |
requiredColors := Set new. |
|
2915 |
self image |
|
2916 |
colorsFromX:x0 y:y0 toX:x1 y:y1 |
|
2917 |
do:[:x :y :clr | |
|
2918 |
requiredColors add:(pixelAction value:x value:y value:clr) |
|
2919 |
]. |
|
2920 |
||
2921 |
missingColors := requiredColors reject:[:clr | (image colorMap includes:clr)]. |
|
2922 |
||
2923 |
missingColors notEmpty ifTrue:[ |
|
2924 |
answer := Dialog |
|
2925 |
confirmWithCancel:(resources stringWithCRs:'Some color(s) cannot be represented in the images colorMap.\Use nearest or compute colorMap ?') |
|
2926 |
labels:#( 'Cancel' 'Add to ColorMap' 'Use Nearest') |
|
2927 |
values:#( nil add nearest) |
|
2928 |
default:3. |
|
2929 |
answer isNil ifTrue:[^ false]. |
|
2930 |
answer == #add ifTrue:[ |
|
2931 |
missingColors size + image colorMap size > (2 raisedTo:image depth) ifTrue:[ |
|
2932 |
self warn:(resources string:'Missing colors cannot be added to images colormap.'). |
|
2933 |
^ false |
|
2934 |
]. |
|
2935 |
missingColors do:[:eachColor | |
|
2936 |
image colorMap add:eachColor |
|
2937 |
]. |
|
2938 |
answer := #nearest. |
|
2939 |
]. |
|
2940 |
]. |
|
2941 |
]. |
|
2942 |
||
2943 |
"/ now, do it |
|
2944 |
self image |
|
2945 |
colorsFromX:x0 y:y0 toX:x1 y:y1 |
|
2946 |
do:[:x :y :clr | |
|
2947 |
|newClr| |
|
2948 |
||
2949 |
newClr := pixelAction value:x value:y value:clr. |
|
2950 |
answer == #nearest ifTrue:[ |
|
2951 |
newClr := newClr nearestIn:image colorMap |
|
2952 |
]. |
|
2953 |
self image colorAtX:x y:y put:newClr |
|
2954 |
]. |
|
2955 |
||
2956 |
self setModified. |
|
2957 |
^ true. |
|
2958 |
||
2959 |
"Created: / 20-02-2017 / 17:30:00 / cg" |
|
5497 | 2960 |
"Modified: / 22-02-2017 / 20:56:51 / cg" |
5491 | 2961 |
! |
2962 |
||
2839 | 2963 |
reduceColorResolutionBy:numBits |
2964 |
|newImage| |
|
2965 |
||
2966 |
numBits > 7 ifTrue:[ |
|
5061 | 2967 |
self warn:(resources string:'Max. number of bits to strip off is 7.'). |
2839 | 2968 |
^ false |
2969 |
]. |
|
2970 |
newImage := image withColorResolutionReducedBy:numBits. |
|
2971 |
newImage isNil ifTrue:[ |
|
5061 | 2972 |
self warn:(resources string:'Could not reduce color resolution.'). |
2839 | 2973 |
^ false. |
2974 |
]. |
|
2975 |
||
4730 | 2976 |
self newImageWithUndo:newImage. |
2839 | 2977 |
^ true |
2978 |
! |
|
2979 |
||
2980 |
resizeImageTo:newSize |
|
4730 | 2981 |
self newImageWithUndo: (self resizedImage:image to:newSize). |
2982 |
! |
|
2983 |
||
2984 |
resizedImage:image to:newSize |
|
2985 |
"helper for image resize and mask resize. |
|
2986 |
return a resized version of image" |
|
2839 | 2987 |
|
2988 |
|newImage newMaskImage| |
|
2989 |
||
2990 |
newImage := image class width: newSize x height: newSize y depth: image depth. |
|
2991 |
newImage photometric:image photometric. |
|
2992 |
newImage colorMap:image colorMap copy. |
|
2993 |
newImage bits: (ByteArray new: newImage bytesPerRow * newSize y). |
|
2994 |
||
2995 |
image mask notNil ifTrue:[ |
|
2996 |
newMaskImage := Depth1Image width: newSize x height: newSize y. |
|
2997 |
newMaskImage photometric: image mask photometric. |
|
2998 |
newMaskImage colorMap: image mask colorMap copy. |
|
2999 |
newMaskImage bits:(ByteArray new: newMaskImage bytesPerRow * newSize y). |
|
3000 |
newImage mask: newMaskImage |
|
3001 |
]. |
|
3002 |
||
3003 |
newImage copyFrom:image x:0 y:0 toX:0 y:0 width: (image width min:newSize x) height: (image height min:newSize y). |
|
4730 | 3004 |
^ newImage. |
2839 | 3005 |
! |
3006 |
||
3007 |
rotateImageBy:rotation |
|
3008 |
"rotate by (degrees)" |
|
3009 |
||
4212 | 3010 |
Error handle:[:ex| |
3435
400079196849
3D perspecitve (first attempt)
Claus Gittinger <cg@exept.de>
parents:
3319
diff
changeset
|
3011 |
self warn: 'Image rotation failed!!\' withCRs, 'Increasing the image depth could help.' |
2839 | 3012 |
] do:[ |
4730 | 3013 |
self newImageWithUndo: (image hardRotated: rotation). |
2839 | 3014 |
] |
3015 |
||
3016 |
"Modified: / 29.7.1998 / 18:21:14 / cg" |
|
3435
400079196849
3D perspecitve (first attempt)
Claus Gittinger <cg@exept.de>
parents:
3319
diff
changeset
|
3017 |
! |
400079196849
3D perspecitve (first attempt)
Claus Gittinger <cg@exept.de>
parents:
3319
diff
changeset
|
3018 |
|
400079196849
3D perspecitve (first attempt)
Claus Gittinger <cg@exept.de>
parents:
3319
diff
changeset
|
3019 |
threeDProjection:dx1 and:dx2 |
400079196849
3D perspecitve (first attempt)
Claus Gittinger <cg@exept.de>
parents:
3319
diff
changeset
|
3020 |
"3D projection" |
400079196849
3D perspecitve (first attempt)
Claus Gittinger <cg@exept.de>
parents:
3319
diff
changeset
|
3021 |
|
4212 | 3022 |
Error handle:[:ex| |
3435
400079196849
3D perspecitve (first attempt)
Claus Gittinger <cg@exept.de>
parents:
3319
diff
changeset
|
3023 |
self warn: 'Image projection failed!!\' withCRs, 'Increasing the image depth could help.' |
400079196849
3D perspecitve (first attempt)
Claus Gittinger <cg@exept.de>
parents:
3319
diff
changeset
|
3024 |
] do:[ |
4730 | 3025 |
self newImageWithUndo:(image threeDProjected:dx1 and:dx2) |
3435
400079196849
3D perspecitve (first attempt)
Claus Gittinger <cg@exept.de>
parents:
3319
diff
changeset
|
3026 |
] |
400079196849
3D perspecitve (first attempt)
Claus Gittinger <cg@exept.de>
parents:
3319
diff
changeset
|
3027 |
|
400079196849
3D perspecitve (first attempt)
Claus Gittinger <cg@exept.de>
parents:
3319
diff
changeset
|
3028 |
"Modified: / 29.7.1998 / 18:21:14 / cg" |
2839 | 3029 |
! ! |
3030 |
||
2511 | 3031 |
!ImageEditView methodsFor:'image-dragging & info'! |
3032 |
||
2838
8525a35121d2
changeHLS fixed dfor depth24-images;
Claus Gittinger <cg@exept.de>
parents:
2824
diff
changeset
|
3033 |
dragRectangleStartingAt:aPointIn emphasis:emphasis |
5413 | 3034 |
"draw a drag rectangle (filled or unfilled, depending on the emphasis arg). |
3035 |
This is called by operation like |
|
3036 |
rectangle, filledRectangle, copy etc. |
|
3037 |
(i.e. any operation which operates on a box). |
|
3038 |
emphasis is one of: |
|
3039 |
box - a frame is drawn |
|
3040 |
inverseFilledBox - the dragged box is filled by the inverse color |
|
3041 |
filledBox - the dragged box is filled with black |
|
3042 |
grayedBox - the dragged box is drawn with a gray shadow |
|
3043 |
" |
|
2511 | 3044 |
|
3045 |
|currentPoint currentExtent firstPoint lastCurrentPoint gridCorrection |
|
5413 | 3046 |
mp lastMp p whichQuarter scrollX scrollY aPoint sensor| |
2511 | 3047 |
|
3048 |
aPoint := aPointIn. |
|
3049 |
firstPoint := currentPoint := lastCurrentPoint := aPoint//magnification*magnification. |
|
3050 |
magnification >= GridMagnificationLimit ifFalse: [gridCorrection := 0] ifTrue: [gridCorrection := 1]. |
|
3051 |
||
5413 | 3052 |
sensor := self sensor. |
3053 |
[sensor anyButtonPressed] whileTrue: [ |
|
3054 |
(sensor hasKeyEventFor:nil) ifTrue:[ |
|
2838
8525a35121d2
changeHLS fixed dfor depth24-images;
Claus Gittinger <cg@exept.de>
parents:
2824
diff
changeset
|
3055 |
self invalidate. |
8525a35121d2
changeHLS fixed dfor depth24-images;
Claus Gittinger <cg@exept.de>
parents:
2824
diff
changeset
|
3056 |
^ nil. |
8525a35121d2
changeHLS fixed dfor depth24-images;
Claus Gittinger <cg@exept.de>
parents:
2824
diff
changeset
|
3057 |
]. |
8525a35121d2
changeHLS fixed dfor depth24-images;
Claus Gittinger <cg@exept.de>
parents:
2824
diff
changeset
|
3058 |
|
5413 | 3059 |
mp := sensor mousePoint. |
2511 | 3060 |
mp = lastMp ifTrue:[ |
3061 |
Delay waitForSeconds:0.05 |
|
3062 |
] ifFalse:[ |
|
3063 |
lastMp := mp. |
|
4999 | 3064 |
mp := device translatePoint:mp fromView:nil toView:self. |
2511 | 3065 |
"/ mp is a device coordinate here ... |
3066 |
scrollX := 0. |
|
3067 |
mp x > width ifTrue:[ |
|
3068 |
scrollX := mp x - width. |
|
3069 |
] ifFalse:[ |
|
3070 |
mp x < 0 ifTrue:[ |
|
3071 |
scrollX := mp x. |
|
3072 |
] |
|
3073 |
]. |
|
3074 |
scrollY := 0. |
|
3075 |
mp y > height ifTrue:[ |
|
3076 |
scrollY := mp y - height. |
|
3077 |
] ifFalse:[ |
|
3078 |
mp y < 0 ifTrue:[ |
|
3079 |
scrollY := mp y. |
|
3080 |
] |
|
3081 |
]. |
|
3082 |
(scrollX + scrollY) ~~ 0 ifTrue:[ |
|
3083 |
self scrollTo:(self viewOrigin + (scrollX @ scrollY)). |
|
3084 |
lastMp := nil. |
|
3085 |
]. |
|
3086 |
||
3087 |
mp := mp + self viewOrigin. |
|
3088 |
"/ mp is now a logical coordinate. |
|
3089 |
||
3090 |
currentPoint := (0@0) max: (image extent * magnification min: (p := mp)). |
|
3091 |
currentPoint := currentPoint//magnification*magnification. |
|
5593 | 3092 |
|
2511 | 3093 |
currentExtent := (firstPoint - currentPoint) abs. |
3094 |
whichQuarter := (firstPoint x - currentPoint x) > 0 |
|
3095 |
ifTrue: [(firstPoint y - currentPoint y) > 0 ifTrue: ["4"1@1] ifFalse: ["3"1@0]] |
|
3096 |
ifFalse: [(firstPoint y - currentPoint y) > 0 ifTrue: ["1"0@1] ifFalse: ["2"0@0]]. |
|
3097 |
||
5413 | 3098 |
self showCursorAt: p andInformation: |
2511 | 3099 |
((firstPoint//magnification - whichQuarter + 1) printString, |
3100 |
' to: ', |
|
3101 |
(currentPoint//magnification + whichQuarter) printString), |
|
3102 |
' (extent: ', |
|
3103 |
(currentExtent//magnification) printString, ')'. |
|
3104 |
||
5413 | 3105 |
currentPoint ~= lastCurrentPoint ifTrue:[ |
3106 |
||
3107 |
emphasis == #grayedBox ifTrue:[ |
|
3108 |
"/ does not yet work |
|
3109 |
|org ext| |
|
3110 |
||
3111 |
"/ org := (firstPoint min: lastCurrentPoint) - 1. |
|
3112 |
"/ ext := (firstPoint - lastCurrentPoint) abs + 2. |
|
3113 |
||
3114 |
(lastCurrentPoint x > currentPoint x |
|
3115 |
or:[ (lastCurrentPoint y > currentPoint y) ] |
|
3116 |
) ifTrue:[ |
|
3117 |
self |
|
3118 |
redrawImageX:firstPoint x"-1" y:firstPoint y"-1" |
|
3119 |
width:(lastCurrentPoint x-firstPoint x"+2") height:(lastCurrentPoint y-firstPoint y"+2") |
|
3120 |
unmaskedOnly:false processColorsWith:[:clr | clr ]. |
|
3121 |
"/ self drawFramesIn:(firstPoint corner:lastCurrentPoint). |
|
3122 |
]. |
|
3123 |
||
3124 |
self |
|
3125 |
redrawImageX:firstPoint x"-1" y:firstPoint y"-1 " |
|
3126 |
width:(currentPoint x-firstPoint x"+2") height:(currentPoint y-firstPoint y"+2") |
|
3127 |
unmaskedOnly:true processColorsWith:[:clr | Color gray: clr grayIntensity / 2 ]. |
|
3128 |
]. |
|
3129 |
||
3130 |
emphasis == #inverseFilledBox ifTrue: [ |
|
5414 | 3131 |
|union invertOutside| |
3132 |
||
3133 |
invertOutside := false. |
|
3134 |
"/ union := (firstPoint corner:currentPoint) merge:(firstPoint corner:lastCurrentPoint). |
|
3135 |
"/ ((lastCurrentPoint x > currentPoint x) |
|
3136 |
"/ and:[ lastCurrentPoint y > currentPoint y ]) ifTrue:[ |
|
3137 |
"/ "/ a real shrink |
|
3138 |
"/ invertOutside := true. |
|
3139 |
"/ self xoring: [ |
|
3140 |
"/ union areasOutside:(firstPoint corner:lastCurrentPoint) do:[:r | |
|
3141 |
"/ self fillRectangle: ((firstPoint min: currentPoint) + margin extent: currentExtent - gridCorrection) |
|
3142 |
"/ ] |
|
3143 |
"/ ] |
|
3144 |
"/ ] ifFalse:[ |
|
3145 |
"/ ((currentPoint x > lastCurrentPoint x) |
|
3146 |
"/ and:[ currentPoint y > lastCurrentPoint y ]) ifTrue:[ |
|
3147 |
"/ "/ a real grow |
|
3148 |
"/ invertOutside := true. |
|
3149 |
"/ self xoring: [ |
|
3150 |
"/ union areasOutside:(firstPoint corner:currentPoint) do:[:r | |
|
3151 |
"/ self fillRectangle: ((firstPoint min: currentPoint) + margin extent: currentExtent - gridCorrection) |
|
3152 |
"/ ] |
|
3153 |
"/ ] |
|
3154 |
"/ ]. |
|
3155 |
"/ ]. |
|
3156 |
invertOutside ifFalse:[ |
|
3157 |
self redraw: ((firstPoint min: lastCurrentPoint) - 1 extent: (firstPoint - lastCurrentPoint) abs + 2). |
|
5432 | 3158 |
gc xoring: [ |
3159 |
gc fillRectangle: ((firstPoint min: currentPoint) + margin extent: currentExtent - gridCorrection) |
|
5414 | 3160 |
] |
3161 |
]. |
|
2511 | 3162 |
]. |
5413 | 3163 |
|
3164 |
emphasis == #box ifTrue:[ |
|
2511 | 3165 |
|origin extent lineWidthY lineWidthX| |
5413 | 3166 |
|
2511 | 3167 |
origin := (firstPoint min: lastCurrentPoint) - 1. |
3168 |
extent := (firstPoint - lastCurrentPoint) abs + 2. |
|
3169 |
lineWidthY := extent y min: (magnification y + 2). |
|
3170 |
lineWidthX := extent x min: (magnification x + 2). |
|
3171 |
self redraw: (origin extent: (extent x@lineWidthY)). |
|
3172 |
self redraw: ((origin x@(origin y + extent y - lineWidthY)) extent: (extent x@lineWidthY)). |
|
3173 |
self redraw: ((origin x@(origin y + lineWidthY)) extent: (lineWidthX@(0 max: (extent y - (lineWidthY * 2))))). |
|
3174 |
self redraw: (((origin x + extent x - lineWidthX)@(origin y + lineWidthY)) extent: (lineWidthX@(extent y - (lineWidthY * 2)))). |
|
5413 | 3175 |
(self selectedColor ~= Color noColor) |
5432 | 3176 |
ifTrue: [gc paint: self selectedColor] |
3177 |
ifFalse: [gc paint: self viewBackground]. |
|
2511 | 3178 |
origin := (firstPoint min: currentPoint) + margin. |
3179 |
extent := currentExtent - gridCorrection. |
|
3180 |
lineWidthY := extent y min: magnification y. |
|
3181 |
lineWidthX := extent x min: magnification x. |
|
5413 | 3182 |
(lineWidthY > 0 and: [lineWidthX > 0]) ifTrue:[ |
5432 | 3183 |
gc fillRectangle: (origin extent: (extent x@lineWidthY)). |
3184 |
gc fillRectangle: ((origin x@(origin y + extent y - lineWidthY)) extent: (extent x@lineWidthY)). |
|
3185 |
gc fillRectangle: ((origin x@(origin y + lineWidthY)) extent: (lineWidthX@(0 max: (extent y - (lineWidthY * 2))))). |
|
3186 |
gc fillRectangle: (((origin x + extent x - lineWidthX)@(origin y + lineWidthY)) extent: (lineWidthX@(extent y - (lineWidthY * 2)))). |
|
2511 | 3187 |
] |
3188 |
]. |
|
5413 | 3189 |
|
3190 |
emphasis == #filledBox ifTrue:[ |
|
2511 | 3191 |
self redraw: ((firstPoint min: lastCurrentPoint) - 1 extent: (firstPoint - lastCurrentPoint) abs + 2). |
5413 | 3192 |
(self selectedColor ~= Color noColor) |
5432 | 3193 |
ifTrue: [gc paint: self selectedColor] |
3194 |
ifFalse: [gc paint: self viewBackground]. |
|
3195 |
gc fillRectangle: ((firstPoint min: currentPoint) + margin extent: currentExtent - gridCorrection). |
|
2511 | 3196 |
]. |
3197 |
]. |
|
3198 |
lastCurrentPoint := currentPoint. |
|
3199 |
]. |
|
3200 |
]. |
|
3201 |
||
3202 |
^((0@0) max: (firstPoint min: currentPoint)) extent: (firstPoint - currentPoint) abs |
|
3203 |
||
5593 | 3204 |
"Created: / 21-08-1998 / 20:17:07 / cg" |
3205 |
"Modified: / 10-10-2001 / 14:13:08 / cg" |
|
3206 |
"Modified (format): / 04-09-2017 / 18:26:06 / cg" |
|
2511 | 3207 |
! |
3208 |
||
3209 |
drawCursorAt:aPoint |
|
5481 | 3210 |
"the mouse was moved to aPoint (in the image). |
3211 |
Update the info (showing rgb + other info) in the lower info bar. |
|
3212 |
Also changes the cursor to a stop-cursor, if outside the image" |
|
3213 |
||
5413 | 3214 |
|imgPoint shownCursor| |
2511 | 3215 |
|
4041 | 3216 |
readOnly ifTrue:[^ self]. |
2511 | 3217 |
image isNil ifTrue: [ |
5481 | 3218 |
self updateImageInfo:(self imageInfoString). |
2511 | 3219 |
self cursor:Cursor stop. |
3220 |
^ self |
|
3221 |
]. |
|
3222 |
||
3223 |
imgPoint := aPoint // magnification. |
|
3224 |
((imgPoint x between:0 and:(image width-1)) |
|
5413 | 3225 |
and:[imgPoint y between:0 and: (image height-1)] |
3226 |
) ifFalse:[ |
|
5481 | 3227 |
self updateImageInfo:(self imageInfoString). |
5413 | 3228 |
shownCursor := Cursor stop. |
2511 | 3229 |
] ifTrue: [ |
3729 | 3230 |
self updateImageInfoFor:imgPoint. |
5413 | 3231 |
shownCursor := Cursor crossHair |
2511 | 3232 |
]. |
5413 | 3233 |
self cursor:shownCursor. |
2511 | 3234 |
|
4041 | 3235 |
"Modified: / 03-05-2011 / 12:27:52 / cg" |
5481 | 3236 |
"Modified (format): / 16-02-2017 / 17:09:13 / cg" |
3237 |
! |
|
3238 |
||
3239 |
imageInfoString |
|
3240 |
image isNil ifTrue: [^ 'No image loaded.']. |
|
3241 |
||
3242 |
^ String streamContents:[:s | |
|
3243 |
|d| |
|
3244 |
||
5585 | 3245 |
s print:('%1x%2 | %3bit%4' |
3246 |
bindWith:image width |
|
3247 |
with:image height |
|
3248 |
with:image depth |
|
3249 |
with:(image mask notNil ifTrue: ['+mask'] ifFalse:[''])). |
|
3250 |
||
5588 | 3251 |
image depth ~~ image bitsPerSample sum ifTrue:[ |
3252 |
s print:' ('. |
|
5656 | 3253 |
image bitsPerSample do:[:each | s print:each] separatedBy:[s print:'·']. |
5588 | 3254 |
s print:')'. |
3255 |
]. |
|
3256 |
||
5481 | 3257 |
d := image depth min:24. |
3258 |
' [%1/%2 colors]' expandPlaceholdersWith:{image nColorsUsed. (2 raisedTo:d)} on:s. |
|
3259 |
]. |
|
3260 |
||
5588 | 3261 |
"Modified: / 31-08-2017 / 18:15:40 / cg" |
2511 | 3262 |
! |
3263 |
||
5413 | 3264 |
showCursorAt: aPoint andInformation: aLabel |
3265 |
|shownCursor| |
|
3266 |
||
4041 | 3267 |
readOnly ifTrue:[^ self]. |
2511 | 3268 |
|
3269 |
((0@0 extent: image extent * magnification) containsPoint: aPoint) |
|
5413 | 3270 |
ifTrue: [ shownCursor := Cursor crossHair ] |
5414 | 3271 |
ifFalse:[ shownCursor := Cursor stop ]. |
5413 | 3272 |
self cursor:shownCursor. |
3273 |
self updateImageInfo: aLabel. |
|
2511 | 3274 |
|
4041 | 3275 |
"Modified: / 03-05-2011 / 12:28:15 / cg" |
2511 | 3276 |
! |
3277 |
||
3278 |
updateActivity: something |
|
3279 |
|msg| |
|
3280 |
||
3281 |
msg := something printString. |
|
3282 |
||
3283 |
activityInfoHolder notNil ifTrue:[ |
|
3847
c09d45071125
comment/format in: #updateImageInfo:
Claus Gittinger <cg@exept.de>
parents:
3840
diff
changeset
|
3284 |
activityInfoHolder value:msg. |
2511 | 3285 |
]. |
3286 |
||
3287 |
"Modified: / 29.7.1998 / 18:41:47 / cg" |
|
3288 |
! |
|
3289 |
||
5583 | 3290 |
updateImageInfo:someTextOrObject |
5581 | 3291 |
"show someText in the lower info area" |
5481 | 3292 |
|
3847
c09d45071125
comment/format in: #updateImageInfo:
Claus Gittinger <cg@exept.de>
parents:
3840
diff
changeset
|
3293 |
|msg| |
2511 | 3294 |
|
3295 |
imageInfoHolder notNil ifTrue:[ |
|
5583 | 3296 |
someTextOrObject isString ifTrue:[ |
3297 |
msg := someTextOrObject |
|
3298 |
] ifFalse:[ |
|
3299 |
msg := someTextOrObject printString. |
|
3300 |
]. |
|
3847
c09d45071125
comment/format in: #updateImageInfo:
Claus Gittinger <cg@exept.de>
parents:
3840
diff
changeset
|
3301 |
msg ~= imageInfoHolder value ifTrue:[ |
c09d45071125
comment/format in: #updateImageInfo:
Claus Gittinger <cg@exept.de>
parents:
3840
diff
changeset
|
3302 |
imageInfoHolder value:msg. |
c09d45071125
comment/format in: #updateImageInfo:
Claus Gittinger <cg@exept.de>
parents:
3840
diff
changeset
|
3303 |
]. |
c09d45071125
comment/format in: #updateImageInfo:
Claus Gittinger <cg@exept.de>
parents:
3840
diff
changeset
|
3304 |
^ self |
2511 | 3305 |
]. |
3306 |
||
5583 | 3307 |
"Modified: / 29-08-2017 / 20:35:57 / cg" |
3729 | 3308 |
! |
3309 |
||
3310 |
updateImageInfoFor:aPoint |
|
5481 | 3311 |
"show info about the pixel at aPoint in the lower info area" |
3312 |
||
3313 |
|clr pixel r g b a m| |
|
3729 | 3314 |
|
3315 |
clr := image colorAt:aPoint. |
|
3316 |
pixel := image pixelAt:aPoint. |
|
3317 |
||
3318 |
r := clr redByte. |
|
3319 |
g := clr greenByte. |
|
3320 |
b := clr blueByte. |
|
5481 | 3321 |
image hasAlphaChannel ifTrue:[ |
5493 | 3322 |
"/ sigh - must return a TranslucentColor from colorAt: |
3323 |
"/ until that is fixed, compute it here... |
|
5481 | 3324 |
"/ a := clr alphaByte. |
5493 | 3325 |
a := (pixel rightShift:(image alphaShiftForPixelValue)) bitAnd:(image alphaMaskForPixelValue). |
5481 | 3326 |
] ifFalse:[ |
3327 |
image mask notNil ifTrue:[ |
|
3328 |
m := image mask pixelAt:aPoint. |
|
3329 |
]. |
|
3330 |
]. |
|
3331 |
||
3729 | 3332 |
self updateImageInfo: |
5583 | 3333 |
(' ' asText backgroundColorizeAllWith:clr) |
3334 |
, ' ' |
|
3335 |
, (String streamContents:[:s | |
|
5582 | 3336 |
|redString greenString blueString greyString |
3337 |
photometric bitsPerSample| |
|
5581 | 3338 |
|
5582 | 3339 |
photometric := image photometric. |
3340 |
bitsPerSample := image bitsPerSample. |
|
3341 |
||
3729 | 3342 |
s print:aPoint. |
5582 | 3343 |
|
3344 |
((photometric == #blackIs0) or:[(photometric == #whiteIs0)]) ifTrue:[ |
|
3345 |
s print:' (g:'; print:pixel. |
|
3346 |
greyString := (pixel hexPrintString:2). |
|
3347 |
] ifFalse:[ |
|
3348 |
s print:' (r:'; print:r. |
|
3349 |
s print:' g:'; print:g. |
|
3350 |
s print:' b:'; print:b. |
|
3351 |
||
3352 |
redString := (r hexPrintString:2). |
|
3353 |
greenString := (g hexPrintString:2). |
|
3354 |
blueString := (b hexPrintString:2). |
|
3355 |
]. |
|
5481 | 3356 |
a notNil ifTrue:[ |
3729 | 3357 |
s print:' a:'; print:a. |
5481 | 3358 |
] ifFalse:[ |
3359 |
m notNil ifTrue:[ |
|
3360 |
s print:' m:'; print:m. |
|
3361 |
]. |
|
5581 | 3362 |
]. |
3363 |
||
5582 | 3364 |
((photometric == #blackIs0) or:[(photometric == #whiteIs0)]) ifTrue:[ |
3365 |
(bitsPerSample at:1) == 16 ifTrue:[ |
|
3366 |
greyString := (pixel hexPrintString:4) |
|
5581 | 3367 |
]. |
5582 | 3368 |
s print:(' #%1' bindWith:greyString). |
3369 |
] ifFalse:[ |
|
3370 |
((photometric == #rgb) or:[(photometric == #rgba)]) ifTrue:[ |
|
3371 |
(bitsPerSample at:1) == 16 ifTrue:[ |
|
3372 |
redString := (r hexPrintString:4) |
|
3373 |
]. |
|
3374 |
(bitsPerSample at:2) == 16 ifTrue:[ |
|
3375 |
greenString := (g hexPrintString:4) |
|
3376 |
]. |
|
3377 |
(bitsPerSample at:2) == 16 ifTrue:[ |
|
3378 |
blueString := (b hexPrintString:4) |
|
3379 |
]. |
|
3380 |
]. |
|
3381 |
s print:(' #%1.%2.%3' bindWith:redString with:greenString with:blueString). |
|
3382 |
]. |
|
5481 | 3383 |
a notNil ifTrue:[ |
3384 |
s print:'.'; print:(a hexPrintString:2) |
|
3385 |
]. |
|
5582 | 3386 |
|
3387 |
photometric == #palette ifTrue:[ |
|
5581 | 3388 |
s print:' pixel index:'; print:pixel. |
3729 | 3389 |
]. |
3390 |
s print:')'. |
|
3391 |
]) |
|
5481 | 3392 |
|
5583 | 3393 |
"Modified: / 29-08-2017 / 20:39:26 / cg" |
2511 | 3394 |
! ! |
3395 |
||
2818 | 3396 |
!ImageEditView methodsFor:'initialization & release'! |
1327 | 3397 |
|
3398 |
destroy |
|
5618 | 3399 |
ClipboardImageMagnified := ClipboardImage := nil. |
1327 | 3400 |
LastMagnification := magnification. |
3401 |
||
3402 |
super destroy |
|
5618 | 3403 |
|
3404 |
"Modified: / 08-10-2017 / 08:54:36 / cg" |
|
1327 | 3405 |
! |
1 | 3406 |
|
161 | 3407 |
initialize |
3408 |
super initialize. |
|
627 | 3409 |
|
4041 | 3410 |
readOnly := false. |
3411 |
||
686 | 3412 |
self enableMotionEvents. |
995 | 3413 |
|
1374 | 3414 |
undoImages := List new: MaxUndos. |
2915 | 3415 |
|
1706 | 3416 |
magnification := LastMagnification ? (8@8). |
2747 | 3417 |
modifiedHolder := false asValue. |
627 | 3418 |
mouseKeyColorMode := 1. |
2908
a759fa87d598
some code cleanup (resourceClass was actually its name)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
3419 |
resourceClass := resourceSelector := nil. |
5499 | 3420 |
drawingColorHolders isNil ifTrue:[ |
3421 |
drawingColorHolders := Array with:(nil asValue) with:(nil asValue). "/ left/right mouse colors |
|
3422 |
]. |
|
2009
4f556ff9fec5
pick with SHIFT-click in the mag-view
Claus Gittinger <cg@exept.de>
parents:
2007
diff
changeset
|
3423 |
drawingPixelHolders := Array with:(nil asValue) with:(nil asValue). "/ left/right mouse colors |
4111 | 3424 |
|
5593 | 3425 |
drawingAlpha isNil ifTrue:[ drawingAlpha := 100 ]. |
4111 | 3426 |
spraySpot := 8. |
3427 |
penWidth := 1. |
|
5483 | 3428 |
floodFillMaxHueError := floodFillMaxLightError := 0. |
5484 | 3429 |
userAllowedToChangeDrawingColor := true. |
5483 | 3430 |
|
2889 | 3431 |
self editMode:EditModePoint. |
4041 | 3432 |
|
5594 | 3433 |
"Modified: / 05-09-2017 / 10:47:11 / cg" |
1 | 3434 |
! ! |
3435 |
||
2915 | 3436 |
!ImageEditView methodsFor:'loading & saving'! |
1 | 3437 |
|
1994 | 3438 |
askForFileNameToSave:msg |
3439 |
"ask for a fileName" |
|
3440 |
||
3441 |
|lastFn fn filters| |
|
3442 |
||
3443 |
filters := FileSelectionBrowser saveImageFileNameFilters. |
|
3444 |
lastFn := self image fileName. |
|
3445 |
lastFn isNil ifTrue:[ |
|
3446 |
fn := FileSelectionBrowser |
|
3447 |
request: msg |
|
3448 |
inDirectory: LastSaveDirectory |
|
3449 |
withFileFilters: filters |
|
3450 |
] ifFalse:[ |
|
3451 |
fn := FileSelectionBrowser |
|
3452 |
request: msg |
|
3453 |
fileName: lastFn |
|
3454 |
withFileFilters: filters |
|
3455 |
]. |
|
3456 |
||
3457 |
^ fn |
|
3458 |
! |
|
3459 |
||
724 | 3460 |
loadFromClass |
2915 | 3461 |
|classAndSelector| |
3462 |
||
3463 |
classAndSelector := ResourceSelectionBrowser |
|
1184 | 3464 |
request: 'Load Image From Class' |
3465 |
onSuperclass: nil |
|
2915 | 3466 |
andClass: self resourceClass |
1184 | 3467 |
andSelector: self resourceSelector |
2915 | 3468 |
withResourceTypes: #(image fileImage programImage). |
3469 |
||
3470 |
classAndSelector notNil ifTrue:[ |
|
3471 |
self loadFromClass:(classAndSelector methodClass) andSelector:(classAndSelector methodSelector) |
|
3472 |
]. |
|
161 | 3473 |
! |
3474 |
||
2915 | 3475 |
loadFromClass:aClassOrClassName andSelector: aStringOrSymbol |
3476 |
"support for names will vanish - obsolete left over from tz" |
|
3477 |
||
3478 |
imageReaderClass := nil. |
|
3479 |
self resourceClass: aClassOrClassName. |
|
3480 |
self resourceSelector: aStringOrSymbol. |
|
3481 |
||
3482 |
resourceClass isBehavior ifFalse:[^ nil]. |
|
3483 |
||
3484 |
(resourceClass respondsTo:resourceSelector) ifTrue:[ |
|
3485 |
image := resourceClass perform:resourceSelector. |
|
3486 |
]. |
|
3487 |
||
3488 |
image isNil ifTrue:[^ nil]. |
|
3489 |
||
3490 |
image := image copy. |
|
3491 |
self releaseUndos. |
|
3492 |
self image:image. |
|
3493 |
self clearModified. |
|
3494 |
^ image |
|
2556 | 3495 |
! |
3496 |
||
2915 | 3497 |
loadFromFile: aFileName |
5510 | 3498 |
^ self loadFromFile:aFileName readerClass:nil |
3499 |
||
3500 |
"Modified: / 07-03-2017 / 17:43:07 / cg" |
|
3501 |
! |
|
3502 |
||
3503 |
loadFromFile:aFileName readerClass:imageReaderClassOrNil |
|
2915 | 3504 |
|imageFromFile| |
3505 |
||
3506 |
aFileName isNil ifTrue: [^nil]. |
|
3507 |
||
5029 | 3508 |
Error handle:[:exception| |
3509 |
self warn: exception errorString. |
|
4351 | 3510 |
^ nil |
2915 | 3511 |
] do:[ |
4351 | 3512 |
(imageFromFile := Image fromFile: aFileName) isNil ifTrue:[ |
5510 | 3513 |
imageFromFile := (imageReaderClassOrNil ? JPEGReader) fromFile:aFileName |
4351 | 3514 |
]. |
3515 |
imageFromFile notNil ifTrue:[ |
|
2915 | 3516 |
self releaseUndos. |
3517 |
self image: imageFromFile. |
|
3518 |
self clearModified. |
|
3519 |
"/ imageReaderClass := ImageReader allSubclasses |
|
3520 |
"/ detect: [:cls| cls isValidImageFile: aFileName asFilename pathName] |
|
3521 |
"/ ifNone: [self error: 'Unknown image file format!!'] |
|
3522 |
] ifFalse:[ |
|
4965 | 3523 |
aFileName asFilename isReadable ifTrue:[ |
3524 |
self error: 'Not an image file (or unrecognized format)' |
|
3525 |
] ifFalse:[ |
|
3526 |
self error: 'File does not exist or is unreadable' |
|
3527 |
] |
|
2915 | 3528 |
] |
2555 | 3529 |
]. |
2915 | 3530 |
^ imageFromFile |
3531 |
||
5510 | 3532 |
"Created: / 07-03-2017 / 17:42:37 / cg" |
2915 | 3533 |
! |
3534 |
||
3535 |
loadFromMessage:classAndSelector |
|
3536 |
"switch to the class and selector specified by classAndSelector." |
|
3537 |
||
3538 |
^ self loadFromClass:(classAndSelector methodClass) andSelector:(classAndSelector methodSelector) |
|
3539 |
! |
|
3540 |
||
3541 |
loadfromClass:aClassOrSymbol andSelector: aStringOrSymbol |
|
3643 | 3542 |
<resource: #obsolete> |
2915 | 3543 |
self obsoleteMethodWarning. |
3544 |
^ self loadFromClass:aClassOrSymbol andSelector: aStringOrSymbol |
|
624 | 3545 |
! |
3546 |
||
3547 |
save |
|
632 | 3548 |
self saveImageOrMask: #image. |
624 | 3549 |
! |
3550 |
||
2239 | 3551 |
save:image imageOrMask:what |
3552 |
"save the image or the mask only (if what == #mask)" |
|
297 | 3553 |
|
2239 | 3554 |
image isNil ifTrue:[ |
4249 | 3555 |
Dialog warn:(resources string:'No image to save!!'). |
2239 | 3556 |
^ self. |
3557 |
]. |
|
3558 |
self save:image imageOrMask:what as:image fileName. |
|
627 | 3559 |
! |
297 | 3560 |
|
2239 | 3561 |
save:image imageOrMask:what as:fileNameArg |
1158
9b413954d34d
issue a warning, if information (mask) is
Claus Gittinger <cg@exept.de>
parents:
1121
diff
changeset
|
3562 |
"save the image or the mask only (if what == #mask)" |
628 | 3563 |
|
2240 | 3564 |
|fileName fileNameString| |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
3565 |
|
2239 | 3566 |
fileName := fileNameArg asFilename. |
2783 | 3567 |
LastSaveDirectory := fileName directoryName. |
2239 | 3568 |
|
4203 | 3569 |
Error handle:[:ex| |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
3570 |
|msg| |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
3571 |
|
4203 | 3572 |
ex creator == Image fileCreationErrorSignal ifTrue:[ |
1896 | 3573 |
msg := resources string:'Cannot create file: ''%1''' with:fileName asFilename pathName allBold |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
3574 |
] ifFalse:[ |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
3575 |
msg := ex errorString. |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
3576 |
]. |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
3577 |
Dialog warn:msg. |
1158
9b413954d34d
issue a warning, if information (mask) is
Claus Gittinger <cg@exept.de>
parents:
1121
diff
changeset
|
3578 |
] do:[ |
5600 | 3579 |
Image informationLostQuerySignal handle:[:ex | |
3580 |
|question| |
|
3581 |
||
3582 |
question := '\\Save anyway ?'. |
|
3583 |
ex creator == Image noMaskButAlphaSupportedQuerySignal ifTrue:[ |
|
3584 |
question := '\\Convert and save with alpha channel ?'. |
|
3585 |
]. |
|
3586 |
(self confirm:(ex errorString , question) withCRs) ifTrue:[ |
|
1158
9b413954d34d
issue a warning, if information (mask) is
Claus Gittinger <cg@exept.de>
parents:
1121
diff
changeset
|
3587 |
ex proceed. |
9b413954d34d
issue a warning, if information (mask) is
Claus Gittinger <cg@exept.de>
parents:
1121
diff
changeset
|
3588 |
] |
9b413954d34d
issue a warning, if information (mask) is
Claus Gittinger <cg@exept.de>
parents:
1121
diff
changeset
|
3589 |
] do:[ |
4137 | 3590 |
windowGroup withWriteCursorDo:[ |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
3591 |
|suff fn| |
1027
5bffbe90b8e2
show a wait-cursor while saving
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
3592 |
|
1158
9b413954d34d
issue a warning, if information (mask) is
Claus Gittinger <cg@exept.de>
parents:
1121
diff
changeset
|
3593 |
image isNil ifTrue:[ |
9b413954d34d
issue a warning, if information (mask) is
Claus Gittinger <cg@exept.de>
parents:
1121
diff
changeset
|
3594 |
^ self error: 'No image to save!!' |
9b413954d34d
issue a warning, if information (mask) is
Claus Gittinger <cg@exept.de>
parents:
1121
diff
changeset
|
3595 |
]. |
632 | 3596 |
|
1158
9b413954d34d
issue a warning, if information (mask) is
Claus Gittinger <cg@exept.de>
parents:
1121
diff
changeset
|
3597 |
what = #mask ifTrue:[ |
9b413954d34d
issue a warning, if information (mask) is
Claus Gittinger <cg@exept.de>
parents:
1121
diff
changeset
|
3598 |
image mask isNil ifTrue: [^self error: 'No image mask to save!!']. |
9b413954d34d
issue a warning, if information (mask) is
Claus Gittinger <cg@exept.de>
parents:
1121
diff
changeset
|
3599 |
]. |
9b413954d34d
issue a warning, if information (mask) is
Claus Gittinger <cg@exept.de>
parents:
1121
diff
changeset
|
3600 |
|
9b413954d34d
issue a warning, if information (mask) is
Claus Gittinger <cg@exept.de>
parents:
1121
diff
changeset
|
3601 |
fileName name size = 0 ifTrue: [^self error: 'No file name detected!!']. |
9b413954d34d
issue a warning, if information (mask) is
Claus Gittinger <cg@exept.de>
parents:
1121
diff
changeset
|
3602 |
suff := fileName suffix asLowercase. |
1373
c949e9f7757c
give a warning, if saving in the given file-format is not
Claus Gittinger <cg@exept.de>
parents:
1327
diff
changeset
|
3603 |
imageReaderClass := nil. |
c949e9f7757c
give a warning, if saving in the given file-format is not
Claus Gittinger <cg@exept.de>
parents:
1327
diff
changeset
|
3604 |
imageReaderClass := MIMETypes imageReaderForSuffix:suff. |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
3605 |
|
1373
c949e9f7757c
give a warning, if saving in the given file-format is not
Claus Gittinger <cg@exept.de>
parents:
1327
diff
changeset
|
3606 |
imageReaderClass isNil ifTrue: [ |
c949e9f7757c
give a warning, if saving in the given file-format is not
Claus Gittinger <cg@exept.de>
parents:
1327
diff
changeset
|
3607 |
imageReaderClass := XPMReader. |
2589
10827ba87692
obsolete method calls cleaned up
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
3608 |
fileNameString := fileName name , '.xpm'. |
2240 | 3609 |
fileName := fileNameString asFilename. |
3610 |
image fileName:fileNameString. |
|
5314 | 3611 |
Dialog warn:(('Don''t know how to write ''.' , suff , '''-files\\Saving in xpm format as ''%1''.') |
2240 | 3612 |
withCRs bindWith:fileNameString allBold). |
1373
c949e9f7757c
give a warning, if saving in the given file-format is not
Claus Gittinger <cg@exept.de>
parents:
1327
diff
changeset
|
3613 |
]. |
c949e9f7757c
give a warning, if saving in the given file-format is not
Claus Gittinger <cg@exept.de>
parents:
1327
diff
changeset
|
3614 |
(imageReaderClass canRepresent:image) ifFalse:[ |
1991 | 3615 |
imageReaderClass == XPMReader ifTrue:[ |
3616 |
Dialog warn:('Saving in ''.' , suff , '''-format is not supported (or image cannot be represented in this format).\\Please try another format.') withCRs. |
|
3617 |
^ self. |
|
3618 |
]. |
|
1373
c949e9f7757c
give a warning, if saving in the given file-format is not
Claus Gittinger <cg@exept.de>
parents:
1327
diff
changeset
|
3619 |
imageReaderClass := XPMReader. |
2589
10827ba87692
obsolete method calls cleaned up
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
3620 |
fileNameString := fileName name , '.xpm'. |
2240 | 3621 |
fileName := fileNameString asFilename. |
3622 |
image fileName:fileNameString. |
|
2690
53bc9dc52ce4
allow cancel when saving in wrong format
Claus Gittinger <cg@exept.de>
parents:
2680
diff
changeset
|
3623 |
(Dialog confirm:(('Saving in ''.' , suff , '''-format is not supported (or image cannot be represented in this format).\\Saving in xpm format as ''%1''.') |
53bc9dc52ce4
allow cancel when saving in wrong format
Claus Gittinger <cg@exept.de>
parents:
2680
diff
changeset
|
3624 |
withCRs bindWith:fileNameString allBold)) ifFalse:[ |
53bc9dc52ce4
allow cancel when saving in wrong format
Claus Gittinger <cg@exept.de>
parents:
2680
diff
changeset
|
3625 |
^ self. |
53bc9dc52ce4
allow cancel when saving in wrong format
Claus Gittinger <cg@exept.de>
parents:
2680
diff
changeset
|
3626 |
]. |
1373
c949e9f7757c
give a warning, if saving in the given file-format is not
Claus Gittinger <cg@exept.de>
parents:
1327
diff
changeset
|
3627 |
]. |
2240 | 3628 |
Transcript showCR:('saving as:' , fileName pathName). |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
3629 |
|
2824 | 3630 |
what = #image ifTrue: [ |
3631 |
image saveOn:fileName using: imageReaderClass. self clearModified. |
|
3632 |
image fileName:fileNameString. |
|
3633 |
]. |
|
3634 |
what = #mask ifTrue: [ |
|
3635 |
image mask saveOn:fileName using: imageReaderClass |
|
3636 |
]. |
|
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
3637 |
|
2240 | 3638 |
fileName exists ifFalse:[ |
1380
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
3639 |
Dialog warn:'Oops image save failed.' |
3b343d2e69ef
fixed copy-paste with masked images.
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
3640 |
] |
1158
9b413954d34d
issue a warning, if information (mask) is
Claus Gittinger <cg@exept.de>
parents:
1121
diff
changeset
|
3641 |
] |
9b413954d34d
issue a warning, if information (mask) is
Claus Gittinger <cg@exept.de>
parents:
1121
diff
changeset
|
3642 |
] |
1027
5bffbe90b8e2
show a wait-cursor while saving
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
3643 |
] |
5bffbe90b8e2
show a wait-cursor while saving
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
3644 |
|
5600 | 3645 |
"Modified: / 13-09-2017 / 09:49:46 / cg" |
633 | 3646 |
! |
3647 |
||
2239 | 3648 |
saveAs |
3649 |
self saveImageFileAs |
|
3650 |
! |
|
3651 |
||
3652 |
saveButtonImageToFileAs |
|
3653 |
|fn| |
|
3654 |
||
3655 |
fn := self askForFileNameToSave:'Save Button Image to File'. |
|
3656 |
self saveButtonImageToFileAs:fn |
|
3657 |
||
3658 |
"Modified: / 30.9.1998 / 23:04:11 / cg" |
|
3659 |
! |
|
3660 |
||
3661 |
saveButtonImageToFileAs: aFileName |
|
3662 |
"save the image as if in a button in aFileName" |
|
3663 |
||
3664 |
|button grabbedImage| |
|
3665 |
||
3666 |
aFileName isNil ifTrue: [^nil]. |
|
3667 |
||
3668 |
image isNil ifTrue:[ |
|
4249 | 3669 |
self warn:(resources string:'No image or image mask to save!!'). |
2239 | 3670 |
^ self. |
3671 |
]. |
|
3672 |
||
3673 |
button := Button label:image. |
|
3674 |
button openAt:5@5. |
|
3675 |
button waitUntilVisible. |
|
3676 |
||
3677 |
grabbedImage := Image fromView:button. |
|
3678 |
button destroy. |
|
3679 |
||
3680 |
self save:grabbedImage imageOrMask:#image as:aFileName |
|
3681 |
||
3682 |
"/ self saveImageOrMask: #mask |
|
3683 |
! |
|
3684 |
||
3685 |
saveImageFileAs |
|
3686 |
"ask for a fileName and save the image" |
|
3687 |
||
3688 |
|fn| |
|
3689 |
||
3690 |
fn := self askForFileNameToSave:'Save Image To File'. |
|
3691 |
self saveImageFileAs:fn |
|
3692 |
! |
|
3693 |
||
3694 |
saveImageFileAs: aFileName |
|
3695 |
"save the image in aFileName" |
|
3696 |
||
3697 |
aFileName isNil ifTrue: [^nil]. |
|
3698 |
image notNil ifTrue:[ |
|
3699 |
self save:image imageOrMask:#image as:aFileName. |
|
3700 |
] ifFalse:[ |
|
4249 | 3701 |
self warn:(resources string:'No image for saving!!') |
2239 | 3702 |
] |
3703 |
||
3704 |
"Modified: / 30.9.1998 / 23:04:55 / cg" |
|
3705 |
! |
|
3706 |
||
3707 |
saveImageMaskFileAs |
|
3708 |
"ask for a fileName and save the mask only" |
|
3709 |
||
3710 |
|fn| |
|
3711 |
||
3712 |
fn := self askForFileNameToSave:'Save Image Mask To File'. |
|
3713 |
self saveImageMaskFileAs:fn |
|
3714 |
||
3715 |
"Modified: / 30.9.1998 / 23:04:11 / cg" |
|
3716 |
! |
|
3717 |
||
3718 |
saveImageMaskFileAs: aFileName |
|
3719 |
"save the mask only in aFileName" |
|
3720 |
||
3721 |
aFileName isNil ifTrue: [^nil]. |
|
3722 |
(image notNil and:[image mask notNil]) ifTrue:[ |
|
3723 |
self save:image imageOrMask:#mask as:aFileName. |
|
3724 |
] ifFalse:[ |
|
4249 | 3725 |
self warn:(resources string:'No image or image mask to save!!') |
2239 | 3726 |
] |
3727 |
||
3728 |
"Modified: / 30.9.1998 / 23:06:24 / cg" |
|
3729 |
! |
|
3730 |
||
3731 |
saveImageOrMask:what |
|
3732 |
"save the image or the mask only (if what == #mask)" |
|
3733 |
||
3734 |
self save:image imageOrMask: what |
|
3735 |
! |
|
3736 |
||
633 | 3737 |
saveMethod |
5364 | 3738 |
"save the image as a resource method. |
3739 |
Return true if ok; false if not" |
|
3740 |
||
4149 | 3741 |
(resourceSelector trimBlanks notEmptyOrNil and:[ resourceClass isBehavior ]) ifFalse: [ |
2915 | 3742 |
^ self saveMethodAs. |
2914 | 3743 |
]. |
3744 |
||
3745 |
windowGroup withExecuteCursorDo:[ |
|
3859 | 3746 |
Error handle:[:ex| |
3747 |
(self confirm:(ex errorString,'\\Debug?' withCRs)) ifTrue:[ ex reject ]. |
|
2915 | 3748 |
^ false |
2914 | 3749 |
] do: [ |
5286 | 3750 |
|img imageSaved depth bestDepth colorsUsed numColorsUsed category imageStoreStream sel mthd imageKey| |
4149 | 3751 |
|
3752 |
img := self image. |
|
4714 | 3753 |
depth := bestDepth := img depth. |
3754 |
colorsUsed := (img usedColorsMax:256). |
|
3755 |
colorsUsed notNil ifTrue:[ |
|
3756 |
numColorsUsed := colorsUsed size. |
|
3757 |
#(8 4 2 1) do:[:d | |
|
3758 |
depth > d ifTrue:[ |
|
3759 |
numColorsUsed <= (1 << d) ifTrue:[ |
|
3760 |
bestDepth := d |
|
3761 |
] |
|
4149 | 3762 |
] |
4714 | 3763 |
]. |
4149 | 3764 |
]. |
5286 | 3765 |
imageSaved := img. |
5656 | 3766 |
(image hasAlphaChannel not and:[ bestDepth < depth ]) ifTrue:[ |
5286 | 3767 |
|answer| |
3768 |
||
3769 |
answer := Dialog |
|
3770 |
confirmWithCancel:(resources stringWithCRs:'Hint:\\You can save some code space, by converting the image from a depth-%1 to a depth-%2 image first.\(only %3 colors used)\\Convert before saving?' |
|
3771 |
with:depth with:bestDepth with:numColorsUsed). |
|
3772 |
answer isNil ifTrue:[ |
|
5579 | 3773 |
"/ canceled |
4149 | 3774 |
^ false |
5286 | 3775 |
]. |
3776 |
answer == true ifTrue:[ |
|
3777 |
imageSaved := (Image implementorForDepth:bestDepth) fromImage:imageSaved |
|
3778 |
]. |
|
4149 | 3779 |
]. |
822
cace81f0a86b
do not overwrite method categories + toggle between mouse button colors
tz
parents:
796
diff
changeset
|
3780 |
|
4000
21106540ffb5
CodeGeneratorTool->SmalltalkCodeGeneratorTool
Claus Gittinger <cg@exept.de>
parents:
3980
diff
changeset
|
3781 |
SmalltalkCodeGeneratorTool |
5286 | 3782 |
createImageSpecMethodFor:imageSaved |
1882
fbb4a3a869f1
made image-method generator a class method (for reusability)
martin
parents:
1875
diff
changeset
|
3783 |
comment:(ResourceSpecEditor codeGenerationCommentForClass: ImageEditor) |
2915 | 3784 |
in:resourceClass class |
3785 |
selector:resourceSelector. |
|
822
cace81f0a86b
do not overwrite method categories + toggle between mouse button colors
tz
parents:
796
diff
changeset
|
3786 |
|
5364 | 3787 |
"/ flush cached images in the Icon class (kludge) |
1901
b4b286ec221f
flush cached icons, when defining a new image-method
Claus Gittinger <cg@exept.de>
parents:
1896
diff
changeset
|
3788 |
Icon flushCachedIcons. |
2590
b811d560e00a
modified flag after edit operations
Claus Gittinger <cg@exept.de>
parents:
2589
diff
changeset
|
3789 |
self clearModified. |
1901
b4b286ec221f
flush cached icons, when defining a new image-method
Claus Gittinger <cg@exept.de>
parents:
1896
diff
changeset
|
3790 |
|
2915 | 3791 |
LastSaveClass := resourceClass. |
1882
fbb4a3a869f1
made image-method generator a class method (for reusability)
martin
parents:
1875
diff
changeset
|
3792 |
] |
2915 | 3793 |
]. |
3794 |
^ true |
|
1027
5bffbe90b8e2
show a wait-cursor while saving
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
3795 |
|
4000
21106540ffb5
CodeGeneratorTool->SmalltalkCodeGeneratorTool
Claus Gittinger <cg@exept.de>
parents:
3980
diff
changeset
|
3796 |
"Modified: / 31-01-2011 / 18:28:06 / cg" |
5579 | 3797 |
"Modified (format): / 24-08-2017 / 15:02:51 / cg" |
633 | 3798 |
! |
3799 |
||
3800 |
saveMethodAs |
|
2915 | 3801 |
"ask for method/selector; save the image there. |
3802 |
Return true if saved, false if not" |
|
3803 |
||
5364 | 3804 |
|className classAndSelector |
3805 |
previousClass previousCategory previousSelector |
|
3806 |
previousMethod newMethod ok| |
|
3807 |
||
3808 |
previousSelector := self resourceSelector. |
|
2908
a759fa87d598
some code cleanup (resourceClass was actually its name)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
3809 |
className := self resourceClassName. |
a759fa87d598
some code cleanup (resourceClass was actually its name)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
3810 |
className isEmptyOrNil ifTrue:[ |
2177 | 3811 |
className := LastSaveClass |
1994 | 3812 |
]. |
5364 | 3813 |
(className notEmptyOrNil and:[previousSelector notNil]) ifTrue:[ |
3814 |
previousClass := Smalltalk classNamed:className. |
|
3815 |
previousClass notNil ifTrue:[ |
|
3816 |
previousMethod := previousClass class compiledMethodAt:previousSelector. |
|
3817 |
previousMethod notNil ifTrue:[ |
|
3818 |
previousCategory := previousMethod category. |
|
3819 |
] |
|
3820 |
] |
|
3821 |
]. |
|
633 | 3822 |
|
3840 | 3823 |
self withWaitCursorDo:[ |
3824 |
classAndSelector := ResourceSelectionBrowser |
|
3825 |
request: 'Save Image In Class' |
|
3826 |
onSuperclass: #Object |
|
3827 |
andClass: className |
|
3828 |
andSelector: self resourceSelector |
|
3829 |
withResourceTypes: #(image fileImage programImage). |
|
3830 |
]. |
|
2915 | 3831 |
classAndSelector isNil ifTrue:[^ false]. |
3832 |
||
3833 |
resourceClass := classAndSelector methodClass. |
|
3834 |
resourceSelector := classAndSelector methodSelector. |
|
3835 |
||
5364 | 3836 |
ok := self saveMethod. |
3837 |
ok ifTrue:[ |
|
3838 |
previousCategory notNil ifTrue:[ |
|
3839 |
newMethod := resourceClass class compiledMethodAt:resourceSelector asSymbol. |
|
3840 |
newMethod notNil ifTrue:[ |
|
3841 |
newMethod category:previousCategory. |
|
3842 |
] |
|
3843 |
] |
|
3844 |
]. |
|
3845 |
^ ok |
|
3846 |
||
3847 |
"Modified: / 25-11-2016 / 09:17:22 / cg" |
|
2915 | 3848 |
! ! |
3849 |
||
3850 |
!ImageEditView methodsFor:'printing'! |
|
3851 |
||
3852 |
||
3853 |
self printWithMagnification:1 |
|
3854 |
! |
|
3855 |
||
3856 |
printMagnified |
|
3857 |
self printWithMagnification:magnification |
|
3858 |
! |
|
3859 |
||
3860 |
printWithMagnification:magnification |
|
3861 |
|stream| |
|
3862 |
||
3863 |
image isNil ifTrue:[^ self]. |
|
3864 |
||
3865 |
Printer supportsPostscript ifFalse:[ |
|
4249 | 3866 |
^ self warn:(resources string:'No postscript printer configured !!') |
2915 | 3867 |
]. |
3868 |
||
3869 |
stream := Printer newNative. |
|
3870 |
stream isNil ifTrue:[ |
|
4249 | 3871 |
^ self warn:(resources string:'Cannot open printer stream !!') |
2915 | 3872 |
]. |
3873 |
||
3874 |
self withWaitCursorDo:[ |
|
3875 |
|psgc| |
|
3876 |
||
3877 |
psgc := PSGraphicsContext on:stream. |
|
3878 |
psgc displayForm: (image magnifiedBy: magnification) x:0 y:0. |
|
3879 |
psgc close |
|
3880 |
] |
|
1 | 3881 |
! ! |
3882 |
||
161 | 3883 |
!ImageEditView methodsFor:'queries'! |
5 | 3884 |
|
161 | 3885 |
heightOfContents |
3886 |
||
686 | 3887 |
image isNil ifTrue:[^0]. |
3888 |
^(image height * magnification y) rounded |
|
5 | 3889 |
! |
3890 |
||
995 | 3891 |
imageContainsPastePoint: aPoint |
5618 | 3892 |
^image notNil |
3893 |
and: [ ClipboardImage notNil |
|
3894 |
and: [ (0@0 corner:(image extent) "- 1" - ClipboardImage extent) |
|
3895 |
containsPoint: (((aPoint - margin + 1) / magnification) floor) |
|
3896 |
]] |
|
3897 |
||
3898 |
"Modified (format): / 08-10-2017 / 08:53:18 / cg" |
|
995 | 3899 |
! |
3900 |
||
627 | 3901 |
imageContainsPoint: aPoint |
632 | 3902 |
|
3903 |
^image notNil and: |
|
1116
441ff42c1472
fixes to allow 24bit images to be (at least) displayed
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
3904 |
[((0@0 corner:(image extent) - 1) containsPoint: (((aPoint - margin + 1) / magnification) floor))] |
627 | 3905 |
! |
3906 |
||
161 | 3907 |
widthOfContents |
5 | 3908 |
|
686 | 3909 |
image isNil ifTrue:[^0]. |
3910 |
^(image width * magnification x) rounded |
|
5 | 3911 |
! ! |
3912 |
||
627 | 3913 |
!ImageEditView methodsFor:'release'! |
3914 |
||
995 | 3915 |
releasePasteDrawing |
2085 | 3916 |
self repairDamage. |
5618 | 3917 |
(lastPastePoint notNil and: [ClipboardImageMagnified notNil]) |
2747 | 3918 |
ifTrue: [ |
5618 | 3919 |
self redraw: ((lastPastePoint"-self viewOrigin") extent: (ClipboardImageMagnified extent)). |
2085 | 3920 |
"/ self repairDamage. |
995 | 3921 |
]. |
5618 | 3922 |
lastPastePoint := ClipboardImageMagnified := nil |
3923 |
||
3924 |
"Modified: / 08-10-2017 / 08:55:06 / cg" |
|
995 | 3925 |
! |
3926 |
||
3927 |
releaseUndos |
|
3928 |
undoImages removeAll. |
|
627 | 3929 |
! ! |
3930 |
||
632 | 3931 |
!ImageEditView methodsFor:'testing'! |
3932 |
||
3933 |
checkModified |
|
2747 | 3934 |
modifiedHolder value ifTrue:[ |
2634 | 3935 |
((YesNoBox title:(resources string:'Image was not saved. Exit anyway ?')) |
2591
87cab7199c7e
Use 'Discard Changes and Exit' instead of 'Forget it...'
Stefan Vogel <sv@exept.de>
parents:
2590
diff
changeset
|
3936 |
noText:(resources string:'Cancel'); |
2634 | 3937 |
yesText:(resources string:'Exit without Saving'); |
2591
87cab7199c7e
Use 'Discard Changes and Exit' instead of 'Forget it...'
Stefan Vogel <sv@exept.de>
parents:
2590
diff
changeset
|
3938 |
showAtPointer; |
2747 | 3939 |
accepted |
3940 |
) ifFalse: [^false]. |
|
3941 |
||
3942 |
self modified:false. |
|
632 | 3943 |
]. |
2591
87cab7199c7e
Use 'Discard Changes and Exit' instead of 'Forget it...'
Stefan Vogel <sv@exept.de>
parents:
2590
diff
changeset
|
3944 |
^ true |
1031
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
3945 |
|
a5ab5869b2ba
cleaned up the interface to the apps infoPanel
Claus Gittinger <cg@exept.de>
parents:
1030
diff
changeset
|
3946 |
"Modified: / 29.7.1998 / 18:55:24 / cg" |
632 | 3947 |
! ! |
3948 |
||
255 | 3949 |
!ImageEditView class methodsFor:'documentation'! |
161 | 3950 |
|
3951 |
version |
|
4853 | 3952 |
^ '$Header$' |
3762 | 3953 |
! |
3954 |
||
3955 |
version_CVS |
|
4853 | 3956 |
^ '$Header$' |
161 | 3957 |
! ! |
2239 | 3958 |
|
4203 | 3959 |
|
1245 | 3960 |
ImageEditView initialize! |