GreycLab / CImg

The CImg Library is a small and open-source C++ toolkit for image processing
http://cimg.eu
Other
1.5k stars 286 forks source link

Add Dithering and Color reduce functions #5

Closed neophob closed 8 years ago

neophob commented 9 years ago

Hi, I need image manipulation functions, which are not yet included in CImg:

The code for those operations (combined) should be pretty straightforward:

static const uint8_t rgb565_matrix[64] = {
    0, 4, 1, 5, 0, 4, 1, 5,
    6, 2, 7, 3, 6, 2, 7, 3,
    1, 5, 0, 4, 1, 5, 0, 4,
    7, 3, 6, 2, 7, 3, 6, 2,
    0, 4, 1, 5, 0, 4, 1, 5,
    6, 2, 7, 3, 6, 2, 7, 3,
    1, 5, 0, 4, 1, 5, 0, 4,
    7, 3, 6, 2, 7, 3, 6, 2
};

/* Dithering by individual subpixel */
#define MIN(a,b) (((a)<(b))?(a):(b))

// indexed dithering 888->565
static void dither_rgb888_to_rgb565_in_place_indexed(unsigned char *src, int w, int h) {
  int i = 0;
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      uint8_t tresshold_id = ((y & 7) << 3) + (x & 7);
      src[i]   = MIN(src[i]   + rgb565_matrix[tresshold_id], 0xff) & 0xF8;
      src[i+1] = MIN(src[i+1] + rgb565_matrix[tresshold_id], 0xff) & 0xFC;
      src[i+2] = MIN(src[i+2] + rgb565_matrix[tresshold_id], 0xff) & 0xF8;
      i += 3;
    }
  }
}

Any chance to add those functions (I guess they need to be splited to up to make sense).

BR Michael

dtschump commented 9 years ago

It seems to be a very specific piece of code. Why don't you write a CImg plug-in ?