RGBHLS.c
Go to the documentation of this file.
1 /****************************************************************
2 /* RGBHLS.c
3 /* (c)1995, Toshihiro Matsui, Electrotechnical Laboratory
4 /****************************************************************/
5 
6 static char *rcsid= "@(#)$Id: RGBHLS.c,v 1.1.1.1 2003/11/20 07:46:30 eus Exp $";
7 
8 #include <math.h>
9 #include "../c/eus.h"
10 
11 #pragma init (init_object_module)
12 pointer RGBHLS();
13 
14 static void init_object_module()
15  { add_module_initializer("RGBHLS", RGBHLS);}
16 
17 void rgb_to_hls(r,g,b,h,l,s)
18 int r,g,b; /* inputs 0..255*/
19 int *h, *l, *s;
20 {
21  int v,m,vm,r2,g2,b2;
22  float f;
23 
24  v = max(r,g); v=max(v,b);
25  m = min(r,g); m=min(m,b);
26 
27  if ((*l = (m + v) / 2) <= 0) {*h= *s=0; return;}
28  if ((*s = vm = v-m) > 0)
29  if (*l <=128) {
30  f=(float)(*s)/(float)(v+m);
31  *s = 255*f;}
32  else {
33  f=(float)(*s)/(float)(511-v-m);
34  *s= 255 * f;}
35  else {*h = 0; return;}
36 
37  r2= 255 * (v-r) / vm;
38  g2= 255 * (v-g) / vm;
39  b2= 255 * (v-b) / vm;
40 
41  if (r==v)
42  *h = (g==m ? 5*255+b2 : 255-g2);
43  else if (g==v)
44  *h= (b==m ? 255+r2 : 3*255-b2);
45  else *h = (r==m ? 3*255 + g2 : 5*255 - r2);
46  *h /= 6;}
47 
48 
49 void hls_to_rgb(h,l,s,r,g,b)
50 int h,l,s;
51 int *r, *g, *b;
52 { float v; }
53 
54 pointer RGB_TO_HLS(ctx,n,argv)
55 context *ctx;
56 int n;
57 register pointer argv[];
58 { int h,l,s,v;
59  ckarg(3);
60  rgb_to_hls(ckintval(argv[0]), ckintval(argv[1]), ckintval(argv[2]),
61  &h, &l, &s);
62  h=min(h,255); l=min(l,255); s=min(s,255);
63  /* printf("h=%d l=%d s=%d\n",h,l,s); */
64  v= (h << 16) | (l << 8) | s;
65  return(makeint(v));}
66 
67 pointer RGBHLS(ctx,n,argv)
68 context *ctx;
69 int n;
70 pointer argv[];
71 { pointer mod=argv[0];
72  defun(ctx,"RGB-TO-HLS", mod, RGB_TO_HLS,NULL);
73  return(T);
74  }
75 
f
#define makeint(v)
Definition: sfttest.c:2
Definition: eus.h:522
static long(* g)()
Definition: test_foreign.c:158
pointer T
Definition: eus.c:110
GLfloat n[6][3]
Definition: cube.c:15
void rgb_to_hls(int r, int g, int b, int *h, int *l, int *s)
Definition: RGBHLS.c:17
defun("ADR_TO_STRING", mod, ADR_TO_STRING)
static void init_object_module()
Definition: RGBHLS.c:14
ckarg(2)
void add_module_initializer(char *, pointer(*)())
Definition: loadelf.c:86
#define min(x, y)
Definition: rmflags.c:17
long l
Definition: structsize.c:3
Definition: eus.h:379
short s
Definition: structsize.c:2
void hls_to_rgb(int h, int l, int s, int *r, int *g, int *b)
Definition: RGBHLS.c:49
pointer RGB_TO_HLS(context *ctx, int n, argv)
Definition: RGBHLS.c:54
pointer RGBHLS()
#define max(I1, I2)
Definition: eustags.c:134
#define NULL
Definition: transargv.c:8
GLfloat v[8][3]
Definition: cube.c:21
static char * rcsid
Definition: RGBHLS.c:6


euslisp
Author(s): Toshihiro Matsui
autogenerated on Fri Feb 21 2020 03:20:54