kmeans.h 895 B

1234567891011121314151617181920
  1. #ifndef KMEANS_H
  2. #define KMEANS_H
  3. // Spread memory touched by different threads at least 64B apart which I assume is the cache line size. This should avoid memory write contention.
  4. #define KMEANS_CACHE_LINE_GAP ((64+sizeof(kmeans_state)-1)/sizeof(kmeans_state))
  5. typedef struct {
  6. double a, r, g, b, total;
  7. } kmeans_state;
  8. typedef void (*kmeans_callback)(hist_item *item, float diff);
  9. LIQ_PRIVATE void kmeans_init(const colormap *map, const unsigned int max_threads, kmeans_state state[]);
  10. LIQ_PRIVATE void kmeans_update_color(const f_pixel acolor, const float value, const colormap *map, unsigned int match, const unsigned int thread, kmeans_state average_color[]);
  11. LIQ_PRIVATE void kmeans_finalize(colormap *map, const unsigned int max_threads, const kmeans_state state[]);
  12. LIQ_PRIVATE double kmeans_do_iteration(histogram *hist, colormap *const map, kmeans_callback callback);
  13. #endif