예제 #1
0
            public capex.image.ImageResizer.IndexMovingBuffer move(int n)
            {
                var v = new capex.image.ImageResizer.IndexMovingBuffer();

                v.setBuf(buf);
                v.setIndex(v.getIndex() + n);
                return(v);
            }
예제 #2
0
        public static void sampleCubic(capex.image.PixelRegionBuffer src, double su, double sv, capex.image.ImageResizer.IndexMovingBuffer dest)
        {
            var aval   = 0.00;
            var arecip = 0.00;
            var i      = 0;
            var iu     = (int)cape.Math.floor(su);
            var iv     = (int)cape.Math.floor(sv);
            var stride = src.getStride();
            var du     = 0.00;
            var dv     = 0.00;
            var br     = src.getBufferRegion(iu - 1, iv - 1);

            if (br == null)
            {
                return;
            }
            dest.setBuf(br);
            du   = su - iu;
            dv   = sv - iv;
            aval = capex.image.ImageResizer.drawableTransformCubic(dv, capex.image.ImageResizer.cubicRow(du, dest.move(3 + stride * 0)), capex.image.ImageResizer.cubicRow(du, dest.move(3 + stride * 1)), capex.image.ImageResizer.cubicRow(du, dest.move(3 + stride * 2)), capex.image.ImageResizer.cubicRow(du, dest.move(3 + stride * 3)));
            if (aval <= 0)
            {
                arecip = 0.00;
                cape.Buffer.setByte(dest.getBuf(), (long)3, (byte)0);
            }
            else if (aval > 255.00)
            {
                arecip = 1.00 / aval;
                cape.Buffer.setByte(dest.getBuf(), (long)3, (byte)255);
            }
            else
            {
                arecip = 1.00 / aval;
                cape.Buffer.setByte(dest.getBuf(), (long)3, (byte)((int)cape.Math.rint(aval)));
            }
            for (i = 0; i < 3; i++)
            {
                var v = (int)cape.Math.rint(arecip * capex.image.ImageResizer.drawableTransformCubic(dv, capex.image.ImageResizer.cubicScaledRow(du, dest.move(i + stride * 0), dest.move(3 + stride * 0)), capex.image.ImageResizer.cubicScaledRow(du, dest.move(i + stride * 1), dest.move(3 + stride * 1)), capex.image.ImageResizer.cubicScaledRow(du, dest.move(i + stride * 2), dest.move(3 + stride * 2)), capex.image.ImageResizer.cubicScaledRow(du, dest.move(i + stride * 3), dest.move(3 + stride * 3))));
                cape.Buffer.setByte(dest.getBuf(), (long)i, (byte)capex.image.ImageFilterUtil.clamp((double)v));
            }
        }
예제 #3
0
        public static capex.image.BitmapBuffer resizeBicubic(capex.image.BitmapBuffer bb, int anw, int anh)
        {
            if (anw == 0 || anh == 0)
            {
                return(null);
            }
            if (anw < 0 && anh < 0)
            {
                return(bb);
            }
            var sb = bb.getBuffer();

            if (sb == null)
            {
                return(null);
            }
            var w      = bb.getWidth();
            var h      = bb.getHeight();
            var scaler = 1.00;
            var nw     = anw;
            var nh     = anh;

            if (nw < 0)
            {
                scaler = (double)nh / (double)h;
            }
            else if (nh < 0)
            {
                scaler = (double)nw / (double)w;
            }
            if (scaler != 1.00)
            {
                nw = (int)((double)w * scaler);
                nh = (int)((double)h * scaler);
            }
            var v = new byte[nw * nh * 4];

            capex.image.ImageResizer.IndexMovingBuffer destp = null;
            destp.setBuf(v);
            var y      = 0;
            var sx     = (double)nw / (double)w;
            var sy     = (double)nh / (double)h;
            var matrix = capex.util.Matrix33.forScale(sx, sy);

            matrix = capex.util.Matrix33.invertMatrix(matrix);
            var uinc   = matrix.v[0];
            var vinc   = matrix.v[1];
            var winc   = matrix.v[2];
            var pixels = capex.image.RGBAPixelIntegerBuffer.create(sb, w, h);
            var pixrgn = capex.image.PixelRegionBuffer.forRgbaPixels(pixels, 4, 4);
            var tu     = new double[5];
            var tv     = new double[5];
            var tw     = new double[5];
            var su     = new double[5];
            var sv     = new double[5];

            for (y = 0; y < nh; y++)
            {
                capex.image.ImageResizer.untransformCoords(matrix, 0, y, tu, tv, tw);
                var width = nw;
                while (width-- > 0)
                {
                    var i = 0;
                    capex.image.ImageResizer.normalizeCoords(5, tu, tv, tw, su, sv);
                    if (capex.image.ImageResizer.superSampleDtest(su[1], sv[1], su[2], sv[2], su[3], sv[3], su[4], sv[4]))
                    {
                        capex.image.ImageResizer.sampleAdapt(pixels, su[0], sv[0], su[1], sv[1], su[2], sv[2], su[3], sv[3], su[4], sv[4], destp);
                    }
                    else
                    {
                        capex.image.ImageResizer.sampleCubic(pixrgn, su[0], sv[0], destp);
                    }
                    destp = destp.move(4);
                    for (i = 0; i < 5; i++)
                    {
                        tu[i] = tu[i] + uinc;
                        tv[i] = tv[i] + vinc;
                        tw[i] = tw[i] + winc;
                    }
                }
            }
            return(capex.image.BitmapBuffer.create(v, nw, nh));
        }