This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated discards 3b9e7725969eafa310c5358783ec8547773f04e4 (commit) via 1109c295817003da4e1da28179040c3060dc1326 (commit)
This update added new revisions after undoing existing revisions. That is to say, the old revision is not a strict subset of the new revision. This situation occurs when you --force push a change and generate a repository containing something like this:
* -- * -- B -- O -- O -- O (3b9e7725969eafa310c5358783ec8547773f04e4) N -- N -- N (1109c295817003da4e1da28179040c3060dc1326)
When this happens we assume that you've already had alert emails for all of the O revisions, and so we here report only the revisions in the N branch from the common base, B.
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/1109c295817003da4e1da28179040c3060dc1...
commit 1109c295817003da4e1da28179040c3060dc1326 Author: Cyril Hrubis metan@ucw.cz Date: Fri Jan 16 10:29:10 2015 +0100
filters: Get rid of FilterParams
* Remove FilterParams
* Rewrite histogram code
* Add GP_PixelChannelCount(), GP_PixelChannelBits() and GP_PixelChannelName()
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/build/syms/Filters_symbols.txt b/build/syms/Filters_symbols.txt index d048bdc6..43049197 100644 --- a/build/syms/Filters_symbols.txt +++ b/build/syms/Filters_symbols.txt @@ -57,8 +57,8 @@ GP_FilterHConvolutionMP_Raw GP_FilterHLinearConvolution_Raw
GP_FilterHistogram -GP_FilterHistogramAlloc -GP_FilterHistogram_Raw +GP_HistogramAlloc +GP_HistogramFree
GP_FilterKernelPrint_Raw
@@ -89,27 +89,6 @@ GP_FilterMultiply GP_FilterMultiplyAlloc GP_FilterMultiply_Raw
-GP_FilterParamChannel -GP_FilterParamChannels -GP_FilterParamCheckChannels -GP_FilterParamCheckPixelType -GP_FilterParamCreate -GP_FilterParamDestroy -GP_FilterParamFreePtrAll -GP_FilterParamInitChannels -GP_FilterParamPrintFloat -GP_FilterParamPrintInt -GP_FilterParamPrintPtr -GP_FilterParamPrintUInt -GP_FilterParamSetFloat -GP_FilterParamSetFloatAll -GP_FilterParamSetInt -GP_FilterParamSetIntAll -GP_FilterParamSetPtr -GP_FilterParamSetPtrAll -GP_FilterParamSetUInt -GP_FilterParamSetUIntAll - GP_FilterResize GP_FilterResizeAlloc
diff --git a/demos/grinder/histogram.c b/demos/grinder/histogram.c index 00bffbdf..9706315b 100644 --- a/demos/grinder/histogram.c +++ b/demos/grinder/histogram.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2015 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -24,10 +24,15 @@
void histogram_to_png(const GP_Context *src, const char *filename) { - GP_FILTER_PARAMS(src->pixel_type, params); + GP_Histogram *hist;
- GP_FilterHistogramAlloc(src->pixel_type, params); - GP_FilterHistogram(src, params, NULL); + hist = GP_HistogramAlloc(src->pixel_type); + if (!hist) { + fprintf(stderr, "Failed to allocate histogramn"); + return; + } + + GP_FilterHistogram(hist, src, NULL);
unsigned int i, j;
@@ -35,27 +40,22 @@ void histogram_to_png(const GP_Context *src, const char *filename)
GP_Fill(res, 0xffffff);
- GP_Histogram *hist_r; - hist_r = (GP_FilterParamChannel(params, "R"))->val.ptr; + GP_HistogramChannel *hist_r = GP_HistogramChannelByName(hist, "R");
for (i = 0; i < hist_r->len; i++) GP_VLineXYH(res, i, 256, -255.00 * hist_r->hist[i] / hist_r->max + 0.5 , 0xff0000);
- GP_Histogram *hist_g; - hist_g = (GP_FilterParamChannel(params, "G"))->val.ptr; + GP_HistogramChannel *hist_g = GP_HistogramChannelByName(hist, "G");
for (i = 0; i < hist_g->len; i++) GP_VLineXYH(res, i+257, 256, -255.00 * hist_g->hist[i] / hist_g->max + 0.5 , 0x00ff00);
- GP_Histogram *hist_b; - hist_b = (GP_FilterParamChannel(params, "B"))->val.ptr; + GP_HistogramChannel *hist_b = GP_HistogramChannelByName(hist, "B");
for (i = 0; i < hist_b->len; i++) GP_VLineXYH(res, i+514, 256, -255.00 * hist_b->hist[i] / hist_b->max + 0.5 , 0x0000ff);
- uint32_t max = GP_MAX(hist_r->max, hist_g->max); - - max = GP_MAX(max, hist_b->max); + uint32_t max = GP_MAX3(hist_r->max, hist_g->max, hist_b->max);
for (i = 0; i < hist_r->len; i++) { for (j = 0; j < hist_r->len; j++) { @@ -77,5 +77,5 @@ void histogram_to_png(const GP_Context *src, const char *filename) GP_SavePNG(res, filename, NULL);
GP_ContextFree(res); - GP_FilterHistogramFree(params); + GP_HistogramFree(hist); } diff --git a/doc/pixels.txt b/doc/pixels.txt index ffc3fa1e..59462ce7 100644 --- a/doc/pixels.txt +++ b/doc/pixels.txt @@ -87,6 +87,12 @@ const char *GP_PixelTypeName(GP_PixelType type);
uint32_t GP_PixelSize(GP_PixelType type);
+unsigned int GP_PixelChannelCount(GP_PixelType type); + +uint8_t GP_PixelChannelBits(GP_PixelType type, uint8_t channel); + +const char *GP_PixelChannelName(GP_PixelType type, uint8_t channel); + int GP_PixelHasFlags(GP_PixelType pixel_type, GP_PixelFlags flags); -------------------------------------------------------------------------------
@@ -99,6 +105,12 @@ The 'GP_PixelTypeName()' function returns static string with pixel type name.
The 'GP_PixelSize()' returns pixel size in bits.
+The 'GP_PixelChannelCount()' returns number of pixel channels. + +The 'GP_PixelChannelBits()' returns number of bits for respective channel. + +The 'GP_PixelChannelName()' returns channel name. + The 'GP_PixelHasFlags()' function returns true if particular pixel type contains the bitmask of pixel flags.
diff --git a/include/core/GP_Pixel.h b/include/core/GP_Pixel.h index bfe7d7fa..1f11a590 100644 --- a/include/core/GP_Pixel.h +++ b/include/core/GP_Pixel.h @@ -19,7 +19,7 @@ * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * * jiri.bluebear.dluhos@gmail.com * * * - * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2015 Cyril Hrubis metan@ucw.cz * * * * Copyright (C) 2011 Tomas Gavenciak gavento@ucw.cz * * * @@ -153,6 +153,25 @@ static inline const GP_PixelTypeDescription *GP_PixelTypeDesc(GP_PixelType type) return &GP_PixelTypes[type]; }
+static inline unsigned int GP_PixelChannelCount(GP_PixelType type) +{ + GP_CHECK_VALID_PIXELTYPE(type); + return GP_PixelTypes[type].numchannels; +} + +static inline uint8_t GP_PixelChannelBits(GP_PixelType type, uint8_t channel) +{ + GP_CHECK_VALID_PIXELTYPE(type); + return GP_PixelTypes[type].channels[channel].size; +} + +static inline const char *GP_PixelChannelName(GP_PixelType type, + uint8_t channel) +{ + GP_CHECK_VALID_PIXELTYPE(type); + return GP_PixelTypes[type].channels[channel].name; +} + /* * Print a human-readable representation of a pixel value to a string. * Arguments as for snprintf(). diff --git a/include/filters/GP_Filter.h b/include/filters/GP_Filter.h index 690a64b8..bc36e2ed 100644 --- a/include/filters/GP_Filter.h +++ b/include/filters/GP_Filter.h @@ -32,6 +32,4 @@ #include "core/GP_Context.h" #include "core/GP_ProgressCallback.h"
-#include "GP_FilterParam.h" - #endif /* FILTERS_GP_FILTER_H */ diff --git a/include/filters/GP_FilterParam.h b/include/filters/GP_FilterParam.h deleted file mode 100644 index 31b7ab66..00000000 --- a/include/filters/GP_FilterParam.h +++ /dev/null @@ -1,167 +0,0 @@ -/***************************************************************************** - * This file is part of gfxprim library. * - * * - * Gfxprim is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation; either * - * version 2.1 of the License, or (at your option) any later version. * - * * - * Gfxprim is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with gfxprim; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, * - * Boston, MA 02110-1301 USA * - * * - * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * - * * - *****************************************************************************/ - -/* - - Filter per channel parameter passing code. - - */ - -#ifndef FILTERS_GP_FILTER_PARAM_H -#define FILTERS_GP_FILTER_PARAM_H - -#include "core/GP_Pixel.h" - -#include <stdint.h> - -typedef union GP_FilterParamVal { - float f; - uint32_t ui; - int32_t i; - void *ptr; -} GP_FilterParamVal; - -/* - * Filter parameter structure for one channel. - * - * Filter takes, empty channel name terminated, arrray of these as parameter. - */ -typedef struct GP_FilterParam { - //TODO: this must be > than maximal channel name (now it's 2) - char channel_name[2]; - union GP_FilterParamVal val; -} GP_FilterParam; - -/* - * Creates filter param structure large enough for given pixel_type. - * - * The returned structure has initalized channel_names and terminator. - */ -GP_FilterParam *GP_FilterParamCreate(GP_PixelType pixel_type); - -/* - * Destroys filter param structure. - */ -void GP_FilterParamDestroy(GP_FilterParam *self); - -/* - * Takes array of filter parameters and returns filter parameter by a channel - * name. - * - * Returns NULL if channel wasn't found. - */ -GP_FilterParam *GP_FilterParamChannel(GP_FilterParam params[], - const char *channel_name); - -/* - * Returns number of filter channels. - */ -uint32_t GP_FilterParamChannels(GP_FilterParam params[]); - -/* - * Compares param channels and pixel type channels. Returns zero if channels - * match. - */ -int GP_FilterParamCheckPixelType(GP_FilterParam params[], - GP_PixelType pixel_type); - -/* - * Returns zero only if params have exactly same channels as array of - * channel_names. - */ -int GP_FilterParamCheckChannels(GP_FilterParam params[], - const char *channel_names[]); - -/* - * Create and initalize the structure on the stack - */ -#define GP_FILTER_PARAMS(pixel_type, name) - GP_FilterParam name[GP_PixelTypes[pixel_type].numchannels + 1]; - GP_FilterParamInitChannels(name, pixel_type); - -/* - * Initalize param names and terminator. - * - * Sets all values to 0. - */ -void GP_FilterParamInitChannels(GP_FilterParam params[], - GP_PixelType pixel_type); - -/* - * Sets all values to integer value. - */ -void GP_FilterParamSetIntAll(GP_FilterParam params[], int32_t val); - -/* - * Sets integer value. Returns 0 if such value was found, non-zero otherwise. - */ -int GP_FilterParamSetInt(GP_FilterParam params[], const char *channel_name, - int32_t val); - -/* - * Sets all values to float value. - */ -void GP_FilterParamSetFloatAll(GP_FilterParam params[], float val); - -/* - * Sets float value. Returns 0 if such value was found, non-zero otherwise. - */ -int GP_FilterParamSetFloat(GP_FilterParam params[], const char *channel_name, - float val); - -/* - * Sets all values to unsigned integer value. - */ -void GP_FilterParamSetUIntAll(GP_FilterParam params[], uint32_t val); - -/* - * Sets unsigned integer value. Returns 0 if such value was found, non-zero - * otherwise. - */ -int GP_FilterParamSetUInt(GP_FilterParam params[], const char *channel_name, - uint32_t val); - -/* - * Sets all values to pointer value. - */ -void GP_FilterParamSetPtrAll(GP_FilterParam params[], void *ptr); - -/* - * Sets pointer value. Returns 0 if such value was found, non-zero otherwise. - */ -int GP_FilterParamSetPtr(GP_FilterParam params[], const char *channel_name, - void *ptr); - -/* - * Call free on all pointer values. - */ -void GP_FilterParamFreePtrAll(GP_FilterParam params[]); - -/* - * Functions to print the array. - */ -void GP_FilterParamPrintInt(GP_FilterParam params[]); -void GP_FilterParamPrintUInt(GP_FilterParam params[]); -void GP_FilterParamPrintFloat(GP_FilterParam params[]); -void GP_FilterParamPrintPtr(GP_FilterParam params[]); - -#endif /* FILTERS_GP_FILTER_PARAM_H */ diff --git a/include/filters/GP_Filters.h b/include/filters/GP_Filters.h index 3fe7afbd..1b68c71f 100644 --- a/include/filters/GP_Filters.h +++ b/include/filters/GP_Filters.h @@ -32,9 +32,6 @@ #ifndef FILTERS_GP_FILTERS_H #define FILTERS_GP_FILTERS_H
-/* Filter per channel parameter passing interface */ -#include "filters/GP_FilterParam.h" - /* Point filters, brightness, contrast ... */ #include "filters/GP_Point.h"
diff --git a/include/filters/GP_Stats.h b/include/filters/GP_Stats.h index 6ad62dff..8d780fe2 100644 --- a/include/filters/GP_Stats.h +++ b/include/filters/GP_Stats.h @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2015 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -31,34 +31,39 @@
#include "GP_Filter.h"
-typedef struct GP_Histogram { - uint32_t min; - uint32_t max; +typedef struct GP_HistogramChannel { + const char *chan_name; + GP_Pixel min; + GP_Pixel max; uint32_t len; uint32_t hist[]; +} GP_HistogramChannel; + +typedef struct GP_Histogram { + GP_PixelType pixel_type; + GP_HistogramChannel *channels[]; } GP_Histogram;
/* - * Histogram filter. - * - * The filter param is expected to hold pointers to struct GP_Histogram + * Allocates histogram for a given pixel type */ -int GP_FilterHistogram(const GP_Context *src, GP_FilterParam histogram[], - GP_ProgressCallback *callback); +GP_Histogram *GP_HistogramAlloc(GP_PixelType pixel_type);
/* - * Allocate and initalize struct GP_Histogram for each channel and stores the - * pointer to filter params array. The pixel type must match the params[] - * channels. + * Frees histogram. */ -void GP_FilterHistogramAlloc(GP_PixelType type, GP_FilterParam params[]); +void GP_HistogramFree(GP_Histogram *self);
/* - * Free the histogram arrays. + * Returns pointer to channel given channel name. */ -static inline void GP_FilterHistogramFree(GP_FilterParam params[]) -{ - GP_FilterParamFreePtrAll(params); -} +GP_HistogramChannel *GP_HistogramChannelByName(GP_Histogram *self, + const char *name); + +/* + * Computes histogram. Returns non-zero on failure (i.e. canceled by callback). + */ +int GP_FilterHistogram(GP_Histogram *self, const GP_Context *src, + GP_ProgressCallback *callback);
#endif /* FILTERS_GP_STATS_H */ diff --git a/libs/filters/GP_FilterParam.c b/libs/filters/GP_FilterParam.c deleted file mode 100644 index fe7537c5..00000000 --- a/libs/filters/GP_FilterParam.c +++ /dev/null @@ -1,257 +0,0 @@ -/***************************************************************************** - * This file is part of gfxprim library. * - * * - * Gfxprim is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation; either * - * version 2.1 of the License, or (at your option) any later version. * - * * - * Gfxprim is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with gfxprim; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, * - * Boston, MA 02110-1301 USA * - * * - * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * - * * - *****************************************************************************/ - -#include <string.h> - -#include "core/GP_Debug.h" - -#include "GP_FilterParam.h" - -GP_FilterParam *GP_FilterParamCreate(GP_PixelType pixel_type) -{ - GP_FilterParam *ret; - - ret = malloc((GP_PixelTypes[pixel_type].numchannels + 1) - * sizeof(GP_FilterParam)); - - if (ret == NULL) { - GP_WARN("Malloc Failed"); - return NULL; - } - - GP_FilterParamInitChannels(ret, pixel_type); - - return ret; -} - -void GP_FilterParamDestroy(GP_FilterParam *self) -{ - free(self); -} - -static unsigned int count_channels(GP_FilterParam params[]) -{ - unsigned int i = 0; - - while (params[i].channel_name[0] != '0') - i++; - - return i; -} - -GP_FilterParam *GP_FilterParamChannel(GP_FilterParam params[], - const char *channel_name) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - if (!strcmp(params[i].channel_name, channel_name)) - return ¶ms[i]; - - return NULL; -} - -uint32_t GP_FilterParamChannels(GP_FilterParam params[]) -{ - return count_channels(params); -} - -int GP_FilterParamCheckPixelType(GP_FilterParam params[], - GP_PixelType pixel_type) -{ - unsigned int i, num_channels; - const GP_PixelTypeChannel *channels; - - num_channels = GP_PixelTypes[pixel_type].numchannels; - channels = GP_PixelTypes[pixel_type].channels; - - i = count_channels(params); - - if (i != num_channels) - return 1; - - for (i = 0; i < num_channels; i++) - if (GP_FilterParamChannel(params, channels[i].name) == NULL) - return 1; - - return 0; -} - -int GP_FilterParamCheckChannels(GP_FilterParam params[], - const char *channel_names[]) -{ - unsigned int i; - - for (i = 0; channel_names[i] != NULL; i++) - if (GP_FilterParamChannel(params, channel_names[i]) == NULL) - return 1; - - if (i != count_channels(params)) - return 1; - - return 0; -} - -void GP_FilterParamInitChannels(GP_FilterParam params[], - GP_PixelType pixel_type) -{ - unsigned int i, num_channels; - const GP_PixelTypeChannel *channels; - - num_channels = GP_PixelTypes[pixel_type].numchannels; - channels = GP_PixelTypes[pixel_type].channels; - - for (i = 0; i < num_channels; i++) { - strcpy(params[i].channel_name, channels[i].name); - memset(¶ms[i].val, 0, sizeof(GP_FilterParamVal)); - } - - params[i].channel_name[0] = '0'; -} - -void GP_FilterParamSetIntAll(GP_FilterParam params[], - int32_t val) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - params[i].val.i = val; -} - -int GP_FilterParamSetInt(GP_FilterParam params[], const char *channel_name, - int32_t val) -{ - GP_FilterParam *param; - param = GP_FilterParamChannel(params, channel_name); - - if (param == NULL) - return 1; - - param->val.i = val; - return 0; -} - -void GP_FilterParamSetFloatAll(GP_FilterParam params[], - float val) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - params[i].val.f = val; -} - -int GP_FilterParamSetFloat(GP_FilterParam params[], const char *channel_name, - float val) -{ - GP_FilterParam *param; - param = GP_FilterParamChannel(params, channel_name); - - if (param == NULL) - return 1; - - param->val.f = val; - return 0; -} - -void GP_FilterParamSetUIntAll(GP_FilterParam params[], - uint32_t val) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - params[i].val.ui = val; -} - -int GP_FilterParamSetUInt(GP_FilterParam params[], const char *channel_name, - uint32_t val) -{ - GP_FilterParam *param; - param = GP_FilterParamChannel(params, channel_name); - - if (param == NULL) - return 1; - - param->val.ui = val; - return 0; -} - -void GP_FilterParamSetPtrAll(GP_FilterParam params[], - void *ptr) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - params[i].val.ptr = ptr; -} - -int GP_FilterParamSetPtr(GP_FilterParam params[], const char *channel_name, - void *ptr) -{ - GP_FilterParam *param; - param = GP_FilterParamChannel(params, channel_name); - - if (param == NULL) - return 1; - - param->val.ptr = ptr; - return 0; -} - -void GP_FilterParamFreePtrAll(GP_FilterParam params[]) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - free(params[i].val.ptr); -} - -void GP_FilterParamPrintInt(GP_FilterParam params[]) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - printf("Chann '%s' = %in", params[i].channel_name, params[i].val.i); -} - -void GP_FilterParamPrintUInt(GP_FilterParam params[]) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - printf("Chann '%s' = %un", params[i].channel_name, params[i].val.ui); -} - -void GP_FilterParamPrintFloat(GP_FilterParam params[]) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - printf("Chann '%s' = %fn", params[i].channel_name, params[i].val.f); -} - -void GP_FilterParamPrintPtr(GP_FilterParam params[]) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - printf("Chann '%s' = %pn", params[i].channel_name, params[i].val.ptr); -} diff --git a/libs/filters/GP_Stats.c b/libs/filters/GP_Histogram.c similarity index 53% rename from libs/filters/GP_Stats.c rename to libs/filters/GP_Histogram.c index 3ed5b683..8657c876 100644 --- a/libs/filters/GP_Stats.c +++ b/libs/filters/GP_Histogram.c @@ -16,72 +16,72 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2015 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
#include <string.h> +#include <errno.h>
-#include <GP_Debug.h> - +#include <core/GP_Debug.h> #include "GP_Stats.h"
-int GP_FilterHistogram_Raw(const GP_Context *src, GP_FilterParam histogram[], - GP_ProgressCallback *callback); - -int GP_FilterHistogram(const GP_Context *src, GP_FilterParam histogram[], - GP_ProgressCallback *callback) +GP_Histogram *GP_HistogramAlloc(GP_PixelType pixel_type) { - int ret; - - ret = GP_FilterHistogram_Raw(src, histogram, callback); - - if (ret) - return ret; - + size_t hsize, size = 0; unsigned int i; + GP_Histogram *hist;
- for (i = 0; histogram[i].channel_name[0] != '0'; i++) { - unsigned int j; - GP_Histogram *hist = histogram[i].val.ptr; + GP_DEBUG(1, "Allocating histogram for %s", + GP_PixelTypeName(pixel_type));
- hist->max = hist->hist[0]; - hist->min = hist->hist[0]; + hsize = sizeof(GP_Histogram) + + GP_PixelChannelCount(pixel_type) * sizeof(void*);
- for (j = 1; j < hist->len; j++) { - if (hist->hist[j] > hist->max) - hist->max = hist->hist[j]; - - if (hist->hist[j] < hist->min) - hist->min = hist->hist[j]; - } + for (i = 0; i < GP_PixelChannelCount(pixel_type); i++) { + size += sizeof(GP_HistogramChannel) + + sizeof(uint32_t) * (1<<GP_PixelChannelBits(pixel_type, i)); }
- return 0; -} + hist = malloc(hsize + size); + if (!hist) { + GP_WARN("Malloc failed :("); + errno = ENOMEM; + return NULL; + }
-void GP_FilterHistogramAlloc(GP_PixelType type, GP_FilterParam params[]) -{ - uint32_t i; + hist->pixel_type = pixel_type;
- GP_FilterParamSetPtrAll(params, NULL); + for (i = 0; i < GP_PixelChannelCount(pixel_type); i++) { + size_t chan_size = 1<<GP_PixelChannelBits(pixel_type, i);
- const GP_PixelTypeChannel *channels = GP_PixelTypes[type].channels; + hist->channels[i] = (void*)hist + hsize;
- for (i = 0; i < GP_PixelTypes[type].numchannels; i++) { - size_t chan_size = 1<<channels[i].size; + hsize += sizeof(GP_HistogramChannel) + + sizeof(uint32_t) * chan_size;
- GP_Histogram *hist = malloc(sizeof(struct GP_Histogram) + - sizeof(uint32_t) * chan_size); + hist->channels[i]->len = chan_size; + hist->channels[i]->chan_name = GP_PixelChannelName(pixel_type, i); + }
- if (hist == NULL) { - GP_FilterHistogramFree(params); - return; - } + return hist; +}
- hist->len = chan_size; - memset(hist->hist, 0, sizeof(uint32_t) * chan_size); +GP_HistogramChannel *GP_HistogramChannelByName(GP_Histogram *self, + const char *name) +{ + unsigned int i;
- (GP_FilterParamChannel(params, channels[i].name))->val.ptr = hist; + for (i = 0; i < GP_PixelChannelCount(self->pixel_type); i++) { + if (!strcmp(self->channels[i]->chan_name, name)) + return self->channels[i]; } + + return NULL; +} + +void GP_HistogramFree(GP_Histogram *self) +{ + GP_DEBUG(1, "Freeing histogram %p", self); + free(self); } diff --git a/libs/filters/GP_Histogram.gen.c.t b/libs/filters/GP_Histogram.gen.c.t index 3436aa63..52bfc5c1 100644 --- a/libs/filters/GP_Histogram.gen.c.t +++ b/libs/filters/GP_Histogram.gen.c.t @@ -2,27 +2,34 @@ /* * Histogram filter -- Compute image histogram * - * Copyright (C) 2009-2014 Cyril Hrubis metan@ucw.cz + * Copyright (C) 2009-2015 Cyril Hrubis metan@ucw.cz */
-#include "core/GP_Context.h" -#include "core/GP_Pixel.h" -#include "core/GP_GetPutPixel.h" -#include "core/GP_Debug.h" -#include "GP_Filter.h" +#include <string.h> +#include <errno.h>
-#include "GP_Stats.h" +#include <core/GP_Context.h> +#include <core/GP_Pixel.h> +#include <core/GP_GetPutPixel.h> +#include <core/GP_Debug.h> +#include <filters/GP_Filter.h> +#include <filters/GP_Stats.h>
@ for pt in pixeltypes: @ if not pt.is_unknown() and not pt.is_palette(): -static int GP_FilterHistogram_{{ pt.name }}(const GP_Context *src, - GP_FilterParam histogram[], GP_ProgressCallback *callback) +static int GP_FilterHistogram_{{ pt.name }}(GP_Histogram *self, + const GP_Context *src, GP_ProgressCallback *callback) { - GP_ASSERT(GP_FilterParamCheckPixelType(histogram, GP_PIXEL_{{ pt.name }}) == 0, - "Invalid params channels for context pixel type"); + if (self->pixel_type != src->pixel_type) { + GP_WARN("Histogram (%s) and context (%s) pixel type must match", + GP_PixelTypeName(self->pixel_type), + GP_PixelTypeName(src->pixel_type)); + errno = EINVAL; + return 1; + }
@ for c in pt.chanslist: - GP_Histogram *{{ c.name }}_hist = (GP_FilterParamChannel(histogram, "{{ c.name }}"))->val.ptr; + GP_HistogramChannel *chan_{{ c.name }} = self->channels[{{ c.idx }}]; @ end
uint32_t x, y; @@ -35,7 +42,7 @@ static int GP_FilterHistogram_{{ pt.name }}(const GP_Context *src, @ end
@ for c in pt.chanslist: - {{ c.name }}_hist->hist[{{ c.name }}]++; + chan_{{ c.name }}->hist[{{ c.name }}]++; @ end }
@@ -49,20 +56,50 @@ static int GP_FilterHistogram_{{ pt.name }}(const GP_Context *src,
@ end @ -int GP_FilterHistogram_Raw(const GP_Context *src, GP_FilterParam histogram[], - GP_ProgressCallback *callback) +int GP_FilterHistogram(GP_Histogram *self, const GP_Context *src, + GP_ProgressCallback *callback) { - GP_DEBUG(1, "Running filter Histogram"); + unsigned int i, j; + int ret; + + GP_DEBUG(1, "Running Histogram filter"); + + for (i = 0; i < GP_PixelChannelCount(self->pixel_type); i++) { + GP_HistogramChannel *chan = self->channels[i]; + printf("CHAN %i %i %pn", i, chan->len, chan->hist); + memset(chan->hist, 0, sizeof(uint32_t) * chan->len); + }
switch (src->pixel_type) { @ for pt in pixeltypes: @ if not pt.is_unknown() and not pt.is_palette(): case GP_PIXEL_{{ pt.name }}: - return GP_FilterHistogram_{{ pt.name }}(src, histogram, callback); + ret = GP_FilterHistogram_{{ pt.name }}(self, src, callback); + break; @ end default: + errno = ENOSYS; + return 1; break; }
- return 1; + if (ret) + return ret; + + for (i = 0; i < GP_PixelChannelCount(self->pixel_type); i++) { + GP_HistogramChannel *chan = self->channels[i]; + + chan->max = chan->hist[0]; + chan->min = chan->hist[0]; + + for (j = 1; j < chan->len; j++) { + if (chan->hist[j] > chan->max) + chan->max = chan->hist[j]; + + if (chan->hist[j] < chan->min) + chan->min = chan->hist[j]; + } + } + + return 0; }
-----------------------------------------------------------------------
Summary of changes: doc/pixels.txt | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.