Jump to content

  • Log In with Google      Sign In   
  • Create Account


Upscaling 1 pixel, is it fast?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 SoulRyder   Members   -  Reputation: 141

Like
1Likes
Like

Posted 25 August 2012 - 02:17 PM

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

Sponsor:

#2 Waterlimon   Crossbones+   -  Reputation: 2376

Like
3Likes
Like

Posted 25 August 2012 - 03:26 PM

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...

Waterlimon (imagine this is handwritten please)


#3 Ravyne   Crossbones+   -  Reputation: 6778

Like
3Likes
Like

Posted 25 August 2012 - 05:27 PM

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, 25 August 2012 - 05:28 PM.


#4 Cornstalks   Crossbones+   -  Reputation: 6966

Like
2Likes
Like

Posted 25 August 2012 - 06:20 PM

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 Posted Image

@OP: I googled "FlashPunk set background color" and found this.
[ 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 ]

#5 Servant of the Lord   Crossbones+   -  Reputation: 17262

Like
2Likes
Like

Posted 25 August 2012 - 09:24 PM

If a spigot is 20 feet away from your pool, it's time to dig a closer pool. Posted Image

@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).

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.

[Fly with me on Twitter] [Google+] [My broken website]

All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.                                                                                                                                                       [Need free cloud storage? I personally like DropBox]

Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal


#6 SoulRyder   Members   -  Reputation: 141

Like
0Likes
Like

Posted 26 August 2012 - 03:03 AM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS