pike.git / src / modules / Image / layers.c

version» Context lines:

pike.git/src/modules/Image/layers.c:1:   /*   **! module Image   **! note - **! $Id: layers.c,v 1.26 1999/07/02 21:19:34 mirar Exp $ + **! $Id: layers.c,v 1.27 1999/07/03 09:10:49 mirar Exp $   **! class Layer   **! see also: layers   **!      **!   **!   **! <add_appendix name="layers" title="Image.Layer modes"><execute>   **! import Image;   **!   **! void write_image(string desc,
pike.git/src/modules/Image/layers.c:157:   **! // write_image("bottom layer image","ai",a->image());   **! // write_image("bottom layer alpha","aa",b->alpha());   **!   **! write_image("top layer","b",lay(({ltrans,b}))->image());   **! write_image("bottom layer","a",lay(({ltrans,a}))->image());   **!   **! write(mktag("tr",0,mktag("td",0,mktag("hr"))));   **!   **! foreach (Layer()->available_modes(),string mode)   **! { + **! if ((&lt;"add","equal","replace","replace_hsv","darken", + **! "dissolve","screen","logic_equal">)[mode]) + **! write(mktag("tr",0,mktag("td",0,mktag("hr")))); + **!   **! ({lc2,lc2b,li2,li2b,lr2,lzo1})->set_mode(mode);   **!   **! object r=   **! lay( ({ lay(({lca1,lc2}),0,0,80,80),   **! lay(({lc1,lc2b}),0,0,80,80)->set_offset(80,0),   **! lay(({li1,li2}),0,0,80,80)->set_offset(160,0),   **! lay(({li1,li2b}),0,0,80,80)->set_offset(240,0),   **! lay(({lr1,lr2}),0,0,80,80)->set_offset(320,0),   **! lay(({lzo0,lzo1}),400,0,160,80) }),   **! 0,0,560,80);
pike.git/src/modules/Image/layers.c:184:   **! }   **!   **! </execute>   **! </add_appendix>   */      #include "global.h"      #include <math.h> /* floor */    - RCSID("$Id: layers.c,v 1.26 1999/07/02 21:19:34 mirar Exp $"); + RCSID("$Id: layers.c,v 1.27 1999/07/03 09:10:49 mirar Exp $");      #include "image_machine.h"      #include "stralloc.h"   #include "pike_macros.h"   #include "object.h"   #include "constants.h"   #include "interpret.h"   #include "svalue.h"   #include "array.h"
pike.git/src/modules/Image/layers.c:265:   #undef THIS   #define THIS ((struct layer *)(fp->current_storage))   #define THISOBJ (fp->current_object)      #define LMFUNC(X) \    static void X(rgb_group *s,rgb_group *l,rgb_group *d, \    rgb_group *sa,rgb_group *la,rgb_group *da, \    int len,double alpha)      LMFUNC(lm_normal); +    LMFUNC(lm_add);   LMFUNC(lm_subtract);   LMFUNC(lm_multiply);   LMFUNC(lm_divide);   LMFUNC(lm_modulo);   LMFUNC(lm_invsubtract);   LMFUNC(lm_invdivide);   LMFUNC(lm_invmodulo);   LMFUNC(lm_difference);   LMFUNC(lm_min);   LMFUNC(lm_max);   LMFUNC(lm_bitwise_and);   LMFUNC(lm_bitwise_or);   LMFUNC(lm_bitwise_xor); - LMFUNC(lm_equal); - LMFUNC(lm_not_equal); - LMFUNC(lm_less); - LMFUNC(lm_more); - LMFUNC(lm_less_or_equal); - LMFUNC(lm_more_or_equal); - LMFUNC(lm_logic_equal); - LMFUNC(lm_logic_not_equal); - LMFUNC(lm_logic_strict_less); - LMFUNC(lm_logic_strict_more); - LMFUNC(lm_logic_strict_less_or_equal); - LMFUNC(lm_logic_strict_more_or_equal); +       LMFUNC(lm_replace);   LMFUNC(lm_red);   LMFUNC(lm_green);   LMFUNC(lm_blue);      LMFUNC(lm_replace_hsv);   LMFUNC(lm_hue);   LMFUNC(lm_saturation);   LMFUNC(lm_value);   LMFUNC(lm_color); -  +    LMFUNC(lm_darken);   LMFUNC(lm_lighten); -  + LMFUNC(lm_saturate); + LMFUNC(lm_desaturate);      LMFUNC(lm_dissolve);   LMFUNC(lm_behind);   LMFUNC(lm_erase);      LMFUNC(lm_screen);   LMFUNC(lm_overlay);    -  + LMFUNC(lm_equal); + LMFUNC(lm_not_equal); + LMFUNC(lm_less); + LMFUNC(lm_more); + LMFUNC(lm_less_or_equal); + LMFUNC(lm_more_or_equal); +  + LMFUNC(lm_logic_equal); + LMFUNC(lm_logic_not_equal); + LMFUNC(lm_logic_strict_less); + LMFUNC(lm_logic_strict_more); + LMFUNC(lm_logic_strict_less_or_equal); + LMFUNC(lm_logic_strict_more_or_equal); +    struct layer_mode_desc   {    char *name;    lm_row_func *func;    int optimize_alpha; /* alpha 0 -> skip layer */    struct pike_string *ps;   } layer_mode[]=   {    {"normal", lm_normal, 1, NULL },    {"add", lm_add, 1, NULL },
pike.git/src/modules/Image/layers.c:335:    {"modulo", lm_modulo, 1, NULL },    {"invsubtract", lm_invsubtract, 1, NULL },    {"invdivide", lm_invdivide, 1, NULL },    {"invmodulo", lm_invmodulo, 1, NULL },    {"difference", lm_difference, 1, NULL },    {"max", lm_max, 1, NULL },    {"min", lm_min, 1, NULL },    {"bitwise_and", lm_bitwise_and, 1, NULL },    {"bitwise_or", lm_bitwise_or, 1, NULL },    {"bitwise_xor", lm_bitwise_xor, 1, NULL }, -  {"equal", lm_equal, 0, NULL }, -  {"not_equal", lm_not_equal, 0, NULL }, -  {"less", lm_less, 0, NULL }, -  {"more", lm_more, 0, NULL }, -  {"less_or_equal", lm_less_or_equal, 0, NULL }, -  {"more_or_equal", lm_more_or_equal, 0, NULL }, -  {"logic_equal", lm_logic_equal, 0, NULL }, -  {"logic_not_equal",lm_logic_not_equal,0, NULL }, -  {"logic_strict_less",lm_logic_strict_less,0, NULL }, -  {"logic_strict_more",lm_logic_strict_more,0, NULL }, -  {"logic_strict_less_equal",lm_logic_strict_less_or_equal,0, NULL }, -  {"logic_strict_more_equal",lm_logic_strict_more_or_equal,0, NULL }, +        {"replace", lm_replace, 1, NULL },    {"red", lm_red, 1, NULL },    {"green", lm_green, 1, NULL },    {"blue", lm_blue, 1, NULL },       {"replace_hsv", lm_replace_hsv, 1, NULL },    {"hue", lm_hue, 1, NULL },    {"saturation", lm_saturation, 1, NULL },    {"value", lm_value, 1, NULL },    {"color", lm_color, 1, NULL }, /* h+s */       {"darken", lm_darken, 1, NULL },    {"lighten", lm_lighten, 1, NULL }, -  +  {"saturate", lm_saturate, 1, NULL }, +  {"desaturate", lm_desaturate, 1, NULL },       {"dissolve", lm_dissolve, 1, NULL },    {"behind", lm_behind, 1, NULL },    {"erase", lm_erase, 1, NULL },       {"screen", lm_screen, 1, NULL },    {"overlay", lm_overlay, 1, NULL }, -  +  +  {"equal", lm_equal, 0, NULL }, +  {"not_equal", lm_not_equal, 0, NULL }, +  {"less", lm_less, 0, NULL }, +  {"more", lm_more, 0, NULL }, +  {"less_or_equal", lm_less_or_equal, 0, NULL }, +  {"more_or_equal", lm_more_or_equal, 0, NULL }, +  +  {"logic_equal", lm_logic_equal, 0, NULL }, +  {"logic_not_equal",lm_logic_not_equal,0, NULL }, +  {"logic_strict_less",lm_logic_strict_less,0, NULL }, +  {"logic_strict_more",lm_logic_strict_more,0, NULL }, +  {"logic_strict_less_equal",lm_logic_strict_less_or_equal,0, NULL }, +  {"logic_strict_more_equal",lm_logic_strict_more_or_equal,0, NULL },   } ;      #define LAYER_MODES ((int)NELEM(layer_mode))      /*      Px=pixel, Ax=alpha [0-1], Rx,Gx,Bx, Hx,Sx,Vx = kanaler   Xs=källbild   Xl=aktuellt lager   Xd=målbild
pike.git/src/modules/Image/layers.c:416:   red Pd=Ps,Rd=(Rl*Al+Rs*(1-Al)*As)/(Al+(1-Al)*As)   green Pd=Ps,Gd=(Gl*Al+Gs*(1-Al)*As)/(Al+(1-Al)*As)   blue Pd=Ps,Bd=(Bl*Al+Bs*(1-Al)*As)/(Al+(1-Al)*As)      replace_hsv same as replace, but r,g,b alpha is operating on h,s,v   hue Pd=Ps,Hd=(Hl*Al+Hs*(1-Al)*As)/(Al+(1-Al)*As)   saturation Pd=Ps,Sd=(Sl*Al+Ss*(1-Al)*As)/(Al+(1-Al)*As)   value Pd=Ps,Vd=(Vl*Al+Vs*(1-Al)*As)/(Al+(1-Al)*As)   color Vd=Vs,HSd=(HSl*Al+HSs*(1-Al)*As)/(Al+(1-Al)*As)    - darken Pd=Ps,Vd=min(Vs,Vl) +    lighten Pd=Ps,Vd=max(Vs,Vl) -  + darken Pd=Ps,Vd=min(Vs,Vl) + saturate Pd=Ps,Vd=max(Ss,Sl) + desaturate Pd=Ps,Vd=min(Ss,Sl)         special layers:      dissolve i=round(random(Al)) typ    Pd=Al*i+As*(1-i)    Ad=i+As      erase Pd=Ps    Ad=As*(1-Al)
pike.git/src/modules/Image/layers.c:1640:    double sh,ss,sv; \    double dh,ds,dv; \    rgb_to_hsv((S),&sh,&ss,&sv); \    rgb_to_hsv((L),&lh,&ls,&lv); \    hsv_to_rgb(sh,ss,MAXIMUM(sv,lv),&(D)); \    } while (0)   #include "layer_channel.h"   #undef L_CHANNEL_DO_V   #undef LM_FUNC    + /* saturate: max s */ +  + #define LM_FUNC lm_saturate + #define L_CHANNEL_DO_V(S,L,D,A,V) \ +  do { \ +  double lh,ls,lv; \ +  double sh,ss,sv; \ +  double dh,ds,dv; \ +  rgb_to_hsv((S),&sh,&ss,&sv); \ +  rgb_to_hsv((L),&lh,&ls,&lv); \ +  hsv_to_rgb(sh,MAXIMUM(ss,ls),sv,&(D)); \ +  } while (0) + #include "layer_channel.h" + #undef L_CHANNEL_DO_V + #undef LM_FUNC +  + /* desaturate: min s */ +  + #define LM_FUNC lm_desaturate + #define L_CHANNEL_DO_V(S,L,D,A,V) \ +  do { \ +  double lh,ls,lv; \ +  double sh,ss,sv; \ +  double dh,ds,dv; \ +  rgb_to_hsv((S),&sh,&ss,&sv); \ +  rgb_to_hsv((L),&lh,&ls,&lv); \ +  hsv_to_rgb(sh,MINIMUM(ss,ls),sv,&(D)); \ +  } while (0) + #include "layer_channel.h" + #undef L_CHANNEL_DO_V + #undef LM_FUNC +    /* screen: 255 - ((255-A)*(255-B)/255) */      #define LM_FUNC lm_screen   #define L_TRUNC(X) (X<0?0:(X>255?255:X))   #define L_OPER(A,B) 255 - CCUT((255-A)*(int)(255-B))   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER