From: <fg...@us...> - 2009-02-15 20:58:31
|
Revision: 999 http://openutils.svn.sourceforge.net/openutils/?rev=999&view=rev Author: fgiust Date: 2009-02-15 20:58:20 +0000 (Sun, 15 Feb 2009) Log Message: ----------- adding support for CMYK/YCCK jpegs Modified Paths: -------------- trunk/openutils-mgnlmedia/pom.xml trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java trunk/openutils-mgnlmedia/src/main/resources/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.html Added Paths: ----------- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/BadImageFormatException.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/JpegUtils.java trunk/openutils-mgnlmedia/src/test/java/net/ trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/ trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/ trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/ trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/ trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/ trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/FileNodeData.java trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtilsTest.java trunk/openutils-mgnlmedia/src/test/resources/images/ trunk/openutils-mgnlmedia/src/test/resources/images/badimage.jpg trunk/openutils-mgnlmedia/src/test/resources/images/badimage.txt trunk/openutils-mgnlmedia/src/test/resources/images/ycck.jpg Property Changed: ---------------- trunk/openutils-mgnlmedia/ Property changes on: trunk/openutils-mgnlmedia ___________________________________________________________________ Modified: svn:ignore - .settings .checkstyle .classpath .project target + .settings .checkstyle .classpath .project target test-output temp-testng-customsuite.xml Modified: trunk/openutils-mgnlmedia/pom.xml =================================================================== --- trunk/openutils-mgnlmedia/pom.xml 2009-02-13 17:53:26 UTC (rev 998) +++ trunk/openutils-mgnlmedia/pom.xml 2009-02-15 20:58:20 UTC (rev 999) @@ -1,4 +1,5 @@ -<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"> +<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"> <parent> <groupId>net.sourceforge.openutils</groupId> <artifactId>openutils</artifactId> @@ -56,6 +57,11 @@ <version>2.1</version> </dependency> <dependency> + <groupId>com.drewnoakes</groupId> + <artifactId>metadata-extractor</artifactId> + <version>2.4.0-beta-1</version> + </dependency> + <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <classifier>jdk15</classifier> Added: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/BadImageFormatException.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/BadImageFormatException.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/BadImageFormatException.java 2009-02-15 20:58:20 UTC (rev 999) @@ -0,0 +1,32 @@ +package net.sourceforge.openutils.mgnlmedia.media.utils; + +/** + * @author fgiust + * @version $Id$ + */ +public class BadImageFormatException extends RuntimeException +{ + + /** + * Stable serialVersionUID. + */ + private static final long serialVersionUID = 42L; + + /** + * @param message + */ + public BadImageFormatException(String message) + { + super(message); + } + + /** + * @param message + * @param cause + */ + public BadImageFormatException(String message, Throwable cause) + { + super(message, cause); + } + +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/BadImageFormatException.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-02-13 17:53:26 UTC (rev 998) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-02-15 20:58:20 UTC (rev 999) @@ -51,6 +51,7 @@ import net.sourceforge.openutils.mgnlmedia.media.configuration.MediaConfigurationManager; import net.sourceforge.openutils.mgnlmedia.media.lifecycle.MediaModuleLifecycle; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang.ClassUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.NumberUtils; @@ -364,7 +365,7 @@ } } - private static InputStream getStream(BufferedImage image, String extension) throws IOException + public static InputStream getStream(BufferedImage image, String extension) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); BufferedOutputStream out = new BufferedOutputStream(bos); @@ -497,16 +498,9 @@ } extension = "jpg"; } - BufferedImage original; - try - { - original = ImageIO.read(image.getStream()); - } - catch (IOException e) - { - throw new RuntimeException(e); - } + BufferedImage original = createBufferedImage(image); + String resolutionName = "res-" + resolution; BufferedImage img = ImageUtils.getImageForResolution(original, resolution); @@ -617,4 +611,36 @@ return "jpg"; } } + + /** + * @param image + * @return + */ + public static BufferedImage createBufferedImage(NodeData image) + { + InputStream is = image.getStream(); + try + { + return ImageIO.read(is); + } + catch (IOException e) + { + // CMYK jpeg can't be read be ImageIO + // Caused by: javax.imageio.IIOException: Unsupported Image Type + BufferedImage result = JpegUtils.processNonStandardImage(image); + + if (result == null) + { + // throw the original exception back + throw new BadImageFormatException("Unable to handle " + image.getHandle(), e); + } + return result; + + } + finally + { + IOUtils.closeQuietly(is); + } + } + } Added: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/JpegUtils.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/JpegUtils.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/JpegUtils.java 2009-02-15 20:58:20 UTC (rev 999) @@ -0,0 +1,198 @@ +package net.sourceforge.openutils.mgnlmedia.media.utils; + +import info.magnolia.cms.core.NodeData; + +import java.awt.Transparency; +import java.awt.color.ColorSpace; +import java.awt.image.BufferedImage; +import java.awt.image.ColorModel; +import java.awt.image.ComponentColorModel; +import java.awt.image.DataBuffer; +import java.awt.image.DataBufferByte; +import java.awt.image.Raster; +import java.awt.image.WritableRaster; +import java.io.IOException; +import java.io.InputStream; +import java.util.Iterator; + +import javax.imageio.ImageIO; +import javax.imageio.ImageReader; +import javax.imageio.stream.ImageInputStream; + +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.drew.imaging.jpeg.JpegProcessingException; +import com.drew.imaging.jpeg.JpegSegmentReader; + + +/** + * Utility class for handling of CMYK/YCCK jpegs. + * @author fgiust + * @version $Id$ + */ +public class JpegUtils +{ + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(JpegUtils.class); + + /** + * Java's ImageIO can't process 4-component images and Java2D can't apply AffineTransformOp either, so convert + * raster data to RGB. Technique due to MArk Stephens. Free for any use. See + * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4799903 or + * http://www.mail-archive.com/jav...@ca.../msg03247.html + */ + public static BufferedImage createJPEG4(Raster raster, boolean ycckProfile) + { + int w = raster.getWidth(); + int h = raster.getHeight(); + byte[] rgb = new byte[w * h * 3]; + + // if (Adobe_APP14 and transform==2) then YCCK else CMYK + if (ycckProfile) + { // YCCK -- Adobe + + float[] Y = raster.getSamples(0, 0, w, h, 0, (float[]) null); + float[] Cb = raster.getSamples(0, 0, w, h, 1, (float[]) null); + float[] Cr = raster.getSamples(0, 0, w, h, 2, (float[]) null); + float[] K = raster.getSamples(0, 0, w, h, 3, (float[]) null); + + for (int i = 0, imax = Y.length, base = 0; i < imax; i++, base += 3) + { + float k = 220 - K[i], y = 255 - Y[i], cb = 255 - Cb[i], cr = 255 - Cr[i]; + + double val = y + 1.402 * (cr - 128) - k; + val = (val - 128) * .65f + 128; + rgb[base] = val < 0.0 ? (byte) 0 : val > 255.0 ? (byte) 0xff : (byte) (val + 0.5); + + val = y - 0.34414 * (cb - 128) - 0.71414 * (cr - 128) - k; + val = (val - 128) * .65f + 128; + rgb[base + 1] = val < 0.0 ? (byte) 0 : val > 255.0 ? (byte) 0xff : (byte) (val + 0.5); + + val = y + 1.772 * (cb - 128) - k; + val = (val - 128) * .65f + 128; + rgb[base + 2] = val < 0.0 ? (byte) 0 : val > 255.0 ? (byte) 0xff : (byte) (val + 0.5); + } + + } + else + { + // assert xform==0: xform; // CMYK + + int[] C = raster.getSamples(0, 0, w, h, 0, (int[]) null); + int[] M = raster.getSamples(0, 0, w, h, 1, (int[]) null); + int[] Y = raster.getSamples(0, 0, w, h, 2, (int[]) null); + int[] K = raster.getSamples(0, 0, w, h, 3, (int[]) null); + + for (int i = 0, imax = C.length, base = 0; i < imax; i++, base += 3) + { + int c = 255 - C[i]; + int m = 255 - M[i]; + int y = 255 - Y[i]; + int k = 255 - K[i]; + float kk = k / 255f; + + rgb[base] = (byte) (255 - Math.min(255f, c * kk + k)); + rgb[base + 1] = (byte) (255 - Math.min(255f, m * kk + k)); + rgb[base + 2] = (byte) (255 - Math.min(255f, y * kk + k)); + } + } + + // from other image types we know InterleavedRaster's can be + // manipulated by AffineTransformOp, so create one of those. + raster = Raster.createInterleavedRaster( + new DataBufferByte(rgb, rgb.length), + w, + h, + w * 3, + 3, + new int[]{0, 1, 2 }, + null); + + ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); + ColorModel cm = new ComponentColorModel(cs, false, true, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); + return new BufferedImage(cm, (WritableRaster) raster, true, null); + } + + /** + * @param image + */ + public static BufferedImage processNonStandardImage(NodeData image) + { + InputStream is2 = image.getStream(); + try + { + // Get an ImageReader. + ImageInputStream input = ImageIO.createImageInputStream(is2); + Iterator readers = ImageIO.getImageReaders(input); + if (readers == null || !readers.hasNext()) + { + throw new RuntimeException("No ImageReaders found"); + } + + ImageReader reader = (ImageReader) readers.next(); + reader.setInput(input); + String format = reader.getFormatName(); + + if ("JPEG".equalsIgnoreCase(format) || "JPG".equalsIgnoreCase(format)) + { + Raster raster = reader.readRaster(0, reader.getDefaultReadParam()); + boolean ycckProfile = false; + + // yes, we need to read it once again to extract metadatas + InputStream is3 = image.getStream(); + try + { + + JpegSegmentReader segmentReader = new JpegSegmentReader(is3); + byte[] exifSegment = segmentReader.readSegment(JpegSegmentReader.SEGMENT_APPE); + + switch (exifSegment[11]) + { + case 2 : + ycckProfile = true; + break; + case 1 : + // "YCbCr" + break; + case 0 : + default : + // Unknown (RGB or CMYK) + break; + } + } + catch (JpegProcessingException e1) + { + log.warn("Unable to read color space"); + } + finally + { + IOUtils.closeQuietly(is3); + } + + if (input != null) + { + input.close(); + } + reader.dispose(); + + return createJPEG4(raster, ycckProfile); + } + throw new BadImageFormatException("No ImageReaders found for " + image.getHandle()); + + } + catch (IOException e1) + { + log.error("Unable to handle " + image.getHandle() + ": " + e1.getMessage(), e1); + throw new BadImageFormatException(image.getHandle(), e1); + } + finally + { + IOUtils.closeQuietly(is2); + } + } +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/JpegUtils.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/openutils-mgnlmedia/src/main/resources/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.html =================================================================== --- trunk/openutils-mgnlmedia/src/main/resources/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.html 2009-02-13 17:53:26 UTC (rev 998) +++ trunk/openutils-mgnlmedia/src/main/resources/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.html 2009-02-15 20:58:20 UTC (rev 999) @@ -9,16 +9,16 @@ <script type="text/javascript" src="${this.request.contextPath}/.resources/media/js/miframe.js"></script> <script type="text/javascript"> // <![CDATA[ -var viewport; -var nodeid = "${this.nodeid!''}"; -var selectMedia = ${this.selectMedia?string("true", "false")}; -var openPath = "${this.openPath!''}"; -var actMediaHandle = "${this.actMediaHandle!''}"; -var mediaType = "${this.mediaType!''}"; // get tree url -function getTreeUrl() { - var url = "${this.request.contextPath}/.magnolia/trees/media.html?mgnlCK=" + (new Date()).getTime(); +var viewport; +var nodeid = "${this.nodeid!''}"; +var selectMedia = ${this.selectMedia?string("true", "false")}; +var openPath = "${this.openPath!''}"; +var actMediaHandle = "${this.actMediaHandle!''}"; +var mediaType = "${this.mediaType!''}"; // get tree url +function getTreeUrl() { + var url = "${this.request.contextPath}/.magnolia/trees/media.html?mgnlCK=" + (new Date()).getTime(); if (selectMedia) - { + { url += "&selectMedia=true"; } url += "&pathOpen="+ openPath +"&pathCurrent=" + openPath +"&pathSelected=" + openPath; @@ -211,12 +211,12 @@ bodyBorder: false, buttons: [ { - text: "${this.msgs.get('buttons.ok')}", + text: "${this.msgs.get('buttons.ok')}", handler: function() { uploadDlg.hide(); var ch = uploadDlg.body.child(".formToSubmit"); ch.dom.submit(); - } + } }, {text: "${this.msgs.get('buttons.cancel')}", handler: function() {uploadDlg.hide();uploadDlg.destroy();} }], keys: [],//{key: 27, fn: function() {ulDialog.hide();ulDialog.destroy();}, scope: this}] stateful: false @@ -232,7 +232,7 @@ <iframe id="mediaFolderView" name="mediaFolderView" class="x-panel-body" src="" style="width:100%;height:100%;border:none; overflow:auto"></iframe> <div id="formDiv" style="display:none"> - <form class="formToSubmit" action="" enctype="multipart/form-data" method="POST"> + <form class="formToSubmit" action="" enctype="multipart/form-data" method="post"> <input type="hidden" name="command" value="saveZip" /> <input id="parentPath" type="hidden" name="parentPath" value="{parentPath}" /> <input type="file" name="zipFile" /> Added: trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/FileNodeData.java =================================================================== --- trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/FileNodeData.java (rev 0) +++ trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/FileNodeData.java 2009-02-15 20:58:20 UTC (rev 999) @@ -0,0 +1,384 @@ +package net.sourceforge.openutils.mgnlmedia.media.utils; + +import info.magnolia.cms.core.Content; +import info.magnolia.cms.core.HierarchyManager; +import info.magnolia.cms.core.NodeData; +import info.magnolia.cms.security.AccessDeniedException; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Calendar; +import java.util.Collection; + +import javax.jcr.ItemNotFoundException; +import javax.jcr.PathNotFoundException; +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.Value; + +import org.apache.commons.io.IOUtils; + + +/** + * @author fgiust + * @version $Id$ + */ +public class FileNodeData implements NodeData +{ + + private byte[] content; + + public FileNodeData(String classpathLocation) throws IOException + { + InputStream is = getClass().getResourceAsStream(classpathLocation); + if (is == null) + { + throw new IllegalArgumentException("Classpath resource " + classpathLocation + " cannot be found"); + } + try + { + content = IOUtils.toByteArray(is); + } + finally + { + IOUtils.closeQuietly(is); + } + } + + /** + * {@inheritDoc} + */ + public void delete() throws RepositoryException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public String getAttribute(String arg0) + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public Collection getAttributeNames() throws RepositoryException + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public boolean getBoolean() + { + // TODO Auto-generated method stub + return false; + } + + /** + * {@inheritDoc} + */ + public long getContentLength() + { + // TODO Auto-generated method stub + return 0; + } + + /** + * {@inheritDoc} + */ + public Calendar getDate() + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public double getDouble() + { + // TODO Auto-generated method stub + return 0; + } + + /** + * {@inheritDoc} + */ + public String getHandle() + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public HierarchyManager getHierarchyManager() throws RepositoryException + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public Property getJCRProperty() + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public long getLong() + { + // TODO Auto-generated method stub + return 0; + } + + /** + * {@inheritDoc} + */ + public String getName() + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public Content getParent() throws AccessDeniedException, ItemNotFoundException, javax.jcr.AccessDeniedException, + RepositoryException + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public Content getReferencedContent() throws RepositoryException, PathNotFoundException, RepositoryException + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public Content getReferencedContent(String arg0) throws PathNotFoundException, RepositoryException + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public InputStream getStream() + { + return new ByteArrayInputStream(content); + } + + /** + * {@inheritDoc} + */ + public String getString() + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public String getString(String arg0) + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public int getType() + { + // TODO Auto-generated method stub + return 0; + } + + /** + * {@inheritDoc} + */ + public Value getValue() + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public Value[] getValues() + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public boolean isExist() + { + // TODO Auto-generated method stub + return false; + } + + /** + * {@inheritDoc} + */ + public boolean isGranted(long arg0) + { + // TODO Auto-generated method stub + return false; + } + + /** + * {@inheritDoc} + */ + public int isMultiValue() + { + // TODO Auto-generated method stub + return 0; + } + + /** + * {@inheritDoc} + */ + public void refresh(boolean arg0) throws RepositoryException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void save() throws RepositoryException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setAttribute(String arg0, String arg1) throws RepositoryException, AccessDeniedException, + UnsupportedOperationException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setAttribute(String arg0, Calendar arg1) throws RepositoryException, AccessDeniedException, + UnsupportedOperationException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setValue(String arg0) throws RepositoryException, AccessDeniedException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setValue(int arg0) throws RepositoryException, AccessDeniedException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setValue(long arg0) throws RepositoryException, AccessDeniedException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setValue(InputStream arg0) throws RepositoryException, AccessDeniedException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setValue(double arg0) throws RepositoryException, AccessDeniedException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setValue(boolean arg0) throws RepositoryException, AccessDeniedException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setValue(Calendar arg0) throws RepositoryException, AccessDeniedException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setValue(Value arg0) throws RepositoryException, AccessDeniedException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setValue(Value[] arg0) throws RepositoryException, AccessDeniedException + { + // TODO Auto-generated method stub + + } + +} Property changes on: trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/FileNodeData.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtilsTest.java =================================================================== --- trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtilsTest.java (rev 0) +++ trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtilsTest.java 2009-02-15 20:58:20 UTC (rev 999) @@ -0,0 +1,64 @@ +package net.sourceforge.openutils.mgnlmedia.media.utils; + +import info.magnolia.cms.core.NodeData; + +import java.awt.image.BufferedImage; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; + +import org.apache.commons.io.IOUtils; +import org.testng.Assert; +import org.testng.annotations.Test; + + +/** + * @author fgiust + * @version $Id$ + */ +public class ImageUtilsTest +{ + + @Test + public void testYcck() throws Exception + { + + NodeData cmyk = new FileNodeData("/images/ycck.jpg"); + BufferedImage bufferedImage = ImageUtils.createBufferedImage(cmyk); + Assert.assertNotNull(bufferedImage); + + bufferedImage = ImageUtils.resizeNoCrop(bufferedImage, 100, 100); + + InputStream is = ImageUtils.getStream(bufferedImage, "jpg"); + + File tempFile = File.createTempFile("image", "jpg"); + OutputStream os = new BufferedOutputStream(new FileOutputStream(tempFile)); + IOUtils.copy(is, os); + + IOUtils.closeQuietly(is); + IOUtils.closeQuietly(os); + + tempFile.delete(); + + } + + @Test + public void testBadImageTxt() throws Exception + { + + NodeData cmyk = new FileNodeData("/images/badimage.txt"); + BufferedImage bufferedImage = ImageUtils.createBufferedImage(cmyk); + Assert.assertNull(bufferedImage); + } + + @Test + public void testBadImageJpg() throws Exception + { + + NodeData cmyk = new FileNodeData("/images/badimage.jpg"); + BufferedImage bufferedImage = ImageUtils.createBufferedImage(cmyk); + Assert.assertNull(bufferedImage); + } +} Property changes on: trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtilsTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-mgnlmedia/src/test/resources/images/badimage.jpg =================================================================== (Binary files differ) Property changes on: trunk/openutils-mgnlmedia/src/test/resources/images/badimage.jpg ___________________________________________________________________ Added: svn:mime-type + image/gif Added: trunk/openutils-mgnlmedia/src/test/resources/images/badimage.txt =================================================================== --- trunk/openutils-mgnlmedia/src/test/resources/images/badimage.txt (rev 0) +++ trunk/openutils-mgnlmedia/src/test/resources/images/badimage.txt 2009-02-15 20:58:20 UTC (rev 999) @@ -0,0 +1 @@ +just a sample bad image \ No newline at end of file Property changes on: trunk/openutils-mgnlmedia/src/test/resources/images/badimage.txt ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-mgnlmedia/src/test/resources/images/ycck.jpg =================================================================== (Binary files differ) Property changes on: trunk/openutils-mgnlmedia/src/test/resources/images/ycck.jpg ___________________________________________________________________ Added: svn:mime-type + image/gif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |