1209 ] |
1209 ] |
1210 ]. |
1210 ]. |
1211 ]. |
1211 ]. |
1212 anyColorMissing ifTrue:[ |
1212 anyColorMissing ifTrue:[ |
1213 answer := Dialog |
1213 answer := Dialog |
1214 confirmWithCancel:'Some color(s) cannot be represented (colorMap full). Use nearest or compute colorMap ?' |
1214 confirmWithCancel:'Some color(s) cannot be represented (colorMap full).\Use nearest or compute colorMap ?' withCRs |
1215 labels:#('use nearest' 'new ColorMap' 'cancel') |
1215 labels:#( 'Cancel' 'New ColorMap' 'Use Nearest' ) |
1216 values:#(nearest new nil) |
1216 values:#( nil new nearest) |
1217 default:1. |
1217 default:3. |
1218 |
1218 |
1219 answer isNil ifTrue:[^ self]. |
1219 answer isNil ifTrue:[^ self]. |
1220 |
1220 |
1221 currentColorMap := image colorMap. |
1221 currentColorMap := image colorMap. |
1222 imgX := imagePoint x. |
1222 imgX := imagePoint x. |
1383 |
1383 |
1384 self pasteAt:aPoint mode:#withMask. |
1384 self pasteAt:aPoint mode:#withMask. |
1385 ! |
1385 ! |
1386 |
1386 |
1387 performSpecialOperationOn:imageBox withColor:clr |
1387 performSpecialOperationOn:imageBox withColor:clr |
1388 |operation x0 y0 x1 y1 grey| |
1388 |operation x0 y0 x1 y1 grey pixelAction requiredColors missingColors answer| |
1389 |
1389 |
1390 operation := Dialog |
1390 operation := Dialog |
1391 choose:'Which Operation:' |
1391 choose:'Which Operation:' |
1392 fromList:#( |
1392 fromList:#( |
1393 "/ 'brighten' |
1393 'slightly brightened' |
1394 "/ 'darken' |
1394 'slightly darkened' |
1395 "/ '-' |
1395 'brightened' |
1396 "/ 'greying' |
1396 'darkened' |
|
1397 '-' |
|
1398 'greyed' |
1397 'grey pattern' |
1399 'grey pattern' |
|
1400 '-' |
|
1401 'reversed' |
1398 ) |
1402 ) |
1399 values:#("brighten darken nil greying "greyPattern) |
1403 values:#(slightlyBrighter slightlyDarker brighter darker nil grey greyPattern nil reversed) |
1400 lines:6 |
1404 lines:6 |
1401 cancel:nil. |
1405 cancel:nil. |
1402 |
1406 |
1403 self invalidate. |
1407 self invalidate. |
1404 self windowGroup processExposeEvents. |
1408 self windowGroup processExposeEvents. |
1408 x0 := imageBox left. |
1412 x0 := imageBox left. |
1409 y0 := imageBox top. |
1413 y0 := imageBox top. |
1410 x1 := imageBox right - 1. |
1414 x1 := imageBox right - 1. |
1411 y1 := imageBox bottom -1 . |
1415 y1 := imageBox bottom -1 . |
1412 |
1416 |
|
1417 operation == #slightlyBrighter ifTrue:[ |
|
1418 pixelAction := [:x :y :clr | clr slightlyLightened]. |
|
1419 ]. |
|
1420 operation == #slightlyDarker ifTrue:[ |
|
1421 pixelAction := [:x :y :clr | clr slightlyDarkened]. |
|
1422 ]. |
1413 operation == #brighten ifTrue:[ |
1423 operation == #brighten ifTrue:[ |
1414 self image colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :clr | |
1424 pixelAction := [:x :y :clr | clr lightened]. |
1415 self image colorAtX:x y:y put:(clr lightened). |
|
1416 ]. |
|
1417 ^ true. |
|
1418 ]. |
1425 ]. |
1419 operation == #darken ifTrue:[ |
1426 operation == #darken ifTrue:[ |
1420 self image colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :clr | |
1427 pixelAction := [:x :y :clr | clr darkened]. |
1421 self image colorAtX:x y:y put:(clr darkened). |
1428 ]. |
1422 ]. |
1429 operation == #reversed ifTrue:[ |
1423 ^ true. |
1430 pixelAction := [:x :y :clr | Color red:(100-clr red) green:(100-clr green) blue:(100-clr blue) ]. |
1424 ]. |
1431 ]. |
1425 operation == #greying ifTrue:[ |
1432 operation == #greying ifTrue:[ |
1426 self image colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :clr | |
1433 pixelAction := [:x :y :clr | clr blendWith:Color grey]. |
1427 self image colorAtX:x y:y put:(clr blendWith:Color grey). |
|
1428 ]. |
|
1429 ^ true. |
|
1430 ]. |
1434 ]. |
1431 operation == #greyPattern ifTrue:[ |
1435 operation == #greyPattern ifTrue:[ |
1432 grey := Color grey nearestIn:(self image colorMap). |
1436 pixelAction := [:x :y :clr | Color grey]. |
1433 self image colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :clr | |
1437 ]. |
1434 (x + y )odd ifTrue:[ |
1438 pixelAction isNil ifTrue:[self halt. ^ false]. |
1435 self image colorAtX:x y:y put:grey. |
1439 |
1436 ] |
1440 "/ compute required colors ... |
1437 ]. |
1441 requiredColors := Set new. |
1438 ^ true. |
1442 self image |
1439 ]. |
1443 colorsFromX:x0 y:y0 toX:x1 y:y1 |
1440 |
1444 do:[:x :y :clr | |
1441 self halt. |
1445 requiredColors add:(pixelAction value:x value:y value:clr) |
1442 ^ false. |
1446 ]. |
|
1447 |
|
1448 missingColors := requiredColors select:[:clr | (image colorMap includes:clr) not]. |
|
1449 |
|
1450 missingColors notEmpty ifTrue:[ |
|
1451 answer := Dialog |
|
1452 confirmWithCancel:'Some color(s) cannot be represented in the images colorMap.\Use nearest or compute colorMap ?' withCRs |
|
1453 labels:#( 'Cancel' 'Add to ColorMap' 'Use Nearest') |
|
1454 values:#( nil add nearest) |
|
1455 default:3. |
|
1456 answer isNil ifTrue:[^ self]. |
|
1457 answer == #add ifTrue:[ |
|
1458 self halt:'this finction is not yet implemented'. |
|
1459 missingColors do:[:eachColor | |
|
1460 ]. |
|
1461 ^ false. |
|
1462 ]. |
|
1463 ]. |
|
1464 |
|
1465 "/ now, do it |
|
1466 self image |
|
1467 colorsFromX:x0 y:y0 toX:x1 y:y1 |
|
1468 do:[:x :y :clr | |
|
1469 |newClr| |
|
1470 |
|
1471 newClr := pixelAction value:x value:y value:clr. |
|
1472 answer == #nearest ifTrue:[ |
|
1473 newClr := newClr nearestIn:image colorMap |
|
1474 ]. |
|
1475 self image colorAtX:x y:y put:newClr |
|
1476 ]. |
|
1477 |
|
1478 ^ true. |
1443 ! |
1479 ! |
1444 |
1480 |
1445 pointAt:aPoint |
1481 pointAt:aPoint |
1446 "draw a single pixel with the currently selected color" |
1482 "draw a single pixel with the currently selected color" |
1447 |
1483 |