--- a/Depth8Image.st Wed Jan 24 14:40:55 2007 +0100
+++ b/Depth8Image.st Wed Jan 24 14:41:11 2007 +0100
@@ -75,16 +75,16 @@
OBJ b = _INST(bytes);
OBJ w = _INST(width);
- if (__isByteArray(b)
- && __bothSmallInteger(x, y)
+ if (__isByteArray(b)
+ && __bothSmallInteger(x, y)
&& __isSmallInteger(w) ) {
- int _idx, _pix;
+ int _idx, _pix;
- _idx = (__intVal(w) * __intVal(y)) + __intVal(x);
- if ((unsigned)_idx < __byteArraySize(b)) {
- _pix = __ByteArrayInstPtr(b)->ba_element[_idx];
- RETURN( __MKSMALLINT(_pix) );
- }
+ _idx = (__intVal(w) * __intVal(y)) + __intVal(x);
+ if ((unsigned)_idx < __byteArraySize(b)) {
+ _pix = __ByteArrayInstPtr(b)->ba_element[_idx];
+ RETURN( __MKSMALLINT(_pix) );
+ }
}
%}.
"/ the code below is only evaluated if the bytes-collection is
@@ -106,16 +106,16 @@
OBJ b = _INST(bytes);
OBJ w = _INST(width);
- if (__isByteArray(b)
- && __bothSmallInteger(x, y)
+ if (__isByteArray(b)
+ && __bothSmallInteger(x, y)
&& __bothSmallInteger(w, aPixelValue) ) {
- int _idx;
+ int _idx;
- _idx = (__intVal(w) * __intVal(y)) + __intVal(x);
- if ((unsigned)_idx < __byteArraySize(b)) {
- __ByteArrayInstPtr(b)->ba_element[_idx] = __intVal(aPixelValue);
- RETURN( self );
- }
+ _idx = (__intVal(w) * __intVal(y)) + __intVal(x);
+ if ((unsigned)_idx < __byteArraySize(b)) {
+ __ByteArrayInstPtr(b)->ba_element[_idx] = __intVal(aPixelValue);
+ RETURN( self );
+ }
}
%}.
"fall back code for nonByteArray or nonInteger arguments"
@@ -131,9 +131,9 @@
|srcIdx|
bytes notNil ifTrue:[
- srcIdx := (y * width) + 1.
- aPixelBuffer replaceFrom:startIndex to:startIndex+width-1 with:bytes startingAt:srcIdx.
- ^ self.
+ srcIdx := (y * width) + 1.
+ aPixelBuffer replaceFrom:startIndex to:startIndex+width-1 with:bytes startingAt:srcIdx.
+ ^ self.
].
^ super rowAt:y into:aPixelBuffer startingAt:startIndex
@@ -166,12 +166,12 @@
dstIdx "{ Class: SmallInteger }"
w "{ Class: SmallInteger }"
h "{ Class: SmallInteger }"
- srcBuffer dstBuffer srcBytes
+ srcBuffer dstBuffer srcBytes
srcDepth map bytes|
srcDepth := anImage depth.
(#(1 2 4) includes:srcDepth) ifFalse:[
- ^ super fromImage:anImage
+ ^ super fromImage:anImage
].
width := w := anImage width.
@@ -182,14 +182,14 @@
self colormapFromImage:anImage.
colorMap isNil ifTrue:[
- "/ if source has no colorMap, more work is needed ...
- map := #(
- #[0 16rFF]
- #[0 16r55 16rAA 16rFF]
- nil
- #[16r00 16r11 16r22 16r33 16r44 16r55 16r66 16r77
- 16r88 16r99 16rAA 16rBB 16rCC 16rDD 16rEE 16rFF]
- ) at:srcDepth.
+ "/ if source has no colorMap, more work is needed ...
+ map := #(
+ #[0 16rFF]
+ #[0 16r55 16rAA 16rFF]
+ nil
+ #[16r00 16r11 16r22 16r33 16r44 16r55 16r66 16r77
+ 16r88 16r99 16rAA 16rBB 16rCC 16rDD 16rEE 16rFF]
+ ) at:srcDepth.
].
self mask:anImage mask.
@@ -205,14 +205,14 @@
dstIdx := 1.
bytes := self bits.
bytes isNil ifTrue:[
- self bits:(bytes := ByteArray new:(self bytesPerRow * self height)).
+ self bits:(bytes := ByteArray new:(self bytesPerRow * self height)).
].
1 to:h do:[:hi |
- srcBuffer replaceFrom:1 to:srcBytesPerRow with:srcBytes startingAt:srcIdx.
- srcBuffer expandPixels:srcDepth width:w height:1 into:dstBuffer mapping:map.
- bytes replaceFrom:dstIdx to:dstIdx+w-1 with:dstBuffer startingAt:1.
- dstIdx := dstIdx + w.
- srcIdx := srcIdx + srcBytesPerRow.
+ srcBuffer replaceFrom:1 to:srcBytesPerRow with:srcBytes startingAt:srcIdx.
+ srcBuffer expandPixels:srcDepth width:w height:1 into:dstBuffer mapping:map.
+ bytes replaceFrom:dstIdx to:dstIdx+w-1 with:dstBuffer startingAt:1.
+ dstIdx := dstIdx + w.
+ srcIdx := srcIdx + srcBytesPerRow.
]
"
@@ -236,52 +236,52 @@
!Depth8Image methodsFor:'converting images'!
anyImageAsPseudoFormOn:aDevice
- "return a pseudoForm from the palette picture.
+ "return a pseudoForm from the palette picture.
The main work is in color reduction, when not all colors can be aquired.
This method works for any photometric."
|bytes pseudoBits f gcRound has8BitImage deviceDepth
imgMap newImage pixelRow dColors
usedColors usageCounts maxIndex map
- fit scale lastOK error
- div
+ fit scale lastOK error
+ div
bitsPerRGB "{Class: SmallInteger }"
shift "{Class: SmallInteger }"
- m "{Class: SmallInteger }"
- mapSize "{Class: SmallInteger }"
+ m "{Class: SmallInteger }"
+ mapSize "{Class: SmallInteger }"
cube nR nG nB ditherColors clr|
(cube := aDevice fixColors) notNil ifTrue:[
- nR := aDevice numFixRed.
- nG := aDevice numFixGreen.
- nB := aDevice numFixBlue.
+ nR := aDevice numFixRed.
+ nG := aDevice numFixGreen.
+ nB := aDevice numFixBlue.
- DitherAlgorithm == #floydSteinberg ifTrue:[
- f := self
- asFloydSteinbergDitheredDepth8FormOn:aDevice
- colors:cube
- nRed:nR
- nGreen:nG
- nBlue:nB.
- ] ifFalse:[
- f := self
- asNearestPaintDepth8FormOn:aDevice
- colors:cube
- nRed:nR
- nGreen:nG
- nBlue:nB.
- ].
- f notNil ifTrue:[^ f].
+ DitherAlgorithm == #floydSteinberg ifTrue:[
+ f := self
+ asFloydSteinbergDitheredDepth8FormOn:aDevice
+ colors:cube
+ nRed:nR
+ nGreen:nG
+ nBlue:nB.
+ ] ifFalse:[
+ f := self
+ asNearestPaintDepth8FormOn:aDevice
+ colors:cube
+ nRed:nR
+ nGreen:nG
+ nBlue:nB.
+ ].
+ f notNil ifTrue:[^ f].
].
"find used colors"
bytes := self bits.
usedColors := bytes usedValues. "gets us an array filled with used values"
- "(could use bytes asBag)"
+ "(could use bytes asBag)"
maxIndex := usedColors max + 1.
usedColors size > 20 ifTrue:[
- ('Depth8Image [info]: allocating ' , usedColors size printString , ' colors ...') infoPrintCR.
+ ('Depth8Image [info]: allocating ' , usedColors size printString , ' colors ...') infoPrintCR.
].
"sort by usage"
@@ -307,190 +307,190 @@
gcRound := 0.
usedColors do:[:aColorIndex |
- |devColor color
- r "{Class: SmallInteger }"
- g "{Class: SmallInteger }"
- b "{Class: SmallInteger }"
- mapIndex "{Class: SmallInteger }"|
+ |devColor color
+ r "{Class: SmallInteger }"
+ g "{Class: SmallInteger }"
+ b "{Class: SmallInteger }"
+ mapIndex "{Class: SmallInteger }"|
- fit ifTrue:[
- mapIndex := aColorIndex + 1.
- "/ color := colorMap at:mapIndex.
+ fit ifTrue:[
+ mapIndex := aColorIndex + 1.
+ "/ color := colorMap at:mapIndex.
- color := self colorFromValue:aColorIndex.
- (color isOnDevice:aDevice) ifTrue:[
- "wow - an immediate hit"
- devColor := color
- ] ifFalse:[
- devColor := color exactOn:aDevice.
- devColor isNil ifTrue:[
- "
- could not allocate color - on the first round, do a GC to flush
- unused colors - this may help if some colors where locked by
- already free images.
- "
- gcRound == 0 ifTrue:[
- ObjectMemory scavenge; finalize.
- devColor := color exactOn:aDevice.
- gcRound := 1
- ].
- devColor isNil ifTrue:[
- gcRound == 1 ifTrue:[
- CollectGarbageWhenRunningOutOfColors ifTrue:[
- 'Depth8Image [info]: force GC for possible color reclamation.' infoPrintCR.
- ObjectMemory incrementalGC; finalize.
- devColor := color exactOn:aDevice.
- ].
- gcRound := 2
- ]
- ]
- ].
- ].
- (devColor notNil and:[devColor colorId notNil]) ifTrue:[
- imgMap at:mapIndex put:devColor.
- lastOK := lastOK + 1.
- ] ifFalse:[
- fit := false
- ]
- ]
+ color := self colorFromValue:aColorIndex.
+ (color isOnDevice:aDevice) ifTrue:[
+ "wow - an immediate hit"
+ devColor := color
+ ] ifFalse:[
+ devColor := color exactOn:aDevice.
+ devColor isNil ifTrue:[
+ "
+ could not allocate color - on the first round, do a GC to flush
+ unused colors - this may help if some colors where locked by
+ already free images.
+ "
+ gcRound == 0 ifTrue:[
+ ObjectMemory scavenge; finalize.
+ devColor := color exactOn:aDevice.
+ gcRound := 1
+ ].
+ devColor isNil ifTrue:[
+ gcRound == 1 ifTrue:[
+ CollectGarbageWhenRunningOutOfColors ifTrue:[
+ 'Depth8Image [info]: force GC for possible color reclamation.' infoPrintCR.
+ ObjectMemory incrementalGC; finalize.
+ devColor := color exactOn:aDevice.
+ ].
+ gcRound := 2
+ ]
+ ]
+ ].
+ ].
+ (devColor notNil and:[devColor colorId notNil]) ifTrue:[
+ imgMap at:mapIndex put:devColor.
+ lastOK := lastOK + 1.
+ ] ifFalse:[
+ fit := false
+ ]
+ ]
].
fit ifFalse:[
- ('Depth8Image [info]: got %1 exact colors (out of %2)' bindWith:lastOK with:usedColors size) infoPrintCR.
+ ('Depth8Image [info]: got %1 exact colors (out of %2)' bindWith:lastOK with:usedColors size) infoPrintCR.
- DitherAlgorithm == #floydSteinberg ifTrue:[
- dColors := imgMap collect:[:clr | clr isNil ifTrue:[clr]
- ifFalse:[clr nearestOn:aDevice]].
- dColors := dColors select:[:clr | clr notNil].
- dColors := dColors collect:[:clr | clr exactOn:aDevice].
- dColors := dColors select:[:clr | clr notNil].
- dColors := dColors asSet.
- dColors addAll:((aDevice colorMap collect:[:c|c onDevice:aDevice])
- select:[:c | c colorId notNil]).
- ditherColors := aDevice availableDitherColors.
- ditherColors notNil ifTrue:[
- dColors addAll:ditherColors.
- ].
- dColors := dColors asArray.
- dColors size > 256 ifTrue:[
- dColors := dColors copyTo:256
- ].
- ^ self asFloydSteinbergDitheredPseudoFormUsing:dColors on:aDevice
- ].
+ DitherAlgorithm == #floydSteinberg ifTrue:[
+ dColors := imgMap collect:[:clr | clr isNil ifTrue:[clr]
+ ifFalse:[clr nearestOn:aDevice]].
+ dColors := dColors select:[:clr | clr notNil].
+ dColors := dColors collect:[:clr | clr exactOn:aDevice].
+ dColors := dColors select:[:clr | clr notNil].
+ dColors := dColors asSet.
+ dColors addAll:((aDevice colorMap collect:[:c|c onDevice:aDevice])
+ select:[:c | c colorId notNil]).
+ ditherColors := aDevice availableDitherColors.
+ ditherColors notNil ifTrue:[
+ dColors addAll:ditherColors.
+ ].
+ dColors := dColors asArray.
+ dColors size > 256 ifTrue:[
+ dColors := dColors copyTo:256
+ ].
+ ^ self asFloydSteinbergDitheredPseudoFormUsing:dColors on:aDevice
+ ].
- "
- again, this time allow wrong colors (loop while increasing allowed error)
- "
- error := 1.
- [fit] whileFalse:[
- fit := true.
- usedColors from:(lastOK+1) to:(usedColors size) do:[:aColorIndex |
- |devColor color
- r "{Class: SmallInteger }"
- g "{Class: SmallInteger }"
- b "{Class: SmallInteger }"
- mapIndex "{Class: SmallInteger }"
- rMask "{Class: SmallInteger }"
- gMask "{Class: SmallInteger }"
- bMask "{Class: SmallInteger }"|
+ "
+ again, this time allow wrong colors (loop while increasing allowed error)
+ "
+ error := 1.
+ [fit] whileFalse:[
+ fit := true.
+ usedColors from:(lastOK+1) to:(usedColors size) do:[:aColorIndex |
+ |devColor color
+ r "{Class: SmallInteger }"
+ g "{Class: SmallInteger }"
+ b "{Class: SmallInteger }"
+ mapIndex "{Class: SmallInteger }"
+ rMask "{Class: SmallInteger }"
+ gMask "{Class: SmallInteger }"
+ bMask "{Class: SmallInteger }"|
- fit ifTrue:[
- gMask := bMask := rMask := m.
+ fit ifTrue:[
+ gMask := bMask := rMask := m.
- mapIndex := aColorIndex + 1.
- "/ color := colorMap at:mapIndex.
- color := self colorFromValue:aColorIndex.
- r := (color red * 255 / 100.0) rounded.
- g := (color green * 255 / 100.0) rounded.
- b := (color blue * 255 / 100.0) rounded.
+ mapIndex := aColorIndex + 1.
+ "/ color := colorMap at:mapIndex.
+ color := self colorFromValue:aColorIndex.
+ r := (color red * 255 / 100.0) rounded.
+ g := (color green * 255 / 100.0) rounded.
+ b := (color blue * 255 / 100.0) rounded.
- color := Color red:((r bitShift:shift) bitAnd:rMask) * scale
- green:((g bitShift:shift) bitAnd:gMask) * scale
- blue:((b bitShift:shift) bitAnd:bMask) * scale.
+ color := Color red:((r bitShift:shift) bitAnd:rMask) * scale
+ green:((g bitShift:shift) bitAnd:gMask) * scale
+ blue:((b bitShift:shift) bitAnd:bMask) * scale.
- (color isOnDevice:aDevice) ifTrue:[
- "wow - an immediate hit"
- devColor := color.
- ] ifFalse:[
- devColor := color nearestOn:aDevice.
- (devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[
- devColor := nil
- ].
- devColor isNil ifTrue:[
- "
- no free color - on the first round, do a GC to flush unused
- colors - this may help if some colors where locked by already
- free images.
- "
- gcRound == 0 ifTrue:[
- ObjectMemory scavenge; finalize.
- devColor := color nearestOn:aDevice.
- (devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[
- devColor := nil
- ].
- gcRound := 1
- ].
- devColor isNil ifTrue:[
- gcRound == 1 ifTrue:[
- CollectGarbageWhenRunningOutOfColors ifTrue:[
- 'Depth8Image [info]: force GC for possible color reclamation.' infoPrintCR.
- ObjectMemory incrementalGC; finalize.
- devColor := color nearestOn:aDevice.
- (devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[
- devColor := nil
- ].
- ].
- gcRound := 2
- ]
- ]
- ].
- ].
- (devColor notNil and:[devColor colorId notNil]) ifTrue:[
- imgMap at:mapIndex put:devColor.
- lastOK := lastOK + 1.
- ] ifFalse:[
- fit := false
- ]
- ].
- ].
+ (color isOnDevice:aDevice) ifTrue:[
+ "wow - an immediate hit"
+ devColor := color.
+ ] ifFalse:[
+ devColor := color nearestOn:aDevice.
+ (devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[
+ devColor := nil
+ ].
+ devColor isNil ifTrue:[
+ "
+ no free color - on the first round, do a GC to flush unused
+ colors - this may help if some colors where locked by already
+ free images.
+ "
+ gcRound == 0 ifTrue:[
+ ObjectMemory scavenge; finalize.
+ devColor := color nearestOn:aDevice.
+ (devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[
+ devColor := nil
+ ].
+ gcRound := 1
+ ].
+ devColor isNil ifTrue:[
+ gcRound == 1 ifTrue:[
+ CollectGarbageWhenRunningOutOfColors ifTrue:[
+ 'Depth8Image [info]: force GC for possible color reclamation.' infoPrintCR.
+ ObjectMemory incrementalGC; finalize.
+ devColor := color nearestOn:aDevice.
+ (devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[
+ devColor := nil
+ ].
+ ].
+ gcRound := 2
+ ]
+ ]
+ ].
+ ].
+ (devColor notNil and:[devColor colorId notNil]) ifTrue:[
+ imgMap at:mapIndex put:devColor.
+ lastOK := lastOK + 1.
+ ] ifFalse:[
+ fit := false
+ ]
+ ].
+ ].
- fit ifTrue:[
- ('Depth8Image [info]: remaining colors with error <= %1' bindWith:error) infoPrintCR.
- ].
+ fit ifTrue:[
+ ('Depth8Image [info]: remaining colors with error <= %1' bindWith:error) infoPrintCR.
+ ].
- error := error * 2.
- error > 100 ifTrue:[
- "
- break out, if the error becomes too big.
- "
- 'Depth8Image [info]: hard color allocation problem - revert to b&w for remaining colors' infoPrintCR.
- "
- map to b&w as a last fallback.
- (should really do a dither here)
- "
- usedColors from:(lastOK+1) to:(usedColors size) do:[:aColorIndex |
- |color
- mapIndex "{ Class: SmallInteger }"|
+ error := error * 2.
+ error > 100 ifTrue:[
+ "
+ break out, if the error becomes too big.
+ "
+ 'Depth8Image [info]: hard color allocation problem - revert to b&w for remaining colors' infoPrintCR.
+ "
+ map to b&w as a last fallback.
+ (should really do a dither here)
+ "
+ usedColors from:(lastOK+1) to:(usedColors size) do:[:aColorIndex |
+ |color
+ mapIndex "{ Class: SmallInteger }"|
- mapIndex := aColorIndex + 1.
- "/ color := colorMap at:mapIndex.
- color := self colorFromValue:aColorIndex.
- color brightness > 0.4 ifTrue:[
- color := Color white.
- ] ifFalse:[
- color := Color black.
- ].
- imgMap at:mapIndex put:(color onDevice:aDevice).
- ].
- fit := true.
- ]
- ].
+ mapIndex := aColorIndex + 1.
+ "/ color := colorMap at:mapIndex.
+ color := self colorFromValue:aColorIndex.
+ color brightness > 0.4 ifTrue:[
+ color := Color white.
+ ] ifFalse:[
+ color := Color black.
+ ].
+ imgMap at:mapIndex put:(color onDevice:aDevice).
+ ].
+ fit := true.
+ ]
+ ].
- error > 10 ifTrue:[
- 'Depth8Image [info]: not enough colors for a reasonable image' infoPrintCR
- ] ifFalse:[
- 'Depth8Image [info]: not enough colors for exact picture' infoPrintCR.
- ]
+ error > 10 ifTrue:[
+ 'Depth8Image [info]: not enough colors for a reasonable image' infoPrintCR
+ ] ifFalse:[
+ 'Depth8Image [info]: not enough colors for exact picture' infoPrintCR.
+ ]
].
"
@@ -499,9 +499,9 @@
mapSize := imgMap size.
map := ByteArray new:256.
1 to:mapSize do:[:i |
- (clr := imgMap at:i) notNil ifTrue:[
- map at:i put:clr colorId
- ]
+ (clr := imgMap at:i) notNil ifTrue:[
+ map at:i put:clr colorId
+ ]
].
"
@@ -509,38 +509,38 @@
"
deviceDepth := aDevice depth.
has8BitImage := (deviceDepth == 8)
- or:[ (aDevice supportedImageFormatForDepth:8) notNil ].
+ or:[ (aDevice supportedImageFormatForDepth:8) notNil ].
"
finally, create a form on the device and copy (& translate)
the pixel values
"
has8BitImage ifTrue:[
- pseudoBits := ByteArray uninitializedNew:(width * height).
+ pseudoBits := ByteArray uninitializedNew:(width * height).
- bytes
- expandPixels:8 "xlate only"
- width:width height:height
- into:pseudoBits
- mapping:map.
+ bytes
+ expandPixels:8 "xlate only"
+ width:width height:height
+ into:pseudoBits
+ mapping:map.
- map := nil.
+ map := nil.
- f := Form width:width height:height depth:deviceDepth on:aDevice.
- f isNil ifTrue:[^ nil].
- f colorMap:imgMap.
- f initGC.
- aDevice
- drawBits:pseudoBits
- bitsPerPixel:8
- depth:deviceDepth
- padding:8
- width:width height:height
- x:0 y:0
- into:(f id) x:0 y:0
- width:width height:height
- with:(f gcId).
- ^ f
+ f := Form width:width height:height depth:deviceDepth on:aDevice.
+ f isNil ifTrue:[^ nil].
+ f colorMap:imgMap.
+ f initGC.
+ aDevice
+ drawBits:pseudoBits
+ bitsPerPixel:8
+ depth:deviceDepth
+ padding:8
+ width:width height:height
+ x:0 y:0
+ into:(f id) x:0 y:0
+ width:width height:height
+ with:(f gcId).
+ ^ f
].
"
@@ -553,30 +553,30 @@
newImage bits:(ByteArray uninitializedNew:(height * newImage bytesPerRow)).
0 to:height-1 do:[:row |
- pixelRow := self rowAt:row.
- pixelRow
- expandPixels:8 "xlate only"
- width:width
- height:1
- into:pixelRow
- mapping:map.
- newImage rowAt:row putAll:pixelRow
+ pixelRow := self rowAt:row.
+ pixelRow
+ expandPixels:8 "xlate only"
+ width:width
+ height:1
+ into:pixelRow
+ mapping:map.
+ newImage rowAt:row putAll:pixelRow
].
f := Form width:width height:height depth:deviceDepth on:aDevice.
f isNil ifTrue:[^ nil].
- f colorMap:imgMap.
+ f colorMap:imgMap.
f initGC.
aDevice
- drawBits:(newImage bits)
- depth:deviceDepth
- padding:8
- width:width height:height
- x:0 y:0
- into:(f id) x:0 y:0
- width:width height:height
- with:(f gcId).
+ drawBits:(newImage bits)
+ depth:deviceDepth
+ padding:8
+ width:width height:height
+ x:0 y:0
+ into:(f id) x:0 y:0
+ width:width height:height
+ with:(f gcId).
^ f
@@ -588,9 +588,9 @@
"return a true-color device-form for the receiver.
Supports true color devices with depths: 8, 16, 24 and 32"
- |depth
- colorValues
- form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel
+ |depth
+ colorValues
+ form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel
usedDevicePadding usedDeviceBytesPerRow padd|
depth := aDevice depth.
@@ -602,7 +602,7 @@
bestFormat := self bestSupportedImageFormatFor:aDevice.
usedDeviceDepth := bestFormat at:#depth.
usedDeviceDepth == 1 ifTrue:[
- ^ self asMonochromeFormOn:aDevice
+ ^ self asMonochromeFormOn:aDevice
].
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
usedDevicePadding := bestFormat at:#padding.
@@ -614,330 +614,330 @@
"/ for now, only support some depths
usedDeviceBitsPerPixel == 16 ifTrue:[
- "/ 16 bits/pixel
+ "/ 16 bits/pixel
- "/ now, walk over the image and replace
- "/ colorMap indices by color values in the bits array
+ "/ now, walk over the image and replace
+ "/ colorMap indices by color values in the bits array
-%{
- unsigned char *srcPtr = 0;
- unsigned char *dstPtr = 0;
- OBJ _bytes = __INST(bytes);
+%{
+ unsigned char *srcPtr = 0;
+ unsigned char *dstPtr = 0;
+ OBJ _bytes = __INST(bytes);
- if (__isByteArray(_bytes)) {
- srcPtr = _ByteArrayInstPtr(_bytes)->ba_element;
- } else {
- if (__isExternalBytesLike(_bytes)) {
- srcPtr = __externalBytesAddress(_bytes);
- }
- }
- if (__isByteArray(imageBits)) {
- dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
- } else {
- if (__isExternalBytesLike(imageBits)) {
- dstPtr = __externalBytesAddress(imageBits);
- }
- }
+ if (__isByteArray(_bytes)) {
+ srcPtr = _ByteArrayInstPtr(_bytes)->ba_element;
+ } else {
+ if (__isExternalBytesLike(_bytes)) {
+ srcPtr = __externalBytesAddress(_bytes);
+ }
+ }
+ if (__isByteArray(imageBits)) {
+ dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
+ } else {
+ if (__isExternalBytesLike(imageBits)) {
+ dstPtr = __externalBytesAddress(imageBits);
+ }
+ }
- if (__bothSmallInteger(_INST(height), _INST(width))
- && __isArrayLike(colorValues)
- && srcPtr
- && dstPtr) {
- int r,p;
- int x, y, w, h, nPix;
- unsigned short pixels[256];
+ if (__bothSmallInteger(_INST(height), _INST(width))
+ && __isArrayLike(colorValues)
+ && srcPtr
+ && dstPtr) {
+ int r,p;
+ int x, y, w, h, nPix;
+ unsigned short pixels[256];
- OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
+ OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
- nPix = __arraySize(colorValues);
- for (p=0; p<nPix; p++) {
- pixels[p] = __intVal(ap[p]);
- }
+ nPix = __arraySize(colorValues);
+ for (p=0; p<nPix; p++) {
+ pixels[p] = __intVal(ap[p]);
+ }
- w = __intVal(_INST(width));
- h = __intVal(_INST(height));
- r = w;
- p = __intVal(padd);
- nPix = w * h;
+ w = __intVal(_INST(width));
+ h = __intVal(_INST(height));
+ r = w;
+ p = __intVal(padd);
+ nPix = w * h;
- while (nPix > 0) {
- unsigned idx, v;
+ while (nPix > 0) {
+ unsigned idx, v;
- if (((unsigned INT)srcPtr & 3) == 0) {
- unsigned INT idx4;
+ if (((unsigned INT)srcPtr & 3) == 0) {
+ unsigned INT idx4;
- while (r > 4) {
-#ifdef __MSBFIRST
- idx4 = ((unsigned int *)srcPtr)[0];
- v = pixels[(idx4 >> 24) & 0xFF];
- ((short *)dstPtr)[0] = v;
- v = pixels[(idx4 >> 16) & 0xFF];
- ((short *)dstPtr)[1] = v;
- v = pixels[(idx4 >> 8) & 0xFF];
- ((short *)dstPtr)[2] = v;
- v = pixels[idx4 & 0xFF];
- ((short *)dstPtr)[3] = v;
+ while (r > 4) {
+#ifdef __MSBFIRST
+ idx4 = ((unsigned int *)srcPtr)[0];
+ v = pixels[(idx4 >> 24) & 0xFF];
+ ((short *)dstPtr)[0] = v;
+ v = pixels[(idx4 >> 16) & 0xFF];
+ ((short *)dstPtr)[1] = v;
+ v = pixels[(idx4 >> 8) & 0xFF];
+ ((short *)dstPtr)[2] = v;
+ v = pixels[idx4 & 0xFF];
+ ((short *)dstPtr)[3] = v;
#else
-# ifdef __LSBFIRST
- idx4 = ((unsigned int *)srcPtr)[0];
- v = pixels[idx4 & 0xFF];
- dstPtr[0] = (v>>8) & 0xFF;
- dstPtr[1] = (v) & 0xFF;
+# ifdef __LSBFIRST
+ idx4 = ((unsigned int *)srcPtr)[0];
+ v = pixels[idx4 & 0xFF];
+ dstPtr[0] = (v>>8) & 0xFF;
+ dstPtr[1] = (v) & 0xFF;
- v = pixels[(idx4 >> 8) & 0xFF];
- dstPtr[2] = (v>>8) & 0xFF;
- dstPtr[3] = (v) & 0xFF;
+ v = pixels[(idx4 >> 8) & 0xFF];
+ dstPtr[2] = (v>>8) & 0xFF;
+ dstPtr[3] = (v) & 0xFF;
- v = pixels[(idx4 >> 16) & 0xFF];
- dstPtr[4] = (v>>8) & 0xFF;
- dstPtr[5] = (v) & 0xFF;
+ v = pixels[(idx4 >> 16) & 0xFF];
+ dstPtr[4] = (v>>8) & 0xFF;
+ dstPtr[5] = (v) & 0xFF;
- v = pixels[(idx4 >> 24) & 0xFF];
- dstPtr[6] = (v>>8) & 0xFF;
- dstPtr[7] = (v) & 0xFF;
+ v = pixels[(idx4 >> 24) & 0xFF];
+ dstPtr[6] = (v>>8) & 0xFF;
+ dstPtr[7] = (v) & 0xFF;
# else /* unknown/unspecified - code below works on any machine */
- idx = srcPtr[0];
- v = pixels[idx];
- dstPtr[0] = (v>>8) & 0xFF;
- dstPtr[1] = (v) & 0xFF;
+ idx = srcPtr[0];
+ v = pixels[idx];
+ dstPtr[0] = (v>>8) & 0xFF;
+ dstPtr[1] = (v) & 0xFF;
- idx = srcPtr[1];
- v = pixels[idx];
- dstPtr[2] = (v>>8) & 0xFF;
- dstPtr[3] = (v) & 0xFF;
+ idx = srcPtr[1];
+ v = pixels[idx];
+ dstPtr[2] = (v>>8) & 0xFF;
+ dstPtr[3] = (v) & 0xFF;
- idx = srcPtr[2];
- v = pixels[idx];
- dstPtr[4] = (v>>8) & 0xFF;
- dstPtr[5] = (v) & 0xFF;
+ idx = srcPtr[2];
+ v = pixels[idx];
+ dstPtr[4] = (v>>8) & 0xFF;
+ dstPtr[5] = (v) & 0xFF;
- idx = srcPtr[3];
- v = pixels[idx];
- dstPtr[6] = (v>>8) & 0xFF;
- dstPtr[7] = (v) & 0xFF;
+ idx = srcPtr[3];
+ v = pixels[idx];
+ dstPtr[6] = (v>>8) & 0xFF;
+ dstPtr[7] = (v) & 0xFF;
# endif
#endif
- r -= 4;
- dstPtr += 8;
- nPix -= 4;
- srcPtr +=4;
- }
- }
+ r -= 4;
+ dstPtr += 8;
+ nPix -= 4;
+ srcPtr +=4;
+ }
+ }
- nPix--;
+ nPix--;
- idx = *srcPtr++;
- v = pixels[idx];
+ idx = *srcPtr++;
+ v = pixels[idx];
#ifdef __MSBFIRST
- ((short *)dstPtr)[0] = v;
+ ((short *)dstPtr)[0] = v;
#else
- dstPtr[0] = (v>>8) & 0xFF;
- dstPtr[1] = (v) & 0xFF;
+ dstPtr[0] = (v>>8) & 0xFF;
+ dstPtr[1] = (v) & 0xFF;
#endif
- dstPtr += 2;
+ dstPtr += 2;
- if (--r == 0) {
- dstPtr += p;
- r = w;
- }
- }
- }
+ if (--r == 0) {
+ dstPtr += p;
+ r = w;
+ }
+ }
+ }
%}.
] ifFalse:[
- usedDeviceBitsPerPixel == 32 ifTrue:[
- "/ 32 bits/pixel
+ usedDeviceBitsPerPixel == 32 ifTrue:[
+ "/ 32 bits/pixel
- "/ now, walk over the image and replace
- "/ colorMap indices by color values in the bits array
+ "/ now, walk over the image and replace
+ "/ colorMap indices by color values in the bits array
-%{
- unsigned char *srcPtr = 0;
- unsigned char *dstPtr = 0;
- OBJ _bytes = __INST(bytes);
+%{
+ unsigned char *srcPtr = 0;
+ unsigned char *dstPtr = 0;
+ OBJ _bytes = __INST(bytes);
- if (__isByteArray(_bytes)) {
- srcPtr = _ByteArrayInstPtr(_bytes)->ba_element;
- } else {
- if (__isExternalBytesLike(_bytes)) {
- srcPtr = __externalBytesAddress(_bytes);
- }
- }
- if (__isByteArray(imageBits)) {
- dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
- } else {
- if (__isExternalBytesLike(imageBits)) {
- dstPtr = __externalBytesAddress(imageBits);
- }
- }
+ if (__isByteArray(_bytes)) {
+ srcPtr = _ByteArrayInstPtr(_bytes)->ba_element;
+ } else {
+ if (__isExternalBytesLike(_bytes)) {
+ srcPtr = __externalBytesAddress(_bytes);
+ }
+ }
+ if (__isByteArray(imageBits)) {
+ dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
+ } else {
+ if (__isExternalBytesLike(imageBits)) {
+ dstPtr = __externalBytesAddress(imageBits);
+ }
+ }
- if (__bothSmallInteger(_INST(height), _INST(width))
- && __isArrayLike(colorValues)
- && srcPtr
- && dstPtr) {
- int x, y, w, h, nPix;
+ if (__bothSmallInteger(_INST(height), _INST(width))
+ && __isArrayLike(colorValues)
+ && srcPtr
+ && dstPtr) {
+ int x, y, w, h, nPix;
- OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
+ OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
- w = __intVal(_INST(width));
- h = __intVal(_INST(height));
- nPix = w * h;
- while (nPix > 0) {
- unsigned idx, v;
- OBJ clr;
+ w = __intVal(_INST(width));
+ h = __intVal(_INST(height));
+ nPix = w * h;
+ while (nPix > 0) {
+ unsigned idx, v;
+ OBJ clr;
- idx = *srcPtr;
- clr = ap[idx];
- v = __intVal(clr);
+ idx = *srcPtr;
+ clr = ap[idx];
+ v = __intVal(clr);
#ifdef __MSBFIRST
- ((long *)dstPtr)[0] = v;
+ ((long *)dstPtr)[0] = v;
#else
- dstPtr[0] = (v>>24) & 0xFF;
- dstPtr[1] = (v>>16) & 0xFF;
- dstPtr[2] = (v>>8) & 0xFF;
- dstPtr[3] = (v) & 0xFF;
+ dstPtr[0] = (v>>24) & 0xFF;
+ dstPtr[1] = (v>>16) & 0xFF;
+ dstPtr[2] = (v>>8) & 0xFF;
+ dstPtr[3] = (v) & 0xFF;
#endif
- dstPtr += 4;
- srcPtr += 1;
- nPix--;
- }
- }
+ dstPtr += 4;
+ srcPtr += 1;
+ nPix--;
+ }
+ }
%}.
- ] ifFalse:[
- usedDeviceBitsPerPixel == 8 ifTrue:[
- "/ 8 bits/pixel
+ ] ifFalse:[
+ usedDeviceBitsPerPixel == 8 ifTrue:[
+ "/ 8 bits/pixel
- "/ now, walk over the image and replace
- "/ colorMap indices by color values in the bits array
+ "/ now, walk over the image and replace
+ "/ colorMap indices by color values in the bits array
-%{
- unsigned char *srcPtr = 0;
- unsigned char *dstPtr = 0;
- OBJ _bytes = __INST(bytes);
+%{
+ unsigned char *srcPtr = 0;
+ unsigned char *dstPtr = 0;
+ OBJ _bytes = __INST(bytes);
- if (__isByteArray(_bytes)) {
- srcPtr = _ByteArrayInstPtr(_bytes)->ba_element;
- } else {
- if (__isExternalBytesLike(_bytes)) {
- srcPtr = __externalBytesAddress(_bytes);
- }
- }
- if (__isByteArray(imageBits)) {
- dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
- } else {
- if (__isExternalBytesLike(imageBits)) {
- dstPtr = __externalBytesAddress(imageBits);
- }
- }
+ if (__isByteArray(_bytes)) {
+ srcPtr = _ByteArrayInstPtr(_bytes)->ba_element;
+ } else {
+ if (__isExternalBytesLike(_bytes)) {
+ srcPtr = __externalBytesAddress(_bytes);
+ }
+ }
+ if (__isByteArray(imageBits)) {
+ dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
+ } else {
+ if (__isExternalBytesLike(imageBits)) {
+ dstPtr = __externalBytesAddress(imageBits);
+ }
+ }
- if (__bothSmallInteger(_INST(height), _INST(width))
- && __isArrayLike(colorValues)
- && srcPtr
- && dstPtr) {
- int x, y, w, h, nPix;
- int r,p;
+ if (__bothSmallInteger(_INST(height), _INST(width))
+ && __isArrayLike(colorValues)
+ && srcPtr
+ && dstPtr) {
+ int x, y, w, h, nPix;
+ int r,p;
- OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
+ OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
- w = __intVal(_INST(width));
- h = __intVal(_INST(height));
- r = w;
- p = __intVal(padd);
+ w = __intVal(_INST(width));
+ h = __intVal(_INST(height));
+ r = w;
+ p = __intVal(padd);
- nPix = w * h;
- while (nPix > 0) {
- unsigned idx, v;
- OBJ clr;
+ nPix = w * h;
+ while (nPix > 0) {
+ unsigned idx, v;
+ OBJ clr;
- idx = *srcPtr;
- clr = ap[idx];
- v = __intVal(clr);
+ idx = *srcPtr;
+ clr = ap[idx];
+ v = __intVal(clr);
- dstPtr[0] = v;
+ dstPtr[0] = v;
- dstPtr += 1;
- srcPtr += 1;
- nPix--;
+ dstPtr += 1;
+ srcPtr += 1;
+ nPix--;
- if (--r == 0) {
- dstPtr += p;
- r = w;
- }
+ if (--r == 0) {
+ dstPtr += p;
+ r = w;
+ }
- }
- }
+ }
+ }
%}.
- ] ifFalse:[
- usedDeviceBitsPerPixel == 24 ifTrue:[
- "/ 24 bits/pixel
+ ] ifFalse:[
+ usedDeviceBitsPerPixel == 24 ifTrue:[
+ "/ 24 bits/pixel
- "/ now, walk over the image and replace
- "/ colorMap indices by color values in the bits array
+ "/ now, walk over the image and replace
+ "/ colorMap indices by color values in the bits array
-%{
- unsigned char *srcPtr = 0;
- unsigned char *dstPtr = 0;
- OBJ _bytes = __INST(bytes);
+%{
+ unsigned char *srcPtr = 0;
+ unsigned char *dstPtr = 0;
+ OBJ _bytes = __INST(bytes);
- if (__isByteArray(_bytes)) {
- srcPtr = _ByteArrayInstPtr(_bytes)->ba_element;
- } else {
- if (__isExternalBytesLike(_bytes)) {
- srcPtr = __externalBytesAddress(_bytes);
- }
- }
- if (__isByteArray(imageBits)) {
- dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
- } else {
- if (__isExternalBytesLike(imageBits)) {
- dstPtr = __externalBytesAddress(imageBits);
- }
- }
+ if (__isByteArray(_bytes)) {
+ srcPtr = _ByteArrayInstPtr(_bytes)->ba_element;
+ } else {
+ if (__isExternalBytesLike(_bytes)) {
+ srcPtr = __externalBytesAddress(_bytes);
+ }
+ }
+ if (__isByteArray(imageBits)) {
+ dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
+ } else {
+ if (__isExternalBytesLike(imageBits)) {
+ dstPtr = __externalBytesAddress(imageBits);
+ }
+ }
- if (__bothSmallInteger(_INST(height), _INST(width))
- && __isArrayLike(colorValues)
- && srcPtr
- && dstPtr) {
- int x, y, w, h, nPix;
- int r,p;
+ if (__bothSmallInteger(_INST(height), _INST(width))
+ && __isArrayLike(colorValues)
+ && srcPtr
+ && dstPtr) {
+ int x, y, w, h, nPix;
+ int r,p;
- OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
+ OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
- w = __intVal(_INST(width));
- h = __intVal(_INST(height));
- r = w;
- p = __intVal(padd);
+ w = __intVal(_INST(width));
+ h = __intVal(_INST(height));
+ r = w;
+ p = __intVal(padd);
- nPix = w * h;
- while (nPix > 0) {
- unsigned idx, v;
- OBJ clr;
+ nPix = w * h;
+ while (nPix > 0) {
+ unsigned idx, v;
+ OBJ clr;
- idx = *srcPtr;
- clr = ap[idx];
- v = __intVal(clr);
+ idx = *srcPtr;
+ clr = ap[idx];
+ v = __intVal(clr);
- dstPtr[0] = (v>>16) & 0xFF;
- dstPtr[1] = (v>>8) & 0xFF;
- dstPtr[2] = (v) & 0xFF;
+ dstPtr[0] = (v>>16) & 0xFF;
+ dstPtr[1] = (v>>8) & 0xFF;
+ dstPtr[2] = (v) & 0xFF;
- dstPtr += 3;
- srcPtr += 1;
- nPix--;
- if (--r == 0) {
- dstPtr += p;
- r = w;
- }
- }
- }
+ dstPtr += 3;
+ srcPtr += 1;
+ nPix--;
+ if (--r == 0) {
+ dstPtr += p;
+ r = w;
+ }
+ }
+ }
%}.
- ]
- ]
- ]
+ ]
+ ]
+ ]
].
- imageBits isNil ifTrue:[
- 'Image [warning]: unimplemented trueColor depth in paletteImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintCR.
- ^ self asMonochromeFormOn:aDevice
+ imageBits isNil ifTrue:[
+ 'Image [warning]: unimplemented trueColor depth in paletteImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintCR.
+ ^ self asMonochromeFormOn:aDevice
].
form := Form width:width height:height depth:usedDeviceDepth on:aDevice.
@@ -945,13 +945,13 @@
form initGC.
form
- copyBitsFrom:imageBits
- bitsPerPixel:usedDeviceBitsPerPixel
- depth:usedDeviceDepth
- padding:usedDevicePadding
- width:width height:height
- x:0 y:0
- toX:0 y:0.
+ copyBitsFrom:imageBits
+ bitsPerPixel:usedDeviceBitsPerPixel
+ depth:usedDeviceDepth
+ padding:usedDevicePadding
+ width:width height:height
+ x:0 y:0
+ toX:0 y:0.
^ form
@@ -970,15 +970,15 @@
map := ByteArray uninitializedNew:256.
1 to:256 do:[:i |
- map at:i put:((self colorFromValue:(i-1)) brightness * 255) rounded
+ map at:i put:((self colorFromValue:(i-1)) brightness * 255) rounded
].
self bits
- expandPixels:8 "xlate only"
- width:width
- height:height
- into:greyBits
- mapping:map.
+ expandPixels:8 "xlate only"
+ width:width
+ height:height
+ into:greyBits
+ mapping:map.
^ self makeDeviceGrayPixmapOn:aDevice depth:8 fromArray:greyBits
@@ -988,7 +988,7 @@
asGrayFormOn:aDevice
"get a gray device form.
- Redefined, since we can do it with simple translate,
+ Redefined, since we can do it with simple translate,
if the depth matches my depth."
(aDevice visualType == #StaticGray) ifTrue:[
@@ -1065,12 +1065,12 @@
floydSteinbergDitheredDepth8BitsColors:colors map:aMapOrNil
"return a floyd-steinberg dithered bitmap from the receiver picture,
- which must be a depth-8 image.
+ which must be a depth-8 image.
This method expects an array of colors to be used for dithering
(which need not be a colorCubes colors)."
- |pseudoBits
- rgbBytes
+ |pseudoBits
+ rgbBytes
ditherRGBBytes ditherColors
w "{Class: SmallInteger }"
h "{Class: SmallInteger }"
@@ -1085,77 +1085,77 @@
rgbBytes := ByteArray uninitializedNew:256 * 3.
photometric == #palette ifTrue:[
- lastColor := colorMap size - 1
+ lastColor := colorMap size - 1
] ifFalse:[
- lastColor := 255.
+ lastColor := 255.
].
index := 1.
0 to:lastColor do:[:pix |
- clr := self colorFromValue:pix.
- rgbBytes at:index put:(clr redByte).
- rgbBytes at:index+1 put:(clr greenByte).
- rgbBytes at:index+2 put:(clr blueByte).
+ clr := self colorFromValue:pix.
+ rgbBytes at:index put:(clr redByte).
+ rgbBytes at:index+1 put:(clr greenByte).
+ rgbBytes at:index+2 put:(clr blueByte).
- index := index + 3.
+ index := index + 3.
].
"/ collect valid ditherColors ...
aMapOrNil isNil ifTrue:[
- ditherColors := colors select:[:clr | clr notNil].
+ ditherColors := colors select:[:clr | clr notNil].
] ifFalse:[
- ditherColors := colors
+ ditherColors := colors
].
"/ ... and sort by manhatten distance from black
qScramble := #(
- "/ 2rX00X00X00X00
+ "/ 2rX00X00X00X00
- 2r000000000000 "/ 0
- 2r000000000100 "/ 1
- 2r000000100000 "/ 2
- 2r000000100100 "/ 3
- 2r000100000000 "/ 4
- 2r000100000100 "/ 5
- 2r000100100000 "/ 6
- 2r000100100100 "/ 7
- 2r100000000000 "/ 8
- 2r100000000100 "/ 9
- 2r100000100000 "/ a
- 2r100000100100 "/ b
- 2r100100000000 "/ c
- 2r100100000100 "/ d
- 2r100100100000 "/ e
- 2r100100100100 "/ f
- ).
+ 2r000000000000 "/ 0
+ 2r000000000100 "/ 1
+ 2r000000100000 "/ 2
+ 2r000000100100 "/ 3
+ 2r000100000000 "/ 4
+ 2r000100000100 "/ 5
+ 2r000100100000 "/ 6
+ 2r000100100100 "/ 7
+ 2r100000000000 "/ 8
+ 2r100000000100 "/ 9
+ 2r100000100000 "/ a
+ 2r100000100100 "/ b
+ 2r100100000000 "/ c
+ 2r100100000100 "/ d
+ 2r100100100000 "/ e
+ 2r100100100100 "/ f
+ ).
ditherColors := ditherColors sort:[:a :b |
- |cr "{Class: SmallInteger }"
- cg "{Class: SmallInteger }"
- cb "{Class: SmallInteger }"
- i1 "{Class: SmallInteger }"
- i2 "{Class: SmallInteger }"|
+ |cr "{Class: SmallInteger }"
+ cg "{Class: SmallInteger }"
+ cb "{Class: SmallInteger }"
+ i1 "{Class: SmallInteger }"
+ i2 "{Class: SmallInteger }"|
- cr := a redByte.
- cg := a greenByte.
- cb := a blueByte.
- i1 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
- i1 := i1 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
- i1 := i1 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
+ cr := a redByte.
+ cg := a greenByte.
+ cb := a blueByte.
+ i1 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
+ i1 := i1 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
+ i1 := i1 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
- cr := b redByte.
- cg := b greenByte.
- cb := b blueByte.
- i2 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
- i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
- i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
+ cr := b redByte.
+ cg := b greenByte.
+ cb := b blueByte.
+ i2 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
+ i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
+ i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
- i1 < i2
- ].
+ i1 < i2
+ ].
aMapOrNil isNil ifTrue:[
- ditherIds := (ditherColors asArray collect:[:clr | clr colorId]) asByteArray.
+ ditherIds := (ditherColors asArray collect:[:clr | clr colorId]) asByteArray.
] ifFalse:[
- ditherIds := aMapOrNil asByteArray
+ ditherIds := aMapOrNil asByteArray
].
"/ build an index table, for fast lookup from manhatten-r-g-b distance
@@ -1164,20 +1164,20 @@
clrLookup := ByteArray new:(4096).
index := 0.
ditherColors keysAndValuesDo:[:clrPosition :clr |
- |r g b i|
+ |r g b i|
- r := clr redByte.
- g := clr greenByte.
- b := clr blueByte.
- i := qScramble at:((r bitShift:-4) bitAnd:16r0F) + 1.
- i := i + ((qScramble at:((g bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
- i := i + ((qScramble at:((b bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
- lookupPos := i.
+ r := clr redByte.
+ g := clr greenByte.
+ b := clr blueByte.
+ i := qScramble at:((r bitShift:-4) bitAnd:16r0F) + 1.
+ i := i + ((qScramble at:((g bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
+ i := i + ((qScramble at:((b bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
+ lookupPos := i.
- [index < lookupPos] whileTrue:[
- clrLookup at:(index+1) put:(clrPosition-1-1).
- index := index + 1
- ]
+ [index < lookupPos] whileTrue:[
+ clrLookup at:(index+1) put:(clrPosition-1-1).
+ index := index + 1
+ ]
].
clrLookup from:index+1 to:4096 put:(ditherColors size - 1).
@@ -1193,16 +1193,16 @@
ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
index := 1.
1 to:lastColor do:[:pix |
- clr := ditherColors at:pix.
- ditherRGBBytes at:index put:(clr redByte).
- ditherRGBBytes at:index+1 put:(clr greenByte).
- ditherRGBBytes at:index+2 put:(clr blueByte).
- aMapOrNil isNil ifTrue:[
- ditherIds at:pix put:clr colorId.
- ] ifFalse:[
- ditherIds at:pix put:(aMapOrNil at:pix).
- ].
- index := index + 3.
+ clr := ditherColors at:pix.
+ ditherRGBBytes at:index put:(clr redByte).
+ ditherRGBBytes at:index+1 put:(clr greenByte).
+ ditherRGBBytes at:index+2 put:(clr blueByte).
+ aMapOrNil isNil ifTrue:[
+ ditherIds at:pix put:clr colorId.
+ ] ifFalse:[
+ ditherIds at:pix put:(aMapOrNil at:pix).
+ ].
+ index := index + 3.
].
pseudoBits := ByteArray uninitializedNew:(width * height).
@@ -1232,23 +1232,23 @@
int __nColors = __intVal(lastColor);
int __wR = -1, __wG, __wB;
static int __qScramble[16] = {
- 0x000 /* 2r000000000000 0 */,
- 0x004 /* 2r000000000100 1 */,
- 0x020 /* 2r000000100000 2 */,
- 0x024 /* 2r000000100100 3 */,
- 0x100 /* 2r000100000000 4 */,
- 0x104 /* 2r000100000100 5 */,
- 0x120 /* 2r000100100000 6 */,
- 0x124 /* 2r000100100100 7 */,
- 0x800 /* 2r100000000000 8 */,
- 0x804 /* 2r100000000100 9 */,
- 0x820 /* 2r100000100000 a */,
- 0x824 /* 2r100000100100 b */,
- 0x900 /* 2r100100000000 c */,
- 0x904 /* 2r100100000100 d */,
- 0x920 /* 2r100100100000 e */,
- 0x924 /* 2r100100100100 f */,
- };
+ 0x000 /* 2r000000000000 0 */,
+ 0x004 /* 2r000000000100 1 */,
+ 0x020 /* 2r000000100000 2 */,
+ 0x024 /* 2r000000100100 3 */,
+ 0x100 /* 2r000100000000 4 */,
+ 0x104 /* 2r000100000100 5 */,
+ 0x120 /* 2r000100100000 6 */,
+ 0x124 /* 2r000100100100 7 */,
+ 0x800 /* 2r100000000000 8 */,
+ 0x804 /* 2r100000000100 9 */,
+ 0x820 /* 2r100000100000 a */,
+ 0x824 /* 2r100000100100 b */,
+ 0x900 /* 2r100100000000 c */,
+ 0x904 /* 2r100100000100 d */,
+ 0x920 /* 2r100100100000 e */,
+ 0x924 /* 2r100100100100 f */,
+ };
if (__isByteArray(__INST(bytes))
&& __isByteArray(pseudoBits)
@@ -1257,50 +1257,50 @@
&& __isByteArray(ditherIds)
&& __isByteArray(clrLookup)
&& __isByteArray(error)) {
- failed = false;
+ failed = false;
- srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element;
- dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
- rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
- idP = __ByteArrayInstPtr(ditherIds)->ba_element;
- __clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element;
- errP = (short *) __ByteArrayInstPtr(error)->ba_element;
+ srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element;
+ dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
+ rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
+ idP = __ByteArrayInstPtr(ditherIds)->ba_element;
+ __clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element;
+ errP = (short *) __ByteArrayInstPtr(error)->ba_element;
- /*
- * clear error accumulator
- */
- eP = errP;
- bzero(eP, (__w+2) * 2 * 3);
+ /*
+ * clear error accumulator
+ */
+ eP = errP;
+ bzero(eP, (__w+2) * 2 * 3);
- for (__y=__h; __y>0; __y--) {
- __eR = __eG = __eB = 0;
+ for (__y=__h; __y>0; __y--) {
+ __eR = __eG = __eB = 0;
- eP = &(errP[3]);
- __eR = eP[0];
- __eG = eP[1];
- __eB = eP[2];
+ eP = &(errP[3]);
+ __eR = eP[0];
+ __eG = eP[1];
+ __eB = eP[2];
- for (__x=__w; __x>0; __x--) {
- int __want;
- int pix;
- int __wantR, __wantG, __wantB;
- int idx;
- int tR, tG, tB;
- int nR, nG, nB;
- int dR, dG, dB;
- int minDelta, bestIdx;
- int cnt;
+ for (__x=__w; __x>0; __x--) {
+ int __want;
+ int pix;
+ int __wantR, __wantG, __wantB;
+ int idx;
+ int tR, tG, tB;
+ int nR, nG, nB;
+ int dR, dG, dB;
+ int minDelta, bestIdx;
+ int cnt;
- pix = *srcP++;
+ pix = *srcP++;
- /*
- * wR, wG and wB is the wanted r/g/b value;
- */
- idx = pix+pix+pix; /* pix * 3 */
+ /*
+ * wR, wG and wB is the wanted r/g/b value;
+ */
+ idx = pix+pix+pix; /* pix * 3 */
- __wantR = rgbP[idx] + __eR;
- __wantG = rgbP[idx+1] + __eG;
- __wantB = rgbP[idx+2] + __eB;
+ __wantR = rgbP[idx] + __eR;
+ __wantG = rgbP[idx+1] + __eG;
+ __wantB = rgbP[idx+2] + __eB;
#define RED_SCALE 30
#define GREEN_SCALE 59
@@ -1317,236 +1317,236 @@
#define NPROBE 8
#ifndef FAST_LOOKUP
- if ((__wantR == __wR)
- && (__wantG == __wG)
- && (__wantB == __wB)) {
- /*
- * same color again - reuse last bestMatch
- */
- } else
+ if ((__wantR == __wR)
+ && (__wantG == __wG)
+ && (__wantB == __wB)) {
+ /*
+ * same color again - reuse last bestMatch
+ */
+ } else
#endif
- {
- __wR = __wantR;
- __wG = __wantG;
- __wB = __wantB;
+ {
+ __wR = __wantR;
+ __wG = __wantG;
+ __wB = __wantB;
#ifdef FAST_LOOKUP
- if(__wR > 255) __wR = 255;
- else if (__wR < 0) __wR = 0;
- if(__wG > 255) __wG = 255;
- else if (__wG < 0) __wG = 0;
- if(__wB > 255) __wB = 255;
- else if (__wB < 0) __wB = 0;
+ if(__wR > 255) __wR = 255;
+ else if (__wR < 0) __wR = 0;
+ if(__wG > 255) __wG = 255;
+ else if (__wG < 0) __wG = 0;
+ if(__wB > 255) __wB = 255;
+ else if (__wB < 0) __wB = 0;
- {
- int lookupIndex;
- int idx, idx0;
- int d, delta;
- unsigned char *dp0;
+ {
+ int lookupIndex;
+ int idx, idx0;
+ int d, delta;
+ unsigned char *dp0;
- dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
- lookupIndex = __qScramble[((__wR & 0xF0)>>4)];
- lookupIndex |= __qScramble[((__wG & 0xF0)>>4)] >> 1;
- lookupIndex |= __qScramble[((__wB & 0xF0)>>4)] >> 2;
- idx = bestIdx =__clrLookup[lookupIndex];
- dp += (idx+idx+idx);
+ dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
+ lookupIndex = __qScramble[((__wR & 0xF0)>>4)];
+ lookupIndex |= __qScramble[((__wG & 0xF0)>>4)] >> 1;
+ lookupIndex |= __qScramble[((__wB & 0xF0)>>4)] >> 2;
+ idx = bestIdx =__clrLookup[lookupIndex];
+ dp += (idx+idx+idx);
- /* try color at lookupIndex */
+ /* try color at lookupIndex */
- d = dp[0];
- delta = (__wR - d) * RED_SCALE;
- if (delta < 0) delta = -delta;
+ d = dp[0];
+ delta = (__wR - d) * RED_SCALE;
+ if (delta < 0) delta = -delta;
- d = dp[1];
- if (__wG > d)
- delta += (__wG - d) * GREEN_SCALE;
- else
- delta += (d - __wG) * GREEN_SCALE;
- d = dp[2];
- if (__wB > d)
- delta += (__wB - d) * BLUE_SCALE;
- else
- delta += (d - __wB) * BLUE_SCALE;
+ d = dp[1];
+ if (__wG > d)
+ delta += (__wG - d) * GREEN_SCALE;
+ else
+ delta += (d - __wG) * GREEN_SCALE;
+ d = dp[2];
+ if (__wB > d)
+ delta += (__wB - d) * BLUE_SCALE;
+ else
+ delta += (d - __wB) * BLUE_SCALE;
- if (delta <= GOOD_DELTA) {
- goto foundBest;
- }
- minDelta = delta;
+ if (delta <= GOOD_DELTA) {
+ goto foundBest;
+ }
+ minDelta = delta;
# ifndef ONE_SHOT
- idx0 = idx; dp0 = dp;
- cnt = 0;
- while ((++cnt <= NPROBE) && (idx > 0)) {
- /* try previous color(s) */
+ idx0 = idx; dp0 = dp;
+ cnt = 0;
+ while ((++cnt <= NPROBE) && (idx > 0)) {
+ /* try previous color(s) */
- idx--; dp -= 3;
- d = dp[0];
- delta = (__wR - d) * RED_SCALE;
- if (delta < 0) delta = -delta;
- d = dp[1];
- if (__wG > d)
- delta += (__wG - d) * GREEN_SCALE;
- else
- delta += (d - __wG) * GREEN_SCALE;
- d = dp[2];
- if (__wB > d)
- delta += (__wB - d) * BLUE_SCALE;
- else
- delta += (d - __wB) * BLUE_SCALE;
+ idx--; dp -= 3;
+ d = dp[0];
+ delta = (__wR - d) * RED_SCALE;
+ if (delta < 0) delta = -delta;
+ d = dp[1];
+ if (__wG > d)
+ delta += (__wG - d) * GREEN_SCALE;
+ else
+ delta += (d - __wG) * GREEN_SCALE;
+ d = dp[2];
+ if (__wB > d)
+ delta += (__wB - d) * BLUE_SCALE;
+ else
+ delta += (d - __wB) * BLUE_SCALE;
- if (delta < minDelta) {
- bestIdx = idx;
- if (delta <= GOOD_DELTA) {
- goto foundBest;
- }
- minDelta = delta;
- }
- }
+ if (delta < minDelta) {
+ bestIdx = idx;
+ if (delta <= GOOD_DELTA) {
+ goto foundBest;
+ }
+ minDelta = delta;
+ }
+ }
- idx = idx0; dp = dp0;
- cnt = 0;
- while ((++cnt <= NPROBE) && (++idx < __nColors)) {
- /* try next color */
+ idx = idx0; dp = dp0;
+ cnt = 0;
+ while ((++cnt <= NPROBE) && (++idx < __nColors)) {
+ /* try next color */
- dp += 3;
- d = dp[0];
- delta = (__wR - d) * RED_SCALE;
- if (delta < 0) delta = -delta;
- d = dp[1];
- if (__wG > d)
- delta += (__wG - d) * GREEN_SCALE;
- else
- delta += (d - __wG) * GREEN_SCALE;
- d = dp[2];
- if (__wB > d)
- delta += (__wB - d) * BLUE_SCALE;
- else
- delta += (d - __wB) * BLUE_SCALE;
+ dp += 3;
+ d = dp[0];
+ delta = (__wR - d) * RED_SCALE;
+ if (delta < 0) delta = -delta;
+ d = dp[1];
+ if (__wG > d)
+ delta += (__wG - d) * GREEN_SCALE;
+ else
+ delta += (d - __wG) * GREEN_SCALE;
+ d = dp[2];
+ if (__wB > d)
+ delta += (__wB - d) * BLUE_SCALE;
+ else
+ delta += (d - __wB) * BLUE_SCALE;
- if (delta < minDelta) {
- bestIdx = idx;
- if (delta <= GOOD_DELTA) {
- goto foundBest;
- }
- minDelta = delta;
- }
- }
+ if (delta < minDelta) {
+ bestIdx = idx;
+ if (delta <= GOOD_DELTA) {
+ goto foundBest;
+ }
+ minDelta = delta;
+ }
+ }
# endif
- }
- foundBest: ;
+ }
+ foundBest: ;
#else
/*
- if(__wR > 255) __wR = 255;
- else if (__wR < 0) __wR = 0;
- if(__wG > 255) __wG = 255;
- else if (__wG < 0) __wG = 0;
- if(__wB > 255) __wB = 255;
- else if (__wB < 0) __wB = 0;
+ if(__wR > 255) __wR = 255;
+ else if (__wR < 0) __wR = 0;
+ if(__wG > 255) __wG = 255;
+ else if (__wG < 0) __wG = 0;
+ if(__wB > 255) __wB = 255;
+ else if (__wB < 0) __wB = 0;
*/
- /* find the best matching color */
+ /* find the best matching color */
- minDelta = 99999;
- bestIdx = -1;
- dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
- for (idx = 0; idx<__nColors; idx++) {
- int d, delta;
+ minDelta = 99999;
+ bestIdx = -1;
+ dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
+ for (idx = 0; idx<__nColors; idx++) {
+ int d, delta;
- d = dp[0];
- delta = (__wR - d) * RED_SCALE;
- if (delta < 0) delta = -delta;
- if (delta < minDelta) {
- d = dp[1];
- if (__wG > d)
- delta += (__wG - d) * GREEN_SCALE;
- else
- delta += (d - __wG) * GREEN_SCALE;
- if (delta < minDelta) {
- d = dp[2];
- if (__wB > d)
- delta += (__wB - d) * BLUE_SCALE;
- else
- delta += (d - __wB) * BLUE_SCALE;
+ d = dp[0];
+ delta = (__wR - d) * RED_SCALE;
+ if (delta < 0) delta = -delta;
+ if (delta < minDelta) {
+ d = dp[1];
+ if (__wG > d)
+ delta += (__wG - d) * GREEN_SCALE;
+ else
+ delta += (d - __wG) * GREEN_SCALE;
+ if (delta < minDelta) {
+ d = dp[2];
+ if (__wB > d)
+ delta += (__wB - d) * BLUE_SCALE;
+ else
+ delta += (d - __wB) * BLUE_SCALE;
- if (delta < minDelta) {
- bestIdx = idx;
- if (delta <= GOOD_DELTA) {
- break;
- }
- minDelta = delta;
- }
- }
- }
- dp += 3;
- }
+ if (delta < minDelta) {
+ bestIdx = idx;
+ if (delta <= GOOD_DELTA) {
+ break;
+ }
+ minDelta = delta;
+ }
+ }
+ }
+ dp += 3;
+ }
#endif
- }
- dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
- dp += bestIdx * 3;
- dR = dp[0];
- dG = dp[1];
- dB = dp[2];
+ }
+ dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
+ dp += bestIdx * 3;
+ dR = dp[0];
+ dG = dp[1];
+ dB = dp[2];
/*
-printf("want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n",
- __wantR, __wantG, __wantB,
- __wR, __wG, __wB,
- dR, dG, dB);
+console_printf("want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n",
+ __wantR, __wantG, __wantB,
+ __wR, __wG, __wB,
+ dR, dG, dB);
*/
- /*
- * store the corresponding dither colors colorId
- */
- *dstP++ = idP[bestIdx];
+ /*
+ * store the corresponding dither colors colorId
+ */
+ *dstP++ = idP[bestIdx];
- /*
- * the new error & distribute the error
- */
- __eR = __wantR - dR;
- if (__eR) {
- tR = __eR >> 4; /* 16th of error */
- nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
- eP[0] = tR*5; /* 5/16th for (x / y+1) */
- eP[-3] = tR*3; /* 3/16th for (x-1 / y+1) */
- eP[3] = __eR - (tR*15); /* 1/16th for (x+1 / y+1) */
- __eR = nR;
- } else {
- __eR = eP[3];
- eP[0] = eP[-3] = eP[3] = 0;
- }
+ /*
+ * the new error & distribute the error
+ */
+ __eR = __wantR - dR;
+ if (__eR) {
+ tR = __eR >> 4; /* 16th of error */
+ nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
+ eP[0] = tR*5; /* 5/16th for (x / y+1) */
+ eP[-3] = tR*3; /* 3/16th for (x-1 / y+1) */
+ eP[3] = __eR - (tR*15); /* 1/16th for (x+1 / y+1) */
+ __eR = nR;
+ } else {
+ __eR = eP[3];
+ eP[0] = eP[-3] = eP[3] = 0;
+ }
- __eG = __wantG - dG;
- if (__eG) {
- tG = __eG >> 4;
- nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
- eP[1] = tG*5;
- eP[-2] = tG*3;
- eP[4] = __eG - (tG*15);
- __eG = nG;
- } else {
- __eG = eP[4];
- eP[1] = eP[-2] = eP[4] = 0;
- }
+ __eG = __wantG - dG;
+ if (__eG) {
+ tG = __eG >> 4;
+ nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
+ eP[1] = tG*5;
+ eP[-2] = tG*3;
+ eP[4] = __eG - (tG*15);
+ __eG = nG;
+ } else {
+ __eG = eP[4];
+ eP[1] = eP[-2] = eP[4] = 0;
+ }
- __eB = __wantB - dB;
- if (__eB) {
- tB = __eB >> 4;
- nB = eP[5] + (tB * 7);
- eP[2] = tB*5;
- eP[-1] = tB*3;
- eP[5] = __eB - (tB*15);
- __eB = nB;
- } else {
- __eB = eP[5];
- eP[2] = eP[-1] = eP[5] = 0;
- }
+ __eB = __wantB - dB;
+ if (__eB) {
+ tB = __eB >> 4;
+ nB = eP[5] + (tB * 7);
+ eP[2] = tB*5;
+ eP[-1] = tB*3;
+ eP[5] = __eB - (tB*15);
+ __eB = nB;
+ } else {
+ __eB = eP[5];
+ eP[2] = eP[-1] = eP[5] = 0;
+ }
- eP += 3;
- }
- }
+ eP += 3;
+ }
+ }
}
%}.
failed ifTrue:[
- self primitiveFailed.
- ^ nil
+ self primitiveFailed.
+ ^ nil
].
^ pseudoBits
@@ -1557,7 +1557,7 @@
with a constant ditherMatrix, this can be used for thresholding.
Redefined to make use of knowing that pixels are 8-bit values."
- |dH nDither bytes
+ |dH nDither bytes
greyLevels greyMap1 greyMap2
bytesPerRow "{Class: SmallInteger }"
bytesPerOutRow "{Class: SmallInteger }"
@@ -1581,25 +1581,25 @@
bytesPerOutRow := (w * depth + 7) // 8.
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
(outBits isNil or:[bytes isNil]) ifTrue:[
- ^ nil
+ ^ nil
].
greyMap1 := self greyMapForRange:(greyLevels-1). "/ the pixels
greyMap1 := (greyMap1 collect:[:b | b isNil ifTrue:[
- 0
- ] ifFalse:[
- b truncated
- ]
- ]) asByteArray.
+ 0
+ ] ifFalse:[
+ b truncated
+ ]
+ ]) asByteArray.
greyMap2 := self greyMapForRange:(greyLevels-1).
- greyMap2 := (greyMap2 collect:[:el |
- el isNil ifTrue:[
- 0
- ] ifFalse:[
- ((el - el truncated) "/ the error (0..1)
- * nDither) rounded
- ]]) asByteArray.
+ greyMap2 := (greyMap2 collect:[:el |
+ el isNil ifTrue:[
+ 0
+ ] ifFalse:[
+ ((el - el truncated) "/ the error (0..1)
+ * nDither) rounded
+ ]]) asByteArray.
%{
int __dW = __intVal(dW);
@@ -1629,51 +1629,51 @@
__oY = __dY = 0;
for (__y=0; __y<__h; __y++) {
- __nextDst = __dstIdx + __bytesPerOutRow;
- __nextSrc = __srcIdx + __bytesPerRow;
+ __nextDst = __dstIdx + __bytesPerOutRow;
+ __nextSrc = __srcIdx + __bytesPerRow;
- __byte = 0;
- __bitCnt = 8;
+ __byte = 0;
+ __bitCnt = 8;
- __oX = 0;
+ __oX = 0;
- for (__x=0; __x<__w; __x++) {
- __grey = __bytes[__srcIdx++]; /* 0..255 */
+ for (__x=0; __x<__w; __x++) {
+ __grey = __bytes[__srcIdx++]; /* 0..255 */
- __pixel = __greyMap1[__grey]; /* 0..(greyLevels-1) */
- __dO = __greyMap2[__grey]; /* 0.. nDither-1) */
- __dT = __ditherMatrix[__dY + __oX];
+ __pixel = __greyMap1[__grey]; /* 0..(greyLevels-1) */
+ __dO = __greyMap2[__grey]; /* 0.. nDither-1) */
+ __dT = __ditherMatrix[__dY + __oX];
- if (__dO > __dT) /* dither says: next pixel */
- __pixel++;
+ if (__dO > __dT) /* dither says: next pixel */
+ __pixel++;
- __oX++;
- if (__oX == __dW) __oX = 0;
+ __oX++;
+ if (__oX == __dW) __oX = 0;
- __byte = (__byte << __depth) | __pixel;
+ __byte = (__byte << __depth) | __pixel;
- __bitCnt = __bitCnt - __depth;
- if (__bitCnt == 0) {
- __outBits[__dstIdx] = __byte;
- __dstIdx++;
- __byte = 0;
- __bitCnt = 8;
- }
- }
+ __bitCnt = __bitCnt - __depth;
+ if (__bitCnt == 0) {
+ __outBits[__dstIdx] = __byte;
+ __dstIdx++;
+ __byte = 0;
+ __bitCnt = 8;
+ }
+ }
- if (__bitCnt != 8) {
- __byte = __byte << __bitCnt;
- __outBits[__dstIdx] = __byte;
- }
+ if (__bitCnt != 8) {
+ __byte = __byte << __bitCnt;
+ __outBits[__dstIdx] = __byte;
+ }
- __oY++; __dY += __dW;
- if (__oY == __dH) {
- __oY = 0;
- __dY = 0;
- }
+ __oY++; __dY += __dW;
+ if (__oY == __dH) {
+ __oY = 0;
+ __dY = 0;
+ }
- __srcIdx = __nextSrc;
- __dstIdx = __nextDst;
+ __srcIdx = __nextSrc;
+ __dstIdx = __nextDst;
}
%}.
^ outBits
@@ -1684,7 +1684,7 @@
with a constant ditherMatrix, this can be used for thresholding.
Redefined to make use of knowing that pixels are 8-bit values."
- |dH nDither bytes
+ |dH nDither bytes
greyMap monoBits
bytesPerMonoRow "{Class: SmallInteger }"
bytesPerRow "{Class: SmallInteger }"
@@ -1703,7 +1703,7 @@
bytesPerMonoRow := w + 7 // 8.
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
(monoBits isNil or:[bytes isNil]) ifTrue:[
- ^ nil
+ ^ nil
].
greyMap := self greyByteMapForRange:nDither.
@@ -1734,51 +1734,51 @@
__oY = __dY = 0;
for (__y=0; __y<__h; __y++) {
- __nextDst = __dstIdx + __bytesPerMonoRow;
- __nextSrc = __srcIdx + __bytesPerRow;
+ __nextDst = __dstIdx + __bytesPerMonoRow;
+ __nextSrc = __srcIdx + __bytesPerRow;
- __byte = 0;
- __bitCnt = 8;
+ __byte = 0;
+ __bitCnt = 8;
- __oX = 0;
+ __oX = 0;
- for (__x=__w; __x>0; __x--) {
- __grey = __bytes[__srcIdx]; /* 0..255 */
- __srcIdx++;
+ for (__x=__w; __x>0; __x--) {
+ __grey = __bytes[__srcIdx]; /* 0..255 */
+ __srcIdx++;
- __grey = __greyMap[__grey];
- __dT = __ditherMatrix[__dY + __oX];
+ __grey = __greyMap[__grey];
+ __dT = __ditherMatrix[__dY + __oX];
- __oX++;
- if (__oX == __dW) __oX = 0;
+ __oX++;
+ if (__oX == __dW) __oX = 0;
- __byte = __byte << 1;
- if (__grey > __dT) {
- __byte = __byte | 1; /* white */
- }
+ __byte = __byte << 1;
+ if (__grey > __dT) {
+ __byte = __byte | 1; /* white */
+ }
- __bitCnt--;
- if (__bitCnt == 0) {
- __monoBits[__dstIdx] = __byte;
- __dstIdx++;
- __byte = 0;
- __bitCnt = 8;
- }
- }
+ __bitCnt--;
+ if (__bitCnt == 0) {
+ __monoBits[__dstIdx] = __byte;
+ __dstIdx++;
+ __byte = 0;
+ __bitCnt = 8;
+ }
+ }
- if (__bitCnt != 8) {
- __byte = __byte << __bitCnt;
- __monoBits[__dstIdx] = __byte;
- }
+ if (__bitCnt != 8) {
+ __byte = __byte << __bitCnt;
+ __monoBits[__dstIdx] = __byte;
+ }
- __oY++; __dY += __dW;
- if (__oY == __dH) {
- __oY = 0;
- __dY = 0;
- }
+ __oY++; __dY += __dW;
+ if (__oY == __dH) {
+ __oY = 0;
+ __dY = 0;
+ }
- __srcIdx = __nextSrc;
- __dstIdx = __nextDst;
+ __srcIdx = __nextSrc;
+ __dstIdx = __nextDst;
}
%}.
@@ -1838,15 +1838,15 @@
colorArray := Array new:256.
x1 to:x2 do:[:x |
- value := bytes at:srcIndex.
- srcIndex := srcIndex + 1.
+ value := bytes at:srcIndex.
+ srcIndex := srcIndex + 1.
- color := colorArray at:value+1.
- color isNil ifTrue:[
- color := self colorFromValue:value.
- colorArray at:value+1 put:color
- ].
- aBlock value:x value:color
+ color := colorArray at:value+1.
+ color isNil ifTrue:[
+ color := self colorFromValue:value.
+ colorArray at:value+1 put:color
+ ].
+ aBlock value:x value:color
]
"Created: 7.6.1996 / 19:12:35 / cg"
@@ -1858,10 +1858,10 @@
yStart..yEnd / xStart..xEnd.
The block is passed the color at each pixel.
This method allows slighly faster processing of an
- image than using individual atX:y: accesses,
+ image than using individual atX:y: accesses,
both since some processing can be avoided when going from pixel to pixel,
- and since the color composition is done outside of the pixel loop.
- However, for real high performance image processing, specialized methods
+ and since the color composition is done outside of the pixel loop.
+ However, for real high performance image processing, specialized methods
should be written which know how to deal with specific photometric interpretations."
|srcIndex "{ Class: SmallInteger }"
@@ -1889,17 +1889,17 @@
maxColor := colorArray size.
y1 to:y2 do:[:y |
- srcNext := srcIndex + bytesPerRow.
- x1 to:x2 do:[:x |
- value := bytes at:srcIndex.
- srcIndex := srcIndex + 1.
+ srcNext := srcIndex + bytesPerRow.
+ x1 to:x2 do:[:x |
+ value := bytes at:srcIndex.
+ srcIndex := srcIndex + 1.
- value >= maxColor ifTrue:[
- value := 0.
- ].
- aBlock value:x value:y value:(colorArray at:value+1)
- ].
- srcIndex := srcNext.
+ value >= maxColor ifTrue:[
+ value := 0.
+ ].
+ aBlock value:x value:y value:(colorArray at:value+1)
+ ].
+ srcIndex := srcNext.
].
^ self
@@ -1927,9 +1927,9 @@
bytes := self bits.
x1 to:x2 do:[:x |
- pixelValue := bytes at:srcIndex.
- srcIndex := srcIndex + 1.
- aBlock value:x value:pixelValue
+ pixelValue := bytes at:srcIndex.
+ srcIndex := srcIndex + 1.
+ aBlock value:x value:pixelValue
]
"Created: 7.6.1996 / 19:09:47 / cg"
@@ -1940,9 +1940,9 @@
yStart..yEnd / xStart..xEnd.
The block is passed the pixelValue at each pixel.
This method allows slighly faster processing of an
- image than using individual valueAtX:y: accesses,
- since some processing can be avoided when going from pixel to pixel..
- However, for real high performance image processing, specialized methods
+ image than using individual valueAtX:y: accesses,
+ since some processing can be avoided when going from pixel to pixel..
+ However, for real high performance image processing, specialized methods
should be written which know how to deal with specific photometric interpretations."
|srcIndex "{ Class: SmallInteger }"
@@ -1965,14 +1965,14 @@
bytes := self bits.
y1 to:y2 do:[:y |
- srcNext := srcIndex + bytesPerRow.
- x1 to:x2 do:[:x |
- value := bytes at:srcIndex.
- srcIndex := srcIndex + 1.
+ srcNext := srcIndex + bytesPerRow.
+ x1 to:x2 do:[:x |
+ value := bytes at:srcIndex.
+ srcIndex := srcIndex + 1.
- aBlock value:x value:y value:value
- ].
- srcIndex := srcNext.
+ aBlock value:x value:y value:value
+ ].
+ srcIndex := srcNext.
].
^ self
@@ -2013,12 +2013,12 @@
].
newImage := self species new.
- newImage
- width:newWidth
- height:newHeight
- photometric:photometric
- samplesPerPixel:samplesPerPixel
- bitsPerSample:#(8)
+ newImage
+ width:newWidth
+ height:newHeight
+ photometric:photometric
+ samplesPerPixel:samplesPerPixel
+ bitsPerSample:#(8)
colorMap:colorMap copy
bits:newBytes
mask:newMask.
@@ -2065,8 +2065,8 @@
^ newImage
!
-magnifyRowFrom:srcBytes offset:srcStart
- into:dstBytes offset:dstStart factor:mX
+magnifyRowFrom:srcBytes offset:srcStart
+ into:dstBytes offset:dstStart factor:mX
"magnify a single pixel row - can only magnify by integer factors.
Specially tuned for factors 2,3 and 4."
@@ -2083,90 +2083,90 @@
if (__bothSmallInteger(srcStart, dstStart)
&& __bothSmallInteger(w, mX)
&& __isByteArray(srcBytes) && __isByteArray(dstBytes)) {
- _mag = __intVal(mX);
- srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart);
- dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart);
- _pixels = __intVal(w);
+ _mag = __intVal(mX);
+ srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart);
+ dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart);
+ _pixels = __intVal(w);
- switch (_mag) {
- case 1:
- break;
+ switch (_mag) {
+ case 1:
+ break;
- case 2:
- /* special code for common case */
- if (((INT)dstP & 1) == 0) {
- while (_pixels--) {
- _byte = *srcP++;
- _word = (_byte<<8) | _byte;
- ((short *)dstP)[0] = _word;
- dstP += 2;
- }
- } else {
- while (_pixels--) {
- _byte = *srcP++;
- *dstP++ = _byte;
- *dstP++ = _byte;
- }
- }
- break;
+ case 2:
+ /* special code for common case */
+ if (((INT)dstP & 1) == 0) {
+ while (_pixels--) {
+ _byte = *srcP++;
+ _word = (_byte<<8) | _byte;
+ ((short *)dstP)[0] = _word;
+ dstP += 2;
+ }
+ } else {
+ while (_pixels--) {
+ _byte = *srcP++;
+ *dstP++ = _byte;
+ *dstP++ = _byte;
+ }
+ }
+ break;
- case 3:
- /* special code for common case */
- while (_pixels--) {
- _byte = *srcP++;
- *dstP++ = _byte;
- *dstP++ = _byte;
- *dstP++ = _byte;
- }
- break;
+ case 3:
+ /* special code for common case */
+ while (_pixels--) {
+ _byte = *srcP++;
+ *dstP++ = _byte;
+ *dstP++ = _byte;
+ *dstP++ = _byte;
+ }
+ break;
- case 4:
- /* special code for common case */
- if (((INT)dstP & 3) == 0) {
- while (_pixels--) {
- _byte = *srcP++;
- _word = (_byte<<8) | _byte;
- _word = (_word<<16) | _word;
- ((int *)dstP)[0] = _word;
- dstP += 4;
- }
- } else {
- while (_pixels--) {
- _byte = *srcP++;
- *dstP++ = _byte;
- *dstP++ = _byte;
- *dstP++ = _byte;
- *dstP++ = _byte;
- }
- }
- break;
+ case 4:
+ /* special code for common case */
+ if (((INT)dstP & 3) == 0) {
+ while (_pixels--) {
+ _byte = *srcP++;
+ _word = (_byte<<8) | _byte;
+ _word = (_word<<16) | _word;
+ ((int *)dstP)[0] = _word;
+ dstP += 4;
+ }
+ } else {
+ while (_pixels--) {
+ _byte = *srcP++;
+ *dstP++ = _byte;
+ *dstP++ = _byte;
+ *dstP++ = _byte;
+ *dstP++ = _byte;
+ }
+ }
+ break;
- default:
- if ((((INT)dstP & 1) == 0)
- && ((_mag & 1) == 0)) {
- while (_pixels--) {
- _byte = *srcP++;
- _word = (_byte<<8) | _byte;
- for (i=_mag; i>0; i-=2) {
- ((short *)dstP)[0] = _word;
- dstP += 2;
- }
- }
- } else {
- while (_pixels--) {
- _byte = *srcP++;
- for (i=_mag; i>0; i--)
- *dstP++ = _byte;
- }
- }
- break;
- }
- RETURN (self);
+ default:
+ if ((((INT)dstP & 1) == 0)
+ && ((_mag & 1) == 0)) {
+ while (_pixels--) {
+ _byte = *srcP++;
+ _word = (_byte<<8) | _byte;
+ for (i=_mag; i>0; i-=2) {
+ ((short *)dstP)[0] = _word;
+ dstP += 2;
+ }
+ }
+ } else {
+ while (_pixels--) {
+ _byte = *srcP++;
+ for (i=_mag; i>0; i--)
+ *dstP++ = _byte;
+ }
+ }
+ break;
+ }
+ RETURN (self);
}
%}.
- super
- magnifyRowFrom:srcBytes offset:srcStart
- into:dstBytes offset:dstStart factor:mX
+ super
+ magnifyRowFrom:srcBytes offset:srcStart
+ into:dstBytes offset:dstStart factor:mX
! !
!Depth8Image methodsFor:'private'!
@@ -2196,25 +2196,25 @@
in those from the dithercolors
"
1 to:nColors do:[:i |
- clr := (map at:i) onDevice:aDevice.
- ditherPattern := clr ditherForm.
+ clr := (map at:i) onDevice:aDevice.
+ ditherPattern := clr ditherForm.
- ditherPattern isNil ifTrue:[
- patterns at:i put:#[2r11111111
- 2r11111111
- 2r11111111
- 2r11111111
- 2r11111111
- 2r11111111
- 2r11111111
- 2r11111111].
- pixel0bytes at:i put:clr colorId.
- pixel1bytes at:i put:clr colorId
- ] ifFalse:[
- patterns at:i put:(ditherPattern bits).
- pixel0bytes at:i put:(ditherPattern colorMap at:1) colorId.
- pixel1bytes at:i put:(ditherPattern colorMap at:2) colorId.
- ].
+ ditherPattern isNil ifTrue:[
+ patterns at:i put:#[2r11111111
+ 2r11111111
+ 2r11111111
+ 2r11111111
+ 2r11111111
+ 2r11111111
+ 2r11111111
+ 2r11111111].
+ pixel0bytes at:i put:clr colorId.
+ pixel1bytes at:i put:clr colorId
+ ] ifFalse:[
+ patterns at:i put:(ditherPattern bits).
+ pixel0bytes at:i put:(ditherPattern colorMap at:1) colorId.
+ pixel1bytes at:i put:(ditherPattern colorMap at:2) colorId.
+ ].
].
%{
@@ -2229,44 +2229,44 @@
_srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element;
_dstP = __ByteArrayInstPtr(formBytes)->ba_element;
for (_h = __intVal(h); _h; _h--) {
- _last = -1;
- for (_w = __intVal(w); _w; _w--) {
- _v = *_srcP++;
- if (_v != _last) {
- _patternBytes = __ArrayInstPtr(patterns)->a_element[_v];
- if (__isByteArray(_patternBytes)) {
- _patternBits = __ByteArrayInstPtr(_patternBytes)->ba_element[_patternOffset];
- } else if (__isArrayLike(_patternBytes)) {
- _patternBits = __intVal(__ArrayInstPtr(_patternBytes)->a_element[_patternOffset]);
- }
- _p0 = __ByteArrayInstPtr(pixel0bytes)->ba_element[_v];
- _p1 = __ByteArrayInstPtr(pixel1bytes)->ba_element[_v];
- _last = _v;
- }
- _outBits <<= 1;
- if (_patternBits & __mask)
- _outBits |= _p1;
- else
- _outBits |= _p0;
- __mask >>= 1;
- if (__mask == 0) {
- __mask = 0x80;
- *_dstP++ = _outBits;
- _outBits = 0;
- }
- }
- if (__mask != 0x80) {
- while (__mask != 0) {
- _outBits <<= 1;
- __mask >>= 1;
- }
- *_dstP++ = _outBits;
- __mask = 0x80;
- _outBits = 0;
- }
- _patternOffset++;
- if (_patternOffset == 8)
- _patternOffset = 0;
+ _last = -1;
+ for (_w = __intVal(w); _w; _w--) {
+ _v = *_srcP++;
+ if (_v != _last) {
+ _patternBytes = __ArrayInstPtr(patterns)->a_element[_v];
+ if (__isByteArray(_patternBytes)) {
+ _patternBits = __ByteArrayInstPtr(_patternBytes)->ba_element[_patternOffset];
+ } else if (__isArrayLike(_patternBytes)) {
+ _patternBits = __intVal(__ArrayInstPtr(_patternBytes)->a_element[_patternOffset]);
+ }
+ _p0 = __ByteArrayInstPtr(pixel0bytes)->ba_element[_v];
+ _p1 = __ByteArrayInstPtr(pixel1bytes)->ba_element[_v];
+ _last = _v;
+ }
+ _outBits <<= 1;
+ if (_patternBits & __mask)
+ _outBits |= _p1;
+ else
+ _outBits |= _p0;
+ __mask >>= 1;
+ if (__mask == 0) {
+ __mask = 0x80;
+ *_dstP++ = _outBits;
+ _outBits = 0;
+ }
+ }
+ if (__mask != 0x80) {
+ while (__mask != 0) {
+ _outBits <<= 1;
+ __mask >>= 1;
+ }
+ *_dstP++ = _outBits;
+ __mask = 0x80;
+ _outBits = 0;
+ }
+ _patternOffset++;
+ if (_patternOffset == 8)
+ _patternOffset = 0;
}
%}
.
@@ -2298,25 +2298,25 @@
in those from the dithercolors"
1 to:nColors do:[:i |
- clr := (map at:i) onDevice:aDevice.
- ditherPattern := clr ditherForm.
+ clr := (map at:i) onDevice:aDevice.
+ ditherPattern := clr ditherForm.
- ditherPattern isNil ifTrue:[
- patterns at:i put:#[2r11111111
- 2r11111111
- 2r11111111
- 2r11111111
- 2r11111111
- 2r11111111
- 2r11111111
- 2r11111111].
- pixel0bytes at:i put:clr colorId.
- pixel1bytes at:i put:clr colorId
- ] ifFalse:[
- patterns at:i put:(ditherPattern bits).
- pixel0bytes at:i put:(ditherPattern colorMap at:1) colorId.
- pixel1bytes at:i put:(ditherPattern colorMap at:2) colorId.
- ].
+ ditherPattern isNil ifTrue:[
+ patterns at:i put:#[2r11111111
+ 2r11111111
+ 2r11111111
+ 2r11111111
+ 2r11111111
+ 2r11111111
+ 2r11111111
+ 2r11111111].
+ pixel0bytes at:i put:clr colorId.
+ pixel1bytes at:i put:clr colorId
+ ] ifFalse:[
+ patterns at:i put:(ditherPattern bits).
+ pixel0bytes at:i put:(ditherPattern colorMap at:1) colorId.
+ pixel1bytes at:i put:(ditherPattern colorMap at:2) colorId.
+ ].
].
%{
@@ -2332,62 +2332,62 @@
_srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element;
_dstP = __ByteArrayInstPtr(formBytes)->ba_element;
for (_h = __intVal(h); _h; _h--) {
- _last = -1;
- _outCount = 0;
- for (_w = __intVal(w); _w; _w--) {
- _v = *_srcP++;
- if (_v != _last) {
- _patternBytes = __ArrayInstPtr(patterns)->a_element[_v];
- if (__isByteArray(_patternBytes)) {
- _patternBits = __ByteArrayInstPtr(_patternBytes)->ba_element[_patternOffset];
- } else if (__isArrayLike(_patternBytes)) {
- _patternBits = __intVal(__ArrayInstPtr(_patternBytes)->a_element[_patternOffset]);
- }
- _p0 = __ByteArrayInstPtr(pixel0bytes)->ba_element[_v];
- _p1 = __ByteArrayInstPtr(pixel1bytes)->ba_element[_v];
- _last = _v;
- }
- _outBits <<= 2;
- if (_patternBits & __mask)
- _outBits |= _p1;
- else
- _outBits |= _p0;
- __mask >>= 1;
- _outCount++;
- if (_outCount == 4) {
- *_dstP++ = _outBits;
- _outCount = 0;
- if (__mask == 0) {
- __mask = 0x80;
- }
- }
- }
- if (_outCount) {
- do {
- _outBits <<= 2;
- } while (++_outCount != 4);
- *_dstP++ = _outBits;
- }
- __mask = 0x80;
- _outBits = 0;
- _patternOffset++;
- if (_patternOffset == 8)
- _patternOffset = 0;
+ _last = -1;
+ _outCount = 0;
+ for (_w = __intVal(w); _w; _w--) {
+ _v = *_srcP++;
+ if (_v != _last) {
+ _patternBytes = __ArrayInstPtr(patterns)->a_element[_v];
+ if (__isByteArray(_patternBytes)) {
+ _patternBits = __ByteArrayInstPtr(_patternBytes)->ba_element[_patternOffset];
+ } else if (__isArrayLike(_patternBytes)) {
+ _patternBits = __intVal(__ArrayInstPtr(_patternBytes)->a_element[_patternOffset]);
+ }
+ _p0 = __ByteArrayInstPtr(pixel0bytes)->ba_element[_v];
+ _p1 = __ByteArrayInstPtr(pixel1bytes)->ba_element[_v];
+ _last = _v;
+ }
+ _outBits <<= 2;
+ if (_patternBits & __mask)
+ _outBits |= _p1;
+ else
+ _outBits |= _p0;
+ __mask >>= 1;
+ _outCount++;
+ if (_outCount == 4) {
+ *_dstP++ = _outBits;
+ _outCount = 0;
+ if (__mask == 0) {
+ __mask = 0x80;
+ }
+ }
+ }
+ if (_outCount) {
+ do {
+ _outBits <<= 2;
+ } while (++_outCount != 4);
+ *_dstP++ = _outBits;
+ }
+ __mask = 0x80;
+ _outBits = 0;
+ _patternOffset++;
+ if (_patternOffset == 8)
+ _patternOffset = 0;
}
%}
.
f := Form width:w height:h depth:2.
f initGC.
- f graphicsDevice
- drawBits:formBytes
- depth:2
- padding:8
- width:w height:h
- x:0 y:0
- into:f id
- x:0 y:0
- width:w height:h
- with:f gcId.
+ f graphicsDevice
+ drawBits:formBytes
+ depth:2
+ padding:8
+ width:w height:h
+ x:0 y:0
+ into:f id
+ x:0 y:0
+ width:w height:h
+ with:f gcId.
^ f
! !
@@ -2416,15 +2416,15 @@
Pixel values start with 0."
photometric == #whiteIs0 ifTrue:[
- ^ Color gray:100 - (100 / 255 * pixelValue)
+ ^ Color gray:100 - (100 / 255 * pixelValue)
].
photometric == #blackIs0 ifTrue:[
- ^ Color gray:(100 / 255 * pixelValue)
+ ^ Color gray:(100 / 255 * pixelValue)
].
photometric == #palette ifTrue:[
- pixelValue < colorMap size ifTrue:[
- ^ colorMap at:(pixelValue + 1)
- ]
+ pixelValue < colorMap size ifTrue:[
+ ^ colorMap at:(pixelValue + 1)
+ ]
].
^ super colorFromValue:pixelValue
!
@@ -2444,5 +2444,5 @@
!Depth8Image class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview/Depth8Image.st,v 1.107 2005-07-13 14:03:09 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview/Depth8Image.st,v 1.108 2007-01-24 13:41:11 cg Exp $'
! !
--- a/GLXWorkstation.st Wed Jan 24 14:40:55 2007 +0100
+++ b/GLXWorkstation.st Wed Jan 24 14:41:11 2007 +0100
@@ -24,7 +24,7 @@
/*
* on SGI, this class is compiled with -DGLX, while
* for simulation (using vogl), this is compiled with -DVGL
- *
+ *
* New note: starting to support openGL (tm) (compile with -DOPENGL)
* or its simulation (compile with -DMESA)
*/
@@ -166,7 +166,7 @@
static struct windowIDToGLContextMapping windowIDToGLContextMapping[MAX_OPENGL_VIEWS];
static OPENGLCONTEXT
-__glxWindowIdToGLContext(xId)
+__glxWindowIdToGLContext(xId)
Window xId;
{
int i;
@@ -310,7 +310,7 @@
/*
* check for and fetch an icoord from ST-arg into C-dst
- * ST-object must be SmallInteger. Return from method if invalid.
+ * ST-object must be SmallInteger. Return from method if invalid.
*/
#define _ICOORD_(arg, dst) \
if (__isSmallInteger(arg)) \
@@ -319,7 +319,7 @@
/*
* check for and fetch an scoord from ST-arg into C-dst
- * ST-object must be SmallInteger. Return from method if invalid.
+ * ST-object must be SmallInteger. Return from method if invalid.
*/
#define _SCOORD_(arg, dst) \
if (__isSmallInteger(arg)) \
@@ -405,25 +405,25 @@
{
XGetErrorText(dpy, event->error_code, lastErrorMsg, 80);
if (lastErrorMsg[0] == '\0') {
- sprintf(lastErrorMsg, "code: %d", event->error_code);
+ sprintf(lastErrorMsg, "code: %d", event->error_code);
}
lastRequestCode = event->request_code;
lastMinorCode = event->minor_code;
lastResource = event->resourceid;
if ((event->error_code == BadWindow) && (lastRequestCode == 4) && (lastMinorCode == 0)) {
- /*
- * this is a BadWindow error for X_DestroyWindow.
- * ignore it here, since it results from the GC freeing windows
- * in non bottom-up window order.
- */
- return 0;
+ /*
+ * this is a BadWindow error for X_DestroyWindow.
+ * ignore it here, since it results from the GC freeing windows
+ * in non bottom-up window order.
+ */
+ return 0;
}
if (@global(ErrorPrinting) == true) {
- fprintf(stderr, "GLXWORKSTAT: x-error caught maj=%d (0x%x) min=%d (0x%x) resource=%x\n",
- event->request_code, event->request_code,
- event->minor_code, event->minor_code, event->resourceid);
- fprintf(stderr, "GLXWORKSTAT: x-error message is [%d] '%s'\n", event->error_code, lastErrorMsg);
+ console_fprintf(stderr, "GLXWORKSTAT: x-error caught maj=%d (0x%x) min=%d (0x%x) resource=%x\n",
+ event->request_code, event->request_code,
+ event->minor_code, event->minor_code, event->resourceid);
+ console_fprintf(stderr, "GLXWORKSTAT: x-error message is [%d] '%s'\n", event->error_code, lastErrorMsg);
}
__errorInterruptWithIDAndParameter__(@symbol(DisplayError), __MKOBJ(dpy));
@@ -433,14 +433,14 @@
extern __XErrorHandler__();
#endif
-/*
+/*
* begin moved from GLXsupport.c
*/
/*
* This provides a helper function "GLXCreateWindow", which does
- * all the necessary magic to create an X window suitable for GL drawing
- * to take place within. See the definition of GLXCreateWindow for a
+ * all the necessary magic to create an X window suitable for GL drawing
+ * to take place within. See the definition of GLXCreateWindow for a
* description of how to call it.
*
* claus: I really had no time to look into all this,
@@ -452,7 +452,7 @@
# include <X11/Xlib.h>
# include <X11/Xutil.h>
# ifndef VGL
-# include <gl/glws.h>
+# include <gl/glws.h>
# endif
# include <signal.h>
# include <setjmp.h>
@@ -462,9 +462,9 @@
* glxhelper.h:
*
* List of drawing modes supported by GLXCreateWindow (in glxhelper.c).
- * More than this are possible with mixed model, but this is just an
- * example. You can either expand this list (and the corresponding code in
- * GLXCreateWindow) or call the mixed model calls yourself, using
+ * More than this are possible with mixed model, but this is just an
+ * example. You can either expand this list (and the corresponding code in
+ * GLXCreateWindow) or call the mixed model calls yourself, using
* GLXCreateWindow as an example.
*/
@@ -483,7 +483,7 @@
* Dorky little helper function used to build up a GLXconfig array.
*/
-static void
+static void
set_entry (GLXconfig* ptr, int b, int m, int a)
{
ptr->buffer = b;
@@ -517,7 +517,7 @@
* type the GLXWindowType (see glxhelper.h) desribing the
* typer of GL drawing to be done in this window
*/
-Window
+Window
__GLXCreateWindow(dpy, parent, x, y, w, h, borderWidth, type)
Display* dpy;
Window parent;
@@ -550,26 +550,26 @@
#endif
if (setjmp(errorReturn)) {
- fprintf(stderr, "hard error in GL - return\n");
+ console_fprintf(stderr, "hard error in GL - return\n");
#ifdef HAS_SIGACTION
- sigaction(SIGSEGV, &oldSig, 0);
-#else
- signal(SIGSEGV, oldSig);
+ sigaction(SIGSEGV, &oldSig, 0);
+#else
+ signal(SIGSEGV, oldSig);
#endif
#if !defined(OPENGL)
- __catchExit(0);
-#endif
- return 0;
+ __catchExit(0);
+#endif
+ return 0;
}
__CONT__
if (w <= 0) {
- fprintf(stderr, "GL: bad width: %d\n", w);
- w = 1;
+ console_fprintf(stderr, "GL: bad width: %d\n", w);
+ w = 1;
}
if (h <= 0) {
- fprintf(stderr, "GL: bad height: %d\n", h);
- h = 1;
+ console_fprintf(stderr, "GL: bad height: %d\n", h);
+ h = 1;
}
#if !defined(OPENGL)
@@ -580,22 +580,22 @@
switch (type) {
case GLXcolorIndexSingleBuffer:
case GLXcolorIndexDoubleBuffer:
- break;
+ break;
case GLXrgbSingleBuffer:
case GLXrgbDoubleBuffer:
- fprintf(stderr, "Sorry, VGL can't support %s type of windows\n", typeToName[type]);
- __catchExit(0);
- return 0;
+ console_fprintf(stderr, "Sorry, VGL can't support %s type of windows\n", typeToName[type]);
+ __catchExit(0);
+ return 0;
}
scr = DefaultScreen(dpy);
visual.visualid = CopyFromParent;
cwa.border_pixel = 0; /* Even if we don't use it, it must be something */
win = XCreateWindow(dpy, parent, x, y, w, h,
- borderWidth, DisplayPlanes(dpy, scr),
- InputOutput, &visual,
- CWBorderPixel, &cwa);
+ borderWidth, DisplayPlanes(dpy, scr),
+ InputOutput, &visual,
+ CWBorderPixel, &cwa);
/*
* on some, seg-violations occur in the GL, if too many
@@ -618,9 +618,9 @@
# endif
if (i < 0) {
- fprintf(stderr, "GLXlink returned %d\n", i);
- __catchExit(0);
- return 0;
+ console_fprintf(stderr, "GLXlink returned %d\n", i);
+ __catchExit(0);
+ return 0;
}
# else /* not VGL */
@@ -632,21 +632,21 @@
next = params;
switch (type) {
case GLXcolorIndexSingleBuffer:
- set_entry(next++, GLX_NORMAL, GLX_RGB, FALSE);
- set_entry(next++, GLX_NORMAL, GLX_DOUBLE, FALSE);
- break;
+ set_entry(next++, GLX_NORMAL, GLX_RGB, FALSE);
+ set_entry(next++, GLX_NORMAL, GLX_DOUBLE, FALSE);
+ break;
case GLXcolorIndexDoubleBuffer:
- set_entry(next++, GLX_NORMAL, GLX_RGB, FALSE);
- set_entry(next++, GLX_NORMAL, GLX_DOUBLE, TRUE);
- break;
+ set_entry(next++, GLX_NORMAL, GLX_RGB, FALSE);
+ set_entry(next++, GLX_NORMAL, GLX_DOUBLE, TRUE);
+ break;
case GLXrgbSingleBuffer:
- set_entry(next++, GLX_NORMAL, GLX_RGB, TRUE);
- set_entry(next++, GLX_NORMAL, GLX_DOUBLE, FALSE);
- break;
+ set_entry(next++, GLX_NORMAL, GLX_RGB, TRUE);
+ set_entry(next++, GLX_NORMAL, GLX_DOUBLE, FALSE);
+ break;
case GLXrgbDoubleBuffer:
- set_entry(next++, GLX_NORMAL, GLX_RGB, TRUE);
- set_entry(next++, GLX_NORMAL, GLX_DOUBLE, TRUE);
- break;
+ set_entry(next++, GLX_NORMAL, GLX_RGB, TRUE);
+ set_entry(next++, GLX_NORMAL, GLX_DOUBLE, TRUE);
+ break;
}
set_entry(next, 0, 0, 0); /* The input to GLXgetconfig is null terminated */
@@ -658,9 +658,9 @@
XGetWindowAttributes(dpy, parent, &pwa);
retconfig = GLXgetconfig(dpy, XScreenNumberOfScreen(pwa.screen), params);
if (retconfig == 0) {
- fprintf(stderr, "Sorry, can't support %s type of windows\n", typeToName[type]);
- __catchExit(0);
- return 0;
+ console_fprintf(stderr, "Sorry, can't support %s type of windows\n", typeToName[type]);
+ __catchExit(0);
+ return 0;
}
/*
@@ -668,24 +668,24 @@
* that supports the rendering mode.
*/
for (next = retconfig; next->buffer; next++) {
- unsigned long buffer = next->buffer;
- unsigned long mode = next->mode;
- unsigned long value = next->arg;
- switch (mode) {
- case GLX_COLORMAP:
- if (buffer == GLX_NORMAL) {
- cmap = value;
- }
- break;
- case GLX_VISUAL:
- if (buffer == GLX_NORMAL) {
- template.visualid = value;
- template.screen = DefaultScreen(dpy);
- vis = XGetVisualInfo(dpy, VisualScreenMask|VisualIDMask,
- &template, &nret);
- }
- break;
- }
+ unsigned long buffer = next->buffer;
+ unsigned long mode = next->mode;
+ unsigned long value = next->arg;
+ switch (mode) {
+ case GLX_COLORMAP:
+ if (buffer == GLX_NORMAL) {
+ cmap = value;
+ }
+ break;
+ case GLX_VISUAL:
+ if (buffer == GLX_NORMAL) {
+ template.visualid = value;
+ template.screen = DefaultScreen(dpy);
+ vis = XGetVisualInfo(dpy, VisualScreenMask|VisualIDMask,
+ &template, &nret);
+ }
+ break;
+ }
}
/*
@@ -694,18 +694,18 @@
cwa.colormap = cmap;
cwa.border_pixel = 0; /* Even if we don't use it, it must be something */
win = XCreateWindow(dpy, parent, x, y, w, h,
- borderWidth, vis->depth, InputOutput, vis->visual,
- CWColormap|CWBorderPixel, &cwa);
+ borderWidth, vis->depth, InputOutput, vis->visual,
+ CWColormap|CWBorderPixel, &cwa);
/*
* Rescan configuration info and find window slot that getconfig
* provided. Fill it in with the window we just created.
*/
for (next = retconfig; next->buffer; next++) {
- if ((next->buffer == GLX_NORMAL) && (next->mode == GLX_WINDOW)) {
- next->arg = win;
- break;
- }
+ if ((next->buffer == GLX_NORMAL) && (next->mode == GLX_WINDOW)) {
+ next->arg = win;
+ break;
+ }
}
/*
@@ -732,9 +732,9 @@
# endif
if (i < 0) {
- fprintf(stderr, "GLXlink returned %d\n", i);
- __catchExit(0);
- return 0;
+ console_fprintf(stderr, "GLXlink returned %d\n", i);
+ __catchExit(0);
+ return 0;
}
/*
@@ -750,12 +750,12 @@
visual.visualid = CopyFromParent;
cwa.border_pixel = 0; /* Even if we don't use it, it must be something */
win = XCreateWindow(dpy, parent, x, y, w, h,
- borderWidth, DisplayPlanes(dpy, scr),
- InputOutput, &visual,
- CWBorderPixel, &cwa);
+ borderWidth, DisplayPlanes(dpy, scr),
+ InputOutput, &visual,
+ CWBorderPixel, &cwa);
vis = XGetVisualInfo(dpy, VisualScreenMask|VisualIDMask, &visual, &nret);
- fprintf(stderr, "vis is %x\n", vis);
+ console_fprintf(stderr, "vis is %x\n", vis);
#endif /* GLX || VGL */
return win;
@@ -784,40 +784,40 @@
float f_angle;
if (__isFloat(angle)) {
- f_angle = (float)(_floatVal(angle));
- if (f_angle != 0.0) {
-#ifdef OPENGL
-#else
- rot(f_angle, axis);
-#endif
- }
- return (true);
+ f_angle = (float)(_floatVal(angle));
+ if (f_angle != 0.0) {
+#ifdef OPENGL
+#else
+ rot(f_angle, axis);
+#endif
+ }
+ return (true);
}
if (__isFraction(angle)
&& __isSmallInteger(_FractionInstPtr(angle)->f_numerator)
&& __isSmallInteger(_FractionInstPtr(angle)->f_denominator)) {
- float n, d;
-
- n = (float)(__intVal(_FractionInstPtr(angle)->f_numerator));
- d = (float)(__intVal(_FractionInstPtr(angle)->f_denominator));
- f_angle = n / d;
- if (f_angle != 0.0) {
-#ifdef OPENGL
-#else
- rot(f_angle, axis);
-#endif
- }
- return (true);
+ float n, d;
+
+ n = (float)(__intVal(_FractionInstPtr(angle)->f_numerator));
+ d = (float)(__intVal(_FractionInstPtr(angle)->f_denominator));
+ f_angle = n / d;
+ if (f_angle != 0.0) {
+#ifdef OPENGL
+#else
+ rot(f_angle, axis);
+#endif
+ }
+ return (true);
}
if (__isSmallInteger(angle)) {
- f_angle = (float)(__intVal(angle));
- if (f_angle != 0.0) {
-#ifdef OPENGL
-#else
- rot(f_angle, axis);
-#endif
- }
- return (true);
+ f_angle = (float)(__intVal(angle));
+ if (f_angle != 0.0) {
+#ifdef OPENGL
+#else
+ rot(f_angle, axis);
+#endif
+ }
+ return (true);
}
return false;
}
@@ -842,10 +842,10 @@
pElem = (char *)(_InstPtr(obj)) + nInstBytes;
if (nByte < (count * sizeof(OBJ))) return (long *)NULL;
for (i=0; i<count; i++) {
- o = *(OBJ *)pElem;
- if (! __isSmallInteger(o)) return (long *)NULL;
- vec[i] = (long)__intVal(o);
- pElem += sizeof(OBJ);
+ o = *(OBJ *)pElem;
+ if (! __isSmallInteger(o)) return (long *)NULL;
+ vec[i] = (long)__intVal(o);
+ pElem += sizeof(OBJ);
}
return vec;
}
@@ -870,16 +870,16 @@
pElem = (char *)(_InstPtr(obj)) + nInstBytes;
if (nByte < (count * sizeof(OBJ))) return (short *)NULL;
for (i=0; i<count; i++) {
- o = *(OBJ *)pElem;
- if (! __isSmallInteger(o)) return (short *)NULL;
- vec[i] = (short)__intVal(o);
- pElem += sizeof(OBJ);
+ o = *(OBJ *)pElem;
+ if (! __isSmallInteger(o)) return (short *)NULL;
+ vec[i] = (short)__intVal(o);
+ pElem += sizeof(OBJ);
}
return vec;
}
/*
- * fetch floats from an st-object into a c-float array
+ * fetch floats from an st-object into a c-float array
* which may be a floatArray, doubleArray or array-of-something,
* where something may be a float, fraction or smallInteger,
*/
@@ -904,56 +904,56 @@
switch (__intVal(_ClassInstPtr(cls)->c_flags) & ARRAYMASK) {
case FLOATARRAY:
- /*
- * best speed for float array
- * - the data is already as we want it
- */
- if (nByte < (count * sizeof(float))) return (float *)0;
- return (float *)pElem;
+ /*
+ * best speed for float array
+ * - the data is already as we want it
+ */
+ if (nByte < (count * sizeof(float))) return (float *)0;
+ return (float *)pElem;
case DOUBLEARRAY:
- /*
- * for double array, have to copy-and-cast
- */
- if (nByte < (count * sizeof(double))) return (float *)0;
- for (i=0; i<count; i++) {
- vec[i] = *((double *)pElem);
- pElem += sizeof(double);
- }
- return vec;
+ /*
+ * for double array, have to copy-and-cast
+ */
+ if (nByte < (count * sizeof(double))) return (float *)0;
+ for (i=0; i<count; i++) {
+ vec[i] = *((double *)pElem);
+ pElem += sizeof(double);
+ }
+ return vec;
case POINTERARRAY:
- /*
- * for other array, have to fetch, check and store
- * the elements can be floats, smallintegers or fractions
- */
- if (nByte < (count * sizeof(OBJ))) return (float *)0;
- /* get elements one-by-one */
- for (i=0; i<count; i++) {
- o = *(OBJ *)pElem;
- if (__isFloat(o)) {
- vec[i] = _floatVal(o);
- } else if (__isSmallInteger(o)) {
- vec[i] = (float)(__intVal(o));
- } else if (__isFraction(o)
- && __isSmallInteger(_FractionInstPtr(o)->f_numerator)
- && __isSmallInteger(_FractionInstPtr(o)->f_denominator)) {
- float n, d;
-
- n = (float)(__intVal(_FractionInstPtr(o)->f_numerator));
- d = (float)(__intVal(_FractionInstPtr(o)->f_denominator));
- vec[i] = n / d;
- } else
- return 0;
- pElem += sizeof(OBJ);
- }
- return vec;
+ /*
+ * for other array, have to fetch, check and store
+ * the elements can be floats, smallintegers or fractions
+ */
+ if (nByte < (count * sizeof(OBJ))) return (float *)0;
+ /* get elements one-by-one */
+ for (i=0; i<count; i++) {
+ o = *(OBJ *)pElem;
+ if (__isFloat(o)) {
+ vec[i] = _floatVal(o);
+ } else if (__isSmallInteger(o)) {
+ vec[i] = (float)(__intVal(o));
+ } else if (__isFraction(o)
+ && __isSmallInteger(_FractionInstPtr(o)->f_numerator)
+ && __isSmallInteger(_FractionInstPtr(o)->f_denominator)) {
+ float n, d;
+
+ n = (float)(__intVal(_FractionInstPtr(o)->f_numerator));
+ d = (float)(__intVal(_FractionInstPtr(o)->f_denominator));
+ vec[i] = n / d;
+ } else
+ return 0;
+ pElem += sizeof(OBJ);
+ }
+ return vec;
}
return (float *)0;
}
/*
- * fetch doubles from an st-object into a c-double array
+ * fetch doubles from an st-object into a c-double array
* which may be a floatArray, doubleArray or array-of-something,
* where something may be a float, fraction or smallInteger,
*/
@@ -975,41 +975,41 @@
switch (__intVal(_ClassInstPtr(cls)->c_flags) & ARRAYMASK) {
case DOUBLEARRAY:
- /* best speed for double array - the data is already as we want it */
- if (nByte < (count * sizeof(double))) return (double *)0;
- return (double *)pElem;
+ /* best speed for double array - the data is already as we want it */
+ if (nByte < (count * sizeof(double))) return (double *)0;
+ return (double *)pElem;
case FLOATARRAY:
- if (nByte < (count * sizeof(float))) return (double *)0;
- for (i=0; i<count; i++) {
- vec[i] = *((float *)pElem);
- pElem += sizeof(float);
- }
- return vec;
+ if (nByte < (count * sizeof(float))) return (double *)0;
+ for (i=0; i<count; i++) {
+ vec[i] = *((float *)pElem);
+ pElem += sizeof(float);
+ }
+ return vec;
case POINTERARRAY:
- if (nByte < (count * sizeof(OBJ))) return (double *)0;
- /* get elements one-by-one */
- for (i=0; i<count; i++) {
- o = *(OBJ *)pElem;
- if (__isFloat(o))
- vec[i] = _floatVal(o);
- else if (__isSmallInteger(o))
- vec[i] = (double)(__intVal(o));
- else if (__isFraction(o)
- && __isSmallInteger(_FractionInstPtr(o)->f_numerator)
- && __isSmallInteger(_FractionInstPtr(o)->f_denominator)) {
- double n, d;
-
- n = (double)(__intVal(_FractionInstPtr(o)->f_numerator));
- d = (double)(__intVal(_FractionInstPtr(o)->f_denominator));
- vec[i] = n / d;
-
- } else
- return 0;
- pElem += sizeof(OBJ);
- }
- return vec;
+ if (nByte < (count * sizeof(OBJ))) return (double *)0;
+ /* get elements one-by-one */
+ for (i=0; i<count; i++) {
+ o = *(OBJ *)pElem;
+ if (__isFloat(o))
+ vec[i] = _floatVal(o);
+ else if (__isSmallInteger(o))
+ vec[i] = (double)(__intVal(o));
+ else if (__isFraction(o)
+ && __isSmallInteger(_FractionInstPtr(o)->f_numerator)
+ && __isSmallInteger(_FractionInstPtr(o)->f_denominator)) {
+ double n, d;
+
+ n = (double)(__intVal(_FractionInstPtr(o)->f_numerator));
+ d = (double)(__intVal(_FractionInstPtr(o)->f_denominator));
+ vec[i] = n / d;
+
+ } else
+ return 0;
+ pElem += sizeof(OBJ);
+ }
+ return vec;
}
return (double *)0;
}
@@ -1038,20 +1038,20 @@
switch (__intVal(_ClassInstPtr(cls)->c_flags) & ARRAYMASK) {
case FLOATARRAY:
- if (nByte < (count * sizeof(float))) return 0;
- for (i=0; i<count; i++) {
- *(float *)pElem = vec[i];
- pElem += sizeof(float);
- }
- return 1;
+ if (nByte < (count * sizeof(float))) return 0;
+ for (i=0; i<count; i++) {
+ *(float *)pElem = vec[i];
+ pElem += sizeof(float);
+ }
+ return 1;
case DOUBLEARRAY:
- if (nByte < (count * sizeof(float))) return 0;
- for (i=0; i<count; i++) {
- *(double *)pElem = vec[i];
- pElem += sizeof(double);
- }
- return 1;
+ if (nByte < (count * sizeof(float))) return 0;
+ for (i=0; i<count; i++) {
+ *(double *)pElem = vec[i];
+ pElem += sizeof(double);
+ }
+ return 1;
}
/* not implemented for others */
@@ -1082,52 +1082,52 @@
pElem = (char *)(_InstPtr(obj)) + nInstBytes;
switch (__intVal(_ClassInstPtr(cls)->c_flags) & ARRAYMASK) {
- case FLOATARRAY:
- /*
- * very easy for FLOATARRAY objects - no copying needed
- */
- if (nByte < (16 * sizeof(float))) return (Matrix *)0;
- return (Matrix *) _FloatArrayInstPtr(obj)->f_element;
-
- case DOUBLEARRAY:
- /*
- * for DOUBLEARRAY objects copy and cast
- */
- if (nByte < (16 * sizeof(double))) return (Matrix *)0;
- for (i=0; i<4; i++) {
- for (j=0; j<4; j++) {
- (*mp)[i][j] = _DoubleArrayInstPtr(obj)->d_element[x];
- x++;
- }
- }
- return mp;
-
- case POINTERARRAY:
- if (nByte < (16 * sizeof(OBJ))) return (Matrix *)0;
- /*
- * get elements one-by-one
- */
- for (i=0; i<4; i++) {
- for (j=0; j<4; j++) {
- o = _ArrayInstPtr(obj)->a_element[x];
- if (__isFloat(o)) {
- (*mp)[i][j] = _floatVal(o);
- } else if (__isSmallInteger(o)) {
- (*mp)[i][j] = (double)__intVal(o);
- } else if (__isFraction(o)
- && __isSmallInteger(_FractionInstPtr(o)->f_numerator)
- && __isSmallInteger(_FractionInstPtr(o)->f_denominator)) {
- double n, d;
-
- n = (double)(__intVal(_FractionInstPtr(o)->f_numerator));
- d = (double)(__intVal(_FractionInstPtr(o)->f_denominator));
- (*mp)[i][j] = n / d;
- } else
- return (Matrix *)0;
- x++;
- }
- }
- return mp;
+ case FLOATARRAY:
+ /*
+ * very easy for FLOATARRAY objects - no copying needed
+ */
+ if (nByte < (16 * sizeof(float))) return (Matrix *)0;
+ return (Matrix *) _FloatArrayInstPtr(obj)->f_element;
+
+ case DOUBLEARRAY:
+ /*
+ * for DOUBLEARRAY objects copy and cast
+ */
+ if (nByte < (16 * sizeof(double))) return (Matrix *)0;
+ for (i=0; i<4; i++) {
+ for (j=0; j<4; j++) {
+ (*mp)[i][j] = _DoubleArrayInstPtr(obj)->d_element[x];
+ x++;
+ }
+ }
+ return mp;
+
+ case POINTERARRAY:
+ if (nByte < (16 * sizeof(OBJ))) return (Matrix *)0;
+ /*
+ * get elements one-by-one
+ */
+ for (i=0; i<4; i++) {
+ for (j=0; j<4; j++) {
+ o = _ArrayInstPtr(obj)->a_element[x];
+ if (__isFloat(o)) {
+ (*mp)[i][j] = _floatVal(o);
+ } else if (__isSmallInteger(o)) {
+ (*mp)[i][j] = (double)__intVal(o);
+ } else if (__isFraction(o)
+ && __isSmallInteger(_FractionInstPtr(o)->f_numerator)
+ && __isSmallInteger(_FractionInstPtr(o)->f_denominator)) {
+ double n, d;
+
+ n = (double)(__intVal(_FractionInstPtr(o)->f_numerator));
+ d = (double)(__intVal(_FractionInstPtr(o)->f_denominator));
+ (*mp)[i][j] = n / d;
+ } else
+ return (Matrix *)0;
+ x++;
+ }
+ }
+ return mp;
}
return (Matrix *)0;
}
@@ -1145,11 +1145,11 @@
if (! _isNonNilObject(obj)) return (float *)0;
cls = __qClass(obj);
if (cls == @global(FloatArray))
- return _FloatArrayInstPtr(obj)->f_element;
+ return _FloatArrayInstPtr(obj)->f_element;
if ((__intVal(_ClassInstPtr(cls)->c_flags) & ARRAYMASK) == FLOATARRAY) {
- ninstVars = __intVal(_ClassInstPtr(cls)->c_ninstvars);
- return (float *) &(_InstPtr(obj)->i_instvars[ninstVars]);
+ ninstVars = __intVal(_ClassInstPtr(cls)->c_ninstvars);
+ return (float *) &(_InstPtr(obj)->i_instvars[ninstVars]);
}
/*
@@ -1198,7 +1198,7 @@
The interface offered here provides a very very low level (i.e one-to-one)
interface to GL functions. More high-level stuff is required, to make
- 3D drawing be more object-oriented.
+ 3D drawing be more object-oriented.
(see a bit of this in 'clients/IRIS-specials')
Some functions are duplicated, Jeff and I developed those in parallel -
@@ -1220,7 +1220,7 @@
VGL stuff dec 93
many many additions jan 94 by Jeff McAffer <jeff@is.s.u-tokyo.ac.jp>
- Since this is a demo (consider it a free add-on goody) there is
+ Since this is a demo (consider it a free add-on goody) there is
*** NO WARRANTY ** for this.
Notice: this should be rewritten to use the openGL library functions
@@ -1718,7 +1718,7 @@
"Return the current character position as a point with integer coordinates"
| x y |
-%{
+%{
short s_x, s_y;
SETWIN(aGLXWindowId)
@@ -1779,8 +1779,8 @@
!GLXWorkstation methodsFor:'color'!
glxColor:index in:aGLXWindowId
- "set the drawing color;
- for non gouraud shading, we dont care if the argument is integer or float;
+ "set the drawing color;
+ for non gouraud shading, we dont care if the argument is integer or float;
otherwise, better results are expected with float values."
%{ /* NOCONTEXT */
@@ -1841,8 +1841,8 @@
%{ /* NOCONTEXT */
SETWIN(aGLXWindowId)
#ifdef GLX
- lRGBrange(_shortVal(rmin), _shortVal(gmin), _shortVal(bmin),
- _shortVal(rmax), _shortVal(gmax), _shortVal(bmax),
+ lRGBrange(_shortVal(rmin), _shortVal(gmin), _shortVal(bmin),
+ _shortVal(rmax), _shortVal(gmax), _shortVal(bmax),
_longVal(znear), _longVal(zfar));
#endif
%}
@@ -2334,7 +2334,7 @@
!
glxRmv2:v in: aGLXWindowId
- "change the graphics position to a 2D point,
+ "change the graphics position to a 2D point,
the relative distance is passed in vector v"
%{ /* NOCONTEXT */
@@ -2354,7 +2354,7 @@
!
glxRmv2X: x y: y in: aGLXWindowId
- "change the graphics position to a 2D point,
+ "change the graphics position to a 2D point,
the relative distance is passed in x/y"
%{ /* NOCONTEXT */
@@ -2375,7 +2375,7 @@
!
glxRmv2iX: x y: y in: aGLXWindowId
- "change the graphics position to a 2D point,
+ "change the graphics position to a 2D point,
the relative distance is passed in x/y.
The arguments must be smallIntegers."
@@ -2397,7 +2397,7 @@
!
glxRmv2sX: x y: y in: aGLXWindowId
- "change the graphics position to a 2D point,
+ "change the graphics position to a 2D point,
the relative distance is passed in x/y.
The arguments must be smallIntegers."
@@ -2419,7 +2419,7 @@
!
glxRmv:v in: aGLXWindowId
- "change the graphics position to a 3D point,
+ "change the graphics position to a 3D point,
the relative distance is passed in vector v"
%{ /* NOCONTEXT */
@@ -2439,7 +2439,7 @@
!
glxRmvX: x y: y z: z in: aGLXWindowId
- "change the graphics position to a 3D point,
+ "change the graphics position to a 3D point,
the relative distance is passed in x/y/z"
%{ /* NOCONTEXT */
@@ -2461,7 +2461,7 @@
!
glxRmviX: x y: y z: z in: aGLXWindowId
- "change the graphics position to a 3D point,
+ "change the graphics position to a 3D point,
the relative distance is passed in x/y/z.
The arguments must be smallIntegers."
@@ -2484,7 +2484,7 @@
!
glxRmvsX: x y: y z: z in: aGLXWindowId
- "change the graphics position to a 3D point,
+ "change the graphics position to a 3D point,
the relative distance is passed in x/y/z.
The arguments must be smallIntegers."
@@ -2529,8 +2529,8 @@
"/ Sorry. (I guess, there are some query functions for that available, but I
"/ have no documentation).
"/ Late note: setting the ForceGL classVar overrides above behavior.
- "/ it may be set from a startupScript with: 'GLXWorkstation forceGL:true'
- "/ however: be careful: only set it to true, if you are certain that remoteGL works
+ "/ it may be set from a startupScript with: 'GLXWorkstation forceGL:true'
+ "/ however: be careful: only set it to true, if you are certain that remoteGL works
(self isTrueGL and:[ForceGL ~~ true]) ifTrue:[
glOK := (displayName = ':0') or:[displayName = ':0.0'].
@@ -2961,8 +2961,8 @@
defType = LIGHT7;
else if (target == @symbol(lightModel))
defType = LMODEL;
- else {
- RETURN (nil);
+ else {
+ RETURN (nil);
}
_INT_ (index, i_index);
@@ -3010,7 +3010,7 @@
} else {
RETURN (nil);
}
- }
+ }
}
SETWIN(aGLXWindowId)
lmdef(defType, i_index, i_np, fp);
@@ -3324,9 +3324,9 @@
#ifdef OPENGL
#else
if (__isSmallInteger(obj)) {
- SETWIN(aGLXWindowId)
- delobj(_objectVal(obj));
- RETURN (true);
+ SETWIN(aGLXWindowId)
+ delobj(_objectVal(obj));
+ RETURN (true);
}
#endif
%}
@@ -3452,18 +3452,18 @@
%}
!
-glxNurbsSurfaceUKnotCount: uKnotCount uKnot: uKnot
+glxNurbsSurfaceUKnotCount: uKnotCount uKnot: uKnot
vKnotCount: vKnotCount vKnot: vKnot
- uOffset: uOffset vOffset: vOffset
- ctlArray: ctlArray
- uOrder: uOrder vOrder: vOrder
+ uOffset: uOffset vOffset: vOffset
+ ctlArray: ctlArray
+ uOrder: uOrder vOrder: vOrder
type: type in: aGLXWindowId
| ctlPoints i |
ctlPoints := DoubleArray new: ctlArray size * (ctlArray first size).
i := 1.
ctlArray do: [:point |
- point do: [:coord |
+ point do: [:coord |
ctlPoints at: i put: coord.
i := i + 1]].
@@ -3486,7 +3486,7 @@
__intVal(uKnotCount), (double *)uKnotElements,
__intVal(vKnotCount), (double *)vKnotElements,
__intVal(uOffset), __intVal(vOffset),
- (double *)ctlElements,
+ (double *)ctlElements,
__intVal(uOrder), __intVal(vOrder), __intVal(type));
RETURN(true);
#endif
@@ -3550,11 +3550,11 @@
Matrix matrixX, matrixY, matrixZ;
Matrix *mX, *mY, *mZ;
- if (! (mX = __glx_getFloatsFromMatrixInto(arrayOf16XFloats, matrixX)))
+ if (! (mX = __glx_getFloatsFromMatrixInto(arrayOf16XFloats, matrixX)))
RETURN (nil);
- if (! (mY = __glx_getFloatsFromMatrixInto(arrayOf16YFloats, matrixY)))
+ if (! (mY = __glx_getFloatsFromMatrixInto(arrayOf16YFloats, matrixY)))
RETURN (nil);
- if (! (mZ = __glx_getFloatsFromMatrixInto(arrayOf16ZFloats, matrixZ)))
+ if (! (mZ = __glx_getFloatsFromMatrixInto(arrayOf16ZFloats, matrixZ)))
RETURN (nil);
SETWIN(aGLXWindowId)
patch(*mX, *mY, *mZ);
@@ -3574,13 +3574,13 @@
Matrix matrixX, matrixY, matrixZ, matrixW;
Matrix *mX, *mY, *mZ, *mW;
- if (! (mX = __glx_getFloatsFromMatrixInto(arrayOf16XFloats, matrixX)))
+ if (! (mX = __glx_getFloatsFromMatrixInto(arrayOf16XFloats, matrixX)))
RETURN (nil);
- if (! (mY = __glx_getFloatsFromMatrixInto(arrayOf16YFloats, matrixY)))
+ if (! (mY = __glx_getFloatsFromMatrixInto(arrayOf16YFloats, matrixY)))
RETURN (nil);
- if (! (mZ = __glx_getFloatsFromMatrixInto(arrayOf16ZFloats, matrixZ)))
+ if (! (mZ = __glx_getFloatsFromMatrixInto(arrayOf16ZFloats, matrixZ)))
RETURN (nil);
- if (! (mW = __glx_getFloatsFromMatrixInto(arrayOf16WFloats, matrixW)))
+ if (! (mW = __glx_getFloatsFromMatrixInto(arrayOf16WFloats, matrixW)))
RETURN (nil);
SETWIN(aGLXWindowId)
rpatch(*mX, *mY, *mZ, *mW);
@@ -3601,8 +3601,8 @@
%{ /* NOCONTEXT */
#ifdef GLX
SETWIN(aGLXWindowId)
- rectcopy(_screencoordVal(x1), _screencoordVal(y1),
- _screencoordVal(x2), _screencoordVal(y2),
+ rectcopy(_screencoordVal(x1), _screencoordVal(y1),
+ _screencoordVal(x2), _screencoordVal(y2),
_screencoordVal(newx), _screencoordVal(newy));
#endif
%}
@@ -3708,7 +3708,7 @@
) {
SETWIN(aGLXWindowId)
nRead = rectread(__intVal(x1), __intVal(sy1),
- __intVal(x2), __intVal(sy2),
+ __intVal(x2), __intVal(sy2),
buffer);
for (i=0; i<nRead;i++) {
__ArrayInstPtr(dest)->a_element[i] = __MKSMALLINT(buffer[i]);
@@ -3902,7 +3902,7 @@
!GLXWorkstation methodsFor:'polygons'!
glxBackface: b in: aGLXWindowId
- "enable/disable culling of backfacing polygons (suppress its drawing).
+ "enable/disable culling of backfacing polygons (suppress its drawing).
A polygon is backfacing if it's orientation in *screen* coords is clockwise"
%{ /* NOCONTEXT */
@@ -3929,8 +3929,8 @@
!
glxFrontface: b in: aGLXWindowId
- "enable/disable culling of frontfacing polygons (suppress its drawing).
- A polygon is frontfacing if it's orientation in *screen* coords is
+ "enable/disable culling of frontfacing polygons (suppress its drawing).
+ A polygon is frontfacing if it's orientation in *screen* coords is
anti-clockwise"
@@ -4426,7 +4426,7 @@
%}
"
- Display glVersion
+ Display glVersion
"
!
@@ -4453,7 +4453,7 @@
^ hasStereoExtension
"
- Display hasStereoExtension
+ Display hasStereoExtension
"
!
@@ -4487,7 +4487,7 @@
maxZValue
"return the max. Z value (only valid if z-buffer is supported)"
-%{
+%{
#ifndef OPENGL
# ifdef GD_ZMAX
long zMax;
@@ -4528,7 +4528,7 @@
^ false
"
- Display supportsDoubleBuffer
+ Display supportsDoubleBuffer
"
!
@@ -4538,7 +4538,7 @@
^ glOK
"
- Display supportsGLDrawing
+ Display supportsGLDrawing
"
!
@@ -4556,7 +4556,7 @@
^ false
"
- Display supportsLight
+ Display supportsLight
"
!
@@ -4575,7 +4575,7 @@
^ false
"
- Display supportsRGB
+ Display supportsRGB
"
!
@@ -4597,7 +4597,7 @@
^ false
"
- Display supportsTextures
+ Display supportsTextures
"
!
@@ -4619,7 +4619,7 @@
^ false
"
- Display supportsZBuffer
+ Display supportsZBuffer
"
! !
@@ -4822,7 +4822,7 @@
int buffer;
Window win;
- if (ISCONNECTED
+ if (ISCONNECTED
&& __isExternalAddress(aWindowId)) {
win = _WindowVal(aWindowId);
if (aBufferSymbol == @symbol(left)) {
@@ -4850,9 +4850,9 @@
v := GLXView origin:0.0@0.0 corner:1.0@1.0 in:t.
t openAndWait.
- v device stereoExtensionBuffer:#left for:(v id).
+ v device stereoExtensionBuffer:#left for:(v id).
(Delay forSeconds:10) wait.
- v device stereoExtensionBuffer:#right for:(v id).
+ v device stereoExtensionBuffer:#right for:(v id).
"
!
@@ -4870,7 +4870,7 @@
unsigned short us_h, us_o;
Window win;
- if (ISCONNECTED
+ if (ISCONNECTED
&& __bothSmallInteger(h, o)
&& __isExternalAddress(aWindowId)) {
win = _WindowVal(aWindowId);
@@ -4900,9 +4900,9 @@
self primitiveFailed
"
- Display stereoExtensionMode:#top height:492 offset:532 for:(Display rootWindowId).
+ Display stereoExtensionMode:#top height:492 offset:532 for:(Display rootWindowId).
(Delay forSeconds:10) wait.
- Display stereoExtensionMode:#off height:0 offset:0 for:(Display rootWindowId).
+ Display stereoExtensionMode:#off height:0 offset:0 for:(Display rootWindowId).
"
!
@@ -4939,7 +4939,7 @@
v openAndWait.
v device stereoExtensionModeIn:(v id)
- Display stereoExtensionModeIn:Display rootWindowId
+ Display stereoExtensionModeIn:Display rootWindowId
"
!
@@ -5518,7 +5518,7 @@
%{ /* NOCONTEXT */
Screencoord c_xmin, c_ymin;
- Coord c_x1, c_y1, c_x2, c_y2;
+ Coord c_x1, c_y1, c_x2, c_y2;
_SCREENCOORD_ (xmin, c_xmin)
_SCREENCOORD_ (ymin, c_ymin)
@@ -5537,7 +5537,7 @@
%{ /* NOCONTEXT */
Screencoord c_xmin, c_ymin;
- Icoord c_x1, c_y1, c_x2, c_y2;
+ Icoord c_x1, c_y1, c_x2, c_y2;
_SCREENCOORD_ (xmin, c_xmin)
_SCREENCOORD_ (ymin, c_ymin)
@@ -5556,7 +5556,7 @@
%{ /* NOCONTEXT */
Screencoord c_xmin, c_ymin;
- Scoord c_x1, c_y1, c_x2, c_y2;
+ Scoord c_x1, c_y1, c_x2, c_y2;
_SCREENCOORD_ (xmin, c_xmin)
_SCREENCOORD_ (ymin, c_ymin)
@@ -5606,7 +5606,7 @@
%{ /* NOCONTEXT */
SETWIN(aGLXWindowId)
#ifdef FULL_GLX
- blendcolor(_floatVal(red), _floatVal(green), _floatVal(blue), _floatVal(alpha));
+ blendcolor(_floatVal(red), _floatVal(green), _floatVal(blue), _floatVal(alpha));
#endif
%}
!
@@ -5626,7 +5626,7 @@
%{ /* NOCONTEXT */
SETWIN(aGLXWindowId)
#ifdef GLX
- blink(_shortVal(rate), _colorindexVal(i),
+ blink(_shortVal(rate), _colorindexVal(i),
_shortVal(red), _shortVal(green), _shortVal(blue));
#endif
%}
@@ -6603,7 +6603,7 @@
%{ /* NOCONTEXT */
#ifdef GLX
SETWIN(aGLXWindowId)
- lshaderange(_colorindexVal(lowin), _colorindexVal(hiwin),
+ lshaderange(_colorindexVal(lowin), _colorindexVal(hiwin),
_longVal(znear), _longVal(zfar));
RETURN (true);
#endif
@@ -6820,14 +6820,14 @@
!
glxNurbscurveKnotCount: knotCount knotList: knotList
- offset: offset ctlArray: ctlArray
+ offset: offset ctlArray: ctlArray
order: order type: type in: aGLXWindowId
| ctlPoints i |
ctlPoints := DoubleArray new: ctlArray size * (ctlArray first size).
i := 1.
ctlArray do: [:point |
- point do: [:coord |
+ point do: [:coord |
ctlPoints at: i put: coord.
i := i + 1]].
@@ -6847,7 +6847,7 @@
nurbscurve (
_longVal(knotCount), (double *)knotElements,
- _longVal(offset), (double *)ctlElements,
+ _longVal(offset), (double *)ctlElements,
_longVal(order), _longVal(type));
RETURN(true);
#endif
@@ -7099,7 +7099,7 @@
glxQreadIn: aGLXWindowId
| dev data |
-%{
+%{
short c_data;
SETWIN(aGLXWindowId)
@@ -7139,14 +7139,14 @@
%}
!
-glxRGBcursorIndex: index red: red green: green blue: blue
+glxRGBcursorIndex: index red: red green: green blue: blue
redm: redm greenm: greenm bluem: bluem in: aGLXWindowId
%{ /* NOCONTEXT */
#ifdef GLX
SETWIN(aGLXWindowId)
- RGBcursor(_shortVal(index),
- _shortVal(red), _shortVal(green), _shortVal(blue),
+ RGBcursor(_shortVal(index),
+ _shortVal(red), _shortVal(green), _shortVal(blue),
_shortVal(redm), _shortVal(greenm), _shortVal(bluem));
RETURN (true);
#endif
@@ -7329,7 +7329,7 @@
%{ /* NOCONTEXT */
#ifdef GLX
SETWIN(aGLXWindowId)
- scrmask(_screencoordVal(left), _screencoordVal(right),
+ scrmask(_screencoordVal(left), _screencoordVal(right),
_screencoordVal(bottom), _screencoordVal(top));
RETURN (true);
#endif
@@ -7512,7 +7512,7 @@
%{ /* NOCONTEXT */
#ifdef GLX
SETWIN(aGLXWindowId)
- shaderange(_colorindexVal(lowin), _colorindexVal(hiwin),
+ shaderange(_colorindexVal(lowin), _colorindexVal(hiwin),
_screencoordVal(z1), _screencoordVal(z2));
RETURN (true);
#endif
@@ -7534,13 +7534,13 @@
^ false
!
-glxStencilEnable: enable ref: ref func: func mask: mask fail: fail
+glxStencilEnable: enable ref: ref func: func mask: mask fail: fail
pass: pass zpass: zpass in: aGLXWindowId
%{ /* NOCONTEXT */
#ifdef GLX
SETWIN(aGLXWindowId)
- stencil(_longVal(enable), (ulong)__intVal(ref), _longVal(func),
+ stencil(_longVal(enable), (ulong)__intVal(ref), _longVal(func),
(ulong)__intVal(mask), _longVal(fail), _longVal(pass), _longVal(zpass));
RETURN (true);
#endif
@@ -7658,7 +7658,7 @@
%{ /* NOCONTEXT */
#ifdef GLX
SETWIN(aGLXWindowId)
- textport(_screencoordVal(left), _screencoordVal(right),
+ textport(_screencoordVal(left), _screencoordVal(right),
_screencoordVal(bottom), _screencoordVal(top));
RETURN (true);
#endif
@@ -8442,7 +8442,7 @@
SETWIN(aGLXWindowId)
#ifdef OPENGL
#else
- viewport(_screencoordVal(left), _screencoordVal(right),
+ viewport(_screencoordVal(left), _screencoordVal(right),
_screencoordVal(bottom), _screencoordVal(top));
#endif
%}
@@ -8783,5 +8783,5 @@
!GLXWorkstation class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview/GLXWorkstation.st,v 1.83 2007-01-18 16:01:50 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libview/GLXWorkstation.st,v 1.84 2007-01-24 13:41:11 cg Exp $'
! !