about summary refs log tree commit diff
path: root/lib/ppmcmap.h
blob: dd3e5c14a7225999da025ee6df5fffac76fcaaae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#ifndef PPMCMAP_INCLUDED
#define PPMCMAP_INCLUDED
/* ppmcmap.h - header file for colormap routines in libppm
*/

#ifdef __cplusplus
extern "C" {
#endif
#if 0
} /* to fake out automatic code indenters */
#endif


/* Color histogram stuff. */

typedef struct colorhist_item* colorhist_vector;
struct colorhist_item {
    pixel color;
    int value;
};

typedef struct colorhist_list_item* colorhist_list;
struct colorhist_list_item {
    struct colorhist_item ch;
    colorhist_list next;
};

colorhist_vector
ppm_computecolorhist( pixel ** const pixels, 
                      const int cols, const int rows, const int maxcolors, 
                      int * const colorsP );
colorhist_vector
ppm_computecolorhist2(FILE * const ifp,
                      const int cols, const int rows, 
                      const pixval maxval, const int format, 
                      const int maxcolors, int * const colorsP );

void
ppm_addtocolorhist(colorhist_vector chv, 
                   int * const colorsP, const int maxcolors, 
                   const pixel * const colorP, 
                   const int value, const int position );

void
ppm_freecolorhist(colorhist_vector const chv);


/* Color hash table stuff. */

typedef colorhist_list* colorhash_table;

colorhash_table
ppm_computecolorhash( pixel ** const pixels, 
                      const int cols, const int rows, 
                      const int maxcolors, int * const colorsP );

colorhash_table
ppm_computecolorhash2(FILE * const ifp,
                      const int cols, const int rows, 
                      const pixval maxval, const int format, 
                      const int maxcolors, int * const colorsP);

int
ppm_lookupcolor(colorhash_table const cht, 
                const pixel *   const colorP );

colorhist_vector
ppm_colorhashtocolorhist(colorhash_table const cht, 
                         int             const maxcolors);

colorhash_table
ppm_colorhisttocolorhash(colorhist_vector const chv, 
                         int              const colors);

int
ppm_addtocolorhash(colorhash_table const cht, 
                   const pixel *   const colorP, 
                   int             const value);

void
ppm_delfromcolorhash(colorhash_table const cht, 
                     const pixel *   const colorP);


colorhash_table
ppm_alloccolorhash(void);

void
ppm_freecolorhash(colorhash_table const cht);


colorhash_table
ppm_colorrowtocolorhash(pixel * const colorrow,
                        int     const ncolors);

pixel *
ppm_computecolorrow(pixel ** const pixels,
                    int      const cols,
                    int      const rows,
                    int      const maxcolors,
                    int *    const ncolorsP);

pixel *
ppm_mapfiletocolorrow(FILE *   const fileP,
                      int      const maxcolors,
                      int *    const ncolorsP,
                      pixval * const maxvalP);

void
ppm_colorrowtomapfile(FILE *  const ofP,
                      pixel * const colormap,
                      int     const ncolors,
                      pixval  const maxval);

void
ppm_sortcolorrow(pixel * const colorrow,
                 int     const ncolors, 
                 int (*cmpfunc)(pixel *, pixel *));

int
ppm_addtocolorrow(pixel * const colorrow,
                  int *   const ncolorsP,
                  int     const maxcolors,
                  pixel * const pixelP);

int
ppm_findclosestcolor(const pixel * const colormap, 
                     int           const ncolors, 
                     const pixel * const pP);

/* standard sort function for ppm_sortcolorrow() */
#define PPM_STDSORT     (int (*)(pixel *, pixel *))0
#endif

#ifdef __cplusplus
}
#endif