This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Scaling...?
Started by LeDark Lua, 15 September 2015 - 01:14 PMPosted 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
Posted 15 September 2015 - 04:44 PM
Scaling what?
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
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.
If that's not your question, please give us an example.
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.
Posted 15 September 2015 - 05:52 PM
as it like, newsize=0.5 originalsize=1 1/0.5 ?
Posted 15 September 2015 - 06:25 PM
Mabie example code? Because I loop trough all of the pixels and I get not the results I want.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.
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.
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
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.
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.