Pixel Manipulation

A fun project I did on my off time

Pixel manipulation

Leaderboard

IMG_4333

iPad Unoptimized - 617.912 sec
iPad Optimized - 40.188 sec (15x faster than unoptimized)
X1 Nano G2 - 128.03 sec (4.8x faster than unoptimized, 3.2x slower than optimized)
Samsung S21 - 34.248 sec
i5-8500 ThinkCentre - 37.322 sec
ten_6044 ASUS WIN 11 - 63.466 sec


Flower Box

iPad Unoptimized - 666.447 sec
iPad Optimized - 36.722 sec (18x faster than unoptimized)
X1 Nano G2 - 124.699 sec (5.2x faster than unoptimized, 3.4x slower than optimized)
Samsung S21 - 31.574 sec
i5-8500 ThinkCentre - 35.44 sec
ten_6044 ASUS WIN 11 - 50.72 sec


IMG_0053

iPad Unoptimized - 672.044 sec
iPad Optimized - 51.888 sec (13x faster than unoptimized)
X1 Nano G2 - 197.089 sec (3.4x faster than unoptimized, 3.8x slower than optimized)
Samsung S21 - 53.895 sec
i5-8500 ThinkCentre - 60.217 sec
ten_6044 ASUS WIN 11 - 84.997 sec


Alonzo

iPad Unoptimized - 41.266 seconds
iPad Optimized - 13.191 sec (3x faster than unoptimized)
X1 Nano G2 - 26.734 sec (1.5x faster than unoptimized, 2x slower than optimized)
Samsung S21 - 13.565 sec
i5-8500 ThinkCentre - 13.208 sec
ten_6044 ASUS WIN 11 - 13.467 sec


ten_6044 Costume

ten_6044 ASUS WIN 11 - 26.469 sec
i5-8500 ThinkCentre - 18.687 sec

Very fun! Brilliant project!

However, the brighten block affects alpha which will make the costume more transparent the darker and more opaque the brighter.

Given that it takes a long time, I have a couple of ideas about making it faster.

  1. Some things that you do using MAP and/or KEEP might be faster using the hyperblock feature, i.e., instead of
    help-test script pic
    you can just say
    help-test script pic (1)
    But this doesn't work for =, alas, because it isn't hyperized.

  2. I think there are quadratic-time parts of the algorithm, especially if there are many unique colors in the original. Some of those might be sped up by sorting the pixels (n log n time) before doing anything else. You're thinking that you can't do that because you need to know where in the costume each pixel is, but you can start by making a list in which each RGBA pixel becomes (LIST (rgba) (index)) and then sort on


    Then rearrange the result into a list of (LIST (rgba) (list-of-indices)), and use that instead of UNIQUES.

  3. If the overall algorithm is quadratic time, little constant-time speedups may not be worth worrying about, but there are an awful lot of bounds checks, if color<0 and if color>255, that could be avoided by making sure that doesn't happen in the first place.

I figured out the problem:

Painting script pic

Insides

The problem was the fact that it wasn’t checking whether or not the color existed in the list, so it was calling the replace color function for all of the colors in the range.

Render script

Now by checking if the color existed in the list, it decreased render times by 3 - 18x for my preset images.

New insides

Render Times

IMG_4333 - 617.912 sec
Optimized - 40.188 sec
15x faster

Flower Box - 666.447 sec
Optimized - 36.722 sec
18x faster

IMG_0053 - 672.044 sec
Optimized - 51.888 sec
13x faster

Alonzo - 41.266 seconds
Optimized - 13.191 sec
3x faster

Interestingly, I got roughly half your time last night, and roughly half time today with your new optimisations.

With my windows machine I can tell you it does that on one core and only one core. I don't know if you could find that data on an ipad, but it probably only uses one core as well.

I'm using a 13th Gen Intel Core i5.

The one score that were different, was alonzo, which took ten seconds. Odd. In my mind, it's much simpler and much smaller, so it should have been much faster. Are you still calculating the whole stage? (A brief check tells me it should just be calculating the costume, hrmmm)

It's probably due to the laptop temperature, the apps you run, and the background task, so it may run faster on a potato.

Cranks her PC's fans to max Nope. No difference. (I'm being "funny" lol)

My 12th Gen i5-1240P X1 Nano G2 got quite worse results, around 2x slower than my iPad.

Tested this with my phone and it actually did pretty good.

For me, the results are:
IMG_4333: 63.466
Flower Box: 50.72
IMG_0053: 84.997
Alonzo: 13.467

My device is ASUS and on Windows 11.

What's unique is that, if you use my PFP in the project, the result would be 26.469 seconds. Test it with this image below:
Ten 33 Bitmap PFP 2

Laptops tend to be made cheaply, this is a full size desktop. I built it myself.

Well I noticed that the second you said that it was half the time for the unoptimized. Desktops are usually way more powerful than mobile devices.

You may have misunderstood me/I may have explained poorly. Last night I ran it before bed it took 5 minutes and your comment said it took a little over 11 minutes. When I woke up this morning you had optimized it to be a lot faster, but my speeds were consistently half your benchmarks no matter the speed.

672 (You) == 300 (Me) / 51.888 (You) == 26 (Me)

What phone did you run it on?

Samsung A70

PFP == 45 seconds
4333 == Error.

Uh, ok, nevermind lol. Snap barely runs on my phone let alone trying to render something. So I won't try the others lol. My PC does your PFP in 14 seconds.

Also, keeping in mind, all the devices are probably only using a single core regardless. Snap! does support threading, but Iunno if you could actually get the pc to run the code on multiple cores.

These speeds would be ludicrously lower on even a dual-core setup, and that's even before we wander into the weeds that is GPU

No, I didn't misunderstand.

I knew you were using a desktop PC the moment you said that it was half of my unoptimized time. Desktop PC are way faster than other mobile devices.

Samsung S21