1 /*****************************************************************************
2 * This file is part of gfxprim library. *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
19 * Copyright (C) 2009-2011 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
29 int GP_FilterHistogram_Raw(const GP_Context
*src
, GP_FilterParam histogram
[],
30 GP_ProgressCallback
*callback
);
32 int GP_FilterHistogram(const GP_Context
*src
, GP_FilterParam histogram
[],
33 GP_ProgressCallback
*callback
)
37 ret
= GP_FilterHistogram_Raw(src
, histogram
, callback
);
44 for (i
= 0; histogram
[i
].channel_name
[0] != '\0'; i
++) {
46 GP_Histogram
*hist
= histogram
[i
].val
.ptr
;
48 hist
->max
= hist
->hist
[0];
49 hist
->min
= hist
->hist
[0];
51 for (j
= 1; j
< hist
->len
; j
++) {
52 if (hist
->hist
[j
] > hist
->max
)
53 hist
->max
= hist
->hist
[j
];
55 if (hist
->hist
[j
] < hist
->min
)
56 hist
->min
= hist
->hist
[j
];
63 void GP_FilterHistogramAlloc(GP_PixelType type
, GP_FilterParam params
[])
67 GP_FilterParamSetPtrAll(params
, NULL
);
69 const GP_PixelTypeChannel
*channels
= GP_PixelTypes
[type
].channels
;
71 for (i
= 0; i
< GP_PixelTypes
[type
].numchannels
; i
++) {
72 size_t chan_size
= 1<<channels
[i
].size
;
74 GP_Histogram
*hist
= malloc(sizeof(struct GP_Histogram
) +
75 sizeof(uint32_t) * chan_size
);
78 GP_FilterHistogramFree(params
);
82 hist
->len
= chan_size
;
83 memset(hist
->hist
, 0, sizeof(uint32_t) * chan_size
);
85 (GP_FilterParamChannel(params
, channels
[i
].name
))->val
.ptr
= hist
;