Depth1Image.st
changeset 886 04b88b61c640
parent 862 1d941b5db534
child 1577 3d8eedcc0ad8
equal deleted inserted replaced
885:07df2e77a8fe 886:04b88b61c640
   475     "Created: 7.6.1996 / 19:09:38 / cg"
   475     "Created: 7.6.1996 / 19:09:38 / cg"
   476     "Modified: 8.6.1996 / 13:36:37 / cg"
   476     "Modified: 8.6.1996 / 13:36:37 / cg"
   477 ! !
   477 ! !
   478 
   478 
   479 !Depth1Image methodsFor:'magnification'!
   479 !Depth1Image methodsFor:'magnification'!
       
   480 
       
   481 hardMagnifiedBy:scalePoint
       
   482     "return a new image magnified by scalePoint, aPoint.
       
   483      This is the general magnification method, handling non-integral values.
       
   484      It is slower than the integral magnification method."
       
   485 
       
   486     |mX        
       
   487      mY        
       
   488      newWidth  "{ Class: SmallInteger }"
       
   489      newHeight "{ Class: SmallInteger }"
       
   490      w         "{ Class: SmallInteger }"
       
   491      h         "{ Class: SmallInteger }"
       
   492      newImage newBits bitsPerPixel newBytesPerRow
       
   493      value srcRow srcCol
       
   494      dstBytes dstRow dstCol|
       
   495 
       
   496     mX := scalePoint x.
       
   497     mY := scalePoint y.
       
   498 
       
   499     newWidth := (width * mX) truncated.
       
   500     newHeight := (height * mY) truncated.
       
   501 
       
   502     bitsPerPixel := self depth.
       
   503     newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
       
   504     newBits := ByteArray new:(newBytesPerRow * newHeight).
       
   505 
       
   506     newImage := self species new.
       
   507 
       
   508     newImage 
       
   509         width:newWidth 
       
   510         height:newHeight 
       
   511         photometric:photometric 
       
   512         samplesPerPixel:samplesPerPixel 
       
   513         bitsPerSample:bitsPerSample 
       
   514         colorMap:colorMap copy
       
   515         bits:newBits.
       
   516 
       
   517     "walk over destination image fetching pixels from source image"
       
   518 
       
   519     mX := mX asFloat.
       
   520     mY := mY asFloat.
       
   521 
       
   522 %{
       
   523 {
       
   524     OBJ b1 = __INST(bytes);
       
   525     int _w1 = __intVal(__INST(width));
       
   526     int _y1, _y2;
       
   527     OBJ b2 = newBits;
       
   528     int _w2 = _intVal(newWidth);
       
   529     int _h2 = _intVal(newHeight);
       
   530     int _x2, _x1;
       
   531     int _idx2;
       
   532     unsigned _byte;
       
   533     double _mY = __floatVal(mY);
       
   534     double _mX = __floatVal(mX);
       
   535 
       
   536     for (_y2 = 0; _y2 < _h2; _y2++) {
       
   537         _y1 = (int)( (double)_y2 / _mY);
       
   538 
       
   539         for (_x2 = 0; _x2 < _w2; _x2++) {
       
   540             _x1 = (int)( (double)_x2 / _mX);
       
   541             
       
   542             _byte = _ByteArrayInstPtr(b1)->ba_element[(_w1 + 7) / 8 * _y1 + (_x1 / 8)];
       
   543 
       
   544             if ((_byte & (0x80 >> (_x1 % 8)))) {
       
   545                 _idx2 = (_w2 + 7) / 8 * _y2 + (_x2 / 8);
       
   546                 _ByteArrayInstPtr(b2)->ba_element[_idx2] |= (0x80 >> (_x2 % 8));
       
   547             }
       
   548         }
       
   549     }
       
   550 }
       
   551 %}.
       
   552 
       
   553 "/    w := newWidth - 1.
       
   554 "/    h := newHeight - 1.
       
   555 "/
       
   556 "/    0 to:h do:[:row |
       
   557 "/        dstRow := row.
       
   558 "/        srcRow := (row // mY).
       
   559 "/        0 to:w do:[:col |
       
   560 "/
       
   561 "/            dstCol := col.
       
   562 "/            srcCol := col // mX.
       
   563 "/            value := self valueAtX:(col // mX) y:srcRow.
       
   564 "/            newImage atX:col y:row putValue:value.
       
   565 "/        ]
       
   566 "/    ].
       
   567 
       
   568     ^ newImage
       
   569 
       
   570     "((Image fromFile:'bitmaps/claus.gif') magnifiedBy:0.5@0.5)"
       
   571 
       
   572     "Created: 18.6.1996 / 16:04:26 / cg"
       
   573 !
   480 
   574 
   481 magnifyRowFrom:srcBytes offset:srcStart  
   575 magnifyRowFrom:srcBytes offset:srcStart  
   482 	  into:dstBytes offset:dstStart factor:mX
   576 	  into:dstBytes offset:dstStart factor:mX
   483 
   577 
   484     "magnify a single pixel row - can only magnify by integer factors.
   578     "magnify a single pixel row - can only magnify by integer factors.
   633 ! !
   727 ! !
   634 
   728 
   635 !Depth1Image class methodsFor:'documentation'!
   729 !Depth1Image class methodsFor:'documentation'!
   636 
   730 
   637 version
   731 version
   638     ^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.27 1996-06-15 12:49:30 cg Exp $'
   732     ^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.28 1996-06-18 15:06:11 cg Exp $'
   639 ! !
   733 ! !