| 1 | /* |
| 2 | * |
| 3 | * Gimp-Print color management module - traditional Gimp-Print algorithm. |
| 4 | * |
| 5 | * Copyright 1997-2000 Michael Sweet ([email protected]) and |
| 6 | * Robert Krawitz ([email protected]) |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the Free |
| 10 | * Software Foundation; either version 2 of the License, or (at your option) |
| 11 | * any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 16 | * for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * This file must include only standard C header files. The core code must |
| 24 | * compile on generic platforms that don't support glib, gimp, gtk, etc. |
| 25 | */ |
| 26 | |
| 27 | #ifdef HAVE_CONFIG_H |
| 28 | #include <config.h> |
| 29 | #endif |
| 30 | #include <gutenprint/gutenprint.h> |
| 31 | #include "gutenprint-internal.h" |
| 32 | #include <gutenprint/gutenprint-intl-internal.h> |
| 33 | #include <gutenprint/curve-cache.h> |
| 34 | #include <math.h> |
| 35 | #ifdef HAVE_LIMITS_H |
| 36 | #include <limits.h> |
| 37 | #endif |
| 38 | #include <string.h> |
| 39 | |
| 40 | void |
| 41 | stp_curve_free_curve_cache(stp_cached_curve_t *cache) |
| 42 | { |
| 43 | if (cache->curve) |
| 44 | stp_curve_destroy(cache->curve); |
| 45 | cache->curve = NULL; |
| 46 | cache->d_cache = NULL; |
| 47 | cache->s_cache = NULL; |
| 48 | cache->count = 0; |
| 49 | } |
| 50 | |
| 51 | void |
| 52 | stp_curve_cache_curve_data(stp_cached_curve_t *cache) |
| 53 | { |
| 54 | if (cache->curve && !cache->d_cache) |
| 55 | { |
| 56 | cache->s_cache = stp_curve_get_ushort_data(cache->curve, &(cache->count)); |
| 57 | cache->d_cache = stp_curve_get_data(cache->curve, &(cache->count)); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | stp_curve_t * |
| 62 | stp_curve_cache_get_curve(stp_cached_curve_t *cache) |
| 63 | { |
| 64 | return cache->curve; |
| 65 | } |
| 66 | |
| 67 | void |
| 68 | stp_curve_cache_curve_invalidate(stp_cached_curve_t *cache) |
| 69 | { |
| 70 | cache->d_cache = NULL; |
| 71 | cache->s_cache = NULL; |
| 72 | cache->count = 0; |
| 73 | } |
| 74 | |
| 75 | void |
| 76 | stp_curve_cache_set_curve(stp_cached_curve_t *cache, stp_curve_t *curve) |
| 77 | { |
| 78 | stp_curve_cache_curve_invalidate(cache); |
| 79 | cache->curve = curve; |
| 80 | } |
| 81 | |
| 82 | void |
| 83 | stp_curve_cache_set_curve_copy(stp_cached_curve_t *cache, const stp_curve_t *curve) |
| 84 | { |
| 85 | stp_curve_cache_curve_invalidate(cache); |
| 86 | cache->curve = stp_curve_create_copy(curve); |
| 87 | } |
| 88 | |
| 89 | size_t |
| 90 | stp_curve_cache_get_count(stp_cached_curve_t *cache) |
| 91 | { |
| 92 | if (cache->curve) |
| 93 | { |
| 94 | if (!cache->d_cache) |
| 95 | cache->d_cache = stp_curve_get_data(cache->curve, &(cache->count)); |
| 96 | return cache->count; |
| 97 | } |
| 98 | else |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | const unsigned short * |
| 103 | stp_curve_cache_get_ushort_data(stp_cached_curve_t *cache) |
| 104 | { |
| 105 | if (cache->curve) |
| 106 | { |
| 107 | if (!cache->s_cache) |
| 108 | cache->s_cache = |
| 109 | stp_curve_get_ushort_data(cache->curve, &(cache->count)); |
| 110 | return cache->s_cache; |
| 111 | } |
| 112 | else |
| 113 | return NULL; |
| 114 | } |
| 115 | |
| 116 | const double * |
| 117 | stp_curve_cache_get_double_data(stp_cached_curve_t *cache) |
| 118 | { |
| 119 | if (cache->curve) |
| 120 | { |
| 121 | if (!cache->d_cache) |
| 122 | cache->d_cache = stp_curve_get_data(cache->curve, &(cache->count)); |
| 123 | return cache->d_cache; |
| 124 | } |
| 125 | else |
| 126 | return NULL; |
| 127 | } |
| 128 | |
| 129 | void |
| 130 | stp_curve_cache_copy(stp_cached_curve_t *dest, const stp_cached_curve_t *src) |
| 131 | { |
| 132 | stp_curve_cache_curve_invalidate(dest); |
| 133 | if (dest != src) |
| 134 | { |
| 135 | if (src->curve) |
| 136 | stp_curve_cache_set_curve_copy(dest, src->curve); |
| 137 | } |
| 138 | } |