Depth1Image.st
changeset 2179 30461fd19cd5
parent 2044 9ea84b4ba249
child 2201 7272763312a0
equal deleted inserted replaced
2178:3b151fc7450e 2179:30461fd19cd5
   578 
   578 
   579     "Created: 18.6.1996 / 16:04:26 / cg"
   579     "Created: 18.6.1996 / 16:04:26 / cg"
   580 !
   580 !
   581 
   581 
   582 magnifyRowFrom:srcBytes offset:srcStart  
   582 magnifyRowFrom:srcBytes offset:srcStart  
   583 	  into:dstBytes offset:dstStart factor:mX
   583           into:dstBytes offset:dstStart factor:mX
   584 
   584 
   585     "magnify a single pixel row - can only magnify by integer factors.
   585     "magnify a single pixel row - can only magnify by integer factors.
   586      This method has been specially tuned for magnification by 2 and 4."
   586      This method has been specially tuned for magnification by 2 and 4."
   587 
   587 
   588 %{
   588 %{
   596     unsigned char byte1, byte2, byte3, byte4;
   596     unsigned char byte1, byte2, byte3, byte4;
   597     OBJ w = _INST(width);
   597     OBJ w = _INST(width);
   598 
   598 
   599     /* helper for monochrome magnification by 2 */
   599     /* helper for monochrome magnification by 2 */
   600     static unsigned char mag1[16] = {0x00, 0x03, 0x0c, 0x0f, 0x30, 0x33, 0x3c, 0x3f, 
   600     static unsigned char mag1[16] = {0x00, 0x03, 0x0c, 0x0f, 0x30, 0x33, 0x3c, 0x3f, 
   601 				     0xc0, 0xc3, 0xcc, 0xcf, 0xf0, 0xf3, 0xfc, 0xff};
   601                                      0xc0, 0xc3, 0xcc, 0xcf, 0xf0, 0xf3, 0xfc, 0xff};
   602 
   602 
   603     if (__bothSmallInteger(srcStart, dstStart)
   603     if (__bothSmallInteger(srcStart, dstStart)
   604      && __bothSmallInteger(w, mX)
   604      && __bothSmallInteger(w, mX)
   605      && __isByteArray(srcBytes) && __isByteArray(dstBytes)) {
   605      && __isByteArray(srcBytes) && __isByteArray(dstBytes)) {
   606 	_mag = __intVal(mX);
   606         _mag = __intVal(mX);
   607 	srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart);
   607         srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart);
   608 	dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart);
   608         dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart);
   609 	_pixels = __intVal(w);
   609         _pixels = __intVal(w);
   610 
   610 
   611 	switch (_mag) {
   611         switch (_mag) {
   612 	    case 1:
   612             case 1:
   613 		break;
   613                 break;
   614 
   614 
   615 	    case 2:
   615             case 2:
   616 		/* tuned for this common case */
   616                 /* tuned for this common case */
   617 		while (_pixels > 0) {
   617                 while (_pixels > 0) {
   618 		    _byte = *srcP++;
   618                     _byte = *srcP++;
   619 		    *dstP++ = mag1[ _byte >> 4 ];
   619                     *dstP++ = mag1[ _byte >> 4 ];
   620 		    if (_pixels > 4) {
   620                     if (_pixels > 4) {
   621 			*dstP++ = mag1[ _byte & 0x0F ];
   621                         *dstP++ = mag1[ _byte & 0x0F ];
   622 		    }
   622                     }
   623 		    _pixels -= 8;
   623                     _pixels -= 8;
   624 		}
   624                 }
   625 		break;
   625                 break;
   626 
   626 
   627 	    case 4:
   627             case 4:
   628 		/* tuned for this common case */
   628                 /* tuned for this common case */
   629 		while (_pixels > 0) {
   629                 while (_pixels > 0) {
   630 		    _byte = *srcP++;
   630                     _byte = *srcP++;
   631 		    byte1 = mag1[_byte >> 4];
   631                     byte1 = mag1[_byte >> 4];
   632 		    byte2 = mag1[byte1 & 0xF];
   632                     byte2 = mag1[byte1 & 0xF];
   633 		    byte1 = mag1[byte1 >> 4];
   633                     byte1 = mag1[byte1 >> 4];
   634 		    byte3 = mag1[ _byte & 0x0F ];
   634                     byte3 = mag1[ _byte & 0x0F ];
   635 		    byte4 = mag1[byte3 & 0xF];
   635                     byte4 = mag1[byte3 & 0xF];
   636 		    byte3 = mag1[byte3 >> 4];
   636                     byte3 = mag1[byte3 >> 4];
   637 
   637 
   638 		    *dstP++ = byte1;
   638                     *dstP++ = byte1;
   639 		    if (_pixels > 2) {
   639                     if (_pixels > 2) {
   640 			*dstP++ = byte2;
   640                         *dstP++ = byte2;
   641 			if (_pixels > 4) {
   641                         if (_pixels > 4) {
   642 			    *dstP++ = byte3;
   642                             *dstP++ = byte3;
   643 			    if (_pixels > 6) {
   643                             if (_pixels > 6) {
   644 				*dstP++ = byte4;
   644                                 *dstP++ = byte4;
   645 			    }
   645                             }
   646 			}
   646                         }
   647 		    }
   647                     }
   648 		    _pixels -= 8;
   648                     _pixels -= 8;
   649 		}
   649                 }
   650 		break;
   650                 break;
   651 
   651 
   652 	    default:
   652             default:
   653 		bits = 0, incnt = 0, outcnt = 0;
   653                 bits = 0, incnt = 0, outcnt = 0;
   654 		mask = 0x80;
   654                 mask = 0x80;
   655 		_byte = *srcP++;
   655                 _byte = *srcP++;
   656 		while (_pixels--) {
   656                 while (_pixels--) {
   657 		    if (_byte & mask)
   657                     if (_byte & mask)
   658 			bit = 1;
   658                         bit = 1;
   659 		    else
   659                     else
   660 			bit = 0;
   660                         bit = 0;
   661 		    incnt++;
   661                     incnt++;
   662 		    if (incnt == 8) {
   662                     if (incnt == 8) {
   663 			incnt = 0;
   663                         incnt = 0;
   664 			mask = 0x80;
   664                         mask = 0x80;
   665 			_byte = *srcP++;
   665                         _byte = *srcP++;
   666 		    } else {
   666                     } else {
   667 			mask >>= 1;
   667                         mask >>= 1;
   668 		    }
   668                     }
   669 
   669 
   670 		    for (i=_mag; i>0; i--) {
   670                     for (i=_mag; i>0; i--) {
   671 			bits = (bits << 1) | bit;
   671                         bits = (bits << 1) | bit;
   672 			outcnt++;
   672                         outcnt++;
   673 			if (outcnt == 8) {
   673                         if (outcnt == 8) {
   674 			    *dstP++ = bits;
   674                             *dstP++ = bits;
   675 			    bits = 0;
   675                             bits = 0;
   676 			    outcnt = 0;
   676                             outcnt = 0;
   677 			}
   677                         }
   678 		    }
   678                     }
   679 		}
   679                 }
   680 		break;
   680                 if (outcnt) {
   681 	}
   681                     *dstP = bits << (8-outcnt);
   682 	RETURN (self);
   682                 }
       
   683                 break;
       
   684         }
       
   685         RETURN (self);
   683     }
   686     }
   684 %}.
   687 %}.
   685     self primitiveFailed
   688     self primitiveFailed
   686 ! !
   689 ! !
   687 
   690 
   734 ! !
   737 ! !
   735 
   738 
   736 !Depth1Image class methodsFor:'documentation'!
   739 !Depth1Image class methodsFor:'documentation'!
   737 
   740 
   738 version
   741 version
   739     ^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.33 1998-02-05 14:29:51 cg Exp $'
   742     ^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.34 1998-07-23 14:32:08 tz Exp $'
   740 ! !
   743 ! !