Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Algorithms
  4. Algorithm to compress Image to RGB565 for embedded screen

Algorithm to compress Image to RGB565 for embedded screen

Scheduled Pinned Locked Moved Algorithms
hardwarealgorithmsphpcomgraphics
3 Posts 2 Posters 7 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    XxKeldecknightxX
    wrote on last edited by
    #1

    Hi Everyone!! I am working on logic for a Microcontroller that dynamically updates a screen via UART. The screen only accepts vector based commands to fill a coordinate with a square and a filled color. The command looks like so fill x,y,h,w, The PHP code I wrote so far takes the image and converts each pixel to the following format, However, there are tons of room for optimization. An idea I had was to take the image and find the most common color then set the whole screen to this color. Then find all pixel's within a given shade and make it the same color than that beings the fill command to a single command because it can then cover two squares by using the command x,y,2,1,. The goal is to generate the picture with lossy compression but without extremely affecting the image and as few FILL commands as possible. It can be your own or someone else's algorithm.. just make it possible to redraw with least amount of commands Examples of algorithms are like this. Cycle through each pixel and neighboring pixels and if they are similar shade make them the same. Then find the most common color and set the background image to that color. then cycle through each pixel if it's not that background color fill in that color. The least amount of times you have to cast the fill command to drop a pixel the better the algorithm! A sample image that will be used is here https://www.faichi.com/sites/default/fi ... %202_0.png[^] In this case, the large portion of the map is gray, so its best to make that shade one distinct RGB565 color then set the image of the full background to that color using a single fill command. Then cycle through each pixel and combine additional like colors to make the least amount of permutations to cast a fill command to fill a pixel or a subset of pixels. When doing this without any compression you would have to cast nearly one fill command for each pixel and would take over 5 minutes to draw a screen which is not a doable solution however there should be a simple way to go upon this. Sample PHP code.

    L 1 Reply Last reply
    0
    • X XxKeldecknightxX

      Hi Everyone!! I am working on logic for a Microcontroller that dynamically updates a screen via UART. The screen only accepts vector based commands to fill a coordinate with a square and a filled color. The command looks like so fill x,y,h,w, The PHP code I wrote so far takes the image and converts each pixel to the following format, However, there are tons of room for optimization. An idea I had was to take the image and find the most common color then set the whole screen to this color. Then find all pixel's within a given shade and make it the same color than that beings the fill command to a single command because it can then cover two squares by using the command x,y,2,1,. The goal is to generate the picture with lossy compression but without extremely affecting the image and as few FILL commands as possible. It can be your own or someone else's algorithm.. just make it possible to redraw with least amount of commands Examples of algorithms are like this. Cycle through each pixel and neighboring pixels and if they are similar shade make them the same. Then find the most common color and set the background image to that color. then cycle through each pixel if it's not that background color fill in that color. The least amount of times you have to cast the fill command to drop a pixel the better the algorithm! A sample image that will be used is here https://www.faichi.com/sites/default/fi ... %202_0.png[^] In this case, the large portion of the map is gray, so its best to make that shade one distinct RGB565 color then set the image of the full background to that color using a single fill command. Then cycle through each pixel and combine additional like colors to make the least amount of permutations to cast a fill command to fill a pixel or a subset of pixels. When doing this without any compression you would have to cast nearly one fill command for each pixel and would take over 5 minutes to draw a screen which is not a doable solution however there should be a simple way to go upon this. Sample PHP code.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Looks like you plan to go to the screen when you should be working (first) in memory. Maybe this will help. [Create an image with PHP pixel by pixel - Stuporglue.org](https://stuporglue.org/create-an-image-with-php-pixel-by-pixel/)

      "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

      X 1 Reply Last reply
      0
      • L Lost User

        Looks like you plan to go to the screen when you should be working (first) in memory. Maybe this will help. [Create an image with PHP pixel by pixel - Stuporglue.org](https://stuporglue.org/create-an-image-with-php-pixel-by-pixel/)

        "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

        X Offline
        X Offline
        XxKeldecknightxX
        wrote on last edited by
        #3

        Creating the output of the pixel's isn't exactly the part I am looking for guidance on but this is a useful read anyhow to keep on my radar. I think maybe I am looking for "image vectoring" perhaps? Im not sure if that the correct term.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups