I am working on a project and in this project I need to capture desktop screen and send it over internet to other client. To compress the image I want to convert it to a 256 color image. I have a general 256 color palette and I am using Euclidean distance to find the nearest color. The problem is that I need to send these images in 10-15 frames per second and making a 256 color image takes 7 seconds. I am wondering how other programs (like teamviewer or real VNC ) are doing this.
for (int y=0;y<900;y++) //loop through the height
for (int x=0;x<1600;x++) //loop through the width
for (int p=0;p<256;p++) //loop through palette colors
{
calculate Euclidean distance of each pixel for each color in pallette and
find the nearest color
** these nested loops take 7 seconds to complete
}
Thanks
OK. After a few days of struggling with many capturing methods and color quantiziers I finally found a solution. Now I am able to send whole desktop image at 10~14 FPS and changed regions of desktop at 20~30 FPS.
In the code I used rcravens's classes to capture screen and changes of screen. Then I cropped the image to 10 samll pieces . After that I took small pieces and made them 256-color using an Octree Color Quantizier explained here thanks to @Dai who pointed me to that direction. After color reduction I converted each piece to a byte array and compressed them using LZ4.Net library.
Here is the code:
I know that my code isn't memory efficient . I'd appreciate it if anyone can help me optimize this code. Thanks again to my friends A. Abramov , Dai , HansPassant , TaW and others.