Enlightenment CVS committal Author : ningerso Project : e17 Module : libs/ewl
Dir : e17/libs/ewl/src/lib Modified Files: ewl_histogram.c ewl_histogram.h Log Message: Change histograms to use an image widget for source data. Allow histogram generation for various color channels. Update test to display histograms for all known color channels. =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_histogram.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- ewl_histogram.c 11 Sep 2006 20:51:41 -0000 1.1 +++ ewl_histogram.c 13 Sep 2006 06:52:21 -0000 1.2 @@ -3,8 +3,13 @@ #include "ewl_macros.h" #include "ewl_private.h" +static void ewl_histogram_cb_data_load(Ewl_Widget *w, void *ev, void *h); static void ewl_histogram_draw(Ewl_Histogram *hist); +/** + * @return Returns a new Ewl_Histogram widget. + * @brief Create a new Ewl_Histogram widget. + */ Ewl_Widget * ewl_histogram_new(void) { @@ -14,13 +19,17 @@ hist = calloc(1, sizeof(Ewl_Histogram)); if (!ewl_histogram_init(hist)) { - free(hist); - hist = NULL; + FREE(hist); } DRETURN_PTR(EWL_WIDGET(hist), DLEVEL_STABLE); } +/** + * @param hist: the histogram widget to initialize + * @return Returns TRUE on success, FALSE on failure. + * @brief Initialize a histogram widget to starting values. + */ int ewl_histogram_init(Ewl_Histogram *hist) { @@ -32,56 +41,176 @@ result = ewl_image_init(EWL_IMAGE(hist)); if (result) { + ewl_widget_appearance_set(w, EWL_HISTOGRAM_TYPE); + ewl_widget_inherit(w, EWL_HISTOGRAM_TYPE); ewl_callback_append(w, EWL_CALLBACK_CONFIGURE, ewl_histogram_cb_configure, NULL); ewl_object_preferred_inner_size_set(EWL_OBJECT(hist), 256, 256); + hist->channel = EWL_HISTOGRAM_CHANNEL_R; } DRETURN_INT(result, DLEVEL_STABLE); } +/** + * @param hist: the histogram widget to change display color + * @param r: red value for histogram drawing color + * @param g: green value for histogram drawing color + * @param b: blue value for histogram drawing color + * @param a: apha value for histogram drawing color + * @return Returns no value. + * @brief Changes the drawing color of a histogram. + */ void -ewl_histogram_color_set(Ewl_Histogram *hist, char r, char g, char b, char a) +ewl_histogram_color_set(Ewl_Histogram *hist, int r, int g, int b, int a) { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("hist", hist); - hist->r = r; - hist->g = g; - hist->b = b; - hist->a = a; + hist->color.r = r; + hist->color.g = g; + hist->color.b = b; + hist->color.a = a; ewl_widget_configure(EWL_WIDGET(hist)); DLEAVE_FUNCTION(DLEVEL_STABLE); } -/* FIXME: Handle different histogram types, currently only outputs the Y - * component of a YIQ conversion, need to handle separate RGB, HSV, CMYK, etc. +/** + * @param hist: the histogram widget to retrieve display color + * @param r: red value for histogram drawing color + * @param g: green value for histogram drawing color + * @param b: blue value for histogram drawing color + * @param a: apha value for histogram drawing color + * @return Returns no value. + * @brief Get the current color values for drawing the histogram. + */ void -ewl_histogram_type_set(Ewl_Histogram *hist, int type) +ewl_histogram_color_get(Ewl_Histogram *hist, int *r, int *g, int *b, int *a) { + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("hist", hist); + + if (r) + *r = hist->color.r; + if (g) + *g = hist->color.g; + if (b) + *b = hist->color.b; + if (a) + *a = hist->color.a; + + DLEAVE_FUNCTION(DLEVEL_STABLE); } + +/** + * @param hist: the histogram to change the channel drawn + * @param channel: the color channel to draw in the histogram + * @return Returns no value. + * @brief Sets the color channel to graph in the histogram. */ +void +ewl_histogram_channel_set(Ewl_Histogram *hist, Ewl_Histogram_Channel channel) +{ + /* + * FIXME: Handle different histogram types, currently only outputs the Y + * component of a YIQ conversion and RGB channels, need to handle HSV, + * CMYK, etc. + */ + + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("hist", hist); + DCHECK_TYPE("hist", hist, EWL_HISTOGRAM_TYPE); + + hist->channel = channel; + if (hist->source && REALIZED(hist->source)) + ewl_histogram_cb_data_load(EWL_WIDGET(hist), NULL, hist); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @param hist: the histogram to change the channel drawn + * @param channel: the color channel to draw in the histogram + * @return Returns the currently drawn color channel. + * @brief Sets the color channel to graph in the histogram. + */ +Ewl_Histogram_Channel +ewl_histogram_channel_get(Ewl_Histogram *hist) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("hist", hist, EWL_HISTOGRAM_CHANNEL_Y); + DCHECK_TYPE_RET("hist", hist, EWL_HISTOGRAM_TYPE, EWL_HISTOGRAM_CHANNEL_Y); + + DRETURN_INT(hist->channel, DLEVEL_STABLE); +} + +/** + * @param hist: the histogram to change source image + * @param image: the new source image for the histogram + * @return Returns no value. + * @brief Change the source image used to generate the histogram + */ +void +ewl_histogram_image_set(Ewl_Histogram *hist, Ewl_Image *image) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("hist", hist); + DCHECK_TYPE("hist", hist, EWL_HISTOGRAM_TYPE); + DCHECK_PARAM_PTR("image", image); + DCHECK_TYPE("image", image, EWL_IMAGE_TYPE); + + hist->source = image; + if (REALIZED(image)) { + ewl_histogram_cb_data_load(EWL_WIDGET(hist), NULL, hist); + } + + /* Append the callback to catch an obscure/reveal */ + ewl_callback_append(EWL_WIDGET(image), EWL_CALLBACK_REVEAL, + ewl_histogram_cb_data_load, hist); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @param hist: the histogram to get source image + * @return Returns a pointer to the current source image. + * @brief Get the source image used to generate the histogram + */ +Ewl_Image * +ewl_histogram_image_get(Ewl_Histogram *hist) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("hist", hist, NULL); + DCHECK_TYPE_RET("hist", hist, EWL_HISTOGRAM_TYPE, NULL); + + DRETURN_PTR(EWL_IMAGE(hist->source), DLEVEL_STABLE); +} -/* a = ((*data) >> 24) & 0xFF; */ #define A_CALC(color) ((color) >> 24) #define R_CALC(color) ((color << 8) >> 24) #define G_CALC(color) ((color << 16) >> 24) #define B_CALC(color) ((color << 24) >> 24) -/* r = ((color) >> 16) & 0xFF; */ -/* g = ((color) >> 8) & 0xFF; */ -/* b = (color) & 0xFF; */ -/* brightness = (unsigned char)(((r * 299) + (g * 587) + (b * 114)) / 1000); */ #define Y_CALC(color) (((R_CALC(color) * 299) + (G_CALC(color) * 587) + (B_CALC(color) * 114)) / 1000) -void -ewl_histogram_data_set(Ewl_Histogram *hist, unsigned int *data, int width, int height) +static void +ewl_histogram_cb_data_load(Ewl_Widget *w, void *ev __UNUSED__, void *h __UNUSED__) { int x, y; int maxv = 0; + unsigned int *data; + Evas_Coord width, height; + Ewl_Histogram *hist = EWL_HISTOGRAM(h); DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("hist", hist); + DCHECK_TYPE("hist", hist, EWL_HISTOGRAM_TYPE); + + if (!hist->source || !REALIZED(hist->source)) + DRETURN(DLEVEL_STABLE); + + data = evas_object_image_data_get(hist->source->image, 0); + evas_object_image_size_get(hist->source->image, &width, &height); hist->data = data; hist->width = width; @@ -93,7 +222,22 @@ unsigned char brightness; color = *data; - brightness = Y_CALC(color); + switch (hist->channel) { + + case EWL_HISTOGRAM_CHANNEL_R: + brightness = R_CALC(color); + break; + case EWL_HISTOGRAM_CHANNEL_G: + brightness = G_CALC(color); + break; + case EWL_HISTOGRAM_CHANNEL_B: + brightness = B_CALC(color); + break; + case EWL_HISTOGRAM_CHANNEL_Y: + default: + brightness = Y_CALC(color); + break; + } hist->graph[brightness]++; data++; } @@ -145,10 +289,28 @@ if (!data) return; - if (!hist->a) - color = (unsigned int)(255 << 24); + /* + * If no color specified, choose a sane default for the channel + * represented. + */ + if (!hist->color.a) { + color = (unsigned int)(128 << 24); + switch (hist->channel) { + case EWL_HISTOGRAM_CHANNEL_R: + color |= (unsigned int)(255 << 16); + break; + case EWL_HISTOGRAM_CHANNEL_G: + color |= (unsigned int)(255 << 8); + break; + case EWL_HISTOGRAM_CHANNEL_B: + color |= (unsigned int)(255); + break; + default: + break; + } + } else - color = (unsigned int)(hist->a << 24 | hist->r << 16 | hist->g << 8 | hist->b); + color = (unsigned int)(hist->color.a << 24 | hist->color.r << 16 | hist->color.g << 8 | hist->color.b); for (y = 0; y < img_h; y++) { for (x = 0; x < img_w; x++) { =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_histogram.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- ewl_histogram.h 11 Sep 2006 20:51:41 -0000 1.1 +++ ewl_histogram.h 13 Sep 2006 06:52:21 -0000 1.2 @@ -1,24 +1,72 @@ #ifndef EWL_HISTOGRAM_H #define EWL_HISTOGRAM_H -typedef struct Ewl_Histogram Ewl_Histogram; +/** + * @addtogroup Ew_lHistogram Ewl_Histogram: A Simple Histogram widget + * + * @{ + */ + +/** + * @def EWL_HISTOGRAM_TYPE + * The type name for the Ewl_Histogram widget + */ +#define EWL_HISTOGRAM_TYPE "histogram" + +enum Ewl_Histogram_Channel +{ + EWL_HISTOGRAM_CHANNEL_Y, + EWL_HISTOGRAM_CHANNEL_R, + EWL_HISTOGRAM_CHANNEL_G, + EWL_HISTOGRAM_CHANNEL_B, + EWL_HISTOGRAM_CHANNEL_MAX +}; + +typedef enum Ewl_Histogram_Channel Ewl_Histogram_Channel; + +/** + * @def EWL_HISTOGRAM(cd) + * Typecast a pointer to an Ewl_Histogram pointer. + */ #define EWL_HISTOGRAM(histogram) ((Ewl_Histogram *)histogram) + +/** + * The Ewl_Histogram + */ +typedef struct Ewl_Histogram Ewl_Histogram; + +/** + * Inherit from the Ewl_Image to create a histogram widget + */ struct Ewl_Histogram { - Ewl_Image image; - int type; - unsigned int *data; - int width, height; - int graph[256]; - int maxv; - unsigned char r, g, b, a; + Ewl_Image image; /**< Inherit from the image widget */ + Ewl_Image *source; /**< Source image used for data graph */ + Ewl_Color_Set color; /**< Color for drawing the histogram */ + + const unsigned int *data; /**< Image data for calculating values */ + int width, height; /**< Dimensions of the image data */ + int graph[256]; /**< Calculated histogram points */ + int maxv; /**< Largest data point in graph */ + Ewl_Histogram_Channel channel; /**< Channel of data for graphing */ }; Ewl_Widget *ewl_histogram_new(void); int ewl_histogram_init(Ewl_Histogram *histogram); -void ewl_histogram_color_set(Ewl_Histogram *histogram, char r, char g, char b, char a); -void ewl_histogram_data_set(Ewl_Histogram *histogram, unsigned int *data, int width, int height); +void ewl_histogram_color_set(Ewl_Histogram *histogram, int r, int g, int b, int a); +void ewl_histogram_color_get(Ewl_Histogram *histogram, int *r, int *g, int *b, int *a); +void ewl_histogram_image_set(Ewl_Histogram *histogram, Ewl_Image *image); +Ewl_Image *ewl_histogram_image_get(Ewl_Histogram *histogram); +void ewl_histogram_channel_set(Ewl_Histogram *histogram, Ewl_Histogram_Channel channel); +Ewl_Histogram_Channel ewl_histogram_channel_get(Ewl_Histogram *histogram); +/** + * Internally used callbacks, override at your own risk + */ void ewl_histogram_cb_configure(Ewl_Widget *w, void *event, void *data); + +/** + * @} + */ #endif ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs