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