Ejemplo n.º 1
0
        unsafe private static void Resample1D(BitmapBase bmpDest, BitmapBase bmpSrc, int transparentOffset, ContributorEntry[] contrib, int alongSize, int crossSize, bool horz)
        {
            using (bmpSrc.UseRead())
                using (bmpDest.UseWrite())
                {
                    byte *srcBytes = bmpSrc.Data + transparentOffset;
                    for (int crossCoord = 0; crossCoord < crossSize; ++crossCoord)
                    {
                        for (int alongCoord = 0; alongCoord < alongSize; ++alongCoord)
                        {
                            for (int channel = 0; channel < 4; ++channel)
                            {
                                double intensity = 0;
                                double wsum      = 0;

                                for (int j = 0; j < contrib[alongCoord].SrcPixelCount; j++)
                                {
                                    int    contribCoord  = contrib[alongCoord].SrcPixel[j].Coord;
                                    int    contribOffset = (horz ? contribCoord : crossCoord) * 4 + (horz ? crossCoord : contribCoord) * bmpSrc.Stride;
                                    double weight        = contrib[alongCoord].SrcPixel[j].Weight;

                                    if (channel != 3)
                                    {
                                        weight *= srcBytes[contribOffset + 3] / 255d;
                                    }

                                    if (weight == 0)
                                    {
                                        continue;
                                    }

                                    wsum      += weight;
                                    intensity += srcBytes[contribOffset + channel] * weight;
                                }

                                bmpDest.Data[(horz ? alongCoord : crossCoord) * 4 + (horz ? crossCoord : alongCoord) * bmpDest.Stride + channel] =
                                    (byte)Math.Min(Math.Max(intensity / wsum, byte.MinValue), byte.MaxValue);
                            }
                        }
                    }
                }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a new image which contains a 1 pixel wide black outline of the specified image.
        /// </summary>
        public void GetOutline(BitmapBase result, Color color, int threshold, bool inside)
        {
            const byte outside = 0;

            using (UseRead())
                using (result.UseWrite())
                {
                    var  src = Data;
                    var  tgt = result.Data;
                    byte cr = color.R, cg = color.G, cb = color.B, ca = color.A;
                    for (int y = 0; y < Height; y++)
                    {
                        int b    = y * Stride;
                        int left = outside;
                        int cur  = src[b + 0 + 3];
                        int right;
                        for (int x = 0; x < Width; x++, b += 4)
                        {
                            right = x == Width - 1 ? outside : src[b + 4 + 3];
                            if ((src[b + 3] <= threshold) ^ inside)
                            {
                                if (
                                    ((left > threshold) ^ inside) ||
                                    ((right > threshold) ^ inside) ||
                                    (((y == 0 ? outside : src[b - Stride + 3]) > threshold) ^ inside) ||
                                    (((y == Height - 1 ? outside : src[b + Stride + 3]) > threshold) ^ inside)
                                    )
                                {
                                    tgt[b]     = cb;
                                    tgt[b + 1] = cg;
                                    tgt[b + 2] = cr;
                                    tgt[b + 3] = ca;
                                }
                            }
                            left = cur;
                            cur  = right;
                        }
                    }
                }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Returns a new image which contains a 1 pixel wide black outline of the specified image.
 /// </summary>
 public void GetOutline(BitmapBase result, Color color, int threshold, bool inside)
 {
     const byte outside = 0;
     using (UseRead())
     using (result.UseWrite())
     {
         var src = Data;
         var tgt = result.Data;
         byte cr = color.R, cg = color.G, cb = color.B, ca = color.A;
         for (int y = 0; y < Height; y++)
         {
             int b = y * Stride;
             int left = outside;
             int cur = src[b + 0 + 3];
             int right;
             for (int x = 0; x < Width; x++, b += 4)
             {
                 right = x == Width - 1 ? outside : src[b + 4 + 3];
                 if ((src[b + 3] <= threshold) ^ inside)
                 {
                     if (
                         ((left > threshold) ^ inside) ||
                         ((right > threshold) ^ inside) ||
                         (((y == 0 ? outside : src[b - Stride + 3]) > threshold) ^ inside) ||
                         (((y == Height - 1 ? outside : src[b + Stride + 3]) > threshold) ^ inside)
                     )
                     {
                         tgt[b] = cb;
                         tgt[b + 1] = cg;
                         tgt[b + 2] = cr;
                         tgt[b + 3] = ca;
                     }
                 }
                 left = cur;
                 cur = right;
             }
         }
     }
 }