Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals  

src/main/color.c

Go to the documentation of this file.
00001 /*
00002  * "$Id: color.c,v 1.9 2004/05/07 19:20:28 rleigh Exp $"
00003  *
00004  *   Gimp-Print color module interface.
00005  *
00006  *   Copyright (C) 2003  Roger Leigh (rleigh@debian.org)
00007  *
00008  *   This program is free software; you can redistribute it and/or modify it
00009  *   under the terms of the GNU General Public License as published by the Free
00010  *   Software Foundation; either version 2 of the License, or (at your option)
00011  *   any later version.
00012  *
00013  *   This program is distributed in the hope that it will be useful, but
00014  *   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00015  *   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016  *   for more details.
00017  *
00018  *   You should have received a copy of the GNU General Public License
00019  *   along with this program; if not, write to the Free Software
00020  *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00021  */
00022 
00023 /*
00024  * This file must include only standard C header files.  The core code must
00025  * compile on generic platforms that don't support glib, gimp, gtk, etc.
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 #include <gimp-print/gimp-print.h>
00032 #include "gimp-print-internal.h"
00033 #include <gimp-print/gimp-print-intl-internal.h>
00034 #include <string.h>
00035 #include <stdlib.h>
00036 
00037 
00038 static const char* stpi_color_namefunc(const void *item);
00039 static const char* stpi_color_long_namefunc(const void *item);
00040 
00041 static stp_list_t *color_list = NULL;
00042 
00043 
00044 static int
00045 stpi_init_color_list(void)
00046 {
00047   if(color_list)
00048     stp_list_destroy(color_list);
00049   color_list = stp_list_create();
00050   stp_list_set_namefunc(color_list, stpi_color_namefunc);
00051   stp_list_set_long_namefunc(color_list, stpi_color_long_namefunc);
00052   /* stp_list_set_sortfunc(color_list, stpi_color_sortfunc); */
00053 
00054   return 0;
00055 }
00056 
00057 static inline void
00058 check_list(void)
00059 {
00060   if (color_list == NULL)
00061     {
00062       stp_erprintf("No color drivers found: "
00063                    "are STP_DATA_PATH and STP_MODULE_PATH correct?\n");
00064       stpi_init_color_list();
00065     }
00066 }
00067 
00068 
00069 
00070 int
00071 stp_color_count(void)
00072 {
00073   if (color_list == NULL)
00074     {
00075       stp_erprintf("No color modules found: "
00076                    "is STP_MODULE_PATH correct?\n");
00077       stpi_init_color_list();
00078     }
00079   return stp_list_get_length(color_list);
00080 }
00081 
00082 
00083 static inline void
00084 check_color(const stp_color_t *c)
00085 {
00086   if (c == NULL)
00087     {
00088       stp_erprintf("Null stp_color_t! Please report this bug.\n");
00089       stp_abort();
00090     }
00091 }
00092 
00093 
00094 const stp_color_t *
00095 stp_get_color_by_index(int idx)
00096 {
00097   stp_list_item_t *color;
00098 
00099   check_list();
00100 
00101   color = stp_list_get_item_by_index(color_list, idx);
00102   if (color == NULL)
00103     return NULL;
00104   return (const stp_color_t *) stp_list_item_get_data(color);
00105 }
00106 
00107 
00108 static const char *
00109 stpi_color_namefunc(const void *item)
00110 {
00111   const stp_color_t *color = (const stp_color_t *) item;
00112   check_color(color);
00113   return color->short_name;
00114 }
00115 
00116 
00117 static const char *
00118 stpi_color_long_namefunc(const void *item)
00119 {
00120   const stp_color_t *color = (const stp_color_t *) item;
00121   check_color(color);
00122   return color->long_name;
00123 }
00124 
00125 
00126 const char *
00127 stp_color_get_name(const stp_color_t *c)
00128 {
00129   const stp_color_t *val = (const stp_color_t *) c;
00130   check_color(val);
00131   return val->short_name;
00132 }
00133 
00134 const char *
00135 stp_color_get_long_name(const stp_color_t *c)
00136 {
00137   const stp_color_t *val = (const stp_color_t *) c;
00138   check_color(val);
00139   return gettext(val->long_name);
00140 }
00141 
00142 
00143 static const stp_colorfuncs_t *
00144 stpi_get_colorfuncs(const stp_color_t *c)
00145 {
00146   const stp_color_t *val = (const stp_color_t *) c;
00147   check_color(val);
00148   return val->colorfuncs;
00149 }
00150 
00151 
00152 const stp_color_t *
00153 stp_get_color_by_name(const char *name)
00154 {
00155   stp_list_item_t *color;
00156 
00157   check_list();
00158 
00159   color = stp_list_get_item_by_name(color_list, name);
00160   if (!color)
00161     return NULL;
00162   return (const stp_color_t *) stp_list_item_get_data(color);
00163 }
00164 
00165 const stp_color_t *
00166 stp_get_color_by_colorfuncs(stp_colorfuncs_t *colorfuncs)
00167 {
00168   stp_list_item_t *color_item;
00169   stp_color_t *color;
00170 
00171   check_list();
00172 
00173   color_item = stp_list_get_start(color_list);
00174   while (color_item)
00175     {
00176       color = (stp_color_t *) stp_list_item_get_data(color_item);
00177       if (color->colorfuncs == colorfuncs)
00178         return color;
00179       color_item = stp_list_item_next(color_item);
00180     }
00181   return NULL;
00182 }
00183 
00184 
00185 int
00186 stp_color_init(stp_vars_t *v,
00187                stp_image_t *image,
00188                size_t steps)
00189 {
00190   const stp_colorfuncs_t *colorfuncs =
00191     stpi_get_colorfuncs(stp_get_color_by_name(stp_get_color_conversion(v)));
00192   return colorfuncs->init(v, image, steps);
00193 }
00194 
00195 int
00196 stp_color_get_row(stp_vars_t *v,
00197                   stp_image_t *image,
00198                   int row,
00199                   unsigned *zero_mask)
00200 {
00201   const stp_colorfuncs_t *colorfuncs =
00202     stpi_get_colorfuncs(stp_get_color_by_name(stp_get_color_conversion(v)));
00203   return colorfuncs->get_row(v, image, row, zero_mask);
00204 }
00205 
00206 stp_parameter_list_t
00207 stp_color_list_parameters(const stp_vars_t *v)
00208 {
00209   const stp_colorfuncs_t *colorfuncs =
00210     stpi_get_colorfuncs(stp_get_color_by_name(stp_get_color_conversion(v)));
00211   return colorfuncs->list_parameters(v);
00212 }
00213 
00214 void
00215 stp_color_describe_parameter(const stp_vars_t *v, const char *name,
00216                              stp_parameter_t *description)
00217 {
00218   const stp_colorfuncs_t *colorfuncs =
00219     stpi_get_colorfuncs(stp_get_color_by_name(stp_get_color_conversion(v)));
00220   colorfuncs->describe_parameter(v, name, description);
00221 }
00222 
00223 
00224 int
00225 stp_color_register(const stp_color_t *color)
00226 {
00227   if (color_list == NULL)
00228     {
00229       stpi_init_color_list();
00230       stp_deprintf(STP_DBG_COLORFUNC,
00231                    "stpi_color_register(): initialising color_list...\n");
00232     }
00233 
00234   check_color(color);
00235 
00236   if (color)
00237     {
00238       /* Add new color algorithm if it does not already exist */
00239       if (stp_get_color_by_name(color->short_name) == NULL)
00240         {
00241           stp_deprintf
00242             (STP_DBG_COLORFUNC,
00243              "stpi_color_register(): registered colour module \"%s\"\n",
00244              color->short_name);
00245           stp_list_item_create(color_list, NULL, color);
00246         }
00247     }
00248 
00249   return 0;
00250 }
00251 
00252 int
00253 stp_color_unregister(const stp_color_t *color)
00254 {
00255   stp_list_item_t *color_item;
00256   stp_color_t *color_data;
00257 
00258   if (color_list == NULL)
00259     {
00260       stpi_init_color_list();
00261       stp_deprintf
00262         (STP_DBG_COLORFUNC,
00263          "stpi_family_unregister(): initialising color_list...\n");
00264     }
00265 
00266   check_color(color);
00267 
00268   color_item = stp_list_get_start(color_list);
00269   while (color_item)
00270     {
00271       color_data = (stp_color_t *) stp_list_item_get_data(color_item);
00272       if (strcmp(color->short_name, color_data->short_name) == 0)
00273         {
00274           stp_deprintf
00275             (STP_DBG_COLORFUNC,
00276              "stpi_color_unregister(): unregistered colour module \"%s\"\n",
00277              color->short_name);
00278           stp_list_item_destroy(color_list, color_item);
00279           break;
00280         }
00281       color_item = stp_list_item_next(color_item);
00282     }
00283 
00284   return 0;
00285 }
00286 

Generated on Wed May 12 20:21:28 2004 for libgimpprint API Reference by doxygen1.2.17