star-cmap

Mapping values onto color ramps
git clone git://git.meso-star.fr/star-cmap.git
Log | Files | Refs | README | LICENSE

scmap.h (5627B)


      1 /* Copyright (C) 2020, 2021, 2023 |Méso|Star> (contact@meso-star.com)
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 3 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     15 
     16 #ifndef SCMAP_H
     17 #define SCMAP_H
     18 
     19 #include <rsys/rsys.h>
     20 
     21 /* Library symbol management */
     22 #if defined(SCMAP_SHARED_BUILD) /* Build shared library */
     23   #define SCMAP_API extern EXPORT_SYM
     24 #elif defined(SCMAP_STATIC) /* Use/build static library */
     25   #define SCMAP_API extern LOCAL_SYM
     26 #else /* Use shared library */
     27   #define SCMAP_API extern IMPORT_SYM
     28 #endif
     29 
     30 /* Helper macro that asserts if the invocation of the scmap function `Func'
     31  * returns an error. One should use this macro on scmap function calls for
     32  * which no explicit error checking is performed */
     33 #ifndef NDEBUG
     34   #define SCMAP(Func) ASSERT(scmap_ ## Func == RES_OK)
     35 #else
     36   #define SCMAP(Func) scmap_ ## Func
     37 #endif
     38 
     39 enum scmap_filter {
     40   SCMAP_FILTER_NEAREST,
     41   SCMAP_FILTER_LINEAR,
     42   SCMAP_FILTERS_COUNT__
     43 };
     44 
     45 struct scmap_palette {
     46   void (*get_color)(const size_t icolor, double color[3], void* context);
     47   size_t ncolors; /* #colors */
     48   void* context;
     49 };
     50 #define SCMAP_PALETTE_NULL__ {NULL, 0, NULL}
     51 static const struct scmap_palette SCMAP_PALETTE_NULL = SCMAP_PALETTE_NULL__;
     52 
     53 /* Forward declarations */
     54 struct scmap;
     55 struct logger;
     56 struct mem_allocator;
     57 
     58 BEGIN_DECLS
     59 
     60 /* Builtin palettes */
     61 SCMAP_API const struct scmap_palette scmap_palette_accent;
     62 SCMAP_API const struct scmap_palette scmap_palette_blues;
     63 SCMAP_API const struct scmap_palette scmap_palette_brbg;
     64 SCMAP_API const struct scmap_palette scmap_palette_bugn;
     65 SCMAP_API const struct scmap_palette scmap_palette_bupu;
     66 SCMAP_API const struct scmap_palette scmap_palette_chromajs;
     67 SCMAP_API const struct scmap_palette scmap_palette_dark2;
     68 SCMAP_API const struct scmap_palette scmap_palette_gnbu;
     69 SCMAP_API const struct scmap_palette scmap_palette_gnpu;
     70 SCMAP_API const struct scmap_palette scmap_palette_greens;
     71 SCMAP_API const struct scmap_palette scmap_palette_greys;
     72 SCMAP_API const struct scmap_palette scmap_palette_inferno;
     73 SCMAP_API const struct scmap_palette scmap_palette_jet;
     74 SCMAP_API const struct scmap_palette scmap_palette_magma;
     75 SCMAP_API const struct scmap_palette scmap_palette_moreland;
     76 SCMAP_API const struct scmap_palette scmap_palette_oranges;
     77 SCMAP_API const struct scmap_palette scmap_palette_orrd;
     78 SCMAP_API const struct scmap_palette scmap_palette_paired;
     79 SCMAP_API const struct scmap_palette scmap_palette_parula;
     80 SCMAP_API const struct scmap_palette scmap_palette_pastel1;
     81 SCMAP_API const struct scmap_palette scmap_palette_pastel2;
     82 SCMAP_API const struct scmap_palette scmap_palette_piyg;
     83 SCMAP_API const struct scmap_palette scmap_palette_plasma;
     84 SCMAP_API const struct scmap_palette scmap_palette_prgn;
     85 SCMAP_API const struct scmap_palette scmap_palette_pubu;
     86 SCMAP_API const struct scmap_palette scmap_palette_pubugn;
     87 SCMAP_API const struct scmap_palette scmap_palette_puor;
     88 SCMAP_API const struct scmap_palette scmap_palette_purd;
     89 SCMAP_API const struct scmap_palette scmap_palette_purples;
     90 SCMAP_API const struct scmap_palette scmap_palette_rdbu;
     91 SCMAP_API const struct scmap_palette scmap_palette_rdgy;
     92 SCMAP_API const struct scmap_palette scmap_palette_rdpu;
     93 SCMAP_API const struct scmap_palette scmap_palette_rdylbu;
     94 SCMAP_API const struct scmap_palette scmap_palette_rdylgn;
     95 SCMAP_API const struct scmap_palette scmap_palette_reds;
     96 SCMAP_API const struct scmap_palette scmap_palette_sand;
     97 SCMAP_API const struct scmap_palette scmap_palette_set1;
     98 SCMAP_API const struct scmap_palette scmap_palette_set2;
     99 SCMAP_API const struct scmap_palette scmap_palette_set3;
    100 SCMAP_API const struct scmap_palette scmap_palette_spectral;
    101 SCMAP_API const struct scmap_palette scmap_palette_viridis;
    102 SCMAP_API const struct scmap_palette scmap_palette_whgnbu;
    103 SCMAP_API const struct scmap_palette scmap_palette_whylrd;
    104 SCMAP_API const struct scmap_palette scmap_palette_ylgn;
    105 SCMAP_API const struct scmap_palette scmap_palette_ylgnbu;
    106 SCMAP_API const struct scmap_palette scmap_palette_ylorbr;
    107 SCMAP_API const struct scmap_palette scmap_palette_ylorrd;
    108 SCMAP_API const struct scmap_palette scmap_palette_ylrd;
    109 
    110 /*******************************************************************************
    111  * Star-ColorMap API
    112  ******************************************************************************/
    113 SCMAP_API res_T
    114 scmap_create
    115   (struct logger* logger, /* NULL <=> use builtin logger */
    116    struct mem_allocator* allocator, /* NULL <=> use default allocator */
    117    const int verbose, /* Verbosity level */
    118    const struct scmap_palette* palette,
    119    struct scmap** scmap);
    120 
    121 SCMAP_API res_T
    122 scmap_ref_get
    123   (struct scmap* scmap);
    124 
    125 SCMAP_API res_T
    126 scmap_ref_put
    127   (struct scmap* scmap);
    128 
    129 SCMAP_API res_T
    130 scmap_fetch_color
    131   (const struct scmap* scmap,
    132    const double value,
    133    const enum scmap_filter filter,
    134    double color[3]); /* In [0, 1] */
    135 
    136 /* Return NULL if the submitted name does not reference a knwon palette */
    137 SCMAP_API const struct scmap_palette*
    138 scmap_get_builtin_palette
    139   (const char* name); /* e.g. "inferno" */
    140 
    141 END_DECLS
    142 
    143 #endif /* SCMAP_H */
    144