00001 /* 00002 * "$Id: curve-cache.c,v 1.4 2004/05/07 19:20:29 rleigh Exp $" 00003 * 00004 * Gimp-Print color management module - traditional Gimp-Print algorithm. 00005 * 00006 * Copyright 1997-2000 Michael Sweet (mike@easysw.com) and 00007 * Robert Krawitz (rlk@alum.mit.edu) 00008 * 00009 * This program is free software; you can redistribute it and/or modify it 00010 * under the terms of the GNU General Public License as published by the Free 00011 * Software Foundation; either version 2 of the License, or (at your option) 00012 * any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, but 00015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00017 * for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 */ 00023 00024 /* 00025 * This file must include only standard C header files. The core code must 00026 * compile on generic platforms that don't support glib, gimp, gtk, etc. 00027 */ 00028 00029 #ifdef HAVE_CONFIG_H 00030 #include <config.h> 00031 #endif 00032 #include <gimp-print/gimp-print.h> 00033 #include "gimp-print-internal.h" 00034 #include <gimp-print/gimp-print-intl-internal.h> 00035 #include <gimp-print/curve-cache.h> 00036 #include <math.h> 00037 #ifdef HAVE_LIMITS_H 00038 #include <limits.h> 00039 #endif 00040 #include <string.h> 00041 00042 void 00043 stp_curve_free_curve_cache(stp_cached_curve_t *cache) 00044 { 00045 if (cache->curve) 00046 stp_curve_destroy(cache->curve); 00047 cache->curve = NULL; 00048 cache->d_cache = NULL; 00049 cache->s_cache = NULL; 00050 cache->count = 0; 00051 } 00052 00053 void 00054 stp_curve_cache_curve_data(stp_cached_curve_t *cache) 00055 { 00056 if (cache->curve && !cache->d_cache) 00057 { 00058 cache->s_cache = stp_curve_get_ushort_data(cache->curve, &(cache->count)); 00059 cache->d_cache = stp_curve_get_data(cache->curve, &(cache->count)); 00060 } 00061 } 00062 00063 stp_curve_t * 00064 stp_curve_cache_get_curve(stp_cached_curve_t *cache) 00065 { 00066 return cache->curve; 00067 } 00068 00069 void 00070 stp_curve_cache_curve_invalidate(stp_cached_curve_t *cache) 00071 { 00072 cache->d_cache = NULL; 00073 cache->s_cache = NULL; 00074 cache->count = 0; 00075 } 00076 00077 void 00078 stp_curve_cache_set_curve(stp_cached_curve_t *cache, stp_curve_t *curve) 00079 { 00080 stp_curve_cache_curve_invalidate(cache); 00081 cache->curve = curve; 00082 } 00083 00084 void 00085 stp_curve_cache_set_curve_copy(stp_cached_curve_t *cache, const stp_curve_t *curve) 00086 { 00087 stp_curve_cache_curve_invalidate(cache); 00088 cache->curve = stp_curve_create_copy(curve); 00089 } 00090 00091 const size_t 00092 stp_curve_cache_get_count(stp_cached_curve_t *cache) 00093 { 00094 if (cache->curve) 00095 { 00096 if (!cache->d_cache) 00097 cache->d_cache = stp_curve_get_data(cache->curve, &(cache->count)); 00098 return cache->count; 00099 } 00100 else 00101 return 0; 00102 } 00103 00104 const unsigned short * 00105 stp_curve_cache_get_ushort_data(stp_cached_curve_t *cache) 00106 { 00107 if (cache->curve) 00108 { 00109 if (!cache->s_cache) 00110 cache->s_cache = 00111 stp_curve_get_ushort_data(cache->curve, &(cache->count)); 00112 return cache->s_cache; 00113 } 00114 else 00115 return NULL; 00116 } 00117 00118 const double * 00119 stp_curve_cache_get_double_data(stp_cached_curve_t *cache) 00120 { 00121 if (cache->curve) 00122 { 00123 if (!cache->d_cache) 00124 cache->d_cache = stp_curve_get_data(cache->curve, &(cache->count)); 00125 return cache->d_cache; 00126 } 00127 else 00128 return NULL; 00129 } 00130 00131 void 00132 stp_curve_cache_copy(stp_cached_curve_t *dest, const stp_cached_curve_t *src) 00133 { 00134 stp_curve_cache_curve_invalidate(dest); 00135 if (dest != src) 00136 { 00137 if (src->curve) 00138 stp_curve_cache_set_curve_copy(dest, src->curve); 00139 } 00140 } 00141