Пример #1
0
        public Image MinC(Image dst, uint color)
        {
            color &= this.MaxColor;
            if (color == this.MaxColor)
            {
                // nothing to set - simple copy
                return(this.Copy(dst, true));
            }

            // create a copy of this image
            dst = this.Copy(dst, false);

            if (color == 0)
            {
                dst.SetToZero();
            }
            else
            {
                unsafe
                {
                    fixed(ulong *bitssrc = this.Bits, bitsdst = dst.Bits)
                    {
                        switch (this.BitsPerPixel)
                        {
                        case 8:
                            Vectors.MinC(this.Height * this.Stride8, (byte *)bitssrc, (byte)color, (byte *)bitsdst);
                            break;

                        case 16:
                            Vectors.MinC(this.Height * this.Stride8 / sizeof(ushort), (ushort *)bitssrc, (ushort)color, (ushort *)bitsdst);
                            break;

                        case 24:
                        case 32:
                        {
                            byte *ptrsrc  = (byte *)bitssrc;
                            byte *ptrdst  = (byte *)bitsdst;
                            int   stride8 = this.Stride8;

                            fixed(ulong *mask = this.ColorScanline(this.Stride, color))
                            {
                                for (int i = 0, ii = this.Height; i < ii; i++, ptrsrc += stride8, ptrdst += stride8)
                                {
                                    Vectors.Min(stride8, ptrsrc, (byte *)mask, ptrdst);
                                }
                            }
                        }

                        break;

                        default:
                            throw new NotSupportedException(string.Format(
                                                                CultureInfo.InvariantCulture,
                                                                Properties.Resources.E_UnsupportedDepth,
                                                                this.BitsPerPixel));
                        }
                    }
                }
            }

            return(dst);
        }