Skip to content

Commit

Permalink
Initial import.
Browse files Browse the repository at this point in the history
  • Loading branch information
kayahr committed Oct 2, 2006
1 parent 306e234 commit 4d5d219
Show file tree
Hide file tree
Showing 19 changed files with 14,605 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .classpath
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
17 changes: 17 additions & 0 deletions .project
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>scilter</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
320 changes: 320 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions .settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,6 @@
#Mon Oct 02 16:29:52 CEST 2006
eclipse.preferences.version=1
formatter_profile=_Ailis
formatter_settings_version=10
internal.default.compliance=default
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates><template autoinsert\="false" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">\n/**\n * Returns the ${bare_field_name}.\n *\n * @return The ${bare_field_name}\n */\n</template><template autoinsert\="false" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">\n/**\n * Sets the ${bare_field_name}.\n *\n * @param ${param} \n * The ${bare_field_name} to set\n */\n</template><template autoinsert\="false" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * Constructor\n *\n * ${tags}\n */\n</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*\n * $$Id$$\n * Copyright (C) 2006 Klaus Reimer &lt;k@ailis.de&gt;\n * \n * This program is free software; you can redistribute it and/or modify it \n * under the terms of the GNU Lesser General Public License as published by the \n * Free Software Foundation; either version 2.1 of the License, or (at your \n * option) any later version.\n * \n * This program is distributed in the hope that it will be useful, but WITHOUT \n * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or \n * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License \n * for more details.\n * \n * You should have received a copy of the GNU Lesser General Public License \n * along with this program; if not, write to the Free Software Foundation, \n * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n */\n</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * ${type_name}\n *\n * @author Klaus Reimer (k@ailis.de)\n * @version $$Revision$$\n * ${tags}\n */\n</template><template autoinsert\="false" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/** ${field} */</template><template autoinsert\="false" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * TODO Document me\!\n *\n * ${tags}\n */\n</template><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/**\n * ${see_to_overridden}\n */\n</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="false" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\n${package_declaration}\n\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="false" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// Ignored</template><template autoinsert\="false" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// Empty</template><template autoinsert\="false" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}</template><template autoinsert\="false" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
63 changes: 63 additions & 0 deletions src/main/java/de/ailis/scilter/AbstractScaleFilter.java
@@ -0,0 +1,63 @@
/*
* $Id$
* Copyright (C) 2006 Klaus Reimer <k@ailis.de>
*
* This program 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 2.1 of the License, or (at your
* option) any later version.
*
* This program 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 this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

package de.ailis.scilter;

import java.awt.image.BufferedImage;


/**
* A base class for the scale filters implementing some common functionality.
*
* @author Klaus Reimer (k@ailis.de)
* @version $Revision$
*/

public abstract class AbstractScaleFilter implements ScaleFilter
{
/**
* @see ScaleFilter#scale(java.awt.image.BufferedImage)
*/

public BufferedImage scale(BufferedImage image)
{
int[] pixels;
int width, height;
int scaleFactor;
int newWidth, newHeight;
BufferedImage out;

// Get the original width
width = image.getWidth();
height = image.getHeight();

// Scale the pixels
pixels = scale(image.getRGB(0, 0, width, height, null, 0, width), width, height);

// Determine new picture size
scaleFactor = getScaleFactor();
newWidth = width * scaleFactor;
newHeight = height * scaleFactor;

// Create and return the new picture
out = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB);
out.setRGB(0, 0, newWidth, newHeight, pixels, 0, newWidth);
return out;
}
}
67 changes: 67 additions & 0 deletions src/main/java/de/ailis/scilter/ScaleFilter.java
@@ -0,0 +1,67 @@
/*
* $Id$
* Copyright (C) 2006 Klaus Reimer <k@ailis.de>
*
* This program 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 2.1 of the License, or (at your
* option) any later version.
*
* This program 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 this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

package de.ailis.scilter;

import java.awt.image.BufferedImage;


/**
* The interface for all scale filters.
*
* @author Klaus Reimer (k@ailis.de)
* @version $Revision$
*/

public interface ScaleFilter
{
/**
* Returns the scale factor of the scale filter (For example 2, 3 or 4).
*
* @return The scale factor.
*/

public int getScaleFactor();


/**
* Scales the specified image and returns the new scaled image.
*
* @param image
* The original image to scale
* @return The scaled image
*/

public BufferedImage scale(BufferedImage image);


/**
* Scales the specified pixel data (In RGB888 format, alpha values will be
* lost). Returns pixel array will also be in RGB888 format.
*
* @param pixels
* The pixel array
* @param width
* The image width
* @param height The image height
* @return The scaled pixel data
*/

public int[] scale(int[] pixels, int width, int height);
}
127 changes: 127 additions & 0 deletions src/main/java/de/ailis/scilter/ScaleFilterFactory.java
@@ -0,0 +1,127 @@
/*
* $Id$
* Copyright (C) 2006 Klaus Reimer <k@ailis.de>
*
* This program 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 2.1 of the License, or (at your
* option) any later version.
*
* This program 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 this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

package de.ailis.scilter;

import java.util.HashMap;
import java.util.Map;

import de.ailis.scilter.filter.Hq2xFilter;
import de.ailis.scilter.filter.Hq3xFilter;
import de.ailis.scilter.filter.Hq4xFilter;
import de.ailis.scilter.filter.Nearest2xFilter;
import de.ailis.scilter.filter.Nearest3xFilter;
import de.ailis.scilter.filter.Nearest4xFilter;
import de.ailis.scilter.filter.NormalFilter;
import de.ailis.scilter.filter.Scale2xFilter;
import de.ailis.scilter.filter.Scale3xFilter;


/**
* The Scale Filter Factory can be queried about the implemented algorithms and
* can return an implementation of a desired algorithm.
*
* @author Klaus Reimer (k@ailis.de)
* @version $Revision$
*/

public class ScaleFilterFactory
{
/** The internal map with filter names and filter classes */
private static final Map<String, Class<? extends ScaleFilter>> filters = buildFilterMap();


/**
* Private constructor
*/

private ScaleFilterFactory()
{
super();
}


/**
* Builds and returns the internal map with filter names and filter classes.
*
* @return The internal filters map
*/

private static final Map<String, Class<? extends ScaleFilter>> buildFilterMap()
{
Map<String, Class<? extends ScaleFilter>> filters;

filters = new HashMap<String, Class<? extends ScaleFilter>>(3);
filters.put("normal", NormalFilter.class);
filters.put("nearest2x", Nearest2xFilter.class);
filters.put("nearest3x", Nearest3xFilter.class);
filters.put("nearest4x", Nearest4xFilter.class);
filters.put("scale2x", Scale2xFilter.class);
filters.put("scale3x", Scale3xFilter.class);
filters.put("hq2x", Hq2xFilter.class);
filters.put("hq3x", Hq3xFilter.class);
filters.put("hq4x", Hq4xFilter.class);
return filters;
}


/**
* Returns an array with all the names of implemented scale filters. These
* names can be used with the createFilter method to get an instance of a
* scale filter implementation.
*
* @return The array with implemented scale filter names
*/

public static String[] getFilterNames()
{
return filters.keySet().toArray(new String[0]);
}


/**
* Returns an instance of the Scale Filter with the specified name.
*
* @param filterName
* The Scale Filter name
* @return The instance of the Scale Filter
*/

public static ScaleFilter createFilter(String filterName)
{
Class<? extends ScaleFilter> c;

c = filters.get(filterName);
if (c == null)
{
throw new IllegalArgumentException(
"No implementation for scale filter with name " + filterName
+ " was found");
}
try
{
return c.newInstance();
}
catch (Exception e)
{
throw new RuntimeException(
"Unable to create instance of scale filter: " + e, e);
}
}
}
82 changes: 82 additions & 0 deletions src/main/java/de/ailis/scilter/Scilter.java
@@ -0,0 +1,82 @@
/*
* $Id$
* Copyright (C) 2006 Klaus Reimer <k@ailis.de>
*
* This program 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 2.1 of the License, or (at your
* option) any later version.
*
* This program 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 this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

package de.ailis.scilter;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import de.ailis.scilter.util.FileUtils;


/**
* A command line program to scale a picture with one of the scaling filters of
* Scilter.
*
* @author Klaus Reimer (k@ailis.de)
* @version $Revision$
*/

public class Scilter
{
/**
* Private constructor
*/

private Scilter()
{
super();
}


/**
* First parameter is the scaling method, second parameter is the source
* file and the third parameter is the destination file.
*
* @param args
* The command line arguments
* @throws IOException
*/

public static void main(String[] args) throws IOException
{
BufferedImage in, out;
File file;

if (args.length != 3)
{
System.out.println("Syntax: Scilter ALGORITHM INFILE OUTFILE");
System.out.println("Implemented algorithms:");
for (String name: ScaleFilterFactory.getFilterNames())
{
System.out.print(" ");
System.out.println(name);
}
System.exit(0);
}

in = ImageIO.read(new File(args[1]));
out = ScaleFilterFactory.createFilter(args[0]).scale(in);
file = new File(args[2]);
ImageIO.write(out, FileUtils.getFileExtension(file), new File(args[2]));
}
}

0 comments on commit 4d5d219

Please sign in to comment.