Пример #1
0
        public static unsafe void DrawCorner(FrameData.Section s, byte *dest, int destX, int destY, int destStride)
        {
            var src       = (byte *)s.Pixels.ToPointer();
            int srcStride = s.Width * s.BytesPerPixel;

            for (int y = 0; y < s.Height; y++)
            {
                for (int x = 0; x < s.Width; x++)
                {
                    for (int i = 0; i < s.BytesPerPixel; i++)
                    {
                        dest[(y + destY) * destStride + (x + destX) * s.BytesPerPixel + i]
                            = src[y * srcStride + x * s.BytesPerPixel + i];
                    }
                }
            }
        }
Пример #2
0
        public static unsafe void DrawVerticalSide(FrameData.Section s, byte *dest, int destXStart, int destYStart, int writeHeight, int destStride)
        {
            var src       = (byte *)s.Pixels.ToPointer();
            int srcStride = s.Width * s.BytesPerPixel;

            if (s.Repeating)
            {
                int repeatCount   = (writeHeight + s.Height - 1) / s.Height;
                var interp        = new SimpleResampler(s.Height * repeatCount, writeHeight);
                int prevDestIndex = 0;
                var averager      = new PixelAverager(s.BytesPerPixel);
                for (int y = 0; y < s.Height * repeatCount; y++)
                {
                    int destY = interp.Map(y);
                    for (int x = 0; x < s.Width; x++)
                    {
                        int destIndex = (x + destXStart) * s.BytesPerPixel + (destY + destYStart) * destStride;
                        if (prevDestIndex != destIndex && averager.Count != 0)
                        {
                            averager.WriteAverage(dest + prevDestIndex);
                        }
                        prevDestIndex = destIndex;
                        averager.Add(src + (y % s.Height) * srcStride + x * s.BytesPerPixel);
                    }
                    averager.WriteAverage(dest + prevDestIndex);
                }
            }
            else if (writeHeight > s.Height)
            {
                var extrapolater = new FastUpsampler(s.Height, writeHeight);
                for (int y = 0; y < writeHeight; y++)
                {
                    extrapolater.Map(y, out int sampleYa, out int sampleYb);
                    for (int x = 0; x < s.Width; x++)
                    {
                        for (int i = 0; i < s.BytesPerPixel; i++)
                        {
                            dest[(y + destYStart) * destStride + (x + destXStart) * s.BytesPerPixel + i] = (byte)((
                                                                                                                      src[sampleYa * srcStride + x * s.BytesPerPixel + i] +
                                                                                                                      src[sampleYb * srcStride + x * s.BytesPerPixel + i]) / 2);
                        }
                    }
                }
            }
            else
            {
                var interp        = new SimpleResampler(s.Height, writeHeight);
                int prevDestIndex = 0;
                var averager      = new PixelAverager(s.BytesPerPixel);
                for (int y = 0; y < s.Height; y++)
                {
                    int destY = interp.Map(y);
                    for (int x = 0; x < s.Width; x++)
                    {
                        int destIndex = (x + destXStart) * s.BytesPerPixel + (destY + destYStart) * destStride;
                        if (prevDestIndex != destIndex && averager.Count != 0)
                        {
                            averager.WriteAverage(dest + prevDestIndex);
                        }
                        prevDestIndex = destIndex;
                        averager.Add(src + y * srcStride + x * s.BytesPerPixel);
                    }
                    averager.WriteAverage(dest + prevDestIndex);
                }
            }
        }