source: golgotha/src/i4/quantize/histogram.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 2.3 KB
Line 
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
9#include "quantize/histogram.hh"
10#include "error/error.hh"
11#include "image/image.hh"
12#include <memory.h>
13#include "palette/pal.hh"
14#include "file/file.hh"
15
16
17i4_histogram_class::i4_histogram_class()
18{
19  memset(reference,0,sizeof(reference));
20  memset(counts,0,sizeof(counts));
21  tcolors=0;
22  total_pixels=0;
23}
24
25void i4_histogram_class::add_image_colors(i4_image_class *im, int counts_per_pixel)
26{
27  if (im->get_pal()->source.pixel_depth!=I4_32BIT)
28  {
29    i4_warning("add_image_colors : image type not supported");
30    return ;
31  }
32 
33 
34
35  w32 loop_count=im->width()*im->height();
36
37  // this will iterate through all the pixels
38  w32 *pixel=(w32 *)im->data;
39 
40  for (; loop_count; loop_count--)
41  {
42    i4_color c=*pixel;
43
44    // convert the color to 16 bit
45    c= 
46      (((c&0xff0000) >> (16+3)) << (6+5)) |
47      (((c&0x00ff00) >> (8+2))  << (5+0)) |
48      (((c&0x0000ff) >> (0+3))  << (0+0)) ;
49
50    increment_color(c,counts_per_pixel);
51
52    // move to the next pixel in the image
53    ++pixel;
54  }
55
56}
57
58void i4_histogram_class::save(i4_file_class *fp)
59{
60  w32 i;
61  fp->write_32(tcolors);
62  fp->write_32(total_pixels);
63
64  for (i=0; i<HIST_SIZE; i++)
65  {
66    reference[i]=s_to_lsb(reference[i]);
67    counts[i]=l_to_lsb(counts[i]);
68  }
69
70  fp->write(reference, sizeof(reference));
71  fp->write(counts, sizeof(counts));
72
73  for (i=0; i<HIST_SIZE; i++)
74  {
75    reference[i]=s_to_lsb(reference[i]);
76    counts[i]=l_to_lsb(counts[i]);
77  }
78}
79
80void i4_histogram_class::load(i4_file_class *fp)
81{
82  w32 i;
83  tcolors=fp->read_32();
84  total_pixels=fp->read_32();
85
86  fp->read(reference, sizeof(reference));
87  fp->read(counts, sizeof(counts));
88
89  for (i=0; i<HIST_SIZE; i++)
90  {
91    reference[i]=s_to_lsb(reference[i]);
92    counts[i]=l_to_lsb(counts[i]);
93  }
94}
Note: See TracBrowser for help on using the repository browser.