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