Upscaling 1 pixel, is it fast?

Started by
4 comments, last by SoulRyder 11 years, 7 months ago
Hello,

Today i was working in FlashPunk. I couldn't find a background color function. (Its probably there but i dont really care).
But instead of that i just made 1 white pixel in photoshop (cause i needed a white background) and scaled it up to the screen width and height.

Now my own theory is that this should be fast cause it only has to load 1 pixel from a .jpg. But on the other side it has to calculate the scaling too.
So I am just wondering, is this an efficient way to make a white background? Or is this a bad way because of the scaling?
Alexander Sarton

Co - Founder / Producer @ Barrelman Games
Advertisement
It would probably use the same method to scale up no matter what size the source is, so the only speed up would be better cache efficiency...

So probably for each pixel it maps it to the source and interpolates stuff (which might be faster for a single pixel source)

idk. "Profile, profile, profile!!!1!1!!11" etcetc...

o3o

Unless it's special-cased, which I doubt, it's probably not as efficient as a proper fill or clear command. Reason being, it still has to calculate where within the one pixel corresponds to each pixel on the screen. It's not much work, and its probably an incremental algorithm, but its still doing it millions of times per frame at any reasonable resolution. And at that it's still assuming that it has to read the value each time, even if it works out to be the same address and stay in the cache, its still an unnecessary read, and more pressure on the registers and instruction cache.

Ignoring the scaling completely, which do you think is quicker -- copying one value to a million+ places one by one, or blasting those million places with a known value (that you don't have to read each time) in a straight shot. Analogy time: You have an empty pool, its your job to fill it. There's a water spigot 20 feet away. Do you run back and forth with a bucket, or find yourself a hose?

throw table_exception("(? ???)? ? ???");


Analogy time: You have an empty pool, its your job to fill it. There's a water spigot 20 feet away. Do you run back and forth with a bucket, or find yourself a hose?

Definitely run back and forth with a bucket tongue.png

@OP: I googled "FlashPunk set background color" and found this.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
If a spigot is 20 feet away from your pool, it's time to dig a closer pool. smile.png

@SoulRyder: Completely unrelated to your actual problem, but worth mentioning: A 1 pixel image should be saved as a BMP or a PNG, but not a JPEG because JPEGs would waste more space than necessary on such a small image - they're better at larger images with many varying values where the original image doens't need to be reproduced 100% accurately. PNGs are good for images small or large, with less color variance, or where the image needs to be exactly as it was originally (like pixel art).
Thanks alot for the replys!
Im going to use the background color function in flashpunk now.
I was just wondering if it was a good idea to do it with the 1 pixel, but not I know a bit better how it works and it doesnt sound like the best way to do it.
And thanks for the tip about the BMP, PNG JPG etc. Didnt know that yet.
Alexander Sarton

Co - Founder / Producer @ Barrelman Games

This topic is closed to new replies.

Advertisement