Exemplo n.º 1
0
        public void ditherImage(PixelProvider img, ColorReducer cr)
        {
            this.img = img;
            int w = img.getWidth ();
            int h = img.getHeight ();
            int [] rgba = new int[4];
            int [] rgbaReduced = new int[4];
            int ofs;

            //final int lastRow = h-1;
            //final int lastColumn = w-1;

            for (int y = 0; y < h; ++y)
                for (int x = 0; x < w; ++x) {
                    ofs = img.ofs (x, y);
                    img.getPixelAt (ofs, rgba);
                    cr.reduceToClosest (rgba, rgbaReduced);
                    img.setPixelAt (ofs, rgbaReduced);

                    calcDiff (rgba, rgbaReduced);

                    //////////////////////////
                    // order, apply error to original pixels
                    // (x-1,y+1) = 3/16 , (x,y+1) = 5/16, (x+1,y+1) = 1/16, (x+1, y)=7/16

                    correctPixel (x - 1, y + 1, 3);
                    correctPixel (x, y + 1, 5);
                    correctPixel (x + 1, y + 1, 1);
                    correctPixel (x + 1, y, 7);
                }

            // no longer need img
            this.img = null;
        }
Exemplo n.º 2
0
Arquivo: Main.cs Projeto: exhu/alimg
        static void reduce(String src, String dst)
        {
            BufImg img = new BufImg();
            img.load(src);

            PixelDither dither = new PixelDither();
            ColorReducer reducer = new ColorReducer(ColorReducer.PixelFormat.pf4444);

            for(int i = 0; i < 100; ++i)
                dither.ditherImage(img, reducer);

            img.save(dst);
        }
Exemplo n.º 3
0
Arquivo: Main.cs Projeto: exhu/alimg
        static void reduce(String src, String dst)
        {
            BufImg img = new BufImg();

            img.load(src);

            PixelDither  dither  = new PixelDither();
            ColorReducer reducer = new ColorReducer(ColorReducer.PixelFormat.pf4444);

            for (int i = 0; i < 100; ++i)
            {
                dither.ditherImage(img, reducer);
            }

            img.save(dst);
        }
Exemplo n.º 4
0
        public void ditherImage(PixelProvider img, ColorReducer cr)
        {
            this.img = img;
            int w = img.getWidth();
            int h = img.getHeight();

            int [] rgba        = new int[4];
            int [] rgbaReduced = new int[4];
            int    ofs;

            //final int lastRow = h-1;
            //final int lastColumn = w-1;


            for (int y = 0; y < h; ++y)
            {
                for (int x = 0; x < w; ++x)
                {
                    ofs = img.ofs(x, y);
                    img.getPixelAt(ofs, rgba);
                    cr.reduceToClosest(rgba, rgbaReduced);
                    img.setPixelAt(ofs, rgbaReduced);


                    calcDiff(rgba, rgbaReduced);

                    //////////////////////////
                    // order, apply error to original pixels
                    // (x-1,y+1) = 3/16 , (x,y+1) = 5/16, (x+1,y+1) = 1/16, (x+1, y)=7/16


                    correctPixel(x - 1, y + 1, 3);
                    correctPixel(x, y + 1, 5);
                    correctPixel(x + 1, y + 1, 1);
                    correctPixel(x + 1, y, 7);
                }
            }


            // no longer need img
            this.img = null;
        }