1608 outBits inspect |
1608 outBits inspect |
1609 " |
1609 " |
1610 ! |
1610 ! |
1611 |
1611 |
1612 expandPixels:nBitsPerPixel width:width height:height into:aByteArray |
1612 expandPixels:nBitsPerPixel width:width height:height into:aByteArray |
1613 mapping:aMapByteArray |
1613 mapping:aMapByteArray |
1614 |
1614 |
1615 "given the receiver with nBitsPerPixel-depth pixels, expand them into |
1615 "given the receiver with nBitsPerPixel-depth pixels, expand them into |
1616 aByteArray with 8-bit pixels. The width/height-arguments are needed |
1616 aByteArray with 8-bit pixels. The width/height-arguments are needed |
1617 to skip any padded src-bits. On the fly, the destination pixels |
1617 to skip any padded src-bits. On the fly, the destination pixels |
1618 are translated using aMapByteArray (if non-nil). |
1618 are translated using aMapByteArray (if non-nil). |
1641 |
1641 |
1642 if ((__qClass(self) == @global(ByteArray)) |
1642 if ((__qClass(self) == @global(ByteArray)) |
1643 && (__qClass(aByteArray) == @global(ByteArray)) |
1643 && (__qClass(aByteArray) == @global(ByteArray)) |
1644 && __isSmallInteger(nBitsPerPixel) |
1644 && __isSmallInteger(nBitsPerPixel) |
1645 && __bothSmallInteger(height, width)) { |
1645 && __bothSmallInteger(height, width)) { |
1646 if ((aMapByteArray != nil) |
1646 if ((aMapByteArray != nil) |
1647 && (__Class(aMapByteArray) == @global(ByteArray))) { |
1647 && (__Class(aMapByteArray) == @global(ByteArray))) { |
1648 map = __ByteArrayInstPtr(aMapByteArray)->ba_element; |
1648 map = __ByteArrayInstPtr(aMapByteArray)->ba_element; |
1649 } else { |
1649 } else { |
1650 map = (unsigned char *)0; |
1650 map = (unsigned char *)0; |
1651 } |
1651 } |
1652 |
1652 |
1653 bitsPerPixel = __intVal(nBitsPerPixel); |
1653 bitsPerPixel = __intVal(nBitsPerPixel); |
1654 w = __intVal(width); |
1654 w = __intVal(width); |
1655 h = __intVal(height); |
1655 h = __intVal(height); |
1656 src = __ByteArrayInstPtr(self)->ba_element; |
1656 src = __ByteArrayInstPtr(self)->ba_element; |
1657 dst = __ByteArrayInstPtr(aByteArray)->ba_element; |
1657 dst = __ByteArrayInstPtr(aByteArray)->ba_element; |
1658 switch (bitsPerPixel) { |
1658 switch (bitsPerPixel) { |
1659 case 1: |
1659 case 1: |
1660 mask = 0x01; |
1660 mask = 0x01; |
1661 break; |
1661 break; |
1662 case 2: |
1662 case 2: |
1663 mask = 0x03; |
1663 mask = 0x03; |
1664 break; |
1664 break; |
1665 case 4: |
1665 case 4: |
1666 mask = 0x0F; |
1666 mask = 0x0F; |
1667 break; |
1667 break; |
1668 case 8: |
1668 case 8: |
1669 mask = 0xFF; |
1669 mask = 0xFF; |
1670 break; |
1670 break; |
1671 default: |
1671 default: |
1672 goto fail; |
1672 fprintf(stderr, "invalid bitsPerPixel\n"); |
1673 } |
1673 goto fail; |
1674 ncells = mask + 1; |
1674 } |
1675 if (map) { |
1675 ncells = mask + 1; |
1676 /* |
1676 if (map) { |
1677 * if a map is present, it must have the correct size |
1677 /* |
1678 * (i.e. 2 raisedTo:nBitsPerPixel) |
1678 * if a map is present, it must have the correct size |
1679 */ |
1679 * (i.e. 2 raisedTo:nBitsPerPixel) |
1680 if ((__qSize(aMapByteArray) - OHDR_SIZE) < ncells) |
1680 */ |
1681 goto fail; |
1681 if ((__qSize(aMapByteArray) - OHDR_SIZE) < ncells) { |
1682 } |
1682 fprintf(stderr, "mapArray size\n"); |
1683 |
1683 goto fail; |
1684 bytesPerRow = (w * bitsPerPixel + 7) / 8; |
1684 } |
1685 shift0 = 8 - bitsPerPixel; |
1685 } |
1686 srcBytes = bytesPerRow * h; |
1686 |
1687 dstBytes = w * h; |
1687 bytesPerRow = (w * bitsPerPixel + 7) / 8; |
1688 |
1688 shift0 = 8 - bitsPerPixel; |
1689 if ((__byteArraySize(self) >= srcBytes) |
1689 srcBytes = bytesPerRow * h; |
1690 && (__byteArraySize(aByteArray) >= dstBytes)) { |
1690 dstBytes = w * h; |
1691 for (hrun=h; hrun; hrun--) { |
1691 |
1692 srcNext = src + bytesPerRow; |
1692 if ((__byteArraySize(self) >= srcBytes) |
1693 shift = shift0; |
1693 && (__byteArraySize(aByteArray) >= dstBytes)) { |
1694 if (map) { |
1694 for (hrun=h; hrun; hrun--) { |
1695 for (wrun=w; wrun; wrun--) { |
1695 srcNext = src + bytesPerRow; |
1696 if (shift == shift0) { |
1696 shift = shift0; |
1697 bits = *src++; |
1697 if (map) { |
1698 } |
1698 for (wrun=w; wrun; wrun--) { |
1699 *dst++ = map[(bits >> shift) & mask]; |
1699 if (shift == shift0) { |
1700 shift -= bitsPerPixel; |
1700 bits = *src++; |
1701 if (shift < 0) { |
1701 } |
1702 shift = shift0; |
1702 *dst++ = map[(bits >> shift) & mask]; |
1703 } |
1703 shift -= bitsPerPixel; |
1704 } |
1704 if (shift < 0) { |
1705 } else { |
1705 shift = shift0; |
1706 for (wrun=w; wrun; wrun--) { |
1706 } |
1707 if (shift == shift0) { |
1707 } |
1708 bits = *src++; |
1708 } else { |
1709 } |
1709 for (wrun=w; wrun; wrun--) { |
1710 *dst++ = (bits >> shift) & mask; |
1710 if (shift == shift0) { |
1711 shift -= bitsPerPixel; |
1711 bits = *src++; |
1712 if (shift < 0) { |
1712 } |
1713 shift = shift0; |
1713 *dst++ = (bits >> shift) & mask; |
1714 } |
1714 shift -= bitsPerPixel; |
1715 } |
1715 if (shift < 0) { |
1716 } |
1716 shift = shift0; |
1717 src = srcNext; |
1717 } |
1718 } |
1718 } |
1719 RETURN ( self ); |
1719 } |
1720 } |
1720 src = srcNext; |
|
1721 } |
|
1722 RETURN ( self ); |
|
1723 } |
|
1724 fprintf(stderr, "not enough bytes\n"); |
1721 } |
1725 } |
1722 fail: ; |
1726 fail: ; |
1723 %} |
1727 %} |
1724 . |
1728 . |
1725 self primitiveFailed |
1729 self primitiveFailed |