#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Wed, 30 Aug 2017 15:15:49 +0200
changeset 8135 821bdfaa563c
parent 8134 711e4517b20c
child 8136 e18855468edd
#FEATURE by cg class: Depth8Image changed: #hardMagnifiedBy:
Depth8Image.st
--- a/Depth8Image.st	Wed Aug 30 15:15:39 2017 +0200
+++ b/Depth8Image.st	Wed Aug 30 15:15:49 2017 +0200
@@ -2154,22 +2154,29 @@
     "
 !
 
-hardMagnifiedBy:scalePoint
+hardMagnifiedBy:scaleArg
     "return a new image magnified by scalePoint, aPoint.
-     This is the general magnification method, handling non-integral values"
-
-    |mX mY
+     This is the general magnification method, handling non-integral values.
+     It is slower than the integral magnification method.
+
+     Notice: this is a naive algorithm, which simply samples the pixel value
+     at the corresponding original pixel's point, without taking neighbors into
+     consideration (i.e. it does not compute an average of those pixels).
+     As a consequence, this will generate bad shrunk images when the original contains
+     sharp lines."
+
+    |scalePoint mX mY
      newWidth  "{ Class: SmallInteger }"
      newHeight "{ Class: SmallInteger }"
      w         "{ Class: SmallInteger }"
      h         "{ Class: SmallInteger }"
-     newImage newBytes
+     newImage newBytes newMask
      value     "{ Class: SmallInteger }"
      srcRowIdx "{ Class: SmallInteger }"
      srcIndex  "{ Class: SmallInteger }"
-     dstIndex  "{ Class: SmallInteger }"
-     newMask|
-
+     dstIndex  "{ Class: SmallInteger }"|
+
+    scalePoint := scaleArg asPoint. 
     mX := scalePoint x.
     mY := scalePoint y.
     ((mX < 0) or:[mY < 0]) ifTrue:[^ nil].
@@ -2186,22 +2193,18 @@
 
     newImage := self species new.
     newImage
-        width:newWidth
-        height:newHeight
-        photometric:photometric
-        samplesPerPixel:samplesPerPixel
-        bitsPerSample:#[8]
+        width:newWidth height:newHeight photometric:photometric
+        samplesPerPixel:samplesPerPixel bitsPerSample:#[8]
         colorMap:colorMap copy
-        bits:newBytes
-        mask:newMask.
+        bits:newBytes mask:newMask.
 
     "walk over destination image fetching pixels from source image"
 
     mY := mY asFloat.
     mX := mX asFloat.
 %{
+    unsigned char *__srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
     unsigned char *__dstP = __ByteArrayInstPtr(newBytes)->ba_element;
-    unsigned char *__srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
     unsigned char *__srcRowP;
     int __width = __intVal(__INST(width));
     int __w = __intVal(newWidth) - 1;
@@ -2235,6 +2238,8 @@
 "/
 
     ^ newImage
+
+    "Modified: / 30-08-2017 / 13:33:22 / cg"
 !
 
 magnifyRowFrom:srcBytes offset:srcStart