HGuys
I succeded making an alternative variation of the Api (At least for Y coord). It loads, enlarge, reduce images of 12 Mb or bigger:) Btw..i´ll fix a small problem of X coord later.
But, i have a doubt on the algorithm ued by strecth api.
It seems it uses nearest neighbour or bilinear algorithms to perform the enlarging/shrinking, but when i tried to implement the nearest neighbour i´m having incorrect results.
I built an variation of the algorithm seem here
http://tech-algorithm.com/articles/nearest-neighbor-image-scaling/public int[] resizePixels(int[] pixels,int w1,int h1,int w2,int h2) {
int[] temp = new int[w2*h2] ;
double x_ratio = w1/(double)w2 ;
double y_ratio = h1/(double)h2 ;
double px, py ;
for (int i=0;i<h2;i++) {
for (int j=0;j<w2;j++) {
px = Math.floor(j*x_ratio) ;
py = Math.floor(i*y_ratio) ;
temp[(i*w2)+j] = pixels[(int)((py*w1)+px)] ;
}
}
return temp ;
}
I ported it to RosAsm, but i added a Starting and Ending area of the inputed image to process. For example, given an image of 640*480, i would like to enlarge only a specific area of the image so the result will be a 1024*720. But, also, I would like to limit the visible area. So, if the enlarging image exceeds the area of the client window it will keep the image proportion. Example, let´s say the visible area is only 800*600. I would like to "view" a resized image from width = 640 to 1024 and height=480 to 720, but limited to a view area of 800*600 (So allowing cropping)
Example of the porting code:
YStart = 30 --> Starting at YPos 30 (CYStart)
YEnd = 290 --> Ending at YPos 290 (CYEnd)
XStart = 120 --> Starting at XPos 120 (CXStart)
XEnd = 500 --> Ending at XPos 500 (CXEnd)
SrcWidth = 640 (WidthSrc)
SrcHeight = 480 (HeightSrc)
TargetWidth = 1024 (WidthDest)
Targetheight = 720 (HeightDest)
MaxViewHeight = 800 (CYDestMax)
MaxViewWidth = 600 (CXDestMax)
Proc resizePixelsEx:
Arguments @Pixels, @CYStart, @CYEnd, @CXStart, @CXEnd, @WidthSrc, @HeightSrc, @WidthDest, @HeightDest, @CYDestMax, @CXDestMax
Local @TempMem, @iCounter, @jCounter, @X2, @Y2, @MemPix
Uses ebx, esi, edi, ecx, edx
xor eax eax
xor edx edx
mov edx D@WidthDest | imul edx D@CYDestMax | shl edx 2
mov D@MemPix 0 | lea eax D@MemPix
call 'RosMem.VMemAlloc' eax, edx
mov D@TempMem eax
fild D@WidthSrc | fidiv D@WidthDest | fstp R$x_ratio
fild D@HeightSrc | fidiv D@HeightDest | fstp R$y_ratio
mov D@iCounter 0
mov eax D@iCounter
mov esi D@Pixels
; Get Starting pos
mov ecx D@CYStart | imul ecx D@WidthSrc | add ecx D@CXStart | shl ecx 2;D@X
add esi ecx
mov edi D@TempMem
mov edx D@WidthDest | shl edx 2 | add edx esi
.While eax < D@CYDestMax;@HeightDest
;mov eax D@HeightDest
mov D@jCounter 0
mov eax D@jCounter
While eax < D@CXDestMax;@WidthDest
fild F@jCounter | fmul R$x_ratio | fistp F$CxMax
fild F@iCounter | fmul R$y_ratio | fistp F$CyMax
;;
X2 = (CyMax*Width1)+CxMax = ((iCounter*y_ratio)*Width1)+(jCounter*x_ratio)
Y2 = (iCounter*Width2)+jCounter
;;
lea eax D@X2 | fild F$CyMax | fimul F@WidthSrc | fiadd F$CxMax | fistp F$eax | mov eax D$eax
lea ecx D@Y2 | fild F@iCounter | fimul F@WidthDest | fiadd F@jCounter | fistp F$ecx | mov ecx D$ecx
mov eax D$esi+eax*4
mov D$edi+ecx*4 eax
inc D@jCounter
mov eax D@jCounter
End_While
inc D@iCounter
mov eax D@iCounter
.End_While
mov eax D@TempMem
EndP
The tests on a 4*2 image with a zoom of 196.50 gave me this result

See, the black pixels area ? This should not to be black but filled tih the proper collors as in the Original Api. I´m pretty sure the problem is with the resizing/scaling algorithm but i´m unable to find the proper solution.
The image should be a bit more to the right and a bit on tht top. Teh proportions are Ok, but the displacement of it is wrong.