views:

417

answers:

3

I'm developing a custom thin-client server that serves rendered webpages to its clients. Server is running on multicore Linux box, with Webkit providing the html rendering engine.

The only problem is the fact that clients display is limited with a 4bit (16 colors) grayscale palette. I'm currently using LibGraphicsMagick to dither images (RGB->4bit grayscale), which is an apparent bottleneck in the server performance. Profiling shows that more than 70% of time is spent running GraphicsMagick dithering functions.

I've explored stackoverflow and the Interwebs for a good high performance solution, but it seems that nobody did any benchmarks on various image manipulation libraries and dithering solutions.

I would be more that happy to find out:

  1. What are the highest performance libraries in regards to dithering / halftoning / quantizing RGB images to 4bit grayscale.
  2. Are there any specilized dithering libs or any public domain code snippets that you could point me to?
  3. What libraries do you prefer for manipulating graphics in regards to high performance?

C language libraries are prefered.

A: 

Dithering is going to take quite a bit of time depending on the algorithm chosen.

It's fairly trivial to implement Bayer (Matrix) and Floyd-Steinberg (Diffusion) dithering.

Bayer filtering can be made extremely fast when coded with with MMX/SSE to process parallel pixels. You may also be able to do the dithering / conversion using a GPU shader.

FWIW, you're already using GraphicsMagick but there's an entire list of OSS graphics libraries here

Adisak
Thanks for the huge list, I just wish there were some benchmarks out there already.
'read this link to get an idea' link is currently broken.
Jamie
@Jamie: Edited links - old link (http://scien.stanford.edu/class/psych221/projects/02/mdeleon/htbasics.html) wasn't working.
Adisak
A: 

I know it's not a C library, but this got me curious about what's available for .NET to do error-diffusion which I used some 20 years ago on a project. I found this and specifically this method.

But to try be helpful :) I found this C library.

kenny
'C Library' link is currently broken.
Jamie
+1  A: 

From the list provided by Adisak, without any testing, I would bet on AfterImage. The Afterstep people are obsessed with speed, and also described a clever algorithm.

You could take an alternative approach, if your server could be equipped with a decent PCI-express graphics card featuring OpenGL. Here are some specs from Nvidia. Search for "index mode". What you could do is select a 16 or 256 color display mode, render your image as a texture on a flat polygon (like the side of cube) and then read the frame back.

When reading a frame from an OpenGL card, it is important that bandwidth is good from the card, hence the need for PCI-express. As the documentation says, you also have to choose your colors in indexed mode for decent effects.

Amigable Clark Kant
+1 for interesting idea. Using a GPGPU for rendering ;-)
Spike0xff
@Spike0xff, actually, it is not even necessary for it to be general purpose GPU (programmable), it's enough with anything that works with OpenGL or DirectX.
Amigable Clark Kant