--- a/ByteArray.st Wed Jun 05 20:14:31 1996 +0200
+++ b/ByteArray.st Mon Jun 10 15:25:29 1996 +0200
@@ -1610,7 +1610,7 @@
!
expandPixels:nBitsPerPixel width:width height:height into:aByteArray
- mapping:aMapByteArray
+ mapping:aMapByteArray
"given the receiver with nBitsPerPixel-depth pixels, expand them into
aByteArray with 8-bit pixels. The width/height-arguments are needed
@@ -1643,81 +1643,85 @@
&& (__qClass(aByteArray) == @global(ByteArray))
&& __isSmallInteger(nBitsPerPixel)
&& __bothSmallInteger(height, width)) {
- if ((aMapByteArray != nil)
- && (__Class(aMapByteArray) == @global(ByteArray))) {
- map = __ByteArrayInstPtr(aMapByteArray)->ba_element;
- } else {
- map = (unsigned char *)0;
- }
-
- bitsPerPixel = __intVal(nBitsPerPixel);
- w = __intVal(width);
- h = __intVal(height);
- src = __ByteArrayInstPtr(self)->ba_element;
- dst = __ByteArrayInstPtr(aByteArray)->ba_element;
- switch (bitsPerPixel) {
- case 1:
- mask = 0x01;
- break;
- case 2:
- mask = 0x03;
- break;
- case 4:
- mask = 0x0F;
- break;
- case 8:
- mask = 0xFF;
- break;
- default:
- goto fail;
- }
- ncells = mask + 1;
- if (map) {
- /*
- * if a map is present, it must have the correct size
- * (i.e. 2 raisedTo:nBitsPerPixel)
- */
- if ((__qSize(aMapByteArray) - OHDR_SIZE) < ncells)
- goto fail;
- }
+ if ((aMapByteArray != nil)
+ && (__Class(aMapByteArray) == @global(ByteArray))) {
+ map = __ByteArrayInstPtr(aMapByteArray)->ba_element;
+ } else {
+ map = (unsigned char *)0;
+ }
- bytesPerRow = (w * bitsPerPixel + 7) / 8;
- shift0 = 8 - bitsPerPixel;
- srcBytes = bytesPerRow * h;
- dstBytes = w * h;
+ bitsPerPixel = __intVal(nBitsPerPixel);
+ w = __intVal(width);
+ h = __intVal(height);
+ src = __ByteArrayInstPtr(self)->ba_element;
+ dst = __ByteArrayInstPtr(aByteArray)->ba_element;
+ switch (bitsPerPixel) {
+ case 1:
+ mask = 0x01;
+ break;
+ case 2:
+ mask = 0x03;
+ break;
+ case 4:
+ mask = 0x0F;
+ break;
+ case 8:
+ mask = 0xFF;
+ break;
+ default:
+ fprintf(stderr, "invalid bitsPerPixel\n");
+ goto fail;
+ }
+ ncells = mask + 1;
+ if (map) {
+ /*
+ * if a map is present, it must have the correct size
+ * (i.e. 2 raisedTo:nBitsPerPixel)
+ */
+ if ((__qSize(aMapByteArray) - OHDR_SIZE) < ncells) {
+ fprintf(stderr, "mapArray size\n");
+ goto fail;
+ }
+ }
- if ((__byteArraySize(self) >= srcBytes)
- && (__byteArraySize(aByteArray) >= dstBytes)) {
- for (hrun=h; hrun; hrun--) {
- srcNext = src + bytesPerRow;
- shift = shift0;
- if (map) {
- for (wrun=w; wrun; wrun--) {
- if (shift == shift0) {
- bits = *src++;
- }
- *dst++ = map[(bits >> shift) & mask];
- shift -= bitsPerPixel;
- if (shift < 0) {
- shift = shift0;
- }
- }
- } else {
- for (wrun=w; wrun; wrun--) {
- if (shift == shift0) {
- bits = *src++;
- }
- *dst++ = (bits >> shift) & mask;
- shift -= bitsPerPixel;
- if (shift < 0) {
- shift = shift0;
- }
- }
- }
- src = srcNext;
- }
- RETURN ( self );
- }
+ bytesPerRow = (w * bitsPerPixel + 7) / 8;
+ shift0 = 8 - bitsPerPixel;
+ srcBytes = bytesPerRow * h;
+ dstBytes = w * h;
+
+ if ((__byteArraySize(self) >= srcBytes)
+ && (__byteArraySize(aByteArray) >= dstBytes)) {
+ for (hrun=h; hrun; hrun--) {
+ srcNext = src + bytesPerRow;
+ shift = shift0;
+ if (map) {
+ for (wrun=w; wrun; wrun--) {
+ if (shift == shift0) {
+ bits = *src++;
+ }
+ *dst++ = map[(bits >> shift) & mask];
+ shift -= bitsPerPixel;
+ if (shift < 0) {
+ shift = shift0;
+ }
+ }
+ } else {
+ for (wrun=w; wrun; wrun--) {
+ if (shift == shift0) {
+ bits = *src++;
+ }
+ *dst++ = (bits >> shift) & mask;
+ shift -= bitsPerPixel;
+ if (shift < 0) {
+ shift = shift0;
+ }
+ }
+ }
+ src = srcNext;
+ }
+ RETURN ( self );
+ }
+ fprintf(stderr, "not enough bytes\n");
}
fail: ;
%}
@@ -1731,12 +1735,12 @@
|inBits outBits|
inBits := #[2r11110000
- 2r11001100
- 2r01010101
- 2r00001111].
+ 2r11001100
+ 2r01010101
+ 2r00001111].
outBits := ByteArray new:(8*4).
inBits expandPixels:1 width:8 height:4
- into:outBits mapping:nil.
+ into:outBits mapping:nil.
outBits inspect
"
@@ -1750,7 +1754,7 @@
inBits := #[2r11110000 2r11001100].
outBits := ByteArray new:16.
inBits expandPixels:1 width:16 height:1
- into:outBits mapping:#[99 176].
+ into:outBits mapping:#[99 176].
outBits inspect
"
!
@@ -2176,5 +2180,5 @@
!ByteArray class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.61 1996-05-12 16:16:39 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.62 1996-06-10 13:25:29 cg Exp $'
! !