pike.git
/
src
/
modules
/
Image
/
colors.c
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/modules/Image/colors.c:15:
**! 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. **! <ref>Image.Color()</ref> takes the following arguments: **! <pre> **! Image.Color(string name) // "red" **! Image.Color(string prefix_string) // "lightblue" **! Image.Color(string hex_name) // "#ff00ff" **! Image.Color(string cmyk_string) // "%17,42,0,19.4"
-
**! Image.Color(string hsv_string) // "
%
@327,90,32"
+
**! Image.Color(string hsv_string) // "@327,90,32"
**! Image.Color(int red, int green, int blue) **! </pre> **! **! The color names available can be listed by using indices **! on Image.Color. The colors are available by name directly **! as <tt>Image.Color.name</tt>, too: **! <pre> **! ...Image.Color.red... **! ...Image.Color.green... **! or, maybe
pike.git/src/modules/Image/colors.c:320:
sp--; dmalloc_touch_svalue(sp); } #ifdef THIS #undef THIS /* Needed for NT */ #endif #define THIS ((struct color_struct*)(Pike_fp->current_storage)) #define THISOBJ (Pike_fp->current_object)
+
#ifdef PIKE_NULL_IS_SPECIAL
static void init_color_struct(struct object *UNUSED(dummy)) {
-
THIS->rgb.r=THIS->rgb.g=THIS->rgb.b=0;
+
THIS->name=NULL; }
-
+
#endif
static void exit_color_struct(struct object *UNUSED(dummy)) { if (THIS->name)
-
{
+
free_string(THIS->name);
-
THIS->name=NULL;
+
}
-
}
+
void _img_nct_map_to_flat_cubicles(rgb_group *s, rgb_group *d, int n, struct neo_colortable *nct, struct nct_dither *dith, int rowlen); static void try_find_name(struct color_struct *this) {
pike.git/src/modules/Image/colors.c:448:
{ INT_TYPE r,g,b; if (args==0) { r=87; g=127; b=41; } else {
-
get_all_args(
"greylevel"
,args,"%i%i%i",&r,&g,&b);
+
get_all_args(
NULL
,args,"%i%i%i",&r,&g,&b);
} pop_n_elems(args); if (r+g+b==0) r=g=b=1; push_int((r*THIS->rgb.r+g*THIS->rgb.g+b*THIS->rgb.b)/(r+g+b)); } #define MAX3(X,Y,Z) MAXIMUM(MAXIMUM(X,Y),Z) #define MIN3(X,Y,Z) MINIMUM(MINIMUM(X,Y),Z) static void image_color_hsvf(INT32 args)
pike.git/src/modules/Image/colors.c:571:
**! method int bits( int rbits, int gbits, int bbits, int rshift, int gshift, int bshift ) **! Returns the color as an integer. The first three parameters state how **! many bits to use for red, green and blue respectively. The last three **! state how many bits each colour should be shifted. For instance, **! <tt>Image.Color("#AABBCC")->bits(8, 8, 8, 16, 8, 0)</tt> returns **! the integer 11189196, that is, 0xAABBCC. */ static void image_color_bits( INT32 args ) { INT_TYPE rb, gb, bb, rs, gs, bs;
-
get_all_args(
"bits"
, args, "%i%i%i%i%i%i", &rb,&gb,&bb, &rs, &gs, &bs );
+
get_all_args(
NULL
, args, "%i%i%i%i%i%i", &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 ) \
pike.git/src/modules/Image/colors.c:649:
**! returns a new <ref>Image.Color.Color</ref> object **! see also: rgb, hsv, Image.Color */ static void image_color_hex(INT32 args) { char buf[80]; INT_TYPE i=sizeof(COLORTYPE)*2; if (args)
-
get_all_args(
"hex"
,args,"%i",&i);
+
get_all_args(
NULL
,args,"%i",&i);
pop_n_elems(args); if (i<1) { push_static_text("#"); /* stupid */ return; } else if (i!=sizeof(COLORTYPE)*2) { ptrdiff_t sh;
pike.git/src/modules/Image/colors.c:748:
**! method array|string cast() **! cast the object to an array, representing red, green **! and blue (equal to <tt>-><ref>rgb</ref>()</tt>), or **! to a string, giving the name (equal to <tt>-><ref>name</ref>()</tt>). **! returns the name as string or rgb as array **! see also: rgb, name */ static void image_color_cast(INT32 args) {
-
if
(args!=1 ||
-
TYPEOF(sp[-1]) != T
_
STRING)
-
bad
_
arg_error
(
"cast"
,
sp-
args,
args,0,
"",
sp-args,
-
"Bad arguments to cast.\n"
);
+
struct
pike_string
*str;
+
get
_
all
_
args
(
NULL
,
args,
"
%n
",
&str
);
-
if (
sp[-1].u.string
==literal_array_string)
+
if (
str
==literal_array_string)
{ image_color_rgb(args); return; }
-
if (
sp[-1].u.string
==literal_string_string)
+
if (
str
==literal_string_string)
{ image_color_name(args); return; }
-
if (
sp[-1].u.string
==literal_int_string)
+
if (
str
==literal_int_string)
{ pop_stack(); push_int( (THIS->rgb.r << 8 | THIS->rgb.g) << 8 | THIS->rgb.b ); return; } pop_stack(); push_undefined(); } static void image_color__sprintf(INT32 args)
pike.git/src/modules/Image/colors.c:1156:
sp[-2].u.float_number+=0.2; sp[-1].u.float_number+=0.2; } image_make_hsv_color(3); } static void image_color_mult(INT32 args) { FLOAT_TYPE x=0.0;
-
get_all_args(
"`*"
,args,"%f",&x);
+
get_all_args(
NULL
,args,"%f",&x);
pop_n_elems(args); _image_make_rgb_color((int)(THIS->rgb.r*x), (int)(THIS->rgb.g*x), (int)(THIS->rgb.b*x)); } int image_color_svalue(struct svalue *v,rgb_group *rgb) { if (TYPEOF(*v) == T_OBJECT) {
pike.git/src/modules/Image/colors.c:1325:
f_sscanf(2); if (TYPEOF(sp[-1]) == T_ARRAY && sp[-1].u.array->size==3) { FLOAT_TYPE h,s,v; stack_swap(); pop_stack(); sp--; dmalloc_touch_svalue(sp); push_array_items(sp->u.array);
-
get_all_args(
"create"
,3,"%f%f%f",&h,&s,&v);
+
get_all_args(
NULL
,3,"%f%f%f",&h,&s,&v);
pop_n_elems(3); push_int((int)(h/360.0*256.0)); push_int((int)(s/100.0*255.4)); push_int((int)(v/100.0*255.4)); image_make_hsv_color(3); return; } pop_stack(); } if (sp[-1].u.string->len>=4 &&
pike.git/src/modules/Image/colors.c:1404:
/* try other stuff here */ pop_stack(); push_undefined(); return; } static void image_guess_color(INT32 args) {
-
if (
args
!=1 && TYPEOF
(
sp[-
args
])
!= T
_STRING
)
-
bad_arg_error("guess"
,
sp-args,args,0,"",sp-args,
-
"Bad arguments to guess.\n"
);
+
check_all_args
(
NULL,
args
,
BIT
_STRING
,
0);
f_lower_case(1); push_static_text(" "); o_subtract(); stack_dup(); image_get_color(1); if (TYPEOF(sp[-1]) == T_OBJECT) { stack_swap();
pike.git/src/modules/Image/colors.c:1559:
if( args==1 && TYPEOF(sp[-1]) == T_INT ) { r = sp[-1].u.integer; b = r & 0xff; r >>= 8; g = r & 0xff; r >>= 8; r &= 0xff; } else
-
get_all_args(
"rgb"
,args,"%i%i%i",&r,&g,&b);
+
get_all_args(
NULL
,args,"%i%i%i",&r,&g,&b);
_image_make_rgb_color(r,g,b); } static void image_make_hsv_color(INT32 args) { FLOAT_TYPE h,s,v; FLOAT_TYPE r=0,g=0,b=0; /* to avoid warning */ if (args && TYPEOF(sp[-args]) == T_INT) { INT_TYPE hi,si,vi;
-
get_all_args(
"hsv"
,args,"%i%i%i",&hi,&si,&vi);
+
get_all_args(
NULL
,args,"%i%i%i",&hi,&si,&vi);
pop_n_elems(args); if (hi<0) hi=(hi%COLORMAX)+COLORMAX; else if (hi>COLORMAX) hi%=COLORMAX; /* repeating */ if (si<0) si=0; else if (si>COLORMAX) si=COLORMAX; if (vi<0) vi=0; else if (vi>COLORMAX) vi=COLORMAX; h = (hi/((double)COLORMAX))*(360.0/60.0); s = si/((double)COLORMAX); v = vi/((double)COLORMAX); } else {
-
get_all_args(
"hsv"
,args,"%f%f%f",&h,&s,&v);
+
get_all_args(
NULL
,args,"%f%f%f",&h,&s,&v);
pop_n_elems(args); if (h<0) h = 360 + h - (((int)h/360)*360); if (h>360.0) h -= (((int)h/360)*360); h/=60; } if(s==0.0) { r = g = b = v; } else {
pike.git/src/modules/Image/colors.c:1628:
#undef p #undef q #undef t _image_make_rgbf_color(r,g,b); } static void image_make_cmyk_color(INT32 args) { FLOAT_TYPE c,m,y,k,r,g,b;
-
get_all_args(
"cmyk"
,args,"%F%F%F%F",&c,&m,&y,&k);
+
get_all_args(
NULL
,args,"%F%F%F%F",&c,&m,&y,&k);
pop_n_elems(args); r=100-(c+k); g=100-(m+k); b=100-(y+k); _image_make_rgbf_color(r*0.01,g*0.01,b*0.01); } static void image_make_greylevel_color(INT32 args) { INT_TYPE i;
-
get_all_args(
"greylevel"
,args,"%i",&i);
+
get_all_args(
NULL
,args,"%i",&i);
pop_n_elems(args); _image_make_rgb_color(i,i,i); } static void image_make_html_color(INT32 args) { int i;
-
+
check_all_args(NULL, args, BIT_STRING, 0);
-
if (args!=1 ||
-
TYPEOF(sp[-1]) != T_STRING)
-
{
-
bad_arg_error("html",sp-args,args,0,"",sp-args,
-
"Bad arguments to html.\n");
-
return;
-
}
-
+
f_lower_case(1); for (i=0; (size_t)i<sizeof(html_color)/sizeof(html_color[0]); i++) if (html_color[i].pname==sp[-1].u.string) { _image_make_rgb_color(html_color[i].r, html_color[i].g, html_color[i].b); return; }
pike.git/src/modules/Image/colors.c:1723:
str_s=make_shared_string("s"); str_v=make_shared_string("v"); no_name=make_shared_string(""); /* make color object program */ start_new_program(); ADD_STORAGE(struct color_struct);
+
#ifdef PIKE_NULL_IS_SPECIAL
set_init_callback(init_color_struct);
-
+
#endif
set_exit_callback(exit_color_struct); /* color info methods */ ADD_FUNCTION("cast",image_color_cast,tFunc(tStr,tOr(tArray,tStr)),ID_PROTECTED); ADD_FUNCTION("_sprintf",image_color__sprintf, 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(tObjImpl_IMAGE_COLOR_COLOR,tInt),