diff --git a/src/com/t_oster/liblasercut/dithering/Average.java b/src/com/t_oster/liblasercut/dithering/Average.java index 3242d3b92bfb957f310fda877b6cda2e793aeefa..1a9adc2424c3be0561924e47aacc5eaa206fe16c 100644 --- a/src/com/t_oster/liblasercut/dithering/Average.java +++ b/src/com/t_oster/liblasercut/dithering/Average.java @@ -2,31 +2,34 @@ * This file is part of VisiCut. * Copyright (C) 2012 Thomas Oster <thomas.oster@rwth-aachen.de> * RWTH Aachen University - 52062 Aachen, Germany - * + * * VisiCut is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * VisiCut is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with VisiCut. If not, see <http://www.gnu.org/licenses/>. **/ package com.t_oster.liblasercut.dithering; +import com.t_oster.liblasercut.BlackWhiteRaster; +import com.t_oster.liblasercut.GreyscaleRaster; + /** * * @author Thomas Oster <thomas.oster@rwth-aachen.de> */ public class Average extends DitheringAlgorithm { - - @Override - protected void doDithering() + + @Override + protected void doDithering(GreyscaleRaster src, BlackWhiteRaster target) { long lumTotal = 0; int pixelcount = 0; @@ -47,7 +50,7 @@ public class Average extends DitheringAlgorithm { for (int x = 0; x < width; x++) { - this.setBlack(x, y, src.getGreyScale(x, y) < thresh); + this.setBlack(src, target, x, y, src.getGreyScale(x, y) < thresh); } setProgress((100 * pixelcount++) / (2 * height)); } @@ -57,7 +60,7 @@ public class Average extends DitheringAlgorithm public DitheringAlgorithm clone() { return new Average(); } - + @Override public String toString() { diff --git a/src/com/t_oster/liblasercut/dithering/DitheringAlgorithm.java b/src/com/t_oster/liblasercut/dithering/DitheringAlgorithm.java index 54c7d2193ece84c80be47764ea4209cb877fa697..c266f96a569e9919af28cea78b74bbe87bbb91e8 100644 --- a/src/com/t_oster/liblasercut/dithering/DitheringAlgorithm.java +++ b/src/com/t_oster/liblasercut/dithering/DitheringAlgorithm.java @@ -2,17 +2,17 @@ * This file is part of VisiCut. * Copyright (C) 2012 Thomas Oster <thomas.oster@rwth-aachen.de> * RWTH Aachen University - 52062 Aachen, Germany - * + * * VisiCut is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * VisiCut is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with VisiCut. If not, see <http://www.gnu.org/licenses/>. **/ @@ -29,11 +29,8 @@ import com.t_oster.liblasercut.TimeIntensiveOperation; */ public abstract class DitheringAlgorithm extends TimeIntensiveOperation implements Customizable, Cloneable { - - protected GreyscaleRaster src; - protected BlackWhiteRaster target; - protected void setBlack(int x, int y, boolean black) + protected void setBlack(GreyscaleRaster src, BlackWhiteRaster target, int x, int y, boolean black) { if (target != null) { @@ -47,28 +44,23 @@ public abstract class DitheringAlgorithm extends TimeIntensiveOperation implemen public BlackWhiteRaster dither(GreyscaleRaster input) { - src = input; - target = new BlackWhiteRaster(input.getWidth(), input.getHeight()); - doDithering(); + BlackWhiteRaster target = new BlackWhiteRaster(input.getWidth(), input.getHeight()); + doDithering(input, target); return target; } public void ditherDirect(GreyscaleRaster input) { - src = input; - target = null; - doDithering(); + doDithering(input, null); } - + public void ditherDirect(GreyscaleRaster input, BlackWhiteRaster output) { - src = input; - target = output; - doDithering(); + doDithering(input, output); } - - protected abstract void doDithering(); - + + protected abstract void doDithering(GreyscaleRaster src, BlackWhiteRaster target); + @Override public String[] getPropertyKeys() { return new String[0]; @@ -82,10 +74,10 @@ public abstract class DitheringAlgorithm extends TimeIntensiveOperation implemen public Object getProperty(String key) { return null; } - + @Override public abstract DitheringAlgorithm clone(); - + @Override public abstract String toString(); } diff --git a/src/com/t_oster/liblasercut/dithering/FloydSteinberg.java b/src/com/t_oster/liblasercut/dithering/FloydSteinberg.java index cc742fe914594ca2f8eaacb57b8c3b45766841f7..538553b9aa48e5c04013663569245acae57db3bb 100644 --- a/src/com/t_oster/liblasercut/dithering/FloydSteinberg.java +++ b/src/com/t_oster/liblasercut/dithering/FloydSteinberg.java @@ -2,22 +2,25 @@ * This file is part of VisiCut. * Copyright (C) 2012 Thomas Oster <thomas.oster@rwth-aachen.de> * RWTH Aachen University - 52062 Aachen, Germany - * + * * VisiCut is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * VisiCut is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with VisiCut. If not, see <http://www.gnu.org/licenses/>. **/ package com.t_oster.liblasercut.dithering; +import com.t_oster.liblasercut.BlackWhiteRaster; +import com.t_oster.liblasercut.GreyscaleRaster; + /** * * @author Thomas Oster <thomas.oster@rwth-aachen.de> @@ -26,7 +29,7 @@ public class FloydSteinberg extends DitheringAlgorithm { @Override - protected void doDithering() + protected void doDithering(GreyscaleRaster src, BlackWhiteRaster target) { int pixelcount = 0; /** @@ -54,7 +57,7 @@ public class FloydSteinberg extends DitheringAlgorithm for (int x = 0; x < input.length; x++) { - this.setBlack(x, y, input[x][0] <= 127); + this.setBlack(src, target, x, y, input[x][0] <= 127); int error = input[x][0] - ((input[x][0] <= 127) ? 0 : 255); if (x + 1 < input.length) { @@ -81,7 +84,7 @@ public class FloydSteinberg extends DitheringAlgorithm public DitheringAlgorithm clone() { return new FloydSteinberg(); } - + @Override public String toString() { diff --git a/src/com/t_oster/liblasercut/dithering/Grid.java b/src/com/t_oster/liblasercut/dithering/Grid.java index 87bee484a87e044bd4024c4c291f061b383b85f7..b6d6968e6bec591d8a051bd377a8f4b93b776d6a 100644 --- a/src/com/t_oster/liblasercut/dithering/Grid.java +++ b/src/com/t_oster/liblasercut/dithering/Grid.java @@ -18,6 +18,9 @@ */ package com.t_oster.liblasercut.dithering; +import com.t_oster.liblasercut.BlackWhiteRaster; +import com.t_oster.liblasercut.GreyscaleRaster; + /** * * @author Thomas Oster <thomas.oster@rwth-aachen.de> @@ -26,13 +29,13 @@ public class Grid extends DitheringAlgorithm { private static String[] properties = new String[]{"Blocksize", "Blockdistance"}; - + @Override public String[] getPropertyKeys() { return properties; } - + @Override public void setProperty(String key, Object value) { @@ -49,7 +52,7 @@ public class Grid extends DitheringAlgorithm throw new IllegalArgumentException("No such key "+key); } } - + @Override public Object getProperty(String key) { @@ -63,12 +66,12 @@ public class Grid extends DitheringAlgorithm } throw new IllegalArgumentException("No such key "+key); } - + protected int blocksize = 10; protected int blockdistance = 5; @Override - protected void doDithering() + protected void doDithering(GreyscaleRaster src, BlackWhiteRaster target) { long lumTotal = 0; int pixelcount = 0; @@ -93,11 +96,11 @@ public class Grid extends DitheringAlgorithm && x % (blocksize + blockdistance) <= blocksize && src.getGreyScale(x, y) < thresh) { - this.setBlack(x, y, true); + this.setBlack(src, target, x, y, true); } else { - this.setBlack(x, y, false); + this.setBlack(src, target, x, y, false); } } setProgress((100 * pixelcount++) / (2 * height)); @@ -111,7 +114,7 @@ public class Grid extends DitheringAlgorithm clone.blocksize = blocksize; return clone; } - + @Override public String toString() { diff --git a/src/com/t_oster/liblasercut/dithering/Ordered.java b/src/com/t_oster/liblasercut/dithering/Ordered.java index 6ebd641d1ec40e2af290f6c4dfc2778655d4616c..9c6b7c185e65313c4616373ebc19151754034c6b 100644 --- a/src/com/t_oster/liblasercut/dithering/Ordered.java +++ b/src/com/t_oster/liblasercut/dithering/Ordered.java @@ -2,22 +2,25 @@ * This file is part of VisiCut. * Copyright (C) 2012 Thomas Oster <thomas.oster@rwth-aachen.de> * RWTH Aachen University - 52062 Aachen, Germany - * + * * VisiCut is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * VisiCut is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with VisiCut. If not, see <http://www.gnu.org/licenses/>. **/ package com.t_oster.liblasercut.dithering; +import com.t_oster.liblasercut.BlackWhiteRaster; +import com.t_oster.liblasercut.GreyscaleRaster; + /** * * @author Thomas Oster <thomas.oster@rwth-aachen.de> @@ -26,7 +29,7 @@ public class Ordered extends DitheringAlgorithm { @Override - protected void doDithering() + protected void doDithering(GreyscaleRaster src, BlackWhiteRaster target) { int width = src.getWidth(); int height = src.getHeight(); @@ -61,7 +64,7 @@ public class Ordered extends DitheringAlgorithm { for (int ydelta = 0; ydelta < nPatWid; ydelta++) { - this.setBlack(x + xdelta, y + ydelta, src.getGreyScale(x + xdelta, y + ydelta) < filter[xdelta][ydelta]); + this.setBlack(src, target, x + xdelta, y + ydelta, src.getGreyScale(x + xdelta, y + ydelta) < filter[xdelta][ydelta]); } } } @@ -72,7 +75,7 @@ public class Ordered extends DitheringAlgorithm if (((x + xdelta) < width) && ((y + ydelta) < height)) { - this.setBlack(x + xdelta, y + ydelta, src.getGreyScale(x + xdelta, y + ydelta) < filter[xdelta][ydelta]); + this.setBlack(src, target, x + xdelta, y + ydelta, src.getGreyScale(x + xdelta, y + ydelta) < filter[xdelta][ydelta]); } } } @@ -89,7 +92,7 @@ public class Ordered extends DitheringAlgorithm if (((x + xdelta) < width) && ((y + ydelta) < height)) { - this.setBlack(x + xdelta, y + ydelta, src.getGreyScale(x + xdelta, y + ydelta) < filter[xdelta][ydelta]); + this.setBlack(src, target, x + xdelta, y + ydelta, src.getGreyScale(x + xdelta, y + ydelta) < filter[xdelta][ydelta]); } } } @@ -100,7 +103,7 @@ public class Ordered extends DitheringAlgorithm public DitheringAlgorithm clone() { return new Ordered(); } - + @Override public String toString() { diff --git a/src/com/t_oster/liblasercut/dithering/Random.java b/src/com/t_oster/liblasercut/dithering/Random.java index 5601919c93c10ce15714dfb653fba4bb29bd7fe8..b7fa0342049d07d4fe04e124aeace48e0e799bdd 100644 --- a/src/com/t_oster/liblasercut/dithering/Random.java +++ b/src/com/t_oster/liblasercut/dithering/Random.java @@ -2,22 +2,25 @@ * This file is part of VisiCut. * Copyright (C) 2012 Thomas Oster <thomas.oster@rwth-aachen.de> * RWTH Aachen University - 52062 Aachen, Germany - * + * * VisiCut is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * VisiCut is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with VisiCut. If not, see <http://www.gnu.org/licenses/>. **/ package com.t_oster.liblasercut.dithering; +import com.t_oster.liblasercut.BlackWhiteRaster; +import com.t_oster.liblasercut.GreyscaleRaster; + /** * * @author Thomas Oster <thomas.oster@rwth-aachen.de> @@ -26,7 +29,7 @@ public class Random extends DitheringAlgorithm { @Override - protected void doDithering() + protected void doDithering(GreyscaleRaster src, BlackWhiteRaster target) { int width = src.getWidth(); int height = src.getHeight(); @@ -37,7 +40,7 @@ public class Random extends DitheringAlgorithm { for (int x = 0; x < width; x++) { - this.setBlack(x, y, src.getGreyScale(x, y) < r.nextInt(256)); + this.setBlack(src, target, x, y, src.getGreyScale(x, y) < r.nextInt(256)); } setProgress((100 * pixelcount++) / (height)); } @@ -47,7 +50,7 @@ public class Random extends DitheringAlgorithm public DitheringAlgorithm clone() { return new Random(); } - + @Override public String toString() {