--- a/Depth1Image.st Wed Aug 30 15:15:34 2017 +0200
+++ b/Depth1Image.st Wed Aug 30 15:15:39 2017 +0200
@@ -375,50 +375,50 @@
!Depth1Image methodsFor:'magnification'!
-hardMagnifiedBy:scalePoint
+hardMagnifiedBy:scaleArg
"return a new image magnified by scalePoint, aPoint.
This is the general magnification method, handling non-integral values.
- It is slower than the integral magnification method."
+ It is slower than the integral magnification method.
- |mX
- mY
+ 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 }"
- newImage newBits bitsPerPixel newBytesPerRow
- newMask
- bytes|
+ newImage newBits bpp newBytesPerRow newMask bits|
- bytes := self bits.
- bytes isNil ifTrue:[
- self error:'cannot magnify image without bits'.
- ^ self
+ bits := self bits.
+ bits isNil ifTrue:[
+ self error:'cannot magnify image without bits'.
+ ^ self
].
+ scalePoint := scaleArg asPoint.
mX := scalePoint x.
mY := scalePoint y.
newWidth := (width * mX) truncated.
newHeight := (height * mY) truncated.
- bitsPerPixel := self depth.
- newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
+ bpp := self depth.
+ newBytesPerRow := ((newWidth * bpp) + 7) // 8.
newBits := ByteArray new:(newBytesPerRow * newHeight).
mask notNil ifTrue:[
- newMask := (mask magnifiedBy:scalePoint)
+ newMask := (mask magnifiedBy:scalePoint)
].
newImage := self species new.
newImage
- width:newWidth
- height:newHeight
- photometric:photometric
- samplesPerPixel:samplesPerPixel
- bitsPerSample:bitsPerSample
- colorMap:colorMap copy
- bits:newBits
- mask:newMask.
+ width:newWidth height:newHeight photometric:photometric
+ samplesPerPixel:samplesPerPixel bitsPerSample:bitsPerSample
+ colorMap:colorMap copy
+ bits:newBits mask:newMask.
"walk over destination image fetching pixels from source image"
@@ -427,7 +427,7 @@
%{
{
- OBJ b1 = bytes;
+ OBJ b1 = bits;
int _w1 = __intVal(__INST(width));
int _y1, _y2;
OBJ b2 = newBits;
@@ -440,18 +440,18 @@
double _mX = __floatVal(mX);
for (_y2 = 0; _y2 < _h2; _y2++) {
- _y1 = (int)( (double)_y2 / _mY);
+ _y1 = (int)( (double)_y2 / _mY);
- for (_x2 = 0; _x2 < _w2; _x2++) {
- _x1 = (int)( (double)_x2 / _mX);
+ for (_x2 = 0; _x2 < _w2; _x2++) {
+ _x1 = (int)( (double)_x2 / _mX);
- _byte = __ByteArrayInstPtr(b1)->ba_element[(_w1 + 7) / 8 * _y1 + (_x1 / 8)];
+ _byte = __ByteArrayInstPtr(b1)->ba_element[(_w1 + 7) / 8 * _y1 + (_x1 / 8)];
- if ((_byte & (0x80 >> (_x1 % 8)))) {
- _idx2 = (_w2 + 7) / 8 * _y2 + (_x2 / 8);
- __ByteArrayInstPtr(b2)->ba_element[_idx2] |= (0x80 >> (_x2 % 8));
- }
- }
+ if ((_byte & (0x80 >> (_x1 % 8)))) {
+ _idx2 = (_w2 + 7) / 8 * _y2 + (_x2 / 8);
+ __ByteArrayInstPtr(b2)->ba_element[_idx2] |= (0x80 >> (_x2 % 8));
+ }
+ }
}
}
%}.
@@ -475,7 +475,8 @@
"((Image fromFile:'bitmaps/claus.gif') magnifiedBy:0.5@0.5)"
- "Created: 18.6.1996 / 16:04:26 / cg"
+ "Created: / 18-06-1996 / 16:04:26 / cg"
+ "Modified: / 30-08-2017 / 13:34:45 / cg"
!
magnifyRowFrom:srcBytes offset:srcStart