Skip to content

Add new arg parameter to GenerateTags for configuring output image scale #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/april/tag/GenerateTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,22 @@
public class GenerateTags {
public static void main(String args[])
{
if (args.length != 2) {
System.out.printf("Usage: <tagclass> <outputdir>\n");
if (args.length < 2 || args.length > 3) {
System.out.printf("Usage: <tagclass> <outputdir> [<scalefactor>]\n");
System.out.printf("Example: april.tag.Tag25h11 /tmp/tag25h11\n");
return;
}

String cls = args[0];
String dirpath = args[1] + "/";
int scaleFactor = 1;
if (args.length > 2) {
scaleFactor = Integer.parseInt(args[2]);
if (scaleFactor < 1) {
System.err.println("Scale factor must be greater or equals 1");
return;
}
}

TagFamily tagFamily = (TagFamily) april.util.ReflectUtil.createObject(cls);
if (tagFamily == null) {
Expand All @@ -56,7 +64,7 @@ public static void main(String args[])
f.mkdirs();

renderer.writeAllImagesMosaic(dirpath+"mosaic.png");
renderer.writeAllImages(dirpath, tagFamily.getFilePrefix());
renderer.writeAllImages(dirpath, tagFamily.getFilePrefix(), scaleFactor);
renderer.writeAllImagesPostScript(dirpath+"alltags.ps");
} catch (IOException ex) {
System.out.println("ex: "+ex);
Expand Down
11 changes: 6 additions & 5 deletions src/april/tag/ImageLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,15 @@ public static int[][] rotate90(int[][] im1) {
return im2;
}

public BufferedImage renderToImage(long code) {
public BufferedImage renderToImage(long code, int scaleFactor) {
int[][] imageData = renderToArray(code);
int scaledSize = size * scaleFactor;

BufferedImage im = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
BufferedImage im = new BufferedImage(scaledSize, scaledSize, BufferedImage.TYPE_INT_ARGB);
for (int y = 0; y < scaledSize; y++) {
for (int x = 0; x < scaledSize; x++) {
int value;
switch(imageData[y][x]) {
switch(imageData[y / scaleFactor][x / scaleFactor]) {
case 0:
value = BLACK;
break;
Expand Down
13 changes: 9 additions & 4 deletions src/april/tag/TagRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ public void writeAllImagesPostScript(String filepath) throws IOException
* the first block is nbits, the second block is hamming distance,
* and the final block is the id.
**/
public void writeAllImages(String dirpath, String prefix) throws IOException
public void writeAllImages(String dirpath, String prefix, int scaleFactor) throws IOException
{
for (int i = 0; i < codes.length; i++) {
BufferedImage im = makeImage(i);
BufferedImage im = makeImage(i, scaleFactor);
String fname = String.format("%s_%05d.png",
prefix,
i);
Expand All @@ -180,9 +180,14 @@ public void writeAllImages(String dirpath, String prefix) throws IOException
}
}

public BufferedImage makeImage(int id)
public BufferedImage makeImage(int id, int scaleFactor)
{
long v = codes[id];
return layout.renderToImage(v);
return layout.renderToImage(v, scaleFactor);
}

public BufferedImage makeImage(int id)
{
return makeImage(id, 1);
}
}