Most Efficient Rectangle

Blitz3D Forums/Blitz3D Beginners Area/Most Efficient Rectangle

_PJ_(Posted 2011) [#1]
I've got a little math problem I'd really appreciate some help with...

Basically, it's regarding animation strips. If I have 'A' frames, then presumably, it's ideal for Blitz to have an image of SQR(A)*SQR(A) frames in a square

(??? Or is it better to have long, thin OR short, tall images?)

If the square is "better", then it's great if A is a square number, however, if it's not, then is there a way to work out the number of rows/columns based on 'A' that would be an almost-square rectangle?

I've been working on the following, but it's not right:

In the code below, 'x' is the value entered, the r and c results should be rows and columns.

Cls
Global x=0
x=Input()
Cls
r=LowestCommonMultiple(x,x-PreviousSquareNumber(x))/x
c=x/r
Print r
Print c

Function GreatestCommonDenominator%(A%,B%)
	Local n%=0
	If ((B%<1)Or (A<1)) Then Return 0
	While (B%)
		n=A% Mod B%
		A%=B%
		B%=n%
	Wend
	Return A%
End Function

Function LowestCommonMultiple%(A%,B%)
	Local GCD=GreatestCommonDenominator%(A%,B%)
	If (GCD)
		Return (A*B)/GCD
	End If
	Return 0
End Function	


Function RectangularDifference(Value)
	Return Value-PreviousSquareNumber(Value)
End Function

Function PreviousSquareNumber(Value)
	Local Square=Floor(Sqr(Float(Value)))
	Return Square*Square
End Function



Yasha(Posted 2011) [#2]
??

How big are your anim images that this is a concern for you?!

If it helps, anim images aren't stored in memory as megatextures but as a vector of individual image frames, so there will be absolutely zero performance difference when it comes to drawing them, no matter how the frames were arranged in the file (i.e. they are converted on loading to linear form). The only place where there could be a difference is at load-time, which generally you shouldn't worry about.

At load-time... the difference between the two is pretty much negligible. I think *cough* Blitz3D has to execute a whopping two whole CPU instructions more per horizontal row, so technically the single long strip should be faster, but it's probably taken you longer to read this sentence than the total amount of extra loading time that using squares would cost in the future.


_PJ_(Posted 2011) [#3]
Well, what it's for is to export (Save) Animstrip bitmaps, there's no SaveAnimImage() function :D

As such, I was hoping to ensure that the resulting filesize was the most efficient (whether for re-loading or just space usage)

Although, I wasn't sure if there was any particualr preferences onw way or the other.

Thanks for the reply, there shouldn't be HUGE numbers of frames, so a single line seems the way to go, thanks :)


Matty(Posted 2011) [#4]
Actually there is a good reason to not have all the frames in a single line.

If you load a texture or image which is more than 8x1 in the ratio of horizontal to vertical some video cards will not load it correctly.

Whether this applies to loadanimimage I am not sure but it will affect things if it is loaded as a single image.


_PJ_(Posted 2011) [#5]
Thanks Matty, I did't know that.

Although, at least personally I've never had such trouble, with ANimImage or otherwise - but usually, long / thin images that I've used with that ratio have been small overall in size,
i.e. 16 * 256 etc.