summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO.txt8
-rw-r--r--src/bjc/imgchain/ImgChain.java10
-rw-r--r--src/bjc/imgchain/ImgPicker.java12
-rw-r--r--src/bjc/imgchain/ImgPickerPanel.java9
-rw-r--r--src/bjc/imgchain/ImgPipeline.java4
-rw-r--r--src/bjc/imgchain/ImgViewer.java39
-rw-r--r--src/bjc/imgchain/pipeline/PipelinePicker.java15
-rw-r--r--src/bjc/imgchain/pipeline/stages/AbstractPipelineStage.java6
-rw-r--r--src/bjc/imgchain/pipeline/stages/AbstractPixelStage.java15
-rw-r--r--src/bjc/imgchain/pipeline/stages/GaussStage.java14
-rw-r--r--src/bjc/imgchain/pipeline/stages/GreyscaleStage.java10
-rw-r--r--src/bjc/imgchain/pipeline/stages/InverseColorStage.java13
-rw-r--r--src/bjc/imgchain/pipeline/stages/LoadStage.java8
-rw-r--r--src/bjc/imgchain/pipeline/stages/PipeStage.java8
-rw-r--r--src/bjc/imgchain/pipeline/stages/RecallStage.java8
-rw-r--r--src/bjc/imgchain/pipeline/stages/SaveStage.java9
-rw-r--r--src/bjc/imgchain/pipeline/stages/StagePicker.java12
-rw-r--r--src/bjc/imgchain/pipeline/stages/StashStage.java9
-rw-r--r--src/bjc/imgchain/pipeline/stages/SubMaskStage.java9
-rw-r--r--src/bjc/imgchain/pipeline/stages/ThresholdStage.java16
-rw-r--r--src/bjc/imgchain/utils/ImmutableTableModel.java11
-rw-r--r--src/bjc/imgchain/utils/Utils.java75
22 files changed, 286 insertions, 34 deletions
diff --git a/TODO.txt b/TODO.txt
new file mode 100644
index 0000000..0537ea5
--- /dev/null
+++ b/TODO.txt
@@ -0,0 +1,8 @@
+@TODO Oct 6th, 2020 - Ben Culkin - :FilePipes
+ Add an ability to write/read pipelines from a file. This will likely
+ involve some fairly serious reconsideration of how stages are configured.
+
+@TODO Oct 6th, 2020 - Ben Culkin - :StageChaining
+ Some better ability to chain stages together without the inefficency
+ of running them one after the other. This won't work great for stages which
+ depend on the context of pixels around, but should work fine for most others. \ No newline at end of file
diff --git a/src/bjc/imgchain/ImgChain.java b/src/bjc/imgchain/ImgChain.java
index a3a9712..1228f68 100644
--- a/src/bjc/imgchain/ImgChain.java
+++ b/src/bjc/imgchain/ImgChain.java
@@ -62,12 +62,12 @@ public class ImgChain {
*/
public JDesktopPane desktop;
- /*
+ /**
* The storage for images.
*/
public final Map<String, Image> imageRepo;
- /*
+ /**
* The storage for images.
*/
public final Map<String, Pipeline> pipelineRepo;
@@ -77,13 +77,15 @@ public class ImgChain {
*/
public static ImgChain chan;
+ /**
+ * The main window.
+ */
public JFrame frame;
/**
* Main method
*
- * @param args
- * Unused CLI args
+ * @param args Unused CLI args.
*/
public static void main(String[] args) {
System.out.println("ImgChain Loading...");
diff --git a/src/bjc/imgchain/ImgPicker.java b/src/bjc/imgchain/ImgPicker.java
index 3113487..aa0d1ac 100644
--- a/src/bjc/imgchain/ImgPicker.java
+++ b/src/bjc/imgchain/ImgPicker.java
@@ -10,11 +10,23 @@ import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
+/**
+ * Image picker dialog.
+ *
+ * @author Ben Culkin
+ *
+ */
public class ImgPicker extends JDialog {
private static final long serialVersionUID = 1L;
+ /**
+ * Nane of the picked image.
+ */
public String imageName;
+ /**
+ * Create a new image picker.
+ */
public ImgPicker() {
super();
diff --git a/src/bjc/imgchain/ImgPickerPanel.java b/src/bjc/imgchain/ImgPickerPanel.java
index 61e2c8d..a400206 100644
--- a/src/bjc/imgchain/ImgPickerPanel.java
+++ b/src/bjc/imgchain/ImgPickerPanel.java
@@ -20,17 +20,26 @@ public class ImgPickerPanel extends JPanel {
* The place to stash the image.
*/
public String stashName;
+
/**
* The field to get the image from.
*/
public LabeledInputPanel imgField;
+ /**
+ * Create a new image picker panel.
+ */
public ImgPickerPanel() {
setLayout(new BorderLayout());
setupGUI("Image name");
}
+ /**
+ * Create a new image picker panel.
+ *
+ * @param lab The title for the label.
+ */
public ImgPickerPanel(String lab) {
setLayout(new BorderLayout());
diff --git a/src/bjc/imgchain/ImgPipeline.java b/src/bjc/imgchain/ImgPipeline.java
index 0c914e9..89ee243 100644
--- a/src/bjc/imgchain/ImgPipeline.java
+++ b/src/bjc/imgchain/ImgPipeline.java
@@ -24,7 +24,7 @@ import bjc.imgchain.pipeline.stages.GaussStage;
import bjc.imgchain.pipeline.stages.GreyscaleStage;
import bjc.imgchain.pipeline.stages.IDStage;
import bjc.imgchain.pipeline.stages.LoadStage;
-import bjc.imgchain.pipeline.stages.NegativeStage;
+import bjc.imgchain.pipeline.stages.InverseColorStage;
import bjc.imgchain.pipeline.stages.PipeStage;
import bjc.imgchain.pipeline.stages.RecallStage;
import bjc.imgchain.pipeline.stages.SaveStage;
@@ -150,7 +150,7 @@ public class ImgPipeline extends JInternalFrame {
}
break;
case "Negative": {
- stag = new NegativeStage();
+ stag = new InverseColorStage();
}
break;
case "Gaussian Blur": {
diff --git a/src/bjc/imgchain/ImgViewer.java b/src/bjc/imgchain/ImgViewer.java
index e9e3278..fc5a944 100644
--- a/src/bjc/imgchain/ImgViewer.java
+++ b/src/bjc/imgchain/ImgViewer.java
@@ -24,20 +24,26 @@ import bjc.imgchain.pipeline.Pipeline;
import bjc.imgchain.pipeline.PipelinePicker;
import bjc.imgchain.utils.Utils;
+/**
+ * Image viewer panel.
+ *
+ * @author Ben Culkin
+ *
+ */
public class ImgViewer extends JInternalFrame {
private final class ReloadImageListener implements ActionListener {
- private final File img;
+ private final File imge;
ReloadImageListener(File img) {
- this.img = img;
+ this.imge = img;
}
@Override
public void actionPerformed(ActionEvent ev) {
try {
- icon.setImage(ImageIO.read(img));
+ icon.setImage(ImageIO.read(imge));
} catch (IOException e) {
- String msg = String.format("Error: Could not load image %s", img.getPath());
+ String msg = String.format("Error: Could not load image %s", imge.getPath());
System.out.printf("%s\n", msg);
@@ -51,7 +57,7 @@ public class ImgViewer extends JInternalFrame {
private final class ChangeImageListener implements ActionListener {
public ChangeImageListener() {
- // TODO Auto-generated constructor stub
+ // TODO Oct 5th, 2020 - Ben Culkin - Do I need to do something here?
}
@Override
@@ -98,6 +104,12 @@ public class ImgViewer extends JInternalFrame {
private JLabel lab;
+ /**
+ * Create a new image viewer.
+ *
+ * @param desk The desktop.
+ * @param img The image being viewed.
+ */
public ImgViewer(ImgChain desk, File img) {
super("Image Viewer - " + img.getName(), false, true, true, true);
initted = false;
@@ -243,19 +255,19 @@ public class ImgViewer extends JInternalFrame {
return bar;
}
- private JLabel loadLabel(File img) {
- JLabel lab = null;
+ private JLabel loadLabel(File imge) {
+ JLabel labl = null;
try {
- URL imgURL = img.toURI().toURL();
+ URL imgURL = imge.toURI().toURL();
icon = new ImageIcon(imgURL);
setSize(icon.getIconWidth(), icon.getIconHeight());
- lab = new JLabel(icon);
+ labl = new JLabel(icon);
} catch (MalformedURLException e) {
- String msg = String.format("Error: Could not load image %s", img.getPath());
+ String msg = String.format("Error: Could not load image %s", imge.getPath());
System.out.printf("%s\n", msg);
@@ -265,9 +277,14 @@ public class ImgViewer extends JInternalFrame {
JOptionPane.ERROR_MESSAGE);
}
- return lab;
+ return labl;
}
+ /**
+ * Has this image viewer been initialized?
+ *
+ * @return The viewer has been initialized.
+ */
public boolean isInitialized() {
return initted;
}
diff --git a/src/bjc/imgchain/pipeline/PipelinePicker.java b/src/bjc/imgchain/pipeline/PipelinePicker.java
index 3539beb..ec5b071 100644
--- a/src/bjc/imgchain/pipeline/PipelinePicker.java
+++ b/src/bjc/imgchain/pipeline/PipelinePicker.java
@@ -12,11 +12,22 @@ import javax.swing.JScrollPane;
import bjc.imgchain.ImgChain;
+/**
+ * GUI to pick a pipeline to apply.
+ * @author Ben Culkin
+ *
+ */
public class PipelinePicker extends JDialog {
private static final long serialVersionUID = 1L;
+ /**
+ * The name of the pipe to apply.
+ */
public String pipeName;
+ /**
+ * Create a new pipeline picker GUI.
+ */
public PipelinePicker() {
super();
@@ -30,8 +41,8 @@ public class PipelinePicker extends JDialog {
setLayout(new BorderLayout());
DefaultListModel<String> pipeModel = new DefaultListModel<>();
- for (String pipeName : ImgChain.chan.pipelineRepo.keySet()) {
- pipeModel.addElement(pipeName);
+ for (String pipelneName : ImgChain.chan.pipelineRepo.keySet()) {
+ pipeModel.addElement(pipelneName);
}
JList<String> pipeList = new JList<>(pipeModel);
diff --git a/src/bjc/imgchain/pipeline/stages/AbstractPipelineStage.java b/src/bjc/imgchain/pipeline/stages/AbstractPipelineStage.java
index 4183f4f..e7e1f33 100644
--- a/src/bjc/imgchain/pipeline/stages/AbstractPipelineStage.java
+++ b/src/bjc/imgchain/pipeline/stages/AbstractPipelineStage.java
@@ -12,6 +12,12 @@ import bjc.imgchain.pipeline.StageType;
public abstract class AbstractPipelineStage implements PipelineStage {
private final StageType type;
+ /**
+ * Create a new abstract pipeline stage
+ *
+ * @param type
+ * The type of this stage.
+ */
protected AbstractPipelineStage(StageType type) {
this.type = type;
}
diff --git a/src/bjc/imgchain/pipeline/stages/AbstractPixelStage.java b/src/bjc/imgchain/pipeline/stages/AbstractPixelStage.java
index 8b161d6..b93f092 100644
--- a/src/bjc/imgchain/pipeline/stages/AbstractPixelStage.java
+++ b/src/bjc/imgchain/pipeline/stages/AbstractPixelStage.java
@@ -8,11 +8,18 @@ import bjc.imgchain.utils.Utils;
/**
* An abstract stage that processes images pixel-by-pixel.
+ *
* @author bjculkin
*
*/
public abstract class AbstractPixelStage extends AbstractPipelineStage {
+ /**
+ * Create a new abstract pixel stage.
+ *
+ * @param type
+ * The type of this stage.
+ */
protected AbstractPixelStage(StageType type) {
super(type);
}
@@ -21,7 +28,8 @@ public abstract class AbstractPixelStage extends AbstractPipelineStage {
public Image process(Image inp) {
BufferedImage buf = (BufferedImage) inp;
- BufferedImage res = new BufferedImage(buf.getWidth(), buf.getHeight(), BufferedImage.TYPE_INT_ARGB);
+ BufferedImage res = new BufferedImage(buf.getWidth(), buf.getHeight(),
+ BufferedImage.TYPE_INT_ARGB);
for (int y = 0; y < buf.getHeight(); y++) {
for (int x = 0; x < buf.getWidth(); x++) {
@@ -38,7 +46,10 @@ public abstract class AbstractPixelStage extends AbstractPipelineStage {
/**
* Process a pixel of data.
- * @param pix The pixel, as an array in the form (A, R, G, B)
+ *
+ * @param pix
+ * The pixel, as an array in the form (A, R, G, B)
+ *
* @return The new pixel, as an array in the form (A, R, G, B)
*/
public abstract int[] processPixel(int[] pix);
diff --git a/src/bjc/imgchain/pipeline/stages/GaussStage.java b/src/bjc/imgchain/pipeline/stages/GaussStage.java
index 5f5d919..80cdaa3 100644
--- a/src/bjc/imgchain/pipeline/stages/GaussStage.java
+++ b/src/bjc/imgchain/pipeline/stages/GaussStage.java
@@ -12,10 +12,18 @@ import javax.swing.JPanel;
import bjc.imgchain.pipeline.StageType;
import bjc.imgchain.utils.LabeledInputPanel;
+/**
+ * Stage which runs a gaussian blur over an image.
+ * @author Ben Culkin
+ *
+ */
public class GaussStage extends AbstractPipelineStage {
private int m;
private double sig, k;
+ /**
+ * Create a new gaussian blur stage.
+ */
public GaussStage() {
super(StageType.IMGTRANS);
}
@@ -33,6 +41,10 @@ public class GaussStage extends AbstractPipelineStage {
return ret;
}
+ /* @TODO 5 Oct, 2020 - Ben Culkin - :GaussianDoc
+ *
+ * Should document this better, when I get a chance to relookup the applicable math.
+ */
private Kernel genKern() {
float[][] w = new float[m][m];
@@ -93,10 +105,12 @@ public class GaussStage extends AbstractPipelineStage {
mField.field.addPropertyChangeListener("value", (ev) -> {
m = (Integer) mField.field.getValue();
});
+
LabeledInputPanel sigField = new LabeledInputPanel("Value for sigma", 3.0);
sigField.field.addPropertyChangeListener("value", (ev) -> {
sig = (Double) sigField.field.getValue();
});
+
LabeledInputPanel kField = new LabeledInputPanel("Value for k", 1.0);
kField.field.addPropertyChangeListener("value", (ev) -> {
k = (Double) kField.field.getValue();
diff --git a/src/bjc/imgchain/pipeline/stages/GreyscaleStage.java b/src/bjc/imgchain/pipeline/stages/GreyscaleStage.java
index 4cc227b..a7dc773 100644
--- a/src/bjc/imgchain/pipeline/stages/GreyscaleStage.java
+++ b/src/bjc/imgchain/pipeline/stages/GreyscaleStage.java
@@ -5,12 +5,22 @@ import javax.swing.JLabel;
import bjc.imgchain.pipeline.StageType;
+/**
+ * Transforms an image to a greyscale version.
+ *
+ * @author Ben Culkin
+ *
+ */
public class GreyscaleStage extends AbstractPixelStage {
+ /**
+ * Create a new greyscale stage.
+ */
public GreyscaleStage() {
super(StageType.IMGTRANS);
}
+ @Override
public int[] processPixel(int[] pix) {
int[] ret = new int[4];
diff --git a/src/bjc/imgchain/pipeline/stages/InverseColorStage.java b/src/bjc/imgchain/pipeline/stages/InverseColorStage.java
index 5157736..b3b8aee 100644
--- a/src/bjc/imgchain/pipeline/stages/InverseColorStage.java
+++ b/src/bjc/imgchain/pipeline/stages/InverseColorStage.java
@@ -5,8 +5,17 @@ import javax.swing.JLabel;
import bjc.imgchain.pipeline.StageType;
-public class NegativeStage extends AbstractPixelStage {
- public NegativeStage() {
+/**
+ * Stage which inverts image colors.
+ *
+ * @author Ben Culkin
+ *
+ */
+public class InverseColorStage extends AbstractPixelStage {
+ /**
+ * Create a new inversion stage.
+ */
+ public InverseColorStage() {
super(StageType.IMGTRANS);
}
diff --git a/src/bjc/imgchain/pipeline/stages/LoadStage.java b/src/bjc/imgchain/pipeline/stages/LoadStage.java
index ddf7939..d34b419 100644
--- a/src/bjc/imgchain/pipeline/stages/LoadStage.java
+++ b/src/bjc/imgchain/pipeline/stages/LoadStage.java
@@ -16,9 +16,17 @@ import javax.swing.JTextField;
import bjc.imgchain.pipeline.StageType;
+/**
+ * Stage which loads an image.
+ * @author Ben Culkin
+ *
+ */
public class LoadStage extends AbstractPipelineStage {
private String fileName;
+ /**
+ * Create a new stage which loads an image.
+ */
public LoadStage() {
super(StageType.IMGSOURCE);
}
diff --git a/src/bjc/imgchain/pipeline/stages/PipeStage.java b/src/bjc/imgchain/pipeline/stages/PipeStage.java
index 3b06b4f..f74e322 100644
--- a/src/bjc/imgchain/pipeline/stages/PipeStage.java
+++ b/src/bjc/imgchain/pipeline/stages/PipeStage.java
@@ -14,9 +14,17 @@ import bjc.imgchain.pipeline.Pipeline;
import bjc.imgchain.pipeline.PipelinePicker;
import bjc.imgchain.pipeline.StageType;
+/**
+ * Stage which runs a sub-pipeline.
+ * @author Ben Culkin
+ *
+ */
public class PipeStage extends AbstractPipelineStage {
private String pipeName;
+ /**
+ * Create a new sub-pipeline stage.
+ */
public PipeStage() {
super(StageType.IMGTRANS);
}
diff --git a/src/bjc/imgchain/pipeline/stages/RecallStage.java b/src/bjc/imgchain/pipeline/stages/RecallStage.java
index bcbbddb..1ee9892 100644
--- a/src/bjc/imgchain/pipeline/stages/RecallStage.java
+++ b/src/bjc/imgchain/pipeline/stages/RecallStage.java
@@ -8,9 +8,17 @@ import bjc.imgchain.ImgChain;
import bjc.imgchain.ImgPickerPanel;
import bjc.imgchain.pipeline.StageType;
+/**
+ * Stage which recalls an image from memory.
+ * @author Ben Culkin
+ *
+ */
public class RecallStage extends AbstractPipelineStage {
private String stashName;
+ /**
+ * Create a new recall stage.
+ */
public RecallStage() {
super(StageType.IMGSOURCE);
}
diff --git a/src/bjc/imgchain/pipeline/stages/SaveStage.java b/src/bjc/imgchain/pipeline/stages/SaveStage.java
index e38e403..82bf8f3 100644
--- a/src/bjc/imgchain/pipeline/stages/SaveStage.java
+++ b/src/bjc/imgchain/pipeline/stages/SaveStage.java
@@ -17,9 +17,18 @@ import javax.swing.JTextField;
import bjc.imgchain.pipeline.StageType;
import bjc.imgchain.utils.Utils;
+/**
+ * Stage which saves an image.
+ *
+ * @author Ben Culkin
+ *
+ */
public class SaveStage extends AbstractPipelineStage {
private String fileName;
+ /**
+ * Create a stage that saves an image.
+ */
public SaveStage() {
super(StageType.IMGSINK);
}
diff --git a/src/bjc/imgchain/pipeline/stages/StagePicker.java b/src/bjc/imgchain/pipeline/stages/StagePicker.java
index a62b15e..0d26139 100644
--- a/src/bjc/imgchain/pipeline/stages/StagePicker.java
+++ b/src/bjc/imgchain/pipeline/stages/StagePicker.java
@@ -11,11 +11,23 @@ import javax.swing.JTable;
import bjc.imgchain.utils.ImmutableTableModel;
+/**
+ * Stage picker GUI.
+ *
+ * @author Ben Culkin
+ *
+ */
public class StagePicker extends JDialog {
private static final long serialVersionUID = 1L;
+ /**
+ * Stage name to pick.
+ */
public String stageName;
+ /**
+ * Create a new stage picker.
+ */
public StagePicker() {
super();
diff --git a/src/bjc/imgchain/pipeline/stages/StashStage.java b/src/bjc/imgchain/pipeline/stages/StashStage.java
index 47689f5..68579c0 100644
--- a/src/bjc/imgchain/pipeline/stages/StashStage.java
+++ b/src/bjc/imgchain/pipeline/stages/StashStage.java
@@ -8,9 +8,18 @@ import bjc.imgchain.ImgChain;
import bjc.imgchain.pipeline.StageType;
import bjc.imgchain.utils.LabeledInputPanel;
+/**
+ * Stage which stashes an image.
+ *
+ * @author Ben Culkin
+ *
+ */
public class StashStage extends AbstractPipelineStage {
private String stashName;
+ /**
+ * Create a new image-stashing stage.
+ */
public StashStage() {
super(StageType.IMGSOURCE);
}
diff --git a/src/bjc/imgchain/pipeline/stages/SubMaskStage.java b/src/bjc/imgchain/pipeline/stages/SubMaskStage.java
index 594c97f..f06bff0 100644
--- a/src/bjc/imgchain/pipeline/stages/SubMaskStage.java
+++ b/src/bjc/imgchain/pipeline/stages/SubMaskStage.java
@@ -10,9 +10,18 @@ import bjc.imgchain.ImgPickerPanel;
import bjc.imgchain.pipeline.StageType;
import bjc.imgchain.utils.Utils;
+/**
+ * Stage which applies a subtraction mask to the image.
+ *
+ * @author Ben Culkin
+ *
+ */
public class SubMaskStage extends AbstractPipelineStage {
private String masqueName;
+ /**
+ * Create a new subtraction mask stage.
+ */
public SubMaskStage() {
super(StageType.IMGTRANS);
}
diff --git a/src/bjc/imgchain/pipeline/stages/ThresholdStage.java b/src/bjc/imgchain/pipeline/stages/ThresholdStage.java
index 55a4dd3..146c5c4 100644
--- a/src/bjc/imgchain/pipeline/stages/ThresholdStage.java
+++ b/src/bjc/imgchain/pipeline/stages/ThresholdStage.java
@@ -10,11 +10,27 @@ import javax.swing.border.TitledBorder;
import bjc.imgchain.pipeline.StageType;
import bjc.imgchain.utils.LabeledInputPanel;
+/**
+ * Stage which converts an image into three-tone.
+ *
+ * @author Ben Culkin
+ *
+ */
public class ThresholdStage extends AbstractPixelStage {
+ /**
+ * Create a new threshold stage, where all of the thresholds are 0.
+ */
public ThresholdStage() {
this(0, 0, 0);
}
+ /**
+ * Creates a new threshold stage.
+ *
+ * @param rr The red threshold.
+ * @param gg The green threshold.
+ * @param bb The blue threshold.
+ */
public ThresholdStage(int rr, int gg, int bb) {
super(StageType.IMGTRANS);
diff --git a/src/bjc/imgchain/utils/ImmutableTableModel.java b/src/bjc/imgchain/utils/ImmutableTableModel.java
index d5e8027..e0b561a 100644
--- a/src/bjc/imgchain/utils/ImmutableTableModel.java
+++ b/src/bjc/imgchain/utils/ImmutableTableModel.java
@@ -2,9 +2,20 @@ package bjc.imgchain.utils;
import javax.swing.table.DefaultTableModel;
+/**
+ * An immmutable table model.
+ * @author Ben Culkin
+ *
+ */
public class ImmutableTableModel extends DefaultTableModel {
private static final long serialVersionUID = 6459890821518409439L;
+ /**
+ * Create a new immutable table model
+ *
+ * @param data The data in the model.
+ * @param columnNames The column names for the model.
+ */
public ImmutableTableModel(Object[][] data, Object[] columnNames) {
super(data, columnNames);
}
diff --git a/src/bjc/imgchain/utils/Utils.java b/src/bjc/imgchain/utils/Utils.java
index 86daa0d..9a1f2be 100644
--- a/src/bjc/imgchain/utils/Utils.java
+++ b/src/bjc/imgchain/utils/Utils.java
@@ -11,7 +11,22 @@ import javax.swing.JLabel;
import bjc.imgchain.ImgChain;
+/**
+ * Utility stuff for ImgChain.
+ *
+ * @author Ben Culkin
+ *
+ */
public class Utils {
+ /**
+ * Converts an image into a buffered image.
+ *
+ * @param img
+ * The image to convert to a buffered image.
+ *
+ * @return The buffered image. Note that if img is already a buffered image, it
+ * will return the same argument.
+ */
public static BufferedImage toBuffered(Image img) {
if (img instanceof BufferedImage) {
return (BufferedImage) img;
@@ -36,21 +51,53 @@ public class Utils {
return bufimg;
}
+ /**
+ * Convert a pixel to an ARGB quad array.
+ *
+ * @param rbg
+ * The pixel to convert.
+ *
+ * @return The pixel as an ARGB array.
+ */
public static int[] toARGBQuad(int rbg) {
- return new int[] { (rbg >> 24) & 0xff, (rbg >> 16) & 0xff, (rbg >> 8) & 0xff, rbg & 0xff };
+ return new int[] {
+ (rbg >> 24) & 0xff, (rbg >> 16) & 0xff, (rbg >> 8) & 0xff, rbg & 0xff
+ };
}
+ /**
+ * Convert an ARGB quad array to a pixel.
+ *
+ * @param argb
+ * An ARGB array.
+ *
+ * @return The pixel
+ */
public static int fromARGBQuad(int[] argb) {
return (argb[0] << 24) | (argb[1] << 16) | (argb[2] << 8) | argb[3];
}
+ /**
+ * Pads an array on both sides.
+ *
+ * @param arr
+ * The initial array.
+ * @param padWith
+ * The element to pad with.
+ * @param numOfPads
+ * The number of pads to apply.
+ *
+ * @return The padded array.
+ */
public static int[][] padarray(int[][] arr, int padWith, int numOfPads) {
int[][] temp = new int[arr.length + numOfPads * 2][arr[0].length + numOfPads * 2];
+
for (int i = 0; i < temp.length; i++) {
for (int j = 0; j < temp[i].length; j++) {
temp[i][j] = padWith;
}
}
+
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
temp[i + numOfPads][j + numOfPads] = arr[i][j];
@@ -59,20 +106,26 @@ public class Utils {
return temp;
}
+ /**
+ * Displays an image.
+ *
+ * @param processed
+ * The image to display.
+ * @param title
+ * The title for the image.
+ */
public static void displayImage(Image processed, String title) {
- {
- BufferedImage resimg = toBuffered(processed);
+ BufferedImage resimg = toBuffered(processed);
- JInternalFrame displayFrame = new JInternalFrame(title, false, true, true);
- displayFrame.setSize(resimg.getWidth(), resimg.getHeight());
- displayFrame.setLayout(new GridLayout(1, 1));
+ JInternalFrame displayFrame = new JInternalFrame(title, false, true, true);
+ displayFrame.setSize(resimg.getWidth(), resimg.getHeight());
+ displayFrame.setLayout(new GridLayout(1, 1));
- JLabel displayLabel = new JLabel(new ImageIcon(resimg));
+ JLabel displayLabel = new JLabel(new ImageIcon(resimg));
- displayFrame.add(displayLabel);
+ displayFrame.add(displayLabel);
- ImgChain.chan.desktop.add(displayFrame);
- displayFrame.setVisible(true);
- }
+ ImgChain.chan.desktop.add(displayFrame);
+ displayFrame.setVisible(true);
}
}