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