Commits

petermr  committed b5d5afe Draft

initial commit

  • Participants

Comments (0)

Files changed (32)

+foo
+^.project$
+^.settings/
+^.classpath$
+^.hgignore~$
+^misc/.*
+^target/.*
+/target/
+^\.idea/
+== Development version of SVG-XOM (petermr) ==
+
+Requires http://bitbucket.org/petermr/euclid-dev
+(This may need updating/checking out as it may not be in WWMM Maven)
+
+
+
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>uk.ac.cam.ch.wwmm</groupId>
+        <artifactId>wwmm-parent</artifactId>
+        <version>4</version>
+    </parent>
+
+    <groupId>org.xml-cml</groupId>
+    <artifactId>imagelib</artifactId>
+    <version>0.1-SNAPSHOT</version>
+    <packaging>jar</packaging>
+    <name>SVG</name>
+    <description>A Java tool for annotating images (e.g. with licences and authors)</description>
+
+    <licenses>
+        <license>
+            <name>Apache License, Version 2.0</name>
+            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+            <distribution>repo</distribution>
+        </license>
+    </licenses>
+    <scm>
+        <url>https://bitbucket.org/petermr/svg/src</url>
+        <connection>scm:hg:http://bitbucket.org/petermr/svg</connection>
+        <developerConnection>scm:hg:https://bitbucket.org/petermr/svg</developerConnection>
+    </scm>
+
+    <developers>
+        <developer>
+            <id>pm286</id>
+            <name>Peter Murray-Rust</name>
+        </developer>
+    </developers>
+
+    <inceptionYear>2007</inceptionYear>
+    <ciManagement>
+        <system>hudson</system>
+        <url>http://hudson.ch.cam.ac.uk/job/svg</url>
+    </ciManagement>
+
+    <organization>
+        <name>Peter Murray-Rust</name>
+        <url>http://blogs.ch.cam.ac.uk/pmr</url>
+    </organization>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>cobertura-maven-plugin</artifactId>
+                <configuration>
+                    <check>
+                        <haltOnFailure>false</haltOnFailure>
+                        <regexes>
+                            <regex>
+                                <pattern>org.xmlcml.cml.*</pattern>
+                                <branchRate>80</branchRate>
+                                <lineRate>80</lineRate>
+                            </regex>
+                        </regexes>
+                    </check>
+                    <instrumentation>
+                        <includes>
+                            <include>org/xmlcml/cml/**/*.class</include>
+                        </includes>
+                    </instrumentation>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>clean</id>
+                        <phase>pre-site</phase>
+                        <goals>
+                            <goal>clean</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>instrument</id>
+                        <phase>site</phase>
+                        <goals>
+                            <goal>instrument</goal>
+                            <goal>cobertura</goal>
+                            <goal>check</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>com.mycila.maven-license-plugin</groupId>
+                <artifactId>maven-license-plugin</artifactId>
+                <configuration>
+                    <header>src/main/resources/header.txt</header>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <!-- remove <repositories> for release to maven central -->
+    <repositories>
+        <repository>
+            <id>ucc-repo</id>
+            <name>UCC Maven Repository</name>
+            <url>https://maven.ch.cam.ac.uk/m2repo</url>
+        </repository>
+    </repositories>
+    
+    <dependencies>
+    <!--  
+        <dependency>
+            <groupId>org.xml-cml</groupId>
+            <artifactId>euclid-dev</artifactId>
+            <version>1.1-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.xml-cml</groupId>
+            <artifactId>cmlxom</artifactId>
+            <version>3.2-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <version>1.1-SNAPSHOT</version>
+            <groupId>org.xml-cml</groupId>
+            <artifactId>jumbo-testutil</artifactId>
+            <scope>test</scope>
+        </dependency>
+-->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.8.2</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <version>1.2.16</version>
+        </dependency>
+        <!-- 
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>2.0.1</version>
+        </dependency>
+        <dependency>
+            <groupId>xom</groupId>
+            <artifactId>xom</artifactId>
+            <version>1.2.5</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-math</artifactId>
+            <version>2.2</version>
+        </dependency>
+        -->
+    </dependencies>
+    <reporting>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-project-info-reports-plugin</artifactId>
+                <reportSets>
+                    <reportSet>
+                        <reports>
+                            <report>index</report>
+                            <report>summary</report>
+                            <report>dependencies</report>
+                            <report>project-team</report>
+                            <report>license</report>
+                            <report>cim</report>
+                            <report>scm</report>
+                        </reports>
+                    </reportSet>
+                </reportSets>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-javadoc-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-report-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jxr-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-pmd-plugin</artifactId>
+                <configuration>
+                    <targetJdk>1.5</targetJdk>
+                    <linkXRef>true</linkXRef>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-checkstyle-plugin</artifactId>
+                <configuration>
+                    <configLocation>src/test/resources/checkstyle.xml</configLocation>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>cobertura-maven-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>apt-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </reporting>
+</project>

File src/main/java/org/xmlcml/imagelib/ImageLib.java

+package org.xmlcml.imagelib;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import java.awt.image.WritableRaster;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.imageio.ImageIO;
+
+import org.apache.log4j.Logger;
+
+public class ImageLib {
+
+	private final static Logger LOG = Logger.getLogger(ImageLib.class);
+	private static final String DATA = "data";
+	private static final String BASE64 = "base64";
+	public static final String IMAGE_PNG = "image/png";
+	public static final String PNG = "PNG";
+	public static final String IMAGE_BMP = "image/bmp";
+	public static final String BMP = "BMP";
+	
+	private static final String XLINK_PREF = "xlink";
+	private static final String HREF = "href";
+	private static final String XLINK_NS = "http://www.w3.org/1999/xlink";
+	public final static String TAG ="image";
+
+	private WritableRaster readRasterText(String text, String filename, int height) {
+		int width = text.length()*6;
+		int imageType = 6;
+		BufferedImage bufferedImage = new BufferedImage(width, height, imageType);
+		debugImage("new image ", bufferedImage);
+		Graphics2D g2d = bufferedImage.createGraphics();
+		g2d.setColor(Color.BLACK);
+		g2d.drawString(text, 0, height);
+		outputImage(bufferedImage, filename, ImageLib.PNG);
+		WritableRaster raster = bufferedImage.getRaster();
+		return raster;
+	}
+
+	void overpaint(BufferedImage image, WritableRaster raster) {
+		debugImage("overpaint", image);
+		debugRaster("overpaint", raster);
+		try {
+			image.setData(raster);
+		} catch (ArrayIndexOutOfBoundsException e) {
+			LOG.debug("AIOOBE: "+e);
+		}
+	}
+
+	WritableRaster readRaster(String inputFile) {
+		BufferedImage bufferedImage = readBufferedImage(inputFile);
+		WritableRaster raster = bufferedImage.getRaster();
+		debugRaster("readRaster", raster);
+		return raster;
+	}
+
+	private void debugImage(String msg, BufferedImage image) {
+		LOG.debug(msg+" image w: "+image.getWidth()+" h: "+image.getHeight()+" type "+image.getType());
+	}
+
+	private void debugRaster(String msg, WritableRaster raster) {
+		LOG.debug(msg+" raster w: "+raster.getWidth()+" h: "+raster.getHeight());
+	}
+
+	private BufferedImage readBufferedImage(String inputFile) {
+		BufferedImage bufferedImage = null;
+		File imgFile = new File(inputFile);
+		try {
+			if (imgFile == null || !imgFile.exists() || imgFile.isDirectory()) {
+				throw new RuntimeException("File is null or does not exist or is Directory: "+inputFile);
+			}
+			FileInputStream fis = new FileInputStream(imgFile);
+			bufferedImage = readBufferedImage(fis);
+		} catch (IOException e) {
+			throw new RuntimeException("Cannot read image", e);
+		}
+		debugImage("readBuffered", bufferedImage);
+		return bufferedImage;
+	}
+
+	private BufferedImage readBufferedImage(File imgFile) throws IOException {
+		BufferedImage bufferedImage;
+		bufferedImage = ImageIO.read(imgFile);
+		return bufferedImage;
+	}
+
+	BufferedImage readBufferedImage(InputStream is) throws IOException {
+		BufferedImage bufferedImage;
+		bufferedImage = ImageIO.read(is);
+		return bufferedImage;
+	}
+
+	void outputImage(BufferedImage bufferedImage, String filename, String type) {
+		try {
+			FileOutputStream fos = new FileOutputStream(new File(filename));
+			outputImage(bufferedImage, type, fos);
+			fos.close();
+		} catch (Exception e) {
+			throw new RuntimeException("Cannot write "+type, e);
+		}
+	}
+
+	public void outputImage(BufferedImage bufferedImage, String type,
+			FileOutputStream fos) throws IOException {
+		if (!ImageIO.write(bufferedImage, type, fos)) {
+			throw new RuntimeException("Failed to find writer for "+type);
+		}
+	}
+
+
+}

File src/test/java/org/xmlcml/imagelib/ImageLibTest.java

+package org.xmlcml.imagelib;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import java.awt.image.WritableRaster;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import javax.imageio.ImageIO;
+
+import org.apache.log4j.Logger;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class ImageLibTest {
+
+	private final static Logger LOG = Logger.getLogger(ImageLibTest.class);
+	
+	private static final String SVG_TEST = "src/test/resources/org/xmlcml/graphics/svg/";
+	
+		
+	@Test
+	public void testFigshare() throws Exception {
+		ImageLib imgLib = new ImageLib();
+		InputStream is = new URL("http://previews.figshare.com/1138891/preview_1138891.jpg").openStream();
+		BufferedImage targetBufferedImage = imgLib.readBufferedImage(is);
+		WritableRaster cc0Raster = imgLib.readRaster(SVG_TEST+"ccby.png");
+		imgLib.overpaint(targetBufferedImage, cc0Raster);
+		imgLib.outputImage(targetBufferedImage, SVG_TEST+"figshare1138891.png", ImageLib.PNG);
+	}
+	
+	// =================================================================
+	
+}

File src/test/resources/org/xmlcml/graphics/svg/canny1.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/capture1.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/cc0.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/ccby.PNG

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/chem.bmp

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/figshare.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/figshare1138891.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/gray1.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/imageTest.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/monochrome.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/monochrome1.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/monochrome2.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/monochrome2pmrcc0.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/monochrome2pubdom.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/monochrome2pubdomStream.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/monochrome2text.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/plots1.bmp

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/plots1.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/plots1a.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/plotscc0.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/plotspubdom.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/pmrcc0.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/pubdom.PNG

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/test.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/test1mini.bmp

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/test1mini.png

Added
New image

File src/test/resources/org/xmlcml/graphics/svg/text.png

Added
New image