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.
39
2000/
08
/
15
12
:
43
:
43
grubba
Exp $
+
**! $Id: colors.c,v 1.
40
2000/
09
/
10
01
:
23
:
58
per
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:172:
**! 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.
39
2000/
08
/
15
12
:
43
:
43
grubba
Exp $");
+
RCSID("$Id: colors.c,v 1.
40
2000/
09
/
10
01
:
23
:
58
per
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:547:
static void image_color_grey(INT32 args) { image_color_greylevel(args); stack_dup(); stack_dup(); image_make_rgb_color(3); } /*
+
**! method int bits( int rbits, int gbits, int bbits, int rshift, int gshift, int bshift )
+
**! Returns the color as an integer
+
*/
+
static void image_color_bits( INT32 args )
+
{
+
INT_TYPE rb, gb, bb, rs, gs, bs;
+
get_all_args( "bits", args, "%d%d%d%d%d%d", &rb,&gb,&bb, &rs, &gs, &bs );
+
pop_n_elems( args );
+
+
+
/* Do it on the stack to support bignums (it's possible to get 2M
+
* bits for each channel this way. Not that that's really useful,
+
* but...
+
*/
+
+
#define push_int_bits( i, b, s ) \
+
if( b <= 31 ) \
+
{ \
+
push_int( i ); \
+
push_int( 31-b ); \
+
f_rsh( 2 ); \
+
push_int( s ); \
+
f_lsh( 2 ); \
+
} \
+
else \
+
{ \
+
int _b = b; \
+
int _i = i; \
+
push_int( 0 ); \
+
while( _b > -31 ) \
+
{ \
+
push_int( _i ); \
+
if( _b > 0 ) \
+
{ \
+
push_int( _b ); \
+
f_lsh( 2 ); \
+
} else { \
+
push_int( -_b ); \
+
f_rsh( 2 ); \
+
} \
+
f_or( 2 ); \
+
_b -= 31; \
+
} \
+
push_int( s ); \
+
f_lsh( 2 ); \
+
}
+
+
push_int_bits( THIS->rgbl.r, rb, rs );
+
push_int_bits( THIS->rgbl.g, gb, gs );
+
push_int_bits( THIS->rgbl.b, bb, bs );
+
f_or( 2 );
+
f_or( 2 );
+
}
+
+
/*
**! method string hex() **! method string hex(int n) **! method string name() **! method string html() **! Information methods. **! **! <ref>hex</ref>() simply gives a string on the <tt>#rrggbb</tt> **! format. If <tt>n</tt> is given, the number of significant **! digits is set to this number. **! (Ie, <tt>n=3</tt> gives <tt>#rrrgggbbb</tt>.)
pike.git/src/modules/Image/colors.c:1642:
tFunc(tInt tMap(tStr,tMix),tStr),0); ADD_FUNCTION("`[]",image_color_index,tFunc(tOr(tStr,tInt),tOr(tInt,tFunction)),0); ADD_FUNCTION("`->",image_color_index,tFunc(tOr(tStr,tInt),tOr(tInt,tFunction)),0); ADD_FUNCTION("`==",image_color_equal,tFunc(tOr(tObj,tInt),tInt),0); ADD_FUNCTION("__hash",image_color___hash,tFunc(tNone,tInt),0); ADD_FUNCTION("name",image_color_name,tFunc(tNone,tStr),0); ADD_FUNCTION("hex",image_color_hex,tFunc(tNone,tStr),0); ADD_FUNCTION("html",image_color_html,tFunc(tNone,tStr),0);
+
ADD_FUNCTION("bits",image_color_bits,tFunc(tInt tInt tInt tInt tInt tInt,tInt),0);
ADD_FUNCTION("rgb",image_color_rgb,tFunc(tNone,tArr(tInt)),0); ADD_FUNCTION("rgbf",image_color_rgbf,tFunc(tNone,tArr(tFlt)),0); ADD_FUNCTION("hsv",image_color_hsv,tFunc(tNone,tArr(tInt)),0); ADD_FUNCTION("hsvf",image_color_hsvf,tFunc(tNone,tArr(tFlt)),0); ADD_FUNCTION("cmyk",image_color_cmyk,tFunc(tNone,tArr(tFlt)),0); ADD_FUNCTION("greylevel",image_color_greylevel,tOr(tFunc(tNone,tInt),tFunc(tInt tInt tInt,tInt)),0); /* color conversion methods */ ADD_FUNCTION("grey",image_color_grey,