UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: Ratty on December 08, 2009, 03:16:40 AM

Title: Scaleimage function for big images
Post by: Ratty on December 08, 2009, 03:16:40 AM
Further to http://www.underwaredesign.com/forums/index.php?topic=3219.0 (http://www.underwaredesign.com/forums/index.php?topic=3219.0) the Scaleimage function does not work with images > 4096x4096 (possibly 8192x8192).

This is particularly limiting when working on images for playbasic maps which have to be very wide (map block images have all the blocks in a line horizontally).  :-\

This function gets round the limit by splitting images up into smaller sections and scaling them:

Psub ScaleBigImage(imageid,scalex#,scaley#)
; alternative scale function due to bugs in built in one
; setup parameters
imx = GetImageWidth(imageid) : imy = GetImageHeight(imageid)

; create final image
imid = GetFreeImage() : CreateImage imid, (0.0 + imx) * scalex#, (0.0 + imy) * scaley#

; loop round image copying and scaling lumps
xlump = 640 : If xlump > imx Then xlump = imx
lastx = 0 : x = xlump
While lastx < imx
ylump = 640 : If ylump > imy Then ylump = imy
lasty = 0 : y = ylump
While lasty < imy
lumpimid = GetFreeImage() : CreateImage lumpimid, xlump, ylump
CopyRect imageid, lastx, lasty, x, y, lumpimid, 0, 0
ScaleImage lumpimid,scalex#,scaley#,0
CopyRect lumpimid,0,0,GetImageWidth(lumpimid),GetImageHeight(lumpimid),imid,(0.0 + lastx) * scalex#, (0.0 + lasty) * scaley#
DeleteImage lumpimid
lasty = y
Inc y, ylump : If y > imy Then y = imy : ylump = y - lasty
EndWhile
lastx = x
Inc x, xlump : If x > imx Then x = imx : xlump = x - lastx
EndWhile
CopyImage imid,imageid
DeleteImage imid
EndPsub


I hope this is useful.

Ratty
Title: Re: Scaleimage function for big images
Post by: kevin on December 08, 2009, 10:33:11 PM

QuoteThis is particularly limiting when working on images for playbasic maps which have to be very wide (map block images have all the blocks in a line horizontally).

  This is not correct.  Map blocks are expected to be a rectangle of tiles.  X tiles across, by X rows.
Title: Re: Scaleimage function for big images
Post by: Ratty on December 09, 2009, 02:47:20 AM
Sorry, this has changed since I last took a close look at this part of the help text.

This scale function is still useful for big images, although it is likely to be rare that anyone will be using such large images with playbasic. Pixel fonts perhaps?