This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
LeDark Lua's profile picture

Scaling...?

Started by LeDark Lua, 15 September 2015 - 01:14 PM
LeDark Lua #1
Posted 15 September 2015 - 03:14 PM
Hello CC's today I'm here with a quest of making scaling. But I don't know how to do it. Does anybody have an example code or an article I could read and then easy copy-rework-paste to Lua? Thanks.
Edited on 15 September 2015 - 01:14 PM
Exerro #2
Posted 15 September 2015 - 04:44 PM
Scaling what?
LeDark Lua #3
Posted 15 September 2015 - 04:54 PM
Aaa screen, for ex I know where the pixels are, so how can I scale that screen up to 10x10 or something
flaghacker #4
Posted 15 September 2015 - 05:40 PM
I don't know if this answers your question, but you can simply multiply every coordinate with your scale factor.

If that's not your question, please give us an example.
Exerro #5
Posted 15 September 2015 - 05:49 PM
You could do that, but you'll be missing pixels if you scale up. I tend to go for a "loop through all target pixels then scale by original_size/new_size". This is probably the quickest, easiest way to get adequate results.
LeDark Lua #6
Posted 15 September 2015 - 05:52 PM
as it like, newsize=0.5 originalsize=1 1/0.5 ?
LeDark Lua #7
Posted 15 September 2015 - 06:25 PM
You could do that, but you'll be missing pixels if you scale up. I tend to go for a "loop through all target pixels then scale by original_size/new_size". This is probably the quickest, easiest way to get adequate results.
Mabie example code? Because I loop trough all of the pixels and I get not the results I want.
Grim Reaper #8
Posted 15 September 2015 - 08:12 PM
This isn't directly what you're asking for, I don't think, but it might help you get started. This is a script that I wrote as an example usage for an API I made a long time ago. It creates animations by shrinking or growing a frame-buffer. However, it doesn't exactly scale. Instead, it just reveals or conceals more and more of the contents of the frame-buffer.

To truly shrink or stretch an image, you'll have to a do a bit more work than you might imagine. Take a look at the wiki on image scaling.
Edited on 15 September 2015 - 06:12 PM
Bomb Bloke #9
Posted 16 September 2015 - 12:14 AM
The Surface API's drawSurfaceScaled() function, or my GIF API's resizeGIF() function, contain examples.

With resizeGIF(), I'm basically supersampling. The image is converted to a table such that image[y][x] == either a space character (indicating transparency), or an index into a palette of RGB values. Loops are then used to iterate over each pixel in the new image, which figure out which pixels of the old image they effectively cover, and add the relevant percentages of those pixel's RGB values together before finally averaging them all out and picking a final palette index which most closely matches the end result.

That technique isn't the best if you want to scale things up. Heck, it's probably overkill for scaling down, but the results look pretty good.