Skip to content
Snippets Groups Projects
Commit 2fc2c194 authored by Thomas Oster's avatar Thomas Oster
Browse files

Dithering algorithms don't have internal variables for source and target, but...

Dithering algorithms don't have internal variables for source and target, but they are provided as method arguments
parent b7c3b5a7
No related branches found
No related tags found
No related merge requests found
......@@ -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()
{
......
......@@ -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();
}
......@@ -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()
{
......
......@@ -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()
{
......
......@@ -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()
{
......
......@@ -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()
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment