05-25-2025, 06:05 PM
Just chiming in with my $0.05, since I understand they are going to eliminate pennies...
Given that a FUNCTION will do everything a SUB will do "plus" return a value, I attach an example of a sub that I had occasion to convert to a function. The only difference being that the function "returns" the ratio as a SINGLE precision that the image is reduced (or expanded) by.
It would be somewhat awkward to pass a dummy variable to a SUB in order to get a ratio figure if it were needed, and one would need to declare a dummy variable to receive a returned value if it were not needed. You can go either way depending upon the project's requirements.
Given that a FUNCTION will do everything a SUB will do "plus" return a value, I attach an example of a sub that I had occasion to convert to a function. The only difference being that the function "returns" the ratio as a SINGLE precision that the image is reduced (or expanded) by.
It would be somewhat awkward to pass a dummy variable to a SUB in order to get a ratio figure if it were needed, and one would need to declare a dummy variable to receive a returned value if it were not needed. You can go either way depending upon the project's requirements.
Code: (Select All)
' Description:
' This routine scales and justifies a target image to fit in a predefined area of another image.
' It maintains the height/width ratio and fits it to the area defined, the image can be justified
' up/down/center in the vertical and left/right/center in the horizontal .
' It incorporates _PUTIMAGE and so it is used in its place.
' Syntax: Image_Resize( up lt x, up lt y, low rt x, low rt y, src handle, dest handle, horiz just, vert just)
' horizontal justifications= "l" left, "c" center, "r" right
' vertical justifications= "u" up, "c" center, "d" down
' Author: OldMoses
SUB Image_Resize (xpos AS INTEGER, ypos AS INTEGER, xlim AS INTEGER, ylim AS INTEGER, i AS LONG, d AS LONG, xj AS STRING, yj AS STRING)
DIM AS INTEGER xs, ys, xp, yp, xl, yl ' ready for OPTION EXPLICIT programs
xp = xpos: yp = ypos: xl = xlim: yl = ylim ' isolate sent parameters from any changes
DIM AS SINGLE rt, xrt, yrt
xrt = (xl - xp) / _WIDTH(i) ' width of area divided by width of image
yrt = (yl - yp) / _HEIGHT(i) ' height of area divided by height of image
rt = -xrt * (xrt < yrt) - yrt * (yrt <= xrt) ' pick the smaller of the two ratios to fit area
xs = _WIDTH(i) * rt ' final image size ratio in x
ys = _HEIGHT(i) * rt ' final image size ratio in y
xp = -xp * (xj = "l") - (_SHR(xl - xp, 1) + xp - _SHR(xs, 1)) * (xj = "c") - (xl - xs) * (xj = "r")
xl = xp + xs
yp = -yp * (yj = "u") - (_SHR(yl - yp, 1) + yp - _SHR(ys, 1)) * (yj = "c") - (yl - ys) * (yj = "d")
yl = yp + ys
_PUTIMAGE (xp, yp)-(xl, yl), i, d
END SUB 'Image_Resize
'as above, but also return the resizing ratio as a single precision value
FUNCTION Image_Resize! (xpos AS INTEGER, ypos AS INTEGER, xlim AS INTEGER, ylim AS INTEGER, i AS LONG, d AS LONG, xj AS STRING, yj AS STRING)
DIM AS INTEGER xs, ys, xp, yp, xl, yl ' ready for OPTION EXPLICIT programs
xp = xpos: yp = ypos: xl = xlim: yl = ylim ' isolate sent parameters from any changes
DIM AS SINGLE rt, xrt, yrt
xrt = (xl - xp) / _WIDTH(i) ' width of area divided by width of image
yrt = (yl - yp) / _HEIGHT(i) ' height of area divided by height of image
rt = -xrt * (xrt < yrt) - yrt * (yrt <= xrt) ' pick the smaller of the two ratios to fit area
xs = _WIDTH(i) * rt ' final image size ratio in x
ys = _HEIGHT(i) * rt ' final image size ratio in y
xp = -xp * (xj = "l") - (_SHR(xl - xp, 1) + xp - _SHR(xs, 1)) * (xj = "c") - (xl - xs) * (xj = "r")
xl = xp + xs
yp = -yp * (yj = "u") - (_SHR(yl - yp, 1) + yp - _SHR(ys, 1)) * (yj = "c") - (yl - ys) * (yj = "d")
yl = yp + ys
_PUTIMAGE (xp, yp)-(xl, yl), i, d
Image_Resize! = rt
END FUNCTION 'Image_Resize!
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
sha_na_na_na_na_na_na_na_na_na: