home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / unofficial-plug-ins / mathmap / tuples.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-21  |  1.9 KB  |  86 lines

  1. /* -*- c -*- */
  2.  
  3. /*
  4.  * tuples.c
  5.  *
  6.  * MathMap
  7.  *
  8.  * Copyright (C) 1997-2000 Mark Probst
  9.  *
  10.  * This program is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU General Public License
  12.  * as published by the Free Software Foundation; either version 2
  13.  * of the License, or (at your option) any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25. #include <assert.h>
  26.  
  27. #include "tuples.h"
  28. #include "tags.h"
  29.  
  30. tuple_info_t
  31. make_tuple_info (int number, int length)
  32. {
  33.     tuple_info_t info = { number, length };
  34.  
  35.     return info;
  36. }
  37.  
  38. void
  39. tuple_to_color (tuple_t *tuple, float *red, float *green, float *blue, float *alpha)
  40. {
  41.     assert(tuple->length == 4);
  42.  
  43.     if (tuple->data[0] <= 0.0)
  44.     *red = 0.0;
  45.     else if (tuple->data[0] >= 1.0)
  46.     *red = 1.0;
  47.     else
  48.     *red = tuple->data[0];
  49.  
  50.     if (tuple->data[1] <= 0.0)
  51.     *green = 0.0;
  52.     else if (tuple->data[1] >= 1.0)
  53.     *green = 1.0;
  54.     else
  55.     *green = tuple->data[1];
  56.  
  57.     if (tuple->data[2] <= 0.0)
  58.     *blue = 0.0;
  59.     else if (tuple->data[2] >= 1.0)
  60.     *blue = 1.0;
  61.     else
  62.     *blue = tuple->data[2];
  63.  
  64.     if (tuple->data[3] <= 0.0)
  65.     *alpha = 0.0;
  66.     else if (tuple->data[3] >= 1.0)
  67.     *alpha = 1.0;
  68.     else
  69.     *alpha = tuple->data[3];
  70. }
  71.  
  72. tuple_t
  73. color_to_tuple (float red, float green, float blue, float alpha)
  74. {
  75.     tuple_t tuple;
  76.  
  77.     tuple.number = nil_tag_number;
  78.     tuple.length = 4;
  79.     tuple.data[0] = red;
  80.     tuple.data[1] = green;
  81.     tuple.data[2] = blue;
  82.     tuple.data[3] = alpha;
  83.  
  84.     return tuple;
  85. }
  86.