Пример #1
0
        internal void NormalizeFrom(ImageFileInfo img)
        {
            Contract.Requires <InvalidOperationException>(Width >= 0 && Height >= 0, "Width and Height cannot be negative");
            Contract.Requires <InvalidOperationException>(ResizeMode == CropScaleMode.Crop || (Width > 0 && Height > 0), "Width and Height must be > 0 with Stretch and Max Modes");
            Contract.Assert(FrameIndex < img.Frames.Length || img.Frames.Length + FrameIndex < 0, "Invalid FrameIndex");

            if (FrameIndex < 0)
            {
                FrameIndex = img.Frames.Length + FrameIndex;
            }

            var frame = img.Frames[FrameIndex];

            if (SaveFormat == FileFormat.Auto)
            {
                if (img.ContainerType == FileFormat.Gif)                 // Restrict to animated only?
                {
                    SaveFormat = FileFormat.Gif;
                }
                else if (img.ContainerType == FileFormat.Png || (frame.HasAlpha && MatteColor.A < 255))
                {
                    SaveFormat = FileFormat.Png;
                }
                else
                {
                    SaveFormat = FileFormat.Jpeg;
                }
            }

            if (SaveFormat != FileFormat.Jpeg)
            {
                JpegSubsampleMode = ChromaSubsampleMode.Default;
                JpegQuality       = 0;
            }

            if (!frame.HasAlpha)
            {
                MatteColor = Color.Empty;
            }

            if (!Sharpen)
            {
                UnsharpMask = UnsharpMaskSettings.None;
            }

            Fixup(frame.Width, frame.Height, frame.Rotated90);

            imageInfo = img;
        }
Пример #2
0
 public UnsharpMaskTransform(PixelSource source, KernelMap <TWeight> mapx, KernelMap <TWeight> mapy, UnsharpMaskSettings ss) : base(source, mapx, mapy, true)
 {
     sharpenSettings = ss;
     processor       = ProcessorMap[Format.FormatGuid];
     blurBuff        = new ArraySegment <byte>(ArrayPool <byte> .Shared.Rent(WorkStride), 0, WorkStride);
 }
Пример #3
0
 public WicUnsharpMask16bpc(IWICBitmapSource source, KernelMap mapx, KernelMap mapy, UnsharpMaskSettings ss) : base(source, mapx, mapy, true)
 {
     sharpenSettings = ss;
     blurBuff        = new ushort[Stride];
 }
        internal void NormalizeFrom(ImageFileInfo img)
        {
            if (Width < 0 || Height < 0)
            {
                throw new InvalidOperationException($"{nameof(Width)} and {nameof(Height)} cannot be negative");
            }
            if (Width == 0 && Height == 0)
            {
                throw new InvalidOperationException($"{nameof(Width)} and {nameof(Height)} may not both be 0");
            }
            if ((Width == 0 || Height == 0) && ResizeMode != CropScaleMode.Crop)
            {
                throw new InvalidOperationException($"{nameof(Width)} or {nameof(Height)} may only be 0 in {nameof(CropScaleMode.Crop)} mode");
            }
            if (FrameIndex >= img.Frames.Length || img.Frames.Length + FrameIndex < 0)
            {
                throw new InvalidOperationException($"Invalid {nameof(FrameIndex)}");
            }

            if (FrameIndex < 0)
            {
                FrameIndex = img.Frames.Length + FrameIndex;
            }

            var frame = img.Frames[FrameIndex];

            if (SaveFormat == FileFormat.Auto)
            {
                if (img.ContainerType == FileFormat.Gif)                 // Restrict to animated only?
                {
                    SaveFormat = FileFormat.Gif;
                }
                else if (img.ContainerType == FileFormat.Png || (frame.HasAlpha && MatteColor.A < byte.MaxValue))
                {
                    SaveFormat = FileFormat.Png;
                }
                else
                {
                    SaveFormat = FileFormat.Jpeg;
                }
            }

            if (SaveFormat != FileFormat.Jpeg)
            {
                JpegSubsampleMode = ChromaSubsampleMode.Default;
                JpegQuality       = 0;
            }

            if (!frame.HasAlpha)
            {
                MatteColor = Color.Empty;
            }

            if (!Sharpen)
            {
                UnsharpMask = UnsharpMaskSettings.None;
            }

            Fixup(frame.Width, frame.Height, frame.Rotated90);

            imageInfo = img;
        }