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.46 2000/08/05 11:07:31 grubba Exp $ + **! $Id: layers.c,v 1.47 2000/08/05 23:47:27 grubba Exp $   **! class Layer   **! see also: layers   **!      **!   **!   **! <add_appendix name="layers" title="Image.Layer modes">   **! <dl compact>   **! <dt><i>The variables in the expression:</i>   **! <dt>L<dd><i>The active layer</i>
pike.git/src/modules/Image/layers.c:208:   **! }   **!   **! </execute>   **! </add_appendix>   */      #include "global.h"      #include <math.h> /* floor */    - RCSID("$Id: layers.c,v 1.46 2000/08/05 11:07:31 grubba Exp $"); + RCSID("$Id: layers.c,v 1.47 2000/08/05 23:47:27 grubba 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:487:      /*** layer helpers ****************************************/      #define COMBINE_METHOD_INT   #define CCUT_METHOD_INT      #define qMAX (1.0/COLORMAX)   #define C2F(Z) (qMAX*(Z))      #ifdef CCUT_METHOD_FLOAT - #define CCUT(Z) ((COLORTYPE)(qMAX*Z)) + #define CCUT(Z) (DOUBLE_TO_COLORTYPE(qMAX*Z))   #else /* CCUT_METHOD_INT */ - #define CCUT(Z) ((COLORTYPE)((Z)/COLORMAX)) + #define CCUT(Z) (DOUBLE_TO_COLORTYPE((Z)/COLORMAX))   #endif      #ifdef COMBINE_METHOD_INT         #define COMBINE_ALPHA_SUM(aS,aL) \ -  CCUT((COLORMAX*(int)(aL))+(COLORMAX-(int)(aL))*(aS)) +  CCUT((COLORMAX*DOUBLE_TO_INT(aL))+(COLORMAX-DOUBLE_TO_INT(aL))*(aS))   #define COMBINE_ALPHA_SUM_V(aS,aL,V) \    COMBINE_ALPHA_SUM(aS,(aL)*(V))      #define COMBINE_ALPHA(S,L,aS,aL) \ -  ( (COLORTYPE)((((S)*((int)(COLORMAX-(aL)))*(aS))+ \ -  ((L)*((int)(aL))*COLORMAX))/ \ -  (((COLORMAX*(int)(aL))+(COLORMAX-(int)(aL))*(aS))) ) ) +  ( (COLORTYPE)((((S)*(DOUBLE_TO_INT(COLORMAX-(aL)))*(aS))+ \ +  ((L)*(DOUBLE_TO_INT(aL))*COLORMAX))/ \ +  (((COLORMAX*DOUBLE_TO_INT(aL))+(COLORMAX-DOUBLE_TO_INT(aL))*(aS))) ) )      #define COMBINE_ALPHA_V(S,L,aS,aL,V) \    COMBINE_ALPHA((S),(L),(aS),((aL)*(V)))      #else   #ifdef COMBINE_METHOD_FLOAT      #define COMBINE_ALPHA(S,L,aS,aL) \    ( (COLORTYPE)( ( (S)*(1.0-C2F(aL))*C2F(aS) + (L)*C2F(aL) ) / \    ( (C2F(aL)+(1-C2F(aL))*C2F(aS))) ) )
pike.git/src/modules/Image/layers.c:530:   #define COMBINE_ALPHA_SUM_V(aS,aL,V) \    COMBINE_ALPHA_SUM(aS,(aL)*(V))      #else /* unknown COMBINE_METHOD */   #error unknown COMBINE_METHOD   #endif /* COMBINE_METHOD_FLOAT */      #endif      #define COMBINE(P,A) CCUT((DOUBLE_TO_INT(P))*(A)) - #define COMBINE_A(P,A) ((COLORTYPE)((P)*(A))) + #define COMBINE_A(P,A) (DOUBLE_TO_COLORTYPE((P)*(A)))   #define COMBINE_V(P,V,A) CCUT((V)*(P)*(A))    - #define F2C(Z) ((COLORTYPE)DOUBLE_TO_INT(COLORMAX*(Z))) + #define F2C(Z) (DOUBLE_TO_COLORTYPE(COLORMAX*(Z)))      #define ALPHA_ADD(S,L,D,SA,LA,DA,C) \    if (!(LA)->C) (D)->C=(S)->C,(DA)->C=(SA)->C; \    else if (!(SA)->C) (D)->C=(L)->C,(DA)->C=(LA)->C; \    else if ((LA)->C==COLORMAX) (D)->C=(L)->C,(DA)->C=(LA)->C; \    else \    (D)->C=COMBINE_ALPHA((S)->C,(L)->C,(SA)->C,(LA)->C), \    (DA)->C=COMBINE_ALPHA_SUM((SA)->C,(LA)->C);      #define ALPHA_ADD_V_NOLA(L,S,D,SA,DA,V,C) \
pike.git/src/modules/Image/layers.c:1409:      #define LM_FUNC lm_divide   #define L_TRUNC(X) MINIMUM(255,(X))   #define L_OPER(A,B) ((A)/C2F(1+DOUBLE_TO_INT(B)))   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_modulo - #define L_TRUNC(X) ((COLORTYPE)(X)) + #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X))   #define L_OPER(A,B) ((A)%((B)?(B):1))   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define L_USE_SA      #define LM_FUNC lm_invsubtract   #define L_TRUNC(X) MAXIMUM(0,(X))
pike.git/src/modules/Image/layers.c:1435:      #define LM_FUNC lm_invdivide   #define L_TRUNC(X) MINIMUM(255,(X))   #define L_OPER(A,B) ((B)/C2F(1+DOUBLE_TO_INT(A)))   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_invmodulo - #define L_TRUNC(X) ((COLORTYPE)(X)) + #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X))   #define L_OPER(A,B) ((B)%((A)?(A):1))   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #undef L_USE_SA      #define LM_FUNC lm_difference - #define L_TRUNC(X) ((COLORTYPE)(X)) + #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X))   #define L_OPER(A,B) abs((A)-(B))   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_max - #define L_TRUNC(X) ((COLORTYPE)(X)) + #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X))   #define L_OPER(A,B) MAXIMUM((A),(B))   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_min - #define L_TRUNC(X) ((COLORTYPE)(X)) + #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X))   #define L_OPER(A,B) MINIMUM((A),(B))   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_bitwise_and - #define L_TRUNC(X) ((COLORTYPE)(X)) + #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X))   #define L_OPER(A,B) ((A)&(B))   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_bitwise_or - #define L_TRUNC(X) ((COLORTYPE)(X)) + #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X))   #define L_OPER(A,B) ((A)|(B))   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_bitwise_xor - #define L_TRUNC(X) ((COLORTYPE)(X)) + #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X))   #define L_OPER(A,B) ((A)^(B))   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_equal - #define L_TRUNC(X) ((COLORTYPE)(X)) + #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X))   #define L_OPER(A,B) (((A)==(B))?COLORMAX:0)   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_not_equal - #define L_TRUNC(X) ((COLORTYPE)(X)) + #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X))   #define L_OPER(A,B) (((A)!=(B))?COLORMAX:0)   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_less - #define L_TRUNC(X) ((COLORTYPE)(X)) + #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X))   #define L_OPER(A,B) (((A)>(B))?COLORMAX:0)   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_more - #define L_TRUNC(X) ((COLORTYPE)(X)) + #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X))   #define L_OPER(A,B) (((A)<(B))?COLORMAX:0)   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_less_or_equal - #define L_TRUNC(X) ((COLORTYPE)(X)) + #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X))   #define L_OPER(A,B) (((A)>=(B))?COLORMAX:0)   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_more_or_equal - #define L_TRUNC(X) ((COLORTYPE)(X)) + #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X))   #define L_OPER(A,B) (((A)<=(B))?COLORMAX:0)   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      /* logic functions */      #define L_LOGIC(A,B,C) (((A)&&(B)&&(C))?white:black)   #define LM_FUNC lm_logic_equal
pike.git/src/modules/Image/layers.c:1992:    da->r=CCUT(sa->r*(int)(COLORMAX-la->r));    da->g=CCUT(sa->g*(int)(COLORMAX-la->g));    da->b=CCUT(sa->b*(int)(COLORMAX-la->b));       la++; sa++; da++;    }    else    if (!la) /* full opaque */    {    rgb_group a; -  a.r=a.g=a.b=COLORMAX-(COLORTYPE)(alpha*COLORMAX); +  a.r=a.g=a.b=COLORMAX-DOUBLE_TO_COLORTYPE(alpha*COLORMAX);    smear_color(da,a,len);    }    else    while (len--)    {    da->r=CCUT(sa->r*(int)(COLORMAX-alpha*la->r));    da->g=CCUT(sa->g*(int)(COLORMAX-alpha*la->g));    da->b=CCUT(sa->b*(int)(COLORMAX-alpha*la->b));       la++; sa++; da++;
pike.git/src/modules/Image/layers.c:2086:    {    double alpha=ly->alpha_value;    while (len--)    {    if ((s->r==COLORMAX &&    s->g==COLORMAX &&    s->b==COLORMAX)    || !l)    {    *d=*s; -  da->r=MINIMUM(sa->r+(COLORTYPE)(alpha*la->r),COLORMAX); -  da->g=MINIMUM(sa->g+(COLORTYPE)(alpha*la->g),COLORMAX); -  da->b=MINIMUM(sa->b+(COLORTYPE)(alpha*la->b),COLORMAX); +  da->r=MINIMUM(sa->r+DOUBLE_TO_COLORTYPE(alpha*la->r),COLORMAX); +  da->g=MINIMUM(sa->g+DOUBLE_TO_COLORTYPE(alpha*la->g),COLORMAX); +  da->b=MINIMUM(sa->b+DOUBLE_TO_COLORTYPE(alpha*la->b),COLORMAX);    }    else    { -  d->r=s->r+(COLORTYPE)(alpha*l->r); -  d->g=s->g+(COLORTYPE)(alpha*l->g); -  d->b=s->b+(COLORTYPE)(alpha*l->b); +  d->r=s->r+DOUBLE_TO_COLORTYPE(alpha*l->r); +  d->g=s->g+DOUBLE_TO_COLORTYPE(alpha*l->g); +  d->b=s->b+DOUBLE_TO_COLORTYPE(alpha*l->b);    -  da->r=MINIMUM(sa->r+(COLORTYPE)(alpha*l->r),COLORMAX); -  da->g=MINIMUM(sa->g+(COLORTYPE)(alpha*l->g),COLORMAX); -  da->b=MINIMUM(sa->b+(COLORTYPE)(alpha*l->b),COLORMAX); +  da->r=MINIMUM(sa->r+DOUBLE_TO_COLORTYPE(alpha*l->r),COLORMAX); +  da->g=MINIMUM(sa->g+DOUBLE_TO_COLORTYPE(alpha*l->g),COLORMAX); +  da->b=MINIMUM(sa->b+DOUBLE_TO_COLORTYPE(alpha*l->b),COLORMAX);    }    da++; sa++; la++; s++; d++;    }    }   }      /*** the add-layer function ***************************/      static INLINE void img_lay_first_line(struct layer *l,    int xoffs,int xsize,