pike.git
/
src
/
modules
/
Image
/
colors.c
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/modules/Image/colors.c:1:
/* **! module Image **! note
-
**! $Id: colors.c,v 1.
56
2001/09/
17
19
:
06
:
21
nilsson
Exp $
+
**! $Id: colors.c,v 1.
57
2001/09/
24
11
:
30
:
25
grubba
Exp $
**! submodule Color **! **! This module keeps names and easy handling **! for easy color support. It gives you an easy **! way to get colors from names. **! **! A color is here an object, containing color **! information and methods for conversion, see below. **! **! <ref>Image.Color</ref> can be called to make a color object.
pike.git/src/modules/Image/colors.c:181:
**! class Color **! This is the color object. It has six readable variables, **! <tt>r</tt>, <tt>g</tt>, <tt>b</tt>, for the <i>red</i>, **! <i>green</i> and <i>blue</i> values, **! and <tt>h</tt>, <tt>s</tt>, <tt>v</tt>, for **! the <i>hue</i>, <i>saturation</i> anv <i>value</i> values. */ #include "global.h"
-
RCSID("$Id: colors.c,v 1.
56
2001/09/
17
19
:
06
:
21
nilsson
Exp $");
+
RCSID("$Id: colors.c,v 1.
57
2001/09/
24
11
:
30
:
25
grubba
Exp $");
#include "image_machine.h" #include <math.h> #include "stralloc.h" #include "pike_macros.h" #include "object.h" #include "constants.h" #include "interpret.h"
pike.git/src/modules/Image/colors.c:500:
Pike_error("internal error, max==0.0\n"); delta = max-min; if(r==max) h = (g-b)/delta; else if(g==max) h = 2+(b-r)/delta; else /*if(b==max)*/ h = 4+(r-g)/delta; h *= 60; /* now in degrees. */ if(h<0) h+=360;
-
push_float(h);
-
push_float(s);
-
push_float(v);
+
push_float(
DO_NOT_WARN((FLOAT_TYPE)
h)
)
;
+
push_float(
DO_NOT_WARN((FLOAT_TYPE)
s)
)
;
+
push_float(
DO_NOT_WARN((FLOAT_TYPE)
v)
)
;
f_aggregate(3); } static void image_color_hsv(INT32 args) { double h,s,v; image_color_hsvf(args); h=sp[-1].u.array->item[0].u.float_number; s=sp[-1].u.array->item[1].u.float_number; v=sp[-1].u.array->item[2].u.float_number;
pike.git/src/modules/Image/colors.c:537:
r=COLORL_TO_FLOAT(THIS->rgbl.r); g=COLORL_TO_FLOAT(THIS->rgbl.g); b=COLORL_TO_FLOAT(THIS->rgbl.b); k=1.0-MAX3(r,g,b); c=1.0-r-k; m=1.0-g-k; y=1.0-b-k;
-
push_float(c*100.0);
-
push_float(m*100.0);
-
push_float(y*100.0);
-
push_float(k*100.0);
+
push_float(
DO_NOT_WARN((FLOAT_TYPE)(
c*100.0)
))
;
+
push_float(
DO_NOT_WARN((FLOAT_TYPE)(
m*100.0)
))
;
+
push_float(
DO_NOT_WARN((FLOAT_TYPE)(
y*100.0)
))
;
+
push_float(
DO_NOT_WARN((FLOAT_TYPE)(
k*100.0)
))
;
f_aggregate(4); } /* **! method object grey() **! method object grey(int red,int green,int blue) **! Gives a new color, containing a grey color, **! which is calculated by the <ref>greylevel</ref> method. **! returns a new <ref>Image.Color.Color</ref> object **! see also: greylevel
pike.git/src/modules/Image/colors.c:1063:
*/ static void image_color_light(INT32 args) { pop_n_elems(args); image_color_hsvf(0); sp--; dmalloc_touch_svalue(sp); push_array_items(sp->u.array); /* frees */
-
sp[-1].u.float_
number+
=
+0
.2;
-
if (sp[-1].u.float_number>=1.0)
-
sp[-2].u.float_number-=sp[-1].u.float_number-1.0;
+
sp[-1].u.float_
number +
=
DO_NOT_WARN((FLOAT_TYPE)0
.2
)
;
+
if (
((double)
sp[-1].u.float_number
)
>=
1.0)
+
sp[-2].u.float_number
-=
DO_NOT_WARN((FLOAT_TYPE)(
sp[-1].u.float_number
-
+
1.0
))
;
image_make_hsv_color(3); } static void image_color_dark(INT32 args) { pop_n_elems(args); image_color_hsvf(0); sp--; dmalloc_touch_svalue(sp);
pike.git/src/modules/Image/colors.c:1118:
{ pop_n_elems(args); image_color_hsvf(0); sp--; dmalloc_touch_svalue(sp); push_array_items(sp->u.array); /* frees */ if (sp[-2].u.float_number==0.0) {
-
sp[-1].u.float_number-=0.2;
+
sp[-1].u.float_number
-=
DO_NOT_WARN((FLOAT_TYPE)
0.2
)
;
} else {
-
sp[-2].u.float_number-=0.2;
-
sp[-1].u.float_number-=0.2;
+
sp[-2].u.float_number
-=
DO_NOT_WARN((FLOAT_TYPE)
0.2
)
;
+
sp[-1].u.float_number
-=
DO_NOT_WARN((FLOAT_TYPE)
0.2
)
;
} image_make_hsv_color(3); } static void image_color_bright(INT32 args) { pop_n_elems(args); image_color_hsvf(0); sp--; dmalloc_touch_svalue(sp);
pike.git/src/modules/Image/colors.c:1572:
if (h>360.0) h -= ((DOUBLE_TO_INT(h)/360)*360); h/=60; } if(s==0.0) { r = g = b = v; } else { #define i floor(h) #define f (h-i)
-
#define p (v * (1 - s))
-
#define q (v * (1 - (s * f)))
-
#define t (v * (1 - (s * (1 -f))))
+
#define p (
(FLOAT_TYPE)(
v * (1 - s))
)
+
#define q (
(FLOAT_TYPE)(
v * (1 - (s * f)))
)
+
#define t (
(FLOAT_TYPE)(
v * (1 - (s * (1 -f))))
)
switch(DOUBLE_TO_INT(i)) { case 6: /* 360 degrees. Same as 0.. */ case 0: r = v; g = t; b = p; break; case 1: r = q; g = v; b = p; break; case 2: r = p; g = v; b = t; break; case 3: r = p; g = q; b = v; break; case 4: r = t; g = p; b = v; break; case 5: r = v; g = p; b = q; break; default: Pike_error("internal error (hue=%d <= hsv[%f,%f,%f])\n",