--- a/Depth24Image.st Fri Jun 07 19:29:05 1996 +0200
+++ b/Depth24Image.st Fri Jun 07 19:32:55 1996 +0200
@@ -39,6 +39,8 @@
It mainly consists of methods already implemented in Image,
reimplemented here for more performance.
+ Only the #rgb format is supported here.
+
[author:]
Claus Gittinger
@@ -136,6 +138,128 @@
!Depth24Image methodsFor:'converting rgb images'!
+orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW
+ "return the dithered monochrome bits for the receiver image;
+ with a constant ditherMatrix, this can be used for thresholding.
+ Redefined to make use of knowing that pixels are 24-bit values."
+
+ |f dH nDither
+ greyMap monoBits
+ bytesPerMonoRow "{Class: SmallInteger }"
+ bytesPerRow "{Class: SmallInteger }"
+ w "{Class: SmallInteger }"
+ h "{Class: SmallInteger }"|
+
+ nDither := ditherMatrix size.
+ dH := nDither / dW.
+
+ w := width.
+ h := height.
+
+ bytesPerRow := self bytesPerRow.
+
+ bytesPerMonoRow := w + 7 // 8.
+ monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
+ (monoBits isNil or:[bytes isNil]) ifTrue:[
+ ^ nil
+ ].
+
+ greyMap := ByteArray new:256.
+ photometric ~~ #rgb ifTrue:[
+ self error:'invalid format'.
+ ^ nil
+ ].
+
+%{
+ int __dW = __intVal(dW);
+ int __dH = __intVal(dH);
+ int __byte;
+ int __nDither = __intVal(nDither);
+ int __dT;
+ int __dstIdx = 0;
+ int __srcIdx = 0;
+ int __bitCnt;
+ int __grey;
+ int __w = __intVal(w);
+ int __h = __intVal(h);
+ int __x;
+ int __y;
+ int __oX, __oY, __dY;
+ int __nextDst;
+ int __nextSrc;
+ int __bytesPerRow = __intVal(bytesPerRow);
+ int __bytesPerMonoRow = __intVal(bytesPerMonoRow);
+
+ char *__monoBits = __ByteArrayInstPtr(monoBits)->ba_element;
+ char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element;
+ unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
+ unsigned char *__greyMap = __ByteArrayInstPtr(greyMap)->ba_element;
+
+ __oY = __dY = 0;
+ for (__y=0; __y<__h; __y++) {
+ __nextDst = __dstIdx + __bytesPerMonoRow;
+ __nextSrc = __srcIdx + __bytesPerRow;
+
+ __byte = 0;
+ __bitCnt = 8;
+
+ __oX = 0;
+
+ for (__x=0; __x<__w; __x++) {
+ __grey = (__bytes[__srcIdx] * 3) /* 0.3*r + 0.6*g + b -> 0..2550 */
+ + (__bytes[__srcIdx+1] * 6)
+ + __bytes[__srcIdx+2];
+ __grey = __grey * (__nDither+1) / 2550; /* 0 .. nDither+1 */
+ __srcIdx += 3;
+
+ __dT = __ditherMatrix[__dY + __oX];
+
+ __oX++;
+ if (__oX == __dW) __oX = 0;
+
+ __byte = __byte << 1;
+ if (__grey > __dT) {
+ __byte = __byte | 1; /* white */
+ }
+
+ __bitCnt--;
+ if (__bitCnt == 0) {
+ __monoBits[__dstIdx] = __byte;
+ __dstIdx++;
+ __byte = 0;
+ __bitCnt = 8;
+ }
+ }
+
+ if (__bitCnt != 8) {
+ __byte = __byte << __bitCnt;
+ __monoBits[__dstIdx] = __byte;
+ }
+
+ __oY++; __dY += __dW;
+ if (__oY == __dH) {
+ __oY = 0;
+ __dY = 0;
+ }
+
+ __srcIdx = __nextSrc;
+ __dstIdx = __nextDst;
+ }
+%}.
+
+ ^ monoBits
+
+ "
+ |i f|
+
+ i := Image fromFile:'bitmaps/granite.tiff'.
+ f := i asOrderedDitheredMonochromeFormOn:Display.
+ "
+
+ "Created: 7.6.1996 / 10:48:06 / cg"
+ "Modified: 7.6.1996 / 11:08:50 / cg"
+!
+
rgbImageAs2PlaneFormOn:aDevice
"return a 2-bit device form for aDevice from the rgb picture,
using a threshold algorithm.
@@ -1511,7 +1635,7 @@
!Depth24Image methodsFor:'enumerating'!
-atY:y from:xLow to:xHigh do:aBlock
+colorsAtY:y from:xLow to:xHigh do:aBlock
"perform aBlock for each pixel from x1 to x2 in row y.
The block is passed the color at each pixel.
This method allows slighly faster processing of an
@@ -1528,8 +1652,8 @@
lastR lastG lastB lastColor|
photometric ~~ #rgb ifTrue:[
- self error:'format not supported'.
- ^ nil
+ self error:'format not supported'.
+ ^ nil
].
x1 := xLow.
@@ -1538,23 +1662,27 @@
srcIndex := 1 + (((width * y) + x1) * 3).
x1 to:x2 do:[:x |
- rVal := bytes at:(srcIndex).
- gVal := bytes at:(srcIndex + 1).
- bVal := bytes at:(srcIndex + 2).
- srcIndex := srcIndex + 3.
- (rVal == lastR and:[gVal == lastG and:[bVal == lastB]]) ifFalse:[
- lastColor := Color red:rVal * 100 / 255
- green:gVal * 100 / 255
- blue:bVal * 100 / 255.
- lastR := rVal.
- lastG := gVal.
- lastB := bVal.
- ].
- aBlock value:x value:lastColor
+ rVal := bytes at:(srcIndex).
+ gVal := bytes at:(srcIndex + 1).
+ bVal := bytes at:(srcIndex + 2).
+ srcIndex := srcIndex + 3.
+
+ (rVal == lastR and:[gVal == lastG and:[bVal == lastB]]) ifFalse:[
+ lastColor := Color red:rVal * 100 / 255
+ green:gVal * 100 / 255
+ blue:bVal * 100 / 255.
+ lastR := rVal.
+ lastG := gVal.
+ lastB := bVal.
+ ].
+ aBlock value:x value:lastColor
]
+
+ "Modified: 7.6.1996 / 12:13:59 / cg"
+ "Created: 7.6.1996 / 19:12:28 / cg"
!
-valueAtY:y from:xLow to:xHigh do:aBlock
+valuesAtY:y from:xLow to:xHigh do:aBlock
"perform aBlock for each pixelValue from x1 to x2 in row y.
The block is passed the pixelValue at each pixel.
This method allows slighly faster processing of an
@@ -1577,12 +1705,14 @@
srcIndex := 1 + (((width * y) + x1) * 3).
x1 to:x2 do:[:x |
- r := bytes at:(srcIndex).
- g := bytes at:(srcIndex + 1).
- b := bytes at:(srcIndex + 2).
- srcIndex := srcIndex + 3.
- aBlock value:x value:(((r bitShift:16) bitOr:(g bitShift:8)) bitOr:b)
+ r := bytes at:(srcIndex).
+ g := bytes at:(srcIndex + 1).
+ b := bytes at:(srcIndex + 2).
+ srcIndex := srcIndex + 3.
+ aBlock value:x value:(((r bitShift:16) bitOr:(g bitShift:8)) bitOr:b)
]
+
+ "Created: 7.6.1996 / 19:09:40 / cg"
! !
!Depth24Image methodsFor:'magnification'!
@@ -1744,5 +1874,5 @@
!Depth24Image class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview/Depth24Image.st,v 1.25 1996-05-28 19:01:08 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview/Depth24Image.st,v 1.26 1996-06-07 17:31:48 cg Exp $'
! !