aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTony McCrary2014-01-01 20:43:32 (EST)
committerLars Vogel2014-01-16 10:32:40 (EST)
commit41a08327f5e29418496b7bf1e519877f7e68df47 (patch)
treed904a3ff158deab8e87deb9a7a5391b54ce2af51
parente2987a13034becd6b6f5f9ac94f5baad7eb2b4d0 (diff)
downloadeclipse.platform.ui-41a08327f5e29418496b7bf1e519877f7e68df47.zip
eclipse.platform.ui-41a08327f5e29418496b7bf1e519877f7e68df47.tar.gz
eclipse.platform.ui-41a08327f5e29418496b7bf1e519877f7e68df47.tar.bz2
Changed the "hires" argument to "scale" allowing the user to specifyrefs/changes/03/20203/3
arbitrary scale values for rendering. Updated the readme to explain the arguments. Change-Id: I80d743d3964bf6cff7630deeeabae44349c177c2 Signed-off-by: Tony McCrary <tmccrary@gmail.com>
-rw-r--r--bundles/org.eclipse.ui.images.renderer/README.md4
-rw-r--r--bundles/org.eclipse.ui.images.renderer/src/main/java/org/eclipse/ui/images/renderer/RenderMojo.java83
2 files changed, 35 insertions, 52 deletions
diff --git a/bundles/org.eclipse.ui.images.renderer/README.md b/bundles/org.eclipse.ui.images.renderer/README.md
index 9d9ead4..ab484ce 100644
--- a/bundles/org.eclipse.ui.images.renderer/README.md
+++ b/bundles/org.eclipse.ui.images.renderer/README.md
@@ -21,6 +21,10 @@ mvn org.eclipse.ui:org.eclipse.ui.images.renderer:render-icons
This renders all of the svg icons in "eclipse-svg" into the "eclipse-png" folder of the org.eclipse.ui.images project, maintaining the directory structure (i.e. eclipse-svg/icondir will be rendered into org.eclipse.ui.images/eclipse-png/icondir).
+Supported runtime arguments (e.g mvn -Declipse.svg.scale=2 ...):
+
+eclipse.svg.scale - an integer that is used to scale output images (e.g. 2 will render a 16x16 svg at 32x32)
+eclipse.svg.renderthreads - an integer that specifies how many threads to use simultaneously while rendering
License
-------
diff --git a/bundles/org.eclipse.ui.images.renderer/src/main/java/org/eclipse/ui/images/renderer/RenderMojo.java b/bundles/org.eclipse.ui.images.renderer/src/main/java/org/eclipse/ui/images/renderer/RenderMojo.java
index 1778e29..baca708 100644
--- a/bundles/org.eclipse.ui.images.renderer/src/main/java/org/eclipse/ui/images/renderer/RenderMojo.java
+++ b/bundles/org.eclipse.ui.images.renderer/src/main/java/org/eclipse/ui/images/renderer/RenderMojo.java
@@ -23,7 +23,6 @@ import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -61,7 +60,7 @@ public class RenderMojo extends AbstractMojo {
Log log;
/** Used for high res rendering support. */
- public static final String ECLIPSE_SVG_HIGHRES = "eclipse.svg.highres";
+ public static final String ECLIPSE_SVG_SCALE = "eclipse.svg.scale";
/** Used to specify the number of render threads when rasterizing icons. */
public static final String RENDERTHREADS = "eclipse.svg.renderthreads";
@@ -119,18 +118,12 @@ public class RenderMojo extends AbstractMojo {
*/
private AtomicInteger counter;
- /**
- * A collection of lists for each Eclipse icon sets (o.e.workbench.ui,
- * o.e.jd.ui, etc).
- */
- Map<String, List<IconEntry>> galleryIconSets;
-
/** List of icons that failed to render, made safe for parallel access */
List<IconEntry> failedIcons = Collections
.synchronizedList(new ArrayList<IconEntry>(5));
- /** Whether to render the icons at 2x for high dpi displays. */
- private boolean highres;
+ /** The amount of scaling to apply to rasterized images. */
+ private int outputScale;
/** Used for creating desaturated icons */
private GrayscaleFilter grayFilter;
@@ -144,7 +137,7 @@ public class RenderMojo extends AbstractMojo {
public int getIconsRendered() {
return counter.get();
}
-
+
/**
* @return the number of icons that failed during the rendering process
*/
@@ -207,7 +200,7 @@ public class RenderMojo extends AbstractMojo {
// Create the document to rasterize
SVGDocument svgDocument = generateSVGDocument(icon);
-
+
if(svgDocument == null) {
return;
}
@@ -221,8 +214,8 @@ public class RenderMojo extends AbstractMojo {
int nativeWidth = Integer.parseInt(nativeWidthStr);
int nativeHeight = Integer.parseInt(nativeHeightStr);
- int doubleWidth = nativeWidth * 2;
- int doubleHeight = nativeHeight * 2;
+ int outputWidth = nativeWidth * outputScale;
+ int outputHeight = nativeHeight * outputScale;
// Guesstimate the PNG size in memory, BAOS will enlarge if necessary.
int outputInitSize = nativeWidth * nativeHeight * 4 + 1024;
@@ -232,13 +225,13 @@ public class RenderMojo extends AbstractMojo {
// Render to SVG
try {
log.info(Thread.currentThread().getName() + " "
- + " Rasterizing: " + icon.nameBase + ".png at " + nativeWidth
- + "x" + nativeHeight);
-
+ + " Rasterizing: " + icon.nameBase + ".png at " + outputWidth
+ + "x" + outputHeight);
+
TranscoderInput svgInput = new TranscoderInput(svgDocument);
-
- boolean success = renderIcon(icon.nameBase, nativeWidth, nativeHeight, svgInput, iconOutput);
-
+
+ boolean success = renderIcon(icon.nameBase, outputWidth, outputHeight, svgInput, iconOutput);
+
if (!success) {
log.error("Failed to render icon: " + icon.nameBase + ".png, skipping.");
failedIcons.add(icon);
@@ -257,7 +250,7 @@ public class RenderMojo extends AbstractMojo {
BufferedImage inputImage = null;
try {
inputImage = ImageIO.read(imageInputStream);
-
+
if(inputImage == null) {
log.error("Failed to generate BufferedImage from rendered icon, ImageIO returned null: " + icon.nameBase);
failedIcons.add(icon);
@@ -268,26 +261,8 @@ public class RenderMojo extends AbstractMojo {
failedIcons.add(icon);
return;
}
-
-
- // Default to the native svg size
- int targetWidth = nativeWidth;
- int targetHeight = nativeHeight;
-
- if(!highres) {
- log.info(Thread.currentThread().getName() + " "
- + " Rasterizing (Scaling Native): " + icon.nameBase
- + ".png at " + nativeWidth + "x" + nativeHeight);
- } else {
- log.info(Thread.currentThread().getName() + " "
- + " Rasterizing (Scaling Half): " + icon.nameBase
- + ".png at " + doubleWidth + "x" + doubleWidth);
-
- targetWidth = doubleWidth;
- targetHeight = doubleHeight;
- }
- writeIcon(icon, targetWidth, targetHeight, inputImage);
+ writeIcon(icon, outputWidth, outputHeight, inputImage);
}
/**
@@ -307,7 +282,7 @@ public class RenderMojo extends AbstractMojo {
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
-
+
// What kind of URI is batik expecting here??? the docs don't say
svgDocument = f.createSVGDocument("file://" + icon.nameBase + ".svg", iconDocumentStream);
} catch (Exception e3) {
@@ -561,7 +536,7 @@ public class RenderMojo extends AbstractMojo {
StringBuilder builder = new StringBuilder();
builder.append("d");
builder.append(parentDirName.substring(1, parentDirName.length()));
-
+
// Disabled variant folder name
String disabledVariant = builder.toString();
@@ -584,7 +559,7 @@ public class RenderMojo extends AbstractMojo {
}
IconEntry icon = createIcon(child, outputDir, disabledOutputDir);
-
+
icons.add(icon);
}
}
@@ -593,15 +568,15 @@ public class RenderMojo extends AbstractMojo {
* <p>Initializes rasterizer defaults</p>
*
* @param threads the number of threads to render with
- * @param highres whether to render high res output
+ * @param scale multiplier to use with icon output dimensions
*/
- private void init(int threads, boolean highres) {
+ private void init(int threads, int scale) {
this.threads = threads;
- this.highres = highres;
+ this.outputScale = Math.max(1, scale);
icons = new ArrayList<IconEntry>();
execPool = Executors.newFixedThreadPool(threads);
counter = new AtomicInteger();
-
+
grayFilter = new GrayscaleFilter();
desaturator = new HSBAdjustFilter();
@@ -627,15 +602,19 @@ public class RenderMojo extends AbstractMojo {
}
}
- // if high res is enabled, the icons will be rendered at 2x their native svg size
- String highresStr = System.getProperty(ECLIPSE_SVG_HIGHRES);
- boolean highres = Boolean.parseBoolean(highresStr);
+ // if high res is enabled, the icons output size will be scaled by iconScale
+ // Defaults to 1, meaning native size
+ int iconScale = 1;
+ String iconScaleStr = System.getProperty(ECLIPSE_SVG_SCALE);
+ if(iconScaleStr != null) {
+ iconScale = Integer.parseInt(iconScaleStr);
+ }
// Track the time it takes to render the entire set
long totalStartTime = System.currentTimeMillis();
// initialize defaults (the old renderer was instantiated via constructor)
- init(threads, highres);
+ init(threads, iconScale);
String workingDirectory = System.getProperty("user.dir");
@@ -658,7 +637,7 @@ public class RenderMojo extends AbstractMojo {
log.info("Working directory: " + outputDir.getAbsolutePath());
log.info("SVG Icon Directory: " + iconDirectoryRoot.getAbsolutePath());
- log.info("Rendering icons with " + threads + " threads, high res output enabled: " + highres);
+ log.info("Rendering icons with " + threads + " threads, scaling output to " + iconScale + "x");
long startTime = System.currentTimeMillis();
// Render the icons