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