Esempio n. 1
0
            public PlanarPipelineContext(PixelSource sourceY, PixelSource sourceCb, PixelSource sourceCr)
            {
                if (sourceY.Format.FormatGuid != Consts.GUID_WICPixelFormat8bppY)
                {
                    throw new ArgumentException("Invalid pixel format", nameof(sourceY));
                }
                if (sourceCb.Format.FormatGuid != Consts.GUID_WICPixelFormat8bppCb)
                {
                    throw new ArgumentException("Invalid pixel format", nameof(sourceCb));
                }
                if (sourceCr.Format.FormatGuid != Consts.GUID_WICPixelFormat8bppCr)
                {
                    throw new ArgumentException("Invalid pixel format", nameof(sourceCr));
                }

                SourceY  = sourceY;
                SourceCb = sourceCb;
                SourceCr = sourceCr;

                ChromaSubsampling =
                    sourceCb.Width < sourceY.Width && sourceCb.Height < sourceY.Height ? ChromaSubsampleMode.Subsample420 :
                    sourceCb.Width < sourceY.Width ? ChromaSubsampleMode.Subsample422 :
                    sourceCb.Height < sourceY.Height ? ChromaSubsampleMode.Subsample440 :
                    ChromaSubsampleMode.Subsample444;
            }
Esempio n. 2
0
 public FormatConversionTransformInternal(PixelSource source, ColorProfile sourceProfile, ColorProfile destProfile, Guid destFormat) : base(source)
 {
     InFormat      = source.Format;
     Format        = PixelFormat.Cache[destFormat];
     SourceProfile = sourceProfile ?? ColorProfile.sRGB;
     DestProfile   = destProfile ?? ColorProfile.sRGB;
     LineBuff      = ArrayPool <byte> .Shared.Rent((int)BufferStride);
 }
Esempio n. 3
0
        public ConvolutionTransform(PixelSource source, KernelMap <TWeight> mapx, KernelMap <TWeight> mapy, bool lumaMode = false) : base(source)
        {
            var fmt = Format;

            if (lumaMode)
            {
                if (fmt.ColorRepresentation == PixelColorRepresentation.Bgr || fmt.ColorRepresentation == PixelColorRepresentation.Grey)
                {
                    fmt = fmt.NumericRepresentation == PixelNumericRepresentation.Float ? PixelFormat.Grey32BppFloat :
                          fmt.NumericRepresentation == PixelNumericRepresentation.Fixed ? PixelFormat.Grey16BppUQ15 :
                          fmt.NumericRepresentation == PixelNumericRepresentation.UnsignedInteger ? PixelFormat.Cache[Consts.GUID_WICPixelFormat8bppGray] :
                          throw new NotSupportedException("Unsupported pixel format");
                }
                else
                {
                    throw new NotSupportedException("Unsupported pixel format");
                }
            }

            if (!ProcessorMap.TryGetValue(fmt.FormatGuid, out XProcessor))
            {
                throw new NotSupportedException("Unsupported pixel format");
            }

            if (fmt == PixelFormat.Bgr96BppLinearFloat)
            {
                Format = fmt = PixelFormat.Bgrx128BppLinearFloat;
            }
            else if (fmt == PixelFormat.Bgr96BppFloat)
            {
                Format = fmt = PixelFormat.Bgrx128BppFloat;
            }

            YProcessor = ProcessorMap[fmt.FormatGuid];
            XMap       = mapx;
            YMap       = mapy;

            BufferSource = lumaMode;
            SourceRect   = new WICRect {
                Width = (int)Width, Height = 1
            };
            IntStartLine = -mapy.Samples;

            IntBpp     = fmt.BitsPerPixel / 8 / Unsafe.SizeOf <TPixel>() * Unsafe.SizeOf <TWeight>();
            IntStride  = mapy.Samples * IntBpp;
            WorkStride = fmt.BitsPerPixel / 8 * (int)Width + (IntPtr.Size - 1) & ~(IntPtr.Size - 1);

            int lineBuffLen = (BufferSource ? mapy.Samples : 1) * (int)BufferStride;
            int intBuffLen  = mapx.OutPixels * IntStride;
            int workBuffLen = mapy.Samples * WorkStride;

            LineBuff = new ArraySegment <byte>(ArrayPool <byte> .Shared.Rent(lineBuffLen), 0, lineBuffLen).Zero();
            IntBuff  = new ArraySegment <byte>(ArrayPool <byte> .Shared.Rent(intBuffLen), 0, intBuffLen).Zero();
            WorkBuff = lumaMode && !Format.IsBinaryCompatibleWith(fmt) ? new ArraySegment <byte>(ArrayPool <byte> .Shared.Rent(workBuffLen), 0, workBuffLen).Zero() : LineBuff;

            Width  = (uint)mapx.OutPixels;
            Height = (uint)mapy.OutPixels;
        }
Esempio n. 4
0
 protected PixelSource(PixelSource source) : this()
 {
     Source       = source;
     WicSource    = this.AsIWICBitmapSource();
     Format       = Source.Format;
     Width        = Source.Width;
     Height       = Source.Height;
     BufferStride = (Width * (uint)Format.BitsPerPixel + 7u) / 8u + ((uint)IntPtr.Size - 1u) & ~((uint)IntPtr.Size - 1u);
 }
Esempio n. 5
0
        public MatteTransform(PixelSource source, Color color) : base(source)
        {
            if (Format.ColorRepresentation != PixelColorRepresentation.Bgr || Format.AlphaRepresentation == PixelAlphaRepresentation.None)
            {
                throw new NotSupportedException("Pixel format not supported.  Must be BGRA");
            }

            maskRed   = color.R;
            maskGreen = color.G;
            maskBlue  = color.B;
        }
Esempio n. 6
0
        public ColorMatrixTransformInternal(PixelSource source, Matrix4x4 matrix) : base(source)
        {
            vec0 = new Vector4(matrix.M11, matrix.M21, matrix.M31, matrix.M41);
            vec1 = new Vector4(matrix.M12, matrix.M22, matrix.M32, matrix.M42);
            vec2 = new Vector4(matrix.M13, matrix.M23, matrix.M33, matrix.M43);
            vec3 = new Vector4(matrix.M14, matrix.M24, matrix.M34, matrix.M44);

            matrixFixed = new[] {
                Fix15(matrix.M11), Fix15(matrix.M21), Fix15(matrix.M31), Fix15(matrix.M41),
                Fix15(matrix.M12), Fix15(matrix.M22), Fix15(matrix.M32), Fix15(matrix.M42),
                Fix15(matrix.M13), Fix15(matrix.M23), Fix15(matrix.M33), Fix15(matrix.M43),
                Fix15(matrix.M14), Fix15(matrix.M24), Fix15(matrix.M34), Fix15(matrix.M44)
            };
        }
Esempio n. 7
0
        public PadTransformInternal(PixelSource source, Color color, Rectangle innerRect, Rectangle outerRect) : base(source)
        {
            bytesPerPixel = Format.BitsPerPixel / 8;

            if (Format.NumericRepresentation != PixelNumericRepresentation.UnsignedInteger || Format.ChannelCount != bytesPerPixel)
            {
                throw new NotSupportedException("Pixel format not supported.");
            }

            bgra  = (uint)color.ToArgb();
            fillB = color.B;
            fillG = color.G;
            fillR = color.R;

            irect  = innerRect;
            Width  = (uint)outerRect.Width;
            Height = (uint)outerRect.Height;
        }
Esempio n. 8
0
        unsafe public MatteTransform(PixelSource source, Color color) : base(source)
        {
            if (Format.ColorRepresentation != PixelColorRepresentation.Bgr || Format.AlphaRepresentation == PixelAlphaRepresentation.None)
            {
                throw new NotSupportedException("Pixel format not supported.  Must be BGRA");
            }

            if (Format == PixelFormat.Pbgra128BppLinearFloat && color.A == byte.MaxValue)
            {
                Format = PixelFormat.Bgrx128BppLinearFloat;
            }

            var igtq = LookupTables.SrgbInverseGammaUQ15;
            var atq  = LookupTables.AlphaUQ15;

            matteB = igtq[color.B];
            matteG = igtq[color.G];
            matteR = igtq[color.R];
            matteA = atq[color.A];

            matteValue32 = (uint)color.ToArgb();
            matteValue64 = ((ulong)matteA << 48) | ((ulong)UnFix15(matteR * matteA) << 32) | ((ulong)UnFix15(matteG * matteA) << 16) | (ushort)UnFix15(matteB * matteA);

            var igtf = LookupTables.SrgbInverseGammaFloat;
            var atf  = LookupTables.AlphaFloat;

            float mr = igtf[color.R], mg = igtf[color.G], mb = igtf[color.B], maa = atf[color.A];

            int *  m0  = stackalloc int[] { -1, -1, -1, -1, 0, 0, 0, 0 };
            int *  m1  = stackalloc int[] { -1, -1, -1, 0, -1, -1, -1, 0 };
            float *mat = stackalloc float[] { mb, mg, mr, 1f, mb, mg, mr, 1f };

            vmask0 = Unsafe.Read <Vector <int> >(m0);
            vmask1 = Unsafe.Read <Vector <int> >(m1);
            vmatte = Unsafe.Read <VectorF>(mat) * new VectorF(maa);
        }

        unsafe protected override void CopyPixelsInternal(in Rectangle prc, uint cbStride, uint cbBufferSize, IntPtr pbBuffer)
 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);
 }
Esempio n. 10
0
 public PixelSourceAsIPixelSource(PixelSource src) => source = src;
Esempio n. 11
0
 public PixelSourceAsIWICBitmapSource(PixelSource src) => source = src;
Esempio n. 12
0
 public FormatConversionTransform(PixelSource source, Guid dstFormat) : base(source)
 {
     InFormat = source.Format;
     Format   = PixelFormat.Cache[dstFormat];
     LineBuff = ArrayPool <byte> .Shared.Rent((int)BufferStride);
 }