e576bb2002-10-11Martin Nilsson /* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. || $Id: layer_oper.h,v 1.10 2002/10/11 01:39:42 nilsson Exp $ */
5e39651999-04-22Mirar (Pontus Hagland) /* template for operator layer row function */
54e0781999-04-24Mirar (Pontus Hagland) static void LM_FUNC(rgb_group *s,rgb_group *l,rgb_group *d, rgb_group *sa,rgb_group *la,rgb_group *da, int len,double alpha) {
a0c6c32001-03-17Mirar (Pontus Hagland)  union { COLORTYPE r,g,b; } tz,*t=&tz;
7383191999-06-21Mirar (Pontus Hagland) #ifndef L_LOGIC
54e0781999-04-24Mirar (Pontus Hagland)  if (alpha==0.0) {
502f1e1999-08-12Per Hedbor #ifdef LAYER_DUAL
54e0781999-04-24Mirar (Pontus Hagland)  MEMCPY(d,s,sizeof(rgb_group)*len); MEMCPY(da,sa,sizeof(rgb_group)*len);
502f1e1999-08-12Per Hedbor #endif
54e0781999-04-24Mirar (Pontus Hagland)  return; } else if (alpha==1.0) {
a0c6c32001-03-17Mirar (Pontus Hagland) #ifdef L_COPY_ALPHA MEMCPY(da,sa,sizeof(rgb_group)*len); #define da da da da /* error */ #endif
54e0781999-04-24Mirar (Pontus Hagland)  if (!la) /* no layer alpha => full opaque */
726c7a1999-08-12Mirar (Pontus Hagland)  { #ifdef L_MMX_OPER #ifdef TRY_USE_MMX extern int try_use_mmx; if(try_use_mmx) { int num=sizeof(rgb_group) * len; unsigned char *source=(char *)s; unsigned char *dest=(char *)d; unsigned char *sourcel=(char *)l; while (num-->0 && (7&(int)dest)) { *dest=L_TRUNC(L_OPER(*source,*sourcel)); source++; sourcel++; dest++; } while(num > 16) {
8223ea1999-08-13Per Hedbor  movq_m2r(*source, mm0); source+=8; movq_m2r(*source, mm1); source += 8;
726c7a1999-08-12Mirar (Pontus Hagland)  L_MMX_OPER(*sourcel, mm0);
8223ea1999-08-13Per Hedbor  sourcel+=8; L_MMX_OPER(*sourcel, mm1); sourcel+=8; movq_r2m(mm0,*dest); dest += 8; movq_r2m(mm1,*dest); dest += 8; num-=16;
726c7a1999-08-12Mirar (Pontus Hagland)  }
8223ea1999-08-13Per Hedbor 
726c7a1999-08-12Mirar (Pontus Hagland)  if (num > 8) { movq_m2r(*source, mm0); L_MMX_OPER(*sourcel, mm0); movq_r2m(mm0,*dest); source+=8; sourcel+=8; dest+=8; num-=8; }
8223ea1999-08-13Per Hedbor 
726c7a1999-08-12Mirar (Pontus Hagland)  emms(); while (num-->0) { *dest=L_TRUNC(L_OPER(*source,*sourcel)); source++; sourcel++; dest++; } } else #endif #endif while (len--) { d->r=L_TRUNC(L_OPER(s->r,l->r)); d->g=L_TRUNC(L_OPER(s->g,l->g)); d->b=L_TRUNC(L_OPER(s->b,l->b));
a0c6c32001-03-17Mirar (Pontus Hagland) #ifndef L_COPY_ALPHA *da=white; da++; #endif l++; s++; sa++; d++;
726c7a1999-08-12Mirar (Pontus Hagland)  } }
54e0781999-04-24Mirar (Pontus Hagland)  else while (len--) { if (la->r==COLORMAX && la->g==COLORMAX && la->b==COLORMAX) { d->r=L_TRUNC(L_OPER(s->r,l->r)); d->g=L_TRUNC(L_OPER(s->g,l->g)); d->b=L_TRUNC(L_OPER(s->b,l->b));
a0c6c32001-03-17Mirar (Pontus Hagland) #ifndef L_COPY_ALPHA
54e0781999-04-24Mirar (Pontus Hagland) #ifdef L_USE_SA *da=*sa;
7383191999-06-21Mirar (Pontus Hagland) #else *da=white;
a0c6c32001-03-17Mirar (Pontus Hagland) #endif
54e0781999-04-24Mirar (Pontus Hagland) #endif } else if (la->r==0 && la->g==0 && la->b==0) { *d=*s;
a0c6c32001-03-17Mirar (Pontus Hagland) #ifndef L_COPY_ALPHA
54e0781999-04-24Mirar (Pontus Hagland)  *da=*sa;
a0c6c32001-03-17Mirar (Pontus Hagland) #endif
54e0781999-04-24Mirar (Pontus Hagland)  } else {
a0c6c32001-03-17Mirar (Pontus Hagland) #ifndef L_COPY_ALPHA t->r=L_TRUNC(L_OPER(s->r,l->r)); ALPHA_ADD(s,t,d,sa,la,da,r); t->g=L_TRUNC(L_OPER(s->g,l->g)); ALPHA_ADD(s,t,d,sa,la,da,g); t->b=L_TRUNC(L_OPER(s->b,l->b)); ALPHA_ADD(s,t,d,sa,la,da,b);
54e0781999-04-24Mirar (Pontus Hagland) #ifdef L_USE_SA *da=*sa;
a0c6c32001-03-17Mirar (Pontus Hagland) #endif #else t->r=L_TRUNC(L_OPER(s->r,l->r)); ALPHA_ADD_nA(s,t,d,sa,la,da,r); t->g=L_TRUNC(L_OPER(s->g,l->g)); ALPHA_ADD_nA(s,t,d,sa,la,da,g); t->b=L_TRUNC(L_OPER(s->b,l->b)); ALPHA_ADD_nA(s,t,d,sa,la,da,b);
54e0781999-04-24Mirar (Pontus Hagland) #endif }
a0c6c32001-03-17Mirar (Pontus Hagland)  l++; s++; la++; sa++; d++; #ifndef L_COPY_ALPHA da++; #endif
54e0781999-04-24Mirar (Pontus Hagland)  } } else {
a0c6c32001-03-17Mirar (Pontus Hagland) #ifdef L_COPY_ALPHA #undef da MEMCPY(da,sa,sizeof(rgb_group)*len); #define da da da #endif
54e0781999-04-24Mirar (Pontus Hagland)  if (!la) /* no layer alpha => full opaque */ while (len--) {
a0c6c32001-03-17Mirar (Pontus Hagland) #ifndef L_COPY_ALPHA t->r=L_TRUNC(L_OPER(s->r,l->r)); ALPHA_ADD_V_NOLA(s,t,d,sa,da,alpha,r); t->g=L_TRUNC(L_OPER(s->g,l->g)); ALPHA_ADD_V_NOLA(s,t,d,sa,da,alpha,g); t->b=L_TRUNC(L_OPER(s->b,l->b)); ALPHA_ADD_V_NOLA(s,t,d,sa,da,alpha,b);
54e0781999-04-24Mirar (Pontus Hagland) #ifdef L_USE_SA *da=*sa; #endif
a0c6c32001-03-17Mirar (Pontus Hagland)  da++; #else t->r=L_TRUNC(L_OPER(s->r,l->r)); ALPHA_ADD_V_NOLA_nA(s,t,d,sa,da,alpha,r); t->g=L_TRUNC(L_OPER(s->g,l->g)); ALPHA_ADD_V_NOLA_nA(s,t,d,sa,da,alpha,g); t->b=L_TRUNC(L_OPER(s->b,l->b)); ALPHA_ADD_V_NOLA_nA(s,t,d,sa,da,alpha,b); #endif l++; s++; sa++; d++;
54e0781999-04-24Mirar (Pontus Hagland)  } else while (len--) {
a0c6c32001-03-17Mirar (Pontus Hagland) #ifndef L_COPY_ALPHA t->r=L_TRUNC(L_OPER(s->r,l->r)); ALPHA_ADD_V(s,t,d,sa,la,da,alpha,r); t->g=L_TRUNC(L_OPER(s->g,l->g)); ALPHA_ADD_V(s,t,d,sa,la,da,alpha,g); t->b=L_TRUNC(L_OPER(s->b,l->b)); ALPHA_ADD_V(s,t,d,sa,la,da,alpha,b);
54e0781999-04-24Mirar (Pontus Hagland) #ifdef L_USE_SA *da=*sa; #endif
a0c6c32001-03-17Mirar (Pontus Hagland)  da++; #else t->r=L_TRUNC(L_OPER(s->r,l->r)); ALPHA_ADD_V_nA(s,t,d,sa,la,da,alpha,r); t->g=L_TRUNC(L_OPER(s->g,l->g)); ALPHA_ADD_V_nA(s,t,d,sa,la,da,alpha,g); t->b=L_TRUNC(L_OPER(s->b,l->b)); ALPHA_ADD_V_nA(s,t,d,sa,la,da,alpha,b); #undef da #endif l++; s++; la++; sa++; d++;
54e0781999-04-24Mirar (Pontus Hagland)  } }
7383191999-06-21Mirar (Pontus Hagland) #else /* L_LOGIC */
5e39651999-04-22Mirar (Pontus Hagland)  if (alpha==0.0) {
7383191999-06-21Mirar (Pontus Hagland)  smear_color(d,L_TRANS,len); smear_color(da,L_TRANS,len);
5e39651999-04-22Mirar (Pontus Hagland)  return; }
7383191999-06-21Mirar (Pontus Hagland)  else
5e39651999-04-22Mirar (Pontus Hagland)  { if (!la) /* no layer alpha => full opaque */ while (len--) {
7383191999-06-21Mirar (Pontus Hagland)  *da=*d=L_LOGIC(L_OPER(s->r,l->r), L_OPER(s->g,l->g), L_OPER(s->b,l->b));
a0c6c32001-03-17Mirar (Pontus Hagland)  l++; s++; sa++; d++; da++;
5e39651999-04-22Mirar (Pontus Hagland)  } else while (len--) {
7383191999-06-21Mirar (Pontus Hagland)  if (la->r==0 && la->g==0 && la->b==0)
a0c6c32001-03-17Mirar (Pontus Hagland)  *da=*d=L_TRANS;
7383191999-06-21Mirar (Pontus Hagland)  else *da=*d=L_LOGIC(L_OPER(s->r,l->r), L_OPER(s->g,l->g), L_OPER(s->b,l->b));
a0c6c32001-03-17Mirar (Pontus Hagland)  l++; s++; la++; sa++; d++; da++;
5e39651999-04-22Mirar (Pontus Hagland)  } }
7383191999-06-21Mirar (Pontus Hagland) #endif /* L_LOGIC */
5e39651999-04-22Mirar (Pontus Hagland) }