Author Topic: Unscramble the picture puzzle  (Read 6158 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Unscramble the picture puzzle
« Reply #15 on: January 28, 2021, 07:51:23 am »
You know, I was thinking about my little image sort experiment last night.  At first, I just tried it as a fun experiment...  Now I’m wondering if it might actually be useful for something — like quickly gathering the colors for a palette of an image.

Normally we’d start with a blank palette, and read pixel-by-pixel, and build and compare against our palette as we go.  By the time we go from top left to bottom right, we might be doing thousands of comparisons per pixel, if the image has a large palette...

But if we sort the image first, all we’d ever need to compare is the previous pixel’s color.

IF this_pixel_color <> last_pixel_color THEN
   increase_palette_by_one
   last_pixel_color = this_pixel_color
END IF

Seems to me that it might be a whole lot faster and more efficient manner to build a color palette index, than just the pixel-by-pixel approach! 

Isn’t it funny how even joking around and goofing off can sometimes lead to substantial improvements in things?  ;D
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Unscramble the picture puzzle
« Reply #16 on: February 04, 2021, 05:57:08 pm »
This is awesome Dav and Steve! Good job.