PHP convert Image to RGB565, compress, show stat's and download

Kapalı İlan edilme: 4 yıl önce Teslim sırasında ödenir
Kapalı Teslim sırasında ödenir

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,<color>

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

The goal is to generate the picture with lossy compression but without extremely affecting the image and as few FILL commands as possible.

During the development of these algorithms, your PHP code will need to display the before and after image and the number of FILL lines required to draw the image.

The Binary data of the x,y, color will then be sent as a .bin file when requested from the .php script.

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

[login to view URL]

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 to get started.

<?php

$img = imagecreatefromjpeg("Path to Image that is 480x272");

$width = ImageSX($img);

$height = ImageSY($img);

for ($y = 0; $y < $height; $y++) {

for ($x = 0; $x < $width; $x++) {

$c = imageColorAt($img, $x, $y);

$r = ($c >> 16) & 0xFF;

$g = ($c >> 8) & 0xFF;

$b = $c & 0xFF;

$r = $r >> 3;

$g = $g >> 2;

$b = $b >> 3;

$oc = ($r << 11) | ($g << 5) | $b;

echo ("fill $x,$y,1,1,$oc<br>");

}

}

?>

Algoritma Image Processing PHP Yazılım Mimarisi

Proje NO: #19339774

Proje hakkında

5 teklif Uzak proje Aktif 4 yıl önce