diff -r 75ff98ae918d -r 62426e8110ae Depth1Image.st --- a/Depth1Image.st Tue May 21 22:49:14 2013 +0200 +++ b/Depth1Image.st Tue May 21 22:50:48 2013 +0200 @@ -45,11 +45,11 @@ #blackIs0 / #whiteIs0 and #palette formats are supported here. [author:] - Claus Gittinger + Claus Gittinger [see also:] - Depth2Image Depth4Image Depth8Image Depth16Image Depth24Image - ImageReader + Depth2Image Depth4Image Depth8Image Depth16Image Depth24Image + ImageReader " ! ! @@ -79,23 +79,23 @@ %{ /* NOCONTEXT */ - OBJ b = _INST(bytes); - OBJ w = _INST(width); + OBJ b = __INST(bytes); + OBJ w = __INST(width); if (__bothSmallInteger(x, y) && __isSmallInteger(w)) { - if (__isByteArrayLike(b)) { - int _w = __intVal(w); - int _y = __intVal(y); - int _x = __intVal(x); - unsigned _byte; - int _idx; + if (__isByteArrayLike(b)) { + int _w = __intVal(w); + int _y = __intVal(y); + int _x = __intVal(x); + unsigned _byte; + int _idx; - _idx = ((_w + 7) >> 3) * _y + (_x >> 3); - if ((unsigned)_idx < __byteArraySize(b)) { - _byte = __ByteArrayInstPtr(b)->ba_element[_idx]; - RETURN( (_byte & (0x80 >> (_x & 7))) ? __MKSMALLINT(1) : __MKSMALLINT(0) ); - } - } + _idx = ((_w + 7) >> 3) * _y + (_x >> 3); + if ((unsigned)_idx < __byteArraySize(b)) { + _byte = __ByteArrayInstPtr(b)->ba_element[_idx]; + RETURN( (_byte & (0x80 >> (_x & 7))) ? __MKSMALLINT(1) : __MKSMALLINT(0) ); + } + } } %}. @@ -122,24 +122,24 @@ %{ /* NOCONTEXT */ - OBJ b = _INST(bytes); - OBJ w = _INST(width); + OBJ b = __INST(bytes); + OBJ w = __INST(width); if (__isByteArray(b) && __bothSmallInteger(x, y) && __isSmallInteger(w) ) { - int _w = __intVal(w); - int _y = __intVal(y); - int _x = __intVal(x); - int _idx; + int _w = __intVal(w); + int _y = __intVal(y); + int _x = __intVal(x); + int _idx; - _idx = ((_w + 7) >> 3) * _y + (_x >> 3); - if ((unsigned)_idx < __byteArraySize(b)) { - if (aPixelValue == __MKSMALLINT(0)) { - __ByteArrayInstPtr(b)->ba_element[_idx] &= ~(0x80 >> (_x & 7)); - } else { - __ByteArrayInstPtr(b)->ba_element[_idx] |= (0x80 >> (_x & 7)); - } - RETURN( self ); - } + _idx = ((_w + 7) >> 3) * _y + (_x >> 3); + if ((unsigned)_idx < __byteArraySize(b)) { + if (aPixelValue == __MKSMALLINT(0)) { + __ByteArrayInstPtr(b)->ba_element[_idx] &= ~(0x80 >> (_x & 7)); + } else { + __ByteArrayInstPtr(b)->ba_element[_idx] |= (0x80 >> (_x & 7)); + } + RETURN( self ); + } } %}. "fall back code for nonByteArray or nonInteger arguments" @@ -150,9 +150,9 @@ byte := bytes at:index. mask := #(16r80 16r40 16r20 16r10 16r08 16r04 16r02 16r01) at:((x \\ 8) + 1). aPixelValue == 0 ifTrue:[ - byte := byte bitAnd:(mask bitInvert) + byte := byte bitAnd:(mask bitInvert) ] ifFalse:[ - byte := byte bitOr:mask + byte := byte bitOr:mask ]. bytes at:index put:byte ! ! @@ -186,14 +186,14 @@ c0 := self colorFromValue:0. c1 := self colorFromValue:1. c0 brightness > 0.5 ifTrue:[ - c0 := Color white + c0 := Color white ] ifFalse:[ - c0 := Color black. + c0 := Color black. ]. c1 brightness > 0.5 ifTrue:[ - c1 := Color white + c1 := Color white ] ifFalse:[ - c1 := Color black. + c1 := Color black. ]. f colorMap:(Array with:c0 with:c1). ^ f @@ -212,12 +212,12 @@ |i| i := Depth1Image - width:4 - height:4 - fromArray:#[ 2r00000000 - 2r11110000 - 2r01010000 - 2r10100000 ]. + width:4 + height:4 + fromArray:#[ 2r00000000 + 2r11110000 + 2r01010000 + 2r10100000 ]. i photometric:#rgb. i samplesPerPixel:3. i bitsPerSample:#(1 0 0). @@ -259,31 +259,31 @@ color1 := self colorFromValue:1. srcIndex := srcIndex + (x1 // 8). - mask := #[2r10000000 - 2r01000000 - 2r00100000 - 2r00010000 - 2r00001000 - 2r00000100 - 2r00000010 - 2r00000001] at:((x1 \\ 8) + 1). + mask := #[2r10000000 + 2r01000000 + 2r00100000 + 2r00010000 + 2r00001000 + 2r00000100 + 2r00000010 + 2r00000001] at:((x1 \\ 8) + 1). byte := bytes at:srcIndex. x1 to:x2 do:[:x | - (byte bitAnd:mask) == 0 ifTrue:[ - aBlock value:x value:color0 - ] ifFalse:[ - aBlock value:x value:color1 - ]. + (byte bitAnd:mask) == 0 ifTrue:[ + aBlock value:x value:color0 + ] ifFalse:[ + aBlock value:x value:color1 + ]. - mask := mask bitShift:-1. - mask == 0 ifTrue:[ - mask := 2r10000000. - srcIndex := srcIndex + 1. - x < x2 ifTrue:[ - byte := bytes at:srcIndex. - ] - ] + mask := mask bitShift:-1. + mask == 0 ifTrue:[ + mask := 2r10000000. + srcIndex := srcIndex + 1. + x < x2 ifTrue:[ + byte := bytes at:srcIndex. + ] + ] ] "Created: 7.6.1996 / 19:12:26 / cg" @@ -307,7 +307,7 @@ bytes := self bits. - "this method needs more tuning, if used heavily + "this method needs more tuning, if used heavily (fetch 8 bits at once, unroll the loop over these 8 pixels)" x1 := xLow. @@ -317,31 +317,31 @@ "left pixel is in high bit" srcIndex := srcIndex + (x1 // 8). - mask := #[2r10000000 - 2r01000000 - 2r00100000 - 2r00010000 - 2r00001000 - 2r00000100 - 2r00000010 - 2r00000001] at:((x1 \\ 8) + 1). + mask := #[2r10000000 + 2r01000000 + 2r00100000 + 2r00010000 + 2r00001000 + 2r00000100 + 2r00000010 + 2r00000001] at:((x1 \\ 8) + 1). byte := bytes at:srcIndex. x1 to:x2 do:[:x | - (byte bitAnd:mask) == 0 ifTrue:[ - aBlock value:x value:0 - ] ifFalse:[ - aBlock value:x value:1 - ]. + (byte bitAnd:mask) == 0 ifTrue:[ + aBlock value:x value:0 + ] ifFalse:[ + aBlock value:x value:1 + ]. - mask := mask bitShift:-1. - mask == 0 ifTrue:[ - mask := 2r10000000. - srcIndex := srcIndex + 1. - x < x2 ifTrue:[ - byte := bytes at:srcIndex. - ] - ] + mask := mask bitShift:-1. + mask == 0 ifTrue:[ + mask := 2r10000000. + srcIndex := srcIndex + 1. + x < x2 ifTrue:[ + byte := bytes at:srcIndex. + ] + ] ] "Created: 7.6.1996 / 19:09:38 / cg" @@ -355,8 +355,8 @@ This is the general magnification method, handling non-integral values. It is slower than the integral magnification method." - |mX - mY + |mX + mY newWidth "{ Class: SmallInteger }" newHeight "{ Class: SmallInteger }" newImage newBits bitsPerPixel newBytesPerRow @@ -365,8 +365,8 @@ bytes := self bits. bytes isNil ifTrue:[ - self error:'cannot magnify image without bits'. - ^ self + self error:'cannot magnify image without bits'. + ^ self ]. mX := scalePoint x. @@ -380,20 +380,20 @@ newBits := ByteArray new:(newBytesPerRow * newHeight). mask notNil ifTrue:[ - newMask := (mask magnifiedBy:scalePoint) + newMask := (mask magnifiedBy:scalePoint) ]. newImage := self species new. - newImage - width:newWidth - height:newHeight - photometric:photometric - samplesPerPixel:samplesPerPixel - bitsPerSample:bitsPerSample - colorMap:colorMap copy - bits:newBits - mask:newMask. + newImage + width:newWidth + height:newHeight + photometric:photometric + samplesPerPixel:samplesPerPixel + bitsPerSample:bitsPerSample + colorMap:colorMap copy + bits:newBits + mask:newMask. "walk over destination image fetching pixels from source image" @@ -415,18 +415,18 @@ double _mX = __floatVal(mX); for (_y2 = 0; _y2 < _h2; _y2++) { - _y1 = (int)( (double)_y2 / _mY); + _y1 = (int)( (double)_y2 / _mY); + + for (_x2 = 0; _x2 < _w2; _x2++) { + _x1 = (int)( (double)_x2 / _mX); - for (_x2 = 0; _x2 < _w2; _x2++) { - _x1 = (int)( (double)_x2 / _mX); - - _byte = __ByteArrayInstPtr(b1)->ba_element[(_w1 + 7) / 8 * _y1 + (_x1 / 8)]; + _byte = __ByteArrayInstPtr(b1)->ba_element[(_w1 + 7) / 8 * _y1 + (_x1 / 8)]; - if ((_byte & (0x80 >> (_x1 % 8)))) { - _idx2 = (_w2 + 7) / 8 * _y2 + (_x2 / 8); - __ByteArrayInstPtr(b2)->ba_element[_idx2] |= (0x80 >> (_x2 % 8)); - } - } + if ((_byte & (0x80 >> (_x1 % 8)))) { + _idx2 = (_w2 + 7) / 8 * _y2 + (_x2 / 8); + __ByteArrayInstPtr(b2)->ba_element[_idx2] |= (0x80 >> (_x2 % 8)); + } + } } } %}. @@ -453,8 +453,8 @@ "Created: 18.6.1996 / 16:04:26 / cg" ! -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. This method has been specially tuned for magnification by 2 and 4." @@ -468,118 +468,118 @@ REGISTER int outcnt, bits, bit, mask, incnt; int shift; unsigned char byte1, byte2, byte3, byte4; - OBJ w = _INST(width); + OBJ w = __INST(width); /* helper for monochrome magnification by 2 */ - static unsigned char mag1[16] = {0x00, 0x03, 0x0c, 0x0f, 0x30, 0x33, 0x3c, 0x3f, - 0xc0, 0xc3, 0xcc, 0xcf, 0xf0, 0xf3, 0xfc, 0xff}; + static unsigned char mag1[16] = {0x00, 0x03, 0x0c, 0x0f, 0x30, 0x33, 0x3c, 0x3f, + 0xc0, 0xc3, 0xcc, 0xcf, 0xf0, 0xf3, 0xfc, 0xff}; if (__bothSmallInteger(srcStart, dstStart) && __bothSmallInteger(w, mX) && __isByteArrayLike(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: - /* tuned for this common case */ - while (_pixels > 4) { - _byte = *srcP++; - *dstP++ = mag1[ _byte >> 4 ]; - *dstP++ = mag1[ _byte & 0x0F ]; - _pixels -= 8; - } - while (_pixels > 0) { - _byte = *srcP++; - *dstP++ = mag1[ _byte >> 4 ]; - _pixels -= 8; - } - break; + case 2: + /* tuned for this common case */ + while (_pixels > 4) { + _byte = *srcP++; + *dstP++ = mag1[ _byte >> 4 ]; + *dstP++ = mag1[ _byte & 0x0F ]; + _pixels -= 8; + } + while (_pixels > 0) { + _byte = *srcP++; + *dstP++ = mag1[ _byte >> 4 ]; + _pixels -= 8; + } + break; - case 4: - /* tuned for this common case */ - while (_pixels > 6) { - _byte = *srcP++; - byte1 = mag1[_byte >> 4]; - byte2 = mag1[byte1 & 0xF]; - byte1 = mag1[byte1 >> 4]; - byte3 = mag1[ _byte & 0x0F ]; - byte4 = mag1[byte3 & 0xF]; - byte3 = mag1[byte3 >> 4]; + case 4: + /* tuned for this common case */ + while (_pixels > 6) { + _byte = *srcP++; + byte1 = mag1[_byte >> 4]; + byte2 = mag1[byte1 & 0xF]; + byte1 = mag1[byte1 >> 4]; + byte3 = mag1[ _byte & 0x0F ]; + byte4 = mag1[byte3 & 0xF]; + byte3 = mag1[byte3 >> 4]; - *dstP++ = byte1; - *dstP++ = byte2; - *dstP++ = byte3; - *dstP++ = byte4; - _pixels -= 8; - } - while (_pixels > 0) { - _byte = *srcP++; - byte1 = mag1[_byte >> 4]; - byte2 = mag1[byte1 & 0xF]; - byte1 = mag1[byte1 >> 4]; - byte3 = mag1[_byte & 0x0F ]; - byte4 = mag1[byte3 & 0xF]; - byte3 = mag1[byte3 >> 4]; + *dstP++ = byte1; + *dstP++ = byte2; + *dstP++ = byte3; + *dstP++ = byte4; + _pixels -= 8; + } + while (_pixels > 0) { + _byte = *srcP++; + byte1 = mag1[_byte >> 4]; + byte2 = mag1[byte1 & 0xF]; + byte1 = mag1[byte1 >> 4]; + byte3 = mag1[_byte & 0x0F ]; + byte4 = mag1[byte3 & 0xF]; + byte3 = mag1[byte3 >> 4]; - *dstP++ = byte1; - if (_pixels > 2) { - *dstP++ = byte2; - if (_pixels > 4) { - *dstP++ = byte3; - if (_pixels > 6) { - *dstP++ = byte4; - } - } - } - _pixels -= 8; - } - break; + *dstP++ = byte1; + if (_pixels > 2) { + *dstP++ = byte2; + if (_pixels > 4) { + *dstP++ = byte3; + if (_pixels > 6) { + *dstP++ = byte4; + } + } + } + _pixels -= 8; + } + break; - default: - bits = 0, incnt = 0, outcnt = 0; - mask = 0x80; - _byte = *srcP++; - while (_pixels--) { - if (_byte & mask) - bit = 1; - else - bit = 0; - incnt++; - if (incnt == 8) { - incnt = 0; - mask = 0x80; - _byte = *srcP++; - } else { - mask >>= 1; - } + default: + bits = 0, incnt = 0, outcnt = 0; + mask = 0x80; + _byte = *srcP++; + while (_pixels--) { + if (_byte & mask) + bit = 1; + else + bit = 0; + incnt++; + if (incnt == 8) { + incnt = 0; + mask = 0x80; + _byte = *srcP++; + } else { + mask >>= 1; + } - for (i=_mag; i>0; i--) { - bits = (bits << 1) | bit; - outcnt++; - if (outcnt == 8) { - *dstP++ = bits; - bits = 0; - outcnt = 0; - } - } - } - if (outcnt) { - *dstP = bits << (8-outcnt); - } - break; - } - RETURN (self); + for (i=_mag; i>0; i--) { + bits = (bits << 1) | bit; + outcnt++; + if (outcnt == 8) { + *dstP++ = bits; + bits = 0; + outcnt = 0; + } + } + } + if (outcnt) { + *dstP = bits << (8-outcnt); + } + 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 ! ! !Depth1Image methodsFor:'private'! @@ -593,25 +593,25 @@ color0 := (self colorFromValue:0) exactOn:aDevice. color1 := (self colorFromValue:1) exactOn:aDevice. - (color0 notNil and:[(color0 isOnDevice:aDevice) + (color0 notNil and:[(color0 isOnDevice:aDevice) and:[color1 notNil and:[color1 isOnDevice:aDevice]]]) ifFalse:[ - "could not allocate colors, do it the hard way ..." - ^ self paletteImageAsFormOn:aDevice. + "could not allocate colors, do it the hard way ..." + ^ self paletteImageAsFormOn:aDevice. ]. "all colors are available, this is easy now" f := Form width:width height:height fromArray:self bits onDevice:aDevice. f notNil ifTrue:[ - f colorMap:(Array with:color0 with:color1). + f colorMap:(Array with:color0 with:color1). - "/ remember deviceForm + "/ remember deviceForm - (device isNil or:[deviceForm isNil]) ifTrue:[ - device := aDevice. - deviceForm := f. - maskedPixelsAre0 := nil. - ] + (device isNil or:[deviceForm isNil]) ifTrue:[ + device := aDevice. + deviceForm := f. + maskedPixelsAre0 := nil. + ] ]. ^ f @@ -649,21 +649,21 @@ Pixel values start with 0." photometric == #blackIs0 ifTrue:[ - (pixelValue == 0) ifTrue:[ - ^ Color black - ]. - ^ Color white + (pixelValue == 0) ifTrue:[ + ^ Color black + ]. + ^ Color white ]. photometric == #whiteIs0 ifTrue:[ - (pixelValue == 0) ifTrue:[ - ^ Color white - ]. - ^ Color black + (pixelValue == 0) ifTrue:[ + ^ Color white + ]. + ^ Color black ]. photometric == #palette ifTrue:[ - pixelValue < colorMap size ifTrue:[ - ^ colorMap at:(pixelValue+1). - ] + pixelValue < colorMap size ifTrue:[ + ^ colorMap at:(pixelValue+1). + ] ]. ^ super colorFromValue:pixelValue. ! @@ -673,21 +673,21 @@ Pixel values start with 0." photometric == #blackIs0 ifTrue:[ - (pixelValue == 0) ifTrue:[ - ^ 0 - ]. - ^ 16rFFFFFF + (pixelValue == 0) ifTrue:[ + ^ 0 + ]. + ^ 16rFFFFFF ]. photometric == #whiteIs0 ifTrue:[ - (pixelValue == 0) ifTrue:[ - ^ 16rFFFFFF - ]. - ^ 0 + (pixelValue == 0) ifTrue:[ + ^ 16rFFFFFF + ]. + ^ 0 ]. photometric == #palette ifTrue:[ - pixelValue < colorMap size ifTrue:[ - ^ (colorMap at:(pixelValue+1)) rgbValue - ] + pixelValue < colorMap size ifTrue:[ + ^ (colorMap at:(pixelValue+1)) rgbValue + ] ]. ^ super rgbFromValue:pixelValue. ! @@ -699,12 +699,12 @@ ... which is not really true - it could be all-white or all-black" (photometric == #whiteIs0 or:[photometric == #blackIs0]) ifTrue:[ - ^ Array - with:(Color black) - with:(Color white). + ^ Array + with:(Color black) + with:(Color white). ]. photometric == #palette ifTrue:[ - ^ colorMap + ^ colorMap ]. ^ super usedColors @@ -728,9 +728,9 @@ ((first == 0) or:[(first == 2r11111111)]) ifFalse:[ ^ #(0 1) ]. bits do:[:eachByte | - (first bitXor:eachByte) ~~ 0 ifTrue:[ - ^ #(0 1) - ]. + (first bitXor:eachByte) ~~ 0 ifTrue:[ + ^ #(0 1) + ]. ]. ^ first == 0 ifTrue:[ #(0) ] ifFalse:[ #(1) ]. ! @@ -742,25 +742,25 @@ |clr0 clr1| photometric == #whiteIs0 ifTrue:[ - clr0 := Color white. - clr1 := Color black. + clr0 := Color white. + clr1 := Color black. ] ifFalse:[ - photometric == #blackIs0 ifTrue:[ - clr0 := Color black. - clr1 := Color white. - ] ifFalse:[ - photometric ~~ #palette ifTrue:[ - ^ super valueFromColor:aColor - ]. - clr0 := colorMap at:1. - clr1 := colorMap at:2 ifAbsent:nil. - ] + photometric == #blackIs0 ifTrue:[ + clr0 := Color black. + clr1 := Color white. + ] ifFalse:[ + photometric ~~ #palette ifTrue:[ + ^ super valueFromColor:aColor + ]. + clr0 := colorMap at:1. + clr1 := colorMap at:2 ifAbsent:nil. + ] ]. aColor = clr0 ifTrue:[ - ^ 0. + ^ 0. ]. aColor = clr1 ifTrue:[ - ^ 1 + ^ 1 ]. " @@ -772,9 +772,9 @@ !Depth1Image class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.57 2009-11-05 14:37:53 stefan Exp $' + ^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.58 2013-05-21 20:50:48 cg Exp $' ! version_CVS - ^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.57 2009-11-05 14:37:53 stefan Exp $' + ^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.58 2013-05-21 20:50:48 cg Exp $' ! !