diff options
| author | Ben Culkin <scorpress@gmail.com> | 2020-10-06 19:15:51 -0400 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2020-10-06 19:15:51 -0400 |
| commit | bdc3409184b28e2371c541a3d76b262d3f9f1f8e (patch) | |
| tree | eb3caf5c38326c668e4208b9d21129d03ebdb9ef /src/bjc/imgchain/utils/Utils.java | |
| parent | aa53ec99ef5a4ed95e010172975399e6a756c806 (diff) | |
Info cleanup
Diffstat (limited to 'src/bjc/imgchain/utils/Utils.java')
| -rw-r--r-- | src/bjc/imgchain/utils/Utils.java | 75 |
1 files changed, 64 insertions, 11 deletions
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);
}
}
|
