histogram.hh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. #ifndef HISTOGRAM_HH
  9. #define HISTOGRAM_HH
  10. #include "arch.hh"
  11. #include "image/image.hh"
  12. class i4_file_class;
  13. class i4_histogram_class
  14. {
  15. public :
  16. enum { HIST_SIZE=0x10000, // 16 bit histogram table
  17. MAX_COLORS=256 };
  18. w16 reference[HIST_SIZE];
  19. w32 counts[HIST_SIZE];
  20. w32 tcolors; // total original colors in the histogram [length of reference]
  21. w32 total_pixels; // total pixels accounted for in image (affected by counts_per_pixel)
  22. i4_histogram_class();
  23. void increment_color(w16 color, // this is expected to be a 16 bit color (5 6 5)
  24. w32 count)
  25. {
  26. if (!counts[color]) // is this an original color?
  27. {
  28. reference[tcolors]=color; // add this color to the reference list
  29. tcolors++;
  30. }
  31. counts[color]+=count; // increment the counter for this color
  32. total_pixels+=count; // count total pixels we've looked at
  33. }
  34. void reset()
  35. {
  36. for (int i=0; i<tcolors; i++)
  37. counts[reference[i]]=0;
  38. tcolors=0;
  39. total_pixels=0;
  40. }
  41. void save(i4_file_class *fp);
  42. void load(i4_file_class *fp);
  43. // counts_per_pixel can be used to give smaller images more emphasis
  44. // I use this to give mip maps of original images more double emphasis
  45. // right now only image's of type i4_image32 will work
  46. void add_image_colors(i4_image_class *image, int counts_per_pixel=1);
  47. } ;
  48. #endif