Photoshop马赛克效果

void _alpha__fastcall_pre_ TAlpha::Mosaic(AlphaPara *Para)
{
 int left;
 int top;
 int right = (left = Para->X) + Para->Width - 1;
 int bottom = (top = Para->Y) + Para->Height - 1;
 int linebytewidth = Para->bmWidthBytes;
 int destheight_1 = Para->bmHeight - 1;
 int pixeladdplus3 = Para->PixelAdd + 3;
 byte *bmBits = Para->bmBits;
 int radius;
 int radius_1;

 if ((radius = *(int *)Para->AdditionalPara) < 2)
  radius = 2;
 else if (radius > 100)
  radius = 100;

 radius_1 = radius - 1;

 for (int x = left; x <= right; x += radius)
  {
   for (int y = top; y <= bottom; y += radius)
    {
     int sumr = 0;
     int sumg = 0;
     int sumb = 0;
     int ri;
     int bo;

     if ((ri = x + radius_1) > right)
      ri = right;
     if ((bo = y + radius_1) > bottom)
      bo = bottom;

     register int i;
     register int j;
     for (j = y; j <= bo; j++)
      {
       byte *bptr = (bmBits + (destheight_1 - j) * linebytewidth) + pixeladdplus3 * x;

       i = ri - x;
       for ( ; i >= 0; i--)
        {
         sumr += *(bptr + 2);
         sumg += *(bptr + 1);
         sumb += *bptr;

         bptr += pixeladdplus3;
        }
      }

     int v;
     byte bsumr = (byte)(sumr /= (v = (ri - x + 1) * (bo - y + 1)));
     byte bsumg = (byte)(sumg /= v);
     byte bsumb = (byte)(sumb /= v);

     for (j = y; j <= bo; j++)
      {
       byte *bptr = (bmBits + (destheight_1 - j) * linebytewidth) + pixeladdplus3 * x;

       i = ri - x;
       for ( ; i >= 0; i--)
        {
         *(bptr + 2) = bsumr;
         *(bptr + 1) = bsumg;
         *bptr = bsumb;

         bptr += pixeladdplus3;
        }
      }
    }
  }
}

你可能感兴趣的:(Photoshop马赛克效果)