448c201999-04-13Mirar (Pontus Hagland) /* $Id: blit_layer_include.h,v 1.6 1999/04/13 12:32:11 mirar Exp $ */
c378911997-03-20Mirar (Pontus Hagland) /* included w/ defines in blit.c, image_add_layer() */
4ce7411997-05-29Mirar (Pontus Hagland) /* **! module Image **! note
448c201999-04-13Mirar (Pontus Hagland) **! $Id: blit_layer_include.h,v 1.6 1999/04/13 12:32:11 mirar Exp $ **! class Image
4ce7411997-05-29Mirar (Pontus Hagland) */
c378911997-03-20Mirar (Pontus Hagland)  i=(y2-y1+1); while (i--) { j=(x2-x1+1); while (j--) { rgb_group rgb; struct img_layer *lr=layer; rgb=*s; for (l=0; l<layers; l++,lr++)
64f1361997-03-25Mirar (Pontus Hagland)  if (lr->opaque!=0)
c378911997-03-20Mirar (Pontus Hagland)  { #ifndef ALL_IS_NOP if (lr->method==LAYER_NOP) { #endif #ifndef ALL_HAVE_MASK if (lr->m) /* mask */ { #endif
64f1361997-03-25Mirar (Pontus Hagland) #ifndef ALL_HAVE_OPAQUE_255 if (lr->opaque==255) /* only mask */
c378911997-03-20Mirar (Pontus Hagland)  { #endif if (lr->m->r==255) rgb.r=lr->s->r; else if (lr->m->r!=0) rgb.r=(unsigned char) ((rgb.r*(255-lr->m->r) +lr->s->r*lr->m->r)*q); if (lr->m->g==255) rgb.g=lr->s->g; else if (lr->m->g!=0) rgb.g=(unsigned char) ((rgb.g*(255-lr->m->g) +lr->s->g*lr->m->g)*q); if (lr->m->b==255) rgb.b=lr->s->b; else if (lr->m->b!=0) rgb.b=(unsigned char) ((rgb.b*(255-lr->m->b) +lr->s->b*lr->m->b)*q);
64f1361997-03-25Mirar (Pontus Hagland) #ifndef ALL_HAVE_OPAQUE_255
c378911997-03-20Mirar (Pontus Hagland)  }
64f1361997-03-25Mirar (Pontus Hagland)  else /* opaque and mask */
c378911997-03-20Mirar (Pontus Hagland)  { rgb.r=(unsigned char)
64f1361997-03-25Mirar (Pontus Hagland)  ((rgb.r*(255*255-lr->m->r*lr->opaque) +lr->s->r*lr->m->r*lr->opaque)*q2);
c378911997-03-20Mirar (Pontus Hagland)  rgb.g=(unsigned char)
64f1361997-03-25Mirar (Pontus Hagland)  ((rgb.g*(255*255-lr->m->g*lr->opaque) +lr->s->g*lr->m->g*lr->opaque)*q2);
c378911997-03-20Mirar (Pontus Hagland)  rgb.b=(unsigned char)
64f1361997-03-25Mirar (Pontus Hagland)  ((rgb.b*(255*255-lr->m->b*lr->opaque) +lr->s->b*lr->m->b*lr->opaque)*q2);
c378911997-03-20Mirar (Pontus Hagland)  } #endif lr->m++; #ifndef ALL_HAVE_MASK } else /* no mask */ {
64f1361997-03-25Mirar (Pontus Hagland) #ifndef ALL_HAVE_OPAQUE_255 if (lr->opaque==255) /* no opaque (bam!) */
c378911997-03-20Mirar (Pontus Hagland) #endif rgb=lr->s[0];
64f1361997-03-25Mirar (Pontus Hagland) #ifndef ALL_HAVE_OPAQUE_255 else /* only opaque */
c378911997-03-20Mirar (Pontus Hagland)  { rgb.r=(unsigned char)
64f1361997-03-25Mirar (Pontus Hagland)  ((rgb.r*(255-lr->opaque) +lr->s->r*lr->opaque)*q);
c378911997-03-20Mirar (Pontus Hagland)  rgb.g=(unsigned char)
64f1361997-03-25Mirar (Pontus Hagland)  ((rgb.g*(255-lr->opaque) +lr->s->g*lr->opaque)*q);
c378911997-03-20Mirar (Pontus Hagland)  rgb.b=(unsigned char)
64f1361997-03-25Mirar (Pontus Hagland)  ((rgb.b*(255-lr->opaque) +lr->s->b*lr->opaque)*q);
c378911997-03-20Mirar (Pontus Hagland)  } #endif } #endif #ifndef ALL_IS_NOP } else { rgb_group res; if (!lr->m || lr->m->r || lr->m->g || lr->m->b) switch (lr->method) { case LAYER_MAX:
75920f1997-12-28Fredrik Hübinette (Hubbe)  res.r=MAXIMUM(lr->s->r,rgb.r); res.g=MAXIMUM(lr->s->g,rgb.g); res.b=MAXIMUM(lr->s->b,rgb.b);
c378911997-03-20Mirar (Pontus Hagland)  break; case LAYER_MIN:
75920f1997-12-28Fredrik Hübinette (Hubbe)  res.r=MINIMUM(lr->s->r,rgb.r); res.g=MINIMUM(lr->s->g,rgb.g); res.b=MINIMUM(lr->s->b,rgb.b);
c378911997-03-20Mirar (Pontus Hagland)  break; case LAYER_ADD:
75920f1997-12-28Fredrik Hübinette (Hubbe)  res.r=(unsigned char)MAXIMUM(255,(lr->s->r+rgb.r)); res.g=(unsigned char)MAXIMUM(255,(lr->s->g+rgb.g)); res.b=(unsigned char)MAXIMUM(255,(lr->s->b+rgb.b));
c378911997-03-20Mirar (Pontus Hagland)  break; case LAYER_MULT: res.r=(unsigned char)((lr->s->r*rgb.r)*q); res.g=(unsigned char)((lr->s->g*rgb.g)*q); res.b=(unsigned char)((lr->s->b*rgb.b)*q); break; case LAYER_DIFF: res.r=absdiff(lr->s->r,rgb.r); res.g=absdiff(lr->s->g,rgb.g); res.b=absdiff(lr->s->b,rgb.b); break; default: res=rgb; } else res=rgb; #ifndef ALL_HAVE_MASK if (lr->m) /* mask */ { #endif
64f1361997-03-25Mirar (Pontus Hagland) #ifndef ALL_HAVE_OPAQUE_255 if (lr->opaque==255) /* only mask */
c378911997-03-20Mirar (Pontus Hagland)  { #endif if (lr->m->r==255) rgb.r=res.r; else if (lr->m->r!=0) rgb.r=(unsigned char) ((rgb.r*(255-lr->m->r) +res.r*lr->m->r)*q); if (lr->m->g==255) rgb.g=res.g; else if (lr->m->g!=0) rgb.g=(unsigned char) ((rgb.g*(255-lr->m->g) +res.g*lr->m->g)*q); if (lr->m->b==255) rgb.b=res.b; else if (lr->m->b!=0) rgb.b=(unsigned char) ((rgb.b*(255-lr->m->b) +res.b*lr->m->b)*q);
64f1361997-03-25Mirar (Pontus Hagland) #ifndef ALL_HAVE_OPAQUE_255
c378911997-03-20Mirar (Pontus Hagland)  }
64f1361997-03-25Mirar (Pontus Hagland)  else /* opaque and mask */
c378911997-03-20Mirar (Pontus Hagland)  { rgb.r=(unsigned char)
64f1361997-03-25Mirar (Pontus Hagland)  ((rgb.r*(255*255-lr->m->r*lr->opaque) +res.r*lr->m->r*lr->opaque)*q2);
c378911997-03-20Mirar (Pontus Hagland)  rgb.g=(unsigned char)
64f1361997-03-25Mirar (Pontus Hagland)  ((rgb.g*(255*255-lr->m->g*lr->opaque) +res.g*lr->m->g*lr->opaque)*q2);
c378911997-03-20Mirar (Pontus Hagland)  rgb.b=(unsigned char)
64f1361997-03-25Mirar (Pontus Hagland)  ((rgb.b*(255*255-lr->m->b*lr->opaque) +res.b*lr->m->b*lr->opaque)*q2);
c378911997-03-20Mirar (Pontus Hagland)  } #endif lr->m++; #ifndef ALL_HAVE_MASK } else /* no mask */ {
64f1361997-03-25Mirar (Pontus Hagland) #ifndef ALL_HAVE_OPAQUE_255 if (lr->opaque==255) /* no opaque (bam!) */
c378911997-03-20Mirar (Pontus Hagland) #endif rgb=res;
64f1361997-03-25Mirar (Pontus Hagland) #ifndef ALL_HAVE_OPAQUE_255 else /* only opaque */
c378911997-03-20Mirar (Pontus Hagland)  { rgb.r=(unsigned char)
64f1361997-03-25Mirar (Pontus Hagland)  ((rgb.r*(255-lr->opaque) +res.r*lr->opaque)*q);
c378911997-03-20Mirar (Pontus Hagland)  rgb.g=(unsigned char)
64f1361997-03-25Mirar (Pontus Hagland)  ((rgb.g*(255-lr->opaque) +res.g*lr->opaque)*q);
c378911997-03-20Mirar (Pontus Hagland)  rgb.b=(unsigned char)
64f1361997-03-25Mirar (Pontus Hagland)  ((rgb.b*(255-lr->opaque) +res.b*lr->opaque)*q);
c378911997-03-20Mirar (Pontus Hagland)  } #endif } #endif } #endif lr->s++; } *(d++)=rgb; s++; } s+=mod; for (l=0; l<layers; l++) { layer[l].s+=mod; if (layer[l].m) layer[l].m+=mod; } }