Jump to content
  • Advertisement
Sign in to follow this  
SoulRyder

Upscaling 1 pixel, is it fast?

This topic is 2221 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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? Edited by Ravyne

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!