ByteArray.st
changeset 3685 04fd42507276
parent 3676 140bdb21d859
child 4019 c9284ca27a4a
--- a/ByteArray.st	Tue Jul 28 20:32:07 1998 +0200
+++ b/ByteArray.st	Tue Jul 28 21:46:27 1998 +0200
@@ -1581,92 +1581,96 @@
      && (__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;
-	}
+        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:
-		printf("invalid depth in expandPixels\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) {
-		printf("invalid map in expandPixels\n");
-		goto fail;
-	    }
-	}
+        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:
+                printf("invalid depth in expandPixels\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) {
+                printf("invalid map in expandPixels\n");
+                goto fail;
+            }
+        }
 
-	bytesPerRow = (w * bitsPerPixel + 7) / 8;
-	shift0 = 8 - bitsPerPixel;
-	srcBytes = bytesPerRow * h;
-	dstBytes = w * h;
+        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) {
-		    if (shift0 == 0) {
-			/* translate only */
-			for (wrun=w; wrun; wrun--) {
-			    bits = *src++;
-			    *dst++ = map[bits];
-			}
-		    } else {
-			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 );
-	}
+        if ((__byteArraySize(self) >= srcBytes)
+         && (__byteArraySize(aByteArray) >= dstBytes)) {
+            for (hrun=h; hrun; hrun--) {
+                srcNext = src + bytesPerRow;
+                shift = shift0;
+                if (map) {
+                    if (shift0 == 0) {
+                        /* translate only */
+                        for (wrun=w; wrun; wrun--) {
+                            bits = *src++;
+                            *dst++ = map[bits];
+                        }
+                    } else {
+                        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 );
+        }
+        printf("buffer size: self:%d expect at least:%d\n", 
+                __byteArraySize(self), srcBytes);
+        printf("buffer size: arg:%d expect at least:%d\n", 
+                __byteArraySize(aByteArray), dstBytes);
     }
     printf("invalid args\n");
 
@@ -1681,12 +1685,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
     "
 
@@ -1700,7 +1704,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
     "
 !
@@ -2163,5 +2167,5 @@
 !ByteArray class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.100 1998-07-27 14:59:49 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.101 1998-07-28 19:46:27 cg Exp $'
 ! !