aboutsummaryrefslogtreecommitdiff
path: root/generic/Color.c
diff options
context:
space:
mode:
authorlecoanet2003-04-16 09:49:22 +0000
committerlecoanet2003-04-16 09:49:22 +0000
commit3261805fee19e346b4d1f84b23816daa1628764a (patch)
tree63ca1d7e4b0a3d9ae49cc0888e58033c3ef3fe22 /generic/Color.c
parenteed2656db0adae2c234c3d74af0913746ed5c444 (diff)
downloadtkzinc-3261805fee19e346b4d1f84b23816daa1628764a.zip
tkzinc-3261805fee19e346b4d1f84b23816daa1628764a.tar.gz
tkzinc-3261805fee19e346b4d1f84b23816daa1628764a.tar.bz2
tkzinc-3261805fee19e346b4d1f84b23816daa1628764a.tar.xz
Update from the Windows port and general cleanup/restructure
Diffstat (limited to 'generic/Color.c')
-rw-r--r--generic/Color.c813
1 files changed, 29 insertions, 784 deletions
diff --git a/generic/Color.c b/generic/Color.c
index 6518aa0..d0c3a81 100644
--- a/generic/Color.c
+++ b/generic/Color.c
@@ -36,7 +36,6 @@
*/
-#include <malloc.h>
#include <string.h>
#include <stdlib.h>
@@ -47,101 +46,6 @@
/*
- * If a colormap fills up, attempts to allocate new colors from that
- * colormap will fail. When that happens, we'll just choose the
- * closest color from those that are available in the colormap.
- * One of the following structures will be created for each "stressed"
- * colormap to keep track of the colors that are available in the
- * colormap (otherwise we would have to re-query from the server on
- * each allocation, which would be very slow). These entries are
- * flushed after a few seconds, since other clients may release or
- * reallocate colors over time.
- */
-typedef struct StressedCmap {
- Colormap colormap; /* X's token for the colormap. */
- int num_colors; /* Number of entries currently active
- * at *colorPtr. */
- XColor *color; /* Pointer to malloc'ed array of all
- * colors that seem to be available in
- * the colormap. Some may not actually
- * be available, e.g. because they are
- * read-write for another client; when
- * we find this out, we remove them
- * from the array. */
- struct StressedCmap *next; /* Next in list of all stressed
- * colormaps for the display. */
-} StressedCmap;
-
-typedef struct StressedDpy {
- Display *dpy;
- StressedCmap *stress;
- struct StressedDpy *next;
-} StressedDpy;
-
-static StressedDpy *stressed_display_list = NULL;
-
-
-#define COLOR_MAGIC ((unsigned int) 0x46140277)
-
-typedef struct ZnColorInfo {
- XColor color; /* Information about this color. */
- unsigned int magic; /* Used for quick integrity check on this
- * structure. Must always have the
- * value COLOR_MAGIC. */
- Screen *screen; /* Screen where this color is valid. Used
- * to delete it, and to find its display. */
- Colormap colormap; /* Colormap from which this entry was
- * allocated. */
- Visual *visual; /* Visual associated with colormap. */
- int ref_count; /* Number of uses of this structure. */
- Tcl_HashTable *table; /* Hash table that indexes this structure
- * (needed when deleting structure). */
- Tcl_HashEntry *hash; /* Pointer to hash table entry for this
- * structure. (for use in deleting entry). */
-} ZnColorInfo;
-
-
-/*
- * A two-level data structure is used to manage the color database.
- * The top level consists of one entry for each color name that is
- * currently active, and the bottom level contains one entry for each
- * pixel value that is still in use. The distinction between
- * levels is necessary because the same pixel may have several
- * different names. There are two hash tables, one used to index into
- * each of the data structures. The name hash table is used when
- * allocating colors, and the pixel hash table is used when freeing
- * colors.
- */
-
-/*
- * Hash table for name -> ZnColorInfo mapping, and key structure used to
- * index into that table:
- */
-static Tcl_HashTable name_table;
-
-typedef struct {
- Tk_Uid name; /* Name of desired color. */
- Colormap colormap; /* Colormap from which color will be
- * allocated. */
- Display *display; /* Display for colormap. */
-} NameKey;
-
-
-/*
- * Hash table for value -> ZnColorInfo mapping, and key structure used to
- * index into that table:
- */
-static Tcl_HashTable value_table;
-
-typedef struct {
- int red, green, blue; /* Values for desired color. */
- Colormap colormap; /* Colormap from which color will be
- * allocated. */
- Display *display; /* Display for colormap. */
-} ValueKey;
-
-
-/*
* Maximum size of a color name including the \0.
*/
#define COLOR_NAME_SIZE 32
@@ -164,238 +68,6 @@ static int initialized = 0; /* 0 means static structures haven't been
/*
*----------------------------------------------------------------------
*
- * GetStressedDisplay --
- *
- *
- *----------------------------------------------------------------------
- */
-static StressedDpy *
-GetStressedDisplay(Display *dpy)
-{
- StressedDpy *cur;
-
- for (cur = stressed_display_list; cur != NULL; cur = cur->next) {
- if (cur->dpy == dpy) {
- break;
- }
- }
- if (cur == NULL) {
- /*
- * Not found, allocate a new one.
- */
- cur = (StressedDpy *) ZnMalloc(sizeof(StressedDpy));
- cur->dpy = dpy;
- cur->stress = NULL;
- cur->next = stressed_display_list;
- stressed_display_list = cur;
- }
-
- return cur;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * DeleteStressedCmap --
- *
- * This procedure releases the information cached for "colormap"
- * so that it will be refetched from the X server the next time
- * it is needed.
- *
- * Results:
- * None.
- *
- * Side effects:
- * The StressedCmap structure for colormap is deleted; the
- * colormap is no longer considered to be "stressed".
- *
- * Note:
- * This procedure is invoked whenever a color in a colormap is
- * freed, and whenever a color allocation in a colormap succeeds.
- * This guarantees that StressedCmap structures are always
- * deleted before the corresponding Colormap is freed.
- *
- *----------------------------------------------------------------------
- */
-static void
-DeleteStressedCmap(Display *display,
- Colormap colormap)
-{
- StressedDpy *dpy = GetStressedDisplay(display);
- StressedCmap *prev, *stress;
-
- for (prev = NULL, stress = dpy->stress; stress != NULL;
- prev = stress, stress = stress->next) {
- if (stress->colormap == colormap) {
- if (prev == NULL) {
- dpy->stress = stress->next;
- }
- else {
- prev->next = stress->next;
- }
- ZnFree(stress->color);
- ZnFree(stress);
- return;
- }
- }
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * FindClosestColor --
- *
- * When Tk can't allocate a color because a colormap has filled
- * up, this procedure is called to find and allocate the closest
- * available color in the colormap.
- *
- * Results:
- * There is no return value, but *actualColorPtr is filled in
- * with information about the closest available color in tkwin's
- * colormap. This color has been allocated via X, so it must
- * be released by the caller when the caller is done with it.
- *
- * Side effects:
- * A color is allocated.
- *
- *----------------------------------------------------------------------
- */
-static void
-FindClosestColor(Tk_Window tkwin, /* Window where color will
- * be used. */
- XColor *desired_color, /* RGB values of color that was
- * wanted (but unavailable). */
- XColor *actual_color) /* Structure to fill in with
- * RGB and pixel for closest
- * available color. */
-{
- StressedDpy *dpy = GetStressedDisplay(Tk_Display(tkwin));
- StressedCmap *stress;
- double tmp, distance, closest_dist;
- int i, closest, num_found;
- XColor *color;
- Colormap colormap = Tk_Colormap(tkwin);
- XVisualInfo template, *vis_info;
-
- /*
- * Find the StressedCmap structure for this colormap, or create
- * a new one if needed.
- */
- for (stress = dpy->stress; ; stress = stress->next) {
- if (stress == NULL) {
- stress = (StressedCmap *) ZnMalloc(sizeof(StressedCmap));
- stress->colormap = colormap;
- template.visualid = XVisualIDFromVisual(Tk_Visual(tkwin));
- vis_info = XGetVisualInfo(Tk_Display(tkwin), VisualIDMask,
- &template, &num_found);
- if (num_found < 1) {
- ZnWarning("FindClosestColor (Zinc) couldn't lookup visual\n");
- abort();
- }
- stress->num_colors = vis_info->colormap_size;
- XFree((char *) vis_info);
- stress->color = (XColor *) ZnMalloc((unsigned)
- (stress->num_colors*sizeof(XColor)));
- for (i = 0; i < stress->num_colors; i++) {
- stress->color[i].pixel = (unsigned long) i;
- }
- XQueryColors(Tk_Display(tkwin), colormap, stress->color, stress->num_colors);
- stress->next = dpy->stress;
- dpy->stress = stress;
- break;
- }
- if (stress->colormap == colormap) {
- break;
- }
- }
-
- /*
- * Find the color that best approximates the desired one, then
- * try to allocate that color. If that fails, it must mean that
- * the color was read-write (so we can't use it, since it's owner
- * might change it) or else it was already freed. Try again,
- * over and over again, until something succeeds.
- */
- while (1) {
- if (stress->num_colors == 0) {
- ZnWarning("FindClosestColor (Zinc) ran out of colors\n");
- abort();
- }
- closest_dist = 1e30;
- closest = 0;
- for (color = stress->color, i = 0; i < stress->num_colors;
- color++, i++) {
- /*
- * Use Euclidean distance in RGB space, weighted by Y (of YIQ)
- * as the objective function; this accounts for differences
- * in the color sensitivity of the eye.
- */
- tmp = 0.30*(((int) desired_color->red) - (int) color->red);
- distance = tmp*tmp;
- tmp = 0.61*(((int) desired_color->green) - (int) color->green);
- distance += tmp*tmp;
- tmp = 0.11*(((int) desired_color->blue) - (int) color->blue);
- distance += tmp*tmp;
- if (distance < closest_dist) {
- closest = i;
- closest_dist = distance;
- }
- }
- if (XAllocColor(Tk_Display(tkwin), colormap, &stress->color[closest]) != 0) {
- *actual_color = stress->color[closest];
- return;
- }
-
- /*
- * Couldn't allocate the color. Remove it from the table and
- * go back to look for the next best color.
- */
- stress->color[closest] = stress->color[stress->num_colors-1];
- stress->num_colors -= 1;
- }
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * CmapStressed --
- *
- * Check to see whether a given colormap is known to be out
- * of entries.
- *
- * Results:
- * 1 is returned if "colormap" is stressed (i.e. it has run out
- * of entries recently), 0 otherwise.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-#if 0
-static ZnBool
-CmapStressed(Tk_Window tkwin,
- Colormap colormap)
-{
- StressedDpy *dpy = GetStressedDisplay(Tk_Display(tkwin));
- StressedCmap *stress;
-
- for (stress = dpy->stress; stress != NULL; stress = stress->next) {
- if (stress->colormap == colormap) {
- return True;
- }
- }
- return False;
-}
-#endif
-
-
-/*
- *----------------------------------------------------------------------
- *
* ColorInit --
*
* Initialize the structure used for color management.
@@ -412,8 +84,6 @@ static void
ColorInit()
{
initialized = 1;
- Tcl_InitHashTable(&name_table, sizeof(NameKey)/sizeof(int));
- Tcl_InitHashTable(&value_table, sizeof(ValueKey)/sizeof(int));
Tcl_InitHashTable(&gradient_table, TCL_STRING_KEYS);
}
@@ -421,431 +91,6 @@ ColorInit()
/*
*----------------------------------------------------------------------
*
- * ZnGetColor --
- *
- * Given a string name for a color, map the name to a corresponding
- * XColor structure.
- *
- * Results:
- * The return value is a pointer to an XColor structure that
- * indicates the red, blue, and green intensities for the color
- * given by "name", and also specifies a pixel value to use to
- * draw in that color. If an error occurs, NULL is returned and
- * an error message will be left in interp->result.
- *
- * Side effects:
- * The color is added to an internal database with a reference count.
- * For each call to this procedure, there should eventually be a call
- * to ZnFreeColor so that the database is cleaned up when colors
- * aren't in use anymore.
- *
- *----------------------------------------------------------------------
- */
-XColor *
-ZnGetColor(Tcl_Interp *interp,
- Tk_Window tkwin, /* Window in which color will be used. */
- Tk_Uid name) /* Name of color to allocated (in form
- * suitable for passing to XParseColor). */
-{
- NameKey name_key;
- Tcl_HashEntry *name_hash;
- int new;
- Display *dpy = Tk_Display(tkwin);
- Colormap colormap = Tk_Colormap(tkwin);
- XColor color, screen;
- ZnColorInfo *tk_col;
-
- if (!initialized) {
- ColorInit();
- }
-
- /*
- * First, check to see if there's already a mapping for this color
- * name.
- */
- name = Tk_GetUid(name);
- name_key.name = name;
- name_key.colormap = Tk_Colormap(tkwin);
- name_key.display = Tk_Display(tkwin);
- name_hash = Tcl_CreateHashEntry(&name_table, (char *) &name_key, &new);
- if (!new) {
- tk_col = (ZnColorInfo *) Tcl_GetHashValue(name_hash);
- tk_col->ref_count++;
- /*printf("ZnGetColor cache hit for: %d %d %d\n",
- tk_col->color.red, tk_col->color.green, tk_col->color.blue);*/
- return &tk_col->color;
- }
-
- /*
- * Map from the name to a pixel value. Call XAllocNamedColor rather than
- * XParseColor for non-# names: this saves a server round-trip for those
- * names.
- */
- if (*name != '#') {
- if (XAllocNamedColor(dpy, colormap, name, &screen, &color) != 0) {
- DeleteStressedCmap(dpy, colormap);
- }
- else {
- /*
- * Couldn't allocate the color. Try translating the name to
- * a color value, to see whether the problem is a bad color
- * name or a full colormap. If the colormap is full, then
- * pick an approximation to the desired color.
- */
- if (XLookupColor(dpy, colormap, name, &color, &screen) == 0) {
- col_err:
- if (*name == '#') {
- Tcl_AppendResult(interp, "invalid color name \"", name,
- "\"", (char *) NULL);
- }
- else {
- Tcl_AppendResult(interp, "unknown color name \"", name,
- "\"", (char *) NULL);
- }
- Tcl_DeleteHashEntry(name_hash);
- return (XColor *) NULL;
- }
- FindClosestColor(tkwin, &screen, &color);
- }
- }
- else {
- if (XParseColor(dpy, colormap, name, &color) == 0) {
- goto col_err;
- }
- /*printf("parsed color : %d %d %d\n", color.red, color.green, color.blue);*/
- if (XAllocColor(dpy, colormap, &color) != 0) {
- /*printf("alloced color : %d %d %d\n", color.red, color.green, color.blue);*/
- DeleteStressedCmap(dpy, colormap);
- }
- else {
- FindClosestColor(tkwin, &color, &color);
- }
- }
-
- tk_col = (ZnColorInfo *) ZnMalloc(sizeof(ZnColorInfo));
- tk_col->color = color;
-
- /*
- * Now create a new ZnColorInfo structure and add it to nameTable.
- */
- tk_col->magic = COLOR_MAGIC;
- tk_col->screen = Tk_Screen(tkwin);
- tk_col->colormap = name_key.colormap;
- tk_col->visual = Tk_Visual(tkwin);
- tk_col->ref_count = 1;
- tk_col->table = &name_table;
- tk_col->hash = name_hash;
- Tcl_SetHashValue(name_hash, tk_col);
-
- /*printf("ZnGetColor created: %x %x %x\n",
- tk_col->color.red, tk_col->color.green, tk_col->color.blue);*/
- return &tk_col->color;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * ZnGetColorByValue --
- *
- * Given a desired set of red-green-blue intensities for a color,
- * locate a pixel value to use to draw that color in a given
- * window.
- *
- * Results:
- * The return value is a pointer to an XColor structure that
- * indicates the closest red, blue, and green intensities available
- * to those specified in colorPtr, and also specifies a pixel
- * value to use to draw in that color.
- *
- * Side effects:
- * The color is added to an internal database with a reference count.
- * For each call to this procedure, there should eventually be a call
- * to ZnFreeColor, so that the database is cleaned up when colors
- * aren't in use anymore.
- *
- *----------------------------------------------------------------------
- */
-XColor *
-ZnGetColorByValue(Tk_Window tkwin,
- XColor *color)
-{
- ValueKey value_key;
- Tcl_HashEntry *value_hash;
- int new;
- ZnColorInfo *tk_col;
- Display *dpy = Tk_Display(tkwin);
- Colormap colormap = Tk_Colormap(tkwin);
-
- if (!initialized) {
- ColorInit();
- }
-
- /*printf("ZnGetColorByValue input color: %x %x %x\n",
- color->red, color->green, color->blue);*/
- /*
- * First, check to see if there's already a mapping for this color
- * name.
- */
- value_key.red = color->red;
- value_key.green = color->green;
- value_key.blue = color->blue;
- value_key.colormap = Tk_Colormap(tkwin);
- value_key.display = Tk_Display(tkwin);
- value_hash = Tcl_CreateHashEntry(&value_table, (char *) &value_key, &new);
- if (!new) {
- tk_col = (ZnColorInfo *) Tcl_GetHashValue(value_hash);
- tk_col->ref_count++;
- return &tk_col->color;
- }
-
- /*
- * The name isn't currently known. Find a pixel value
- * to use to draw that color in a given window.
- */
- tk_col = (ZnColorInfo *) ZnMalloc(sizeof(ZnColorInfo));
- tk_col->color.red = color->red;
- tk_col->color.green = color->green;
- tk_col->color.blue = color->blue;
- if (XAllocColor(dpy, colormap, &tk_col->color) != 0) {
- /*if (tk_col->color.red != color->red ||
- tk_col->color.green != color->green ||
- tk_col->color.blue != color->blue) {
- printf("couleur allouée approximative %d %d %d --> %d %d %d\n",
- tk_col->color.red, tk_col->color.green, tk_col->color.blue,
- color->red, color->green, color->blue);
- }*/
- DeleteStressedCmap(dpy, colormap);
- }
- else {
- /*printf("ZnGetColorByValue XAllocColor failed\n");*/
- FindClosestColor(tkwin, &tk_col->color, &tk_col->color);
- }
-
- tk_col->magic = COLOR_MAGIC;
- tk_col->screen = Tk_Screen(tkwin);
- tk_col->colormap = value_key.colormap;
- tk_col->visual = Tk_Visual(tkwin);
- tk_col->ref_count = 1;
- tk_col->table = &value_table;
- tk_col->hash = value_hash;
- Tcl_SetHashValue(value_hash, tk_col);
-
- /*printf("ZnGetColorByValue created: %x %x %x\n",
- tk_col->color.red, tk_col->color.green, tk_col->color.blue);*/
-
- return &tk_col->color;
-}
-
-
-/*
- *--------------------------------------------------------------
- *
- * ZnNameOfColor --
- *
- * Given a color, return a textual string identifying
- * the color.
- *
- * Results:
- * If colorPtr was created by Tk_GetColor, then the return
- * value is the "string" that was used to create it.
- * Otherwise the return value is a string that could have
- * been passed to Tk_GetColor to allocate that color. The
- * storage for the returned string is only guaranteed to
- * persist up until the next call to this procedure.
- *
- * Side effects:
- * None.
- *
- *--------------------------------------------------------------
- */
-Tk_Uid
-ZnNameOfColor(XColor *color)
-{
- register ZnColorInfo *tk_col = (ZnColorInfo *) color;
- static char string[20];
-
- if ((tk_col->magic == COLOR_MAGIC) && (tk_col->table == &name_table)) {
- return ((NameKey *) tk_col->hash->key.words)->name;
- }
- sprintf(string, "#%04x%04x%04x", color->red, color->green, color->blue);
- return string;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * ZnFreeColor --
- *
- * This procedure is called to release a color allocated by
- * ZnGetColor or ZnGetColorByValue.
- *
- * Results:
- * None.
- *
- * Side effects:
- * The reference count associated with colorPtr is deleted, and
- * the color is released to X if there are no remaining uses
- * for it.
- *
- *----------------------------------------------------------------------
- */
-void
-ZnFreeColor(XColor *color) /* Color to be released. Must have been
- * allocated by ZnGetColor or
- * ZnGetColorByValue. */
-{
- ZnColorInfo *tk_col = (ZnColorInfo *) color;
- Visual *visual;
- Screen *screen = tk_col->screen;
- Tk_ErrorHandler handler;
-
- /*
- * Do a quick sanity check to make sure this color was really
- * allocated by ZnGetColor.
- */
- if (tk_col->magic != COLOR_MAGIC) {
- ZnWarning("ZnFreeColor called with bogus color\n");
- abort();
- }
-
- tk_col->ref_count--;
- if (tk_col->ref_count == 0) {
- /*printf("ZnFreeColor freeing %s\n", ZnNameOfColor(color));*/
- /*
- * Careful! Don't free black or white, since this will
- * make some servers very unhappy. Also, there is a bug in
- * some servers (such Sun's X11/NeWS server) where reference
- * counting is performed incorrectly, so that if a color is
- * allocated twice in different places and then freed twice,
- * the second free generates an error (this bug existed as of
- * 10/1/92). To get around this problem, ignore errors that
- * occur during the free operation.
- */
- visual = tk_col->visual;
- if ((visual->class != StaticGray) && (visual->class != StaticColor) &&
- (tk_col->color.pixel != BlackPixelOfScreen(screen)) &&
- (tk_col->color.pixel != WhitePixelOfScreen(screen))) {
- handler = Tk_CreateErrorHandler(DisplayOfScreen(screen),
- -1, -1, -1, (Tk_ErrorProc *) NULL,
- (ClientData) NULL);
- XFreeColors(DisplayOfScreen(screen), tk_col->colormap,
- &tk_col->color.pixel, 1, 0L);
- Tk_DeleteErrorHandler(handler);
- }
- DeleteStressedCmap(DisplayOfScreen(screen), tk_col->colormap);
-
- Tcl_DeleteHashEntry(tk_col->hash);
- tk_col->magic = 0;
- ZnFree(tk_col);
- }
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * RgbToHsv
- * HsvToRgb --
- *
- *----------------------------------------------------------------------
- */
-#if 0
-static void
-RgbToHsv(int r,
- int g,
- int b,
- ZnReal *h,
- ZnReal *s,
- ZnReal *v)
-{
- ZnReal max, min, range, rc, gc, bc;
-
- max = (r > g) ? ((b > r) ? b : r) : ((b > g) ? b : g);
- min = (r < g) ? ((b < r) ? b : r) : ((b < g) ? b : g);
- range = max - min;
- if (max == 0) {
- *s = 0.0;
- }
- else {
- *s = range / max;
- }
- if (*s == 0) {
- *h = 0;
- }
- else {
- rc = (max - r) / range;
- gc = (max - g) / range;
- bc = (max - b) / range;
- *h = (max == r) ? (0.166667*(bc-gc)) : ((max == g) ? (0.166667*(2+rc-bc)) : (0.166667*(4+gc-rc)));
- }
- *v = max/65535.0;
-}
-
-static void
-HsvToRgb(ZnReal h,
- ZnReal s,
- ZnReal v,
- unsigned short *r,
- unsigned short *g,
- unsigned short *b)
-{
- int lv, i, p, q, t;
- ZnReal f;
-
- lv = (int) (65535 * v);
- if (s == 0) {
- *r = *g = *b = lv;
- return;
- }
- h *= 6.0;
- if (h >= 6.0) {
- h = 0.0;
- }
- i = (int) h;
- f = h - i;
- p = (int) (65535 * v * (1 - s));
- q = (int) (65535 * v * (1 - (s * f)));
- t = (int) (65535 * v * (1 - (s * (1 - f))));
- switch (i) {
- case 0:
- *r = lv;
- *g = t;
- *b = p;
- break;
- case 1:
- *r = q;
- *g = lv;
- *b = p;
- break;
- case 2:
- *r = p;
- *g = lv;
- *b = t;
- break;
- case 3:
- *r = p;
- *g = q;
- *b = lv;
- break;
- case 4:
- *r = t;
- *g = p;
- *b = lv;
- break;
- case 5:
- *r = lv;
- *g = p;
- *b = q;
- break;
- }
-}
-#endif
-
-/*
- *----------------------------------------------------------------------
- *
* ZnGetGradientColor --
*
*----------------------------------------------------------------------
@@ -853,7 +98,7 @@ HsvToRgb(ZnReal h,
XColor *
ZnGetGradientColor(ZnGradient *grad,
ZnReal position,
- int *alpha)
+ unsigned short *alpha)
{
int index, min, max;
XColor *shade=NULL;
@@ -941,15 +186,15 @@ ZnGradient *
ZnGetReliefGradient(Tcl_Interp *interp,
Tk_Window tkwin,
Tk_Uid name,
- int alpha)
+ unsigned short alpha)
{
- XColor *base, light_color, dark_color, color;
- char color_name[COLOR_NAME_SIZE];
- char buffer[COLOR_NAME_SIZE*(3+2*RELIEF_STEPS)];
- int j, tmp1, tmp2;
- int red_range, green_range, blue_range;
+ XColor *base, light_color, dark_color, color;
+ char color_name[COLOR_NAME_SIZE];
+ char buffer[COLOR_NAME_SIZE*(3+2*ZN_RELIEF_STEPS)];
+ int j, tmp1, tmp2;
+ int red_range, green_range, blue_range;
- base = ZnGetColor(interp, tkwin, name);
+ base = Tk_GetColor(interp, tkwin, name);
/*
* Compute the border gradient.
*
@@ -1006,12 +251,12 @@ ZnGetReliefGradient(Tcl_Interp *interp,
green_range = (int) base->green - (int) dark_color.green;
blue_range = (int) base->blue - (int) dark_color.blue;
strcat(buffer, color_name);
- for (j = 1; j < RELIEF_STEPS; j++) {
- color.red =(int) dark_color.red + red_range * j/RELIEF_STEPS;
- color.green = (int) dark_color.green + green_range * j/RELIEF_STEPS;
- color.blue = (int) dark_color.blue + blue_range * j/RELIEF_STEPS;
+ for (j = 1; j < ZN_RELIEF_STEPS; j++) {
+ color.red =(int) dark_color.red + red_range * j/ZN_RELIEF_STEPS;
+ color.green = (int) dark_color.green + green_range * j/ZN_RELIEF_STEPS;
+ color.blue = (int) dark_color.blue + blue_range * j/ZN_RELIEF_STEPS;
sprintf(color_name, "#%02x%02x%02x;%d %d|",
- color.red/256, color.green/256, color.blue/256, alpha, 50/RELIEF_STEPS*j);
+ color.red/256, color.green/256, color.blue/256, alpha, 50/ZN_RELIEF_STEPS*j);
strcat(buffer, color_name);
}
sprintf(color_name, "#%02x%02x%02x;%d 50|",
@@ -1020,12 +265,12 @@ ZnGetReliefGradient(Tcl_Interp *interp,
red_range = (int) light_color.red - (int) base->red;
green_range = (int) light_color.green - (int) base->green;
blue_range = (int) light_color.blue - (int) base->blue;
- for (j = 1; j < RELIEF_STEPS; j++) {
- color.red = (int) base->red + red_range * j/RELIEF_STEPS;
- color.green = (int) base->green + green_range * j/RELIEF_STEPS;
- color.blue = (int) base->blue + blue_range * j/RELIEF_STEPS;
+ for (j = 1; j < ZN_RELIEF_STEPS; j++) {
+ color.red = (int) base->red + red_range * j/ZN_RELIEF_STEPS;
+ color.green = (int) base->green + green_range * j/ZN_RELIEF_STEPS;
+ color.blue = (int) base->blue + blue_range * j/ZN_RELIEF_STEPS;
sprintf(color_name, "#%02x%02x%02x;%d %d|",
- color.red/256, color.green/256, color.blue/256, alpha, 50+50/RELIEF_STEPS*j);
+ color.red/256, color.green/256, color.blue/256, alpha, 50+50/ZN_RELIEF_STEPS*j);
strcat(buffer, color_name);
}
sprintf(color_name, "#%02x%02x%02x;%d",
@@ -1128,7 +373,7 @@ ZnDeleteGradientName(char *name)
* gradient := [graddesc|]color[|....|color]
* where the | are real characters not meta-syntax.
*
- * graddesc := @type args
+ * graddesc := =type args
* where type := axial | radial | path
* args := angle if type = axial; angle in (0..360)
* args := x y if type = (radial| path); x and
@@ -1172,7 +417,7 @@ ZnGetGradient(Tcl_Interp *interp,
#define SEGMENT_SIZE 64
Tcl_HashEntry *hash;
ZnGradient *grad;
- int i, j, nspace, new, num_colors;
+ unsigned int i, j, nspace, num_colors;
unsigned int size;
char type;
char const *scan_ptr, *next_ptr, *str_ptr;
@@ -1181,7 +426,7 @@ ZnGetGradient(Tcl_Interp *interp,
char *color_ptr, *end, segment[SEGMENT_SIZE];
ZnGradientColor *first, *last;
XColor color;
- int red_range, green_range, blue_range;
+ int new, red_range, green_range, blue_range;
/* printf("ZnGetGradient : %s\n", desc);*/
if (!desc || !*desc) {
@@ -1325,7 +570,7 @@ ZnGetGradient(Tcl_Interp *interp,
desc, "\",", NULL);
grad_err2:
for (j = 0; j < i; j++) {
- ZnFreeColor(grad->colors[j].rgb);
+ Tk_FreeColor(grad->colors[j].rgb);
}
ZnFree(grad);
goto grad_err1;
@@ -1362,7 +607,7 @@ ZnGetGradient(Tcl_Interp *interp,
if (color_ptr) {
*color_ptr = 0;
}
- grad->colors[i].rgb = ZnGetColor(interp, tkwin, Tk_GetUid(segment));
+ grad->colors[i].rgb = Tk_GetColor(interp, tkwin, Tk_GetUid(segment));
if (grad->colors[i].rgb == NULL) {
Tcl_AppendResult(interp, "incorrect color value in gradient \"",
desc, "\",", NULL);
@@ -1412,7 +657,7 @@ ZnGetGradient(Tcl_Interp *interp,
color.red =(int) first->rgb->red + red_range/2;
color.green = (int) first->rgb->green + green_range/2;
color.blue = (int) first->rgb->blue + blue_range/2;
- first->mid_rgb = ZnGetColorByValue(tkwin, &color);
+ first->mid_rgb = Tk_GetColorByValue(tkwin, &color);
first->mid_alpha = first->alpha + (last->alpha-first->alpha)/2;
}
grad->colors[grad->num_colors-1].mid_rgb = NULL;
@@ -1467,15 +712,15 @@ ZnNameOfGradient(ZnGradient *grad)
void
ZnFreeGradient(ZnGradient *grad)
{
- int i;
+ unsigned int i;
grad->ref_count--;
if (grad->ref_count == 0) {
Tcl_DeleteHashEntry(grad->hash);
for (i = 0; i < grad->num_colors; i++) {
- ZnFreeColor(grad->colors[i].rgb);
+ Tk_FreeColor(grad->colors[i].rgb);
if (grad->colors[i].mid_rgb) {
- ZnFreeColor(grad->colors[i].mid_rgb);
+ Tk_FreeColor(grad->colors[i].mid_rgb);
}
}
ZnFree(grad);
@@ -1494,8 +739,8 @@ ZnFreeGradient(ZnGradient *grad)
*--------------------------------------------------------------
*/
int
-ZnComposeAlpha(int alpha1,
- int alpha2)
+ZnComposeAlpha(unsigned short alpha1,
+ unsigned short alpha2)
{
return (alpha1*alpha2/100)*65535/100;
}