Beispiel #1
0
        private int[] GetHistogram(IEnumerable <VideoFrame> frames, VideoFrame maskFrame, int pixelSize, int channel, YUVPlanes plane, ColorSpaces pixelType, int bits, bool limitedRange)
        {
            var hist       = new int[1 << bits];
            var chroma     = plane == YUVPlanes.PLANAR_U || plane == YUVPlanes.PLANAR_V;
            var widthMult  = chroma ? pixelType.GetWidthSubsample() : 1;
            var heightMult = chroma ? pixelType.GetHeightSubsample() : 1;
            var maskPitch  = maskFrame?.GetPitch() * heightMult ?? 0;
            var maskPtr    = maskFrame?.GetReadPtr() + channel ?? IntPtr.Zero;

            foreach (var frame in frames)
            {
                NativeUtils.FillHistogram(hist,
                                          frame.GetRowSize(plane), frame.GetHeight(plane), channel,
                                          frame.GetReadPtr(plane), frame.GetPitch(plane), pixelSize,
                                          maskPtr, maskPitch, widthMult);
            }
            if (limitedRange)
            {
                var min = GetLowColor(bits);
                for (var color = 0; color < min; color++)
                {
                    hist[min]  += hist[color];
                    hist[color] = 0;
                }
                var max = GetHighColor(bits, plane);
                for (var color = max + 1; color < 1 << bits; color++)
                {
                    hist[max]  += hist[color];
                    hist[color] = 0;
                }
            }
            return(GetUniHistogram(hist));
        }
Beispiel #2
0
 public static Size GetSubSample(this ColorSpaces colorSpace)
 {
     return(new Size(colorSpace.GetWidthSubsample(), colorSpace.GetHeightSubsample()));
 }