07-19-2005, 04:52 PM
So I tried doing a routine to scale an image, but it's only working correctly with the factors set to 0.5, or 1 (...). Here's what I have:
if the scale factor numbers are changed to something else, the image does scale, but it gets twisted in a weird way. I suppose it's something with the skip-a-certain-amount-of-pixels algo Im using, but I don't really know any other algo, and google results are confusling.
Code:
'$dynamic
CONST ul_IMGSCALE_RELATIVE = 0, _
ul_IMGSCALE_ABSOLUTE = 1
CONST ul_IMG_8b = 2^29, _
ul_IMG_16b = 2^30, _
ul_IMG_32b = 2^31
sub ul_imgScale(imgSrc() as ubyte, imgDst() as ubyte, scaleX as double, scaleY as double, flags as integer = ul_IMGSCALE_RELATIVE OR ul_IMG_32b) export
dim as integer oriW, oriH, newW, newH
dim as double x, y, springX, springY
oriH = imgSrc(0) / 8 + imgSrc(1) * 32
oriW = imgSrc(2) + imgSrc(3) * 256
if (flags AND ul_IMGSCALE_ABSOLUTE) = ul_IMGSCALE_ABSOLUTE then
scaleX = scaleX / oriW
scaleY = scaleY / oriH
end if
newW = int(oriW * scaleX)
newH = int(oriH * scaleY)
springX = 1 / scaleX
springY = 1 / scaleY
redim imgDst(4 + ((newW - 1) * (newH - 1)) * 4)
imgDst(0) = (newH mod 32) * 8
imgDst(1) = newH \ 32
imgDst(2) = newW mod 256
imgDst(3) = newW \ 256
for x = 0 to oriW - 1 step springX
for y = 0 to oriH - 1 step springY
imgDst((y / springY) * newW + (x / springX) + 4) = imgSrc(y * oriW + x + 4)
next y
next x
end sub
'-------------------
'-- Testing it:
dim as ubyte sprt(4 + (100 * 100) * 4), scaled(0 to 0)
screen 18,8
paint (0,0),100
circle (50,50), 49
line (5, 5) - (5, 50), 200
print "This is a test"
get (0,0)-(99,99), sprt
sleep
cls
ul_imgScale sprt(), scaled(), 0.5, 0.5 '<--- try changing these to eg 0.49 or 0.7 and see the screwup.
put (0,0), scaled
sleep
if the scale factor numbers are changed to something else, the image does scale, but it gets twisted in a weird way. I suppose it's something with the skip-a-certain-amount-of-pixels algo Im using, but I don't really know any other algo, and google results are confusling.