|
From: <fg...@us...> - 2009-06-04 09:39:06
|
Revision: 1221
http://openutils.svn.sourceforge.net/openutils/?rev=1221&view=rev
Author: fgiust
Date: 2009-06-04 09:38:57 +0000 (Thu, 04 Jun 2009)
Log Message:
-----------
better logging of invalid image binaries (lenght=0)
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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-05-26 10:32:35 UTC (rev 1220)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-06-04 09:38:57 UTC (rev 1221)
@@ -548,6 +548,15 @@
throw new RuntimeException(e);
}
NodeData image = node.getNodeData("image");
+
+ if (image.getContentLength() == 0)
+ {
+ log.error(
+ "Invalid image nodedata " + image.getHandle() + ", size " + image.getContentLength(),
+ new Exception());
+ return;
+ }
+
String extension = image.getAttribute(FileProperties.PROPERTY_EXTENSION);
if (!Arrays.asList(extensions).contains(extension))
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fg...@us...> - 2009-08-13 16:22:49
|
Revision: 1264
http://openutils.svn.sourceforge.net/openutils/?rev=1264&view=rev
Author: fgiust
Date: 2009-08-13 16:22:41 +0000 (Thu, 13 Aug 2009)
Log Message:
-----------
avoid error logs for missing images
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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-08-13 13:10:41 UTC (rev 1263)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-08-13 16:22:41 UTC (rev 1264)
@@ -516,6 +516,18 @@
try
{
+ if (!media.hasNodeData("image"))
+ {
+ return false;
+ }
+ }
+ catch (RepositoryException e2)
+ {
+ log.warn(e2.getMessage(), e2);
+ }
+
+ try
+ {
MgnlContext.doInSystemContext(new MgnlContext.SystemContextOperation()
{
@@ -546,17 +558,6 @@
throw new RuntimeException(e);
}
- try
- {
- if (!node.hasNodeData("image"))
- {
- throw new RuntimeException("No \"image\" nodedata for media " + media.getHandle());
- }
- }
- catch (RepositoryException e)
- {
- throw new RuntimeException(e);
- }
NodeData image = node.getNodeData("image");
if (image.getContentLength() == 0)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mol...@us...> - 2009-10-08 14:25:07
|
Revision: 1469
http://openutils.svn.sourceforge.net/openutils/?rev=1469&view=rev
Author: molaschi
Date: 2009-10-08 14:24:52 +0000 (Thu, 08 Oct 2009)
Log Message:
-----------
MEDIA-25
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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-10-08 14:21:20 UTC (rev 1468)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-10-08 14:24:52 UTC (rev 1469)
@@ -37,6 +37,7 @@
import java.awt.Image;
import java.awt.Point;
import java.awt.RenderingHints;
+import java.awt.Transparency;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
@@ -181,6 +182,10 @@
{
graphics2D.clearRect(0, 0, canvasX, canvasY);
+ if (background == null && original.getColorModel().getTransparency() == Transparency.OPAQUE)
+ {
+ background = Color.WHITE;
+ }
// fill bands
if (background != null)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mol...@us...> - 2009-10-08 16:40:18
|
Revision: 1478
http://openutils.svn.sourceforge.net/openutils/?rev=1478&view=rev
Author: molaschi
Date: 2009-10-08 16:40:09 +0000 (Thu, 08 Oct 2009)
Log Message:
-----------
MEDIA-27 add image quality support
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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-10-08 15:39:13 UTC (rev 1477)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-10-08 16:40:09 UTC (rev 1478)
@@ -56,9 +56,10 @@
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
+import javax.imageio.ImageTypeSpecifier;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
-import javax.imageio.stream.MemoryCacheImageOutputStream;
+import javax.imageio.stream.ImageOutputStream;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
@@ -329,13 +330,15 @@
* @param image image to save
* @param saveTo node to save to
* @param extension extension
+ * @param quality image quality
+ * @param forceProgressive true to force progressive mode
* @throws RepositoryException exception in jcr operations
* @throws IOException exception converting image to jpg
*/
- public static void saveResolution(BufferedImage image, Content saveTo, String extension)
- throws RepositoryException, IOException
+ public static void saveResolution(BufferedImage image, Content saveTo, String extension, float quality,
+ boolean forceProgressive) throws RepositoryException, IOException
{
- saveResolution(image, saveTo, null, extension);
+ saveResolution(image, saveTo, null, extension, quality, forceProgressive);
}
/**
@@ -344,11 +347,13 @@
* @param saveTo node to save to
* @param name name for this resolution
* @param extension extension
+ * @param quality image quality
+ * @param forceProgressive true to force progressive mode
* @throws RepositoryException exception in jcr operations
* @throws IOException exception converting image to jpg
*/
- public static void saveResolution(BufferedImage image, Content saveTo, String name, String extension)
- throws RepositoryException, IOException
+ public static void saveResolution(BufferedImage image, Content saveTo, String name, String extension,
+ float quality, boolean forceProgressive) throws RepositoryException, IOException
{
Content resolutions = saveTo.getChildByName("resolutions");
if (resolutions == null)
@@ -375,7 +380,7 @@
}
NodeData nd = resolutions.createNodeData(resolution, PropertyType.BINARY);
- nd.setValue(getStream(image, extension));
+ nd.setValue(getStream(image, extension, quality, forceProgressive));
String mimetype = "image/" + extension;
if ("jpg".equals(extension))
{
@@ -414,37 +419,73 @@
* @return inputstream
* @throws IOException
*/
- public static InputStream getStream(BufferedImage image, String extension) throws IOException
+ public static InputStream getStream(BufferedImage image, String extension, float quality, boolean forceProgressive)
+ throws IOException
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
BufferedOutputStream out = new BufferedOutputStream(bos);
- if ("jpg".equals(extension))
+ try
{
- Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("jpeg");
- ImageWriter writer = iter.next();
- ImageWriteParam iwp = writer.getDefaultWriteParam();
- iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
- iwp.setCompressionQuality(1.0f); // an integer between 0 and 1
- // 1 specifies minimum compression and maximum quality
- MemoryCacheImageOutputStream output = new MemoryCacheImageOutputStream(out);
- writer.setOutput(output);
- IIOImage iioimage = new IIOImage(image, null, null);
- writer.write(null, iioimage, iwp);
- }
- else
- {
- try
+ Iterator writers;
+ ImageOutputStream imageOutputStream;
+ ImageWriteParam params;
+ ImageWriter imageWriter;
+
+ writers = ImageIO.getImageWritersBySuffix(extension);
+
+ if (writers != null && writers.hasNext())
{
- ImageIO.write(image, extension, out);
+ // Fetch the first writer in the list
+ imageWriter = (ImageWriter) writers.next();
+
+ // Specify the parameters according to those the output file will be written
+
+ // Get Default parameters
+ params = imageWriter.getDefaultWriteParam();
+
+ // Define compression mode
+ params.setCompressionMode(javax.imageio.ImageWriteParam.MODE_EXPLICIT);
+
+ // Define compression quality
+ params.setCompressionQuality(quality);
+
+ // Define progressive mode
+ if (forceProgressive)
+ {
+ params.setProgressiveMode(javax.imageio.ImageWriteParam.MODE_DEFAULT);
+ }
+ else
+ {
+ params.setProgressiveMode(javax.imageio.ImageWriteParam.MODE_COPY_FROM_METADATA);
+ }
+
+ // Deine destination type - used the ColorModel and SampleModel of the Input Image
+ params.setDestinationType(new ImageTypeSpecifier(image.getColorModel(), image.getSampleModel()));
+
+ // Set the output stream to Second Argument
+ // imageOutputStream = ImageIO.createImageOutputStream( new FileOutputStream(args[1]) );
+ imageOutputStream = ImageIO.createImageOutputStream(out);
+ imageWriter.setOutput(imageOutputStream);
+
+ // Write the changed Image
+ imageWriter.write(null, new IIOImage(image, null, null), params);
+
+ // Close the streams
+ imageOutputStream.close();
+ imageWriter.dispose();
}
- catch (IOException ex)
+ else
{
- log.error("Error writing image to buffer", ex);
- throw ex;
+ ImageIO.write(image, extension, out);
}
}
+ catch (IOException ex)
+ {
+ log.error("Error writing image to buffer", ex);
+ throw ex;
+ }
return new ByteArrayInputStream(bos.toByteArray());
}
@@ -569,17 +610,41 @@
String resolutionName = "res-" + resolution;
- BufferedImage img = ImageUtils.getImageForResolution(original, resolution);
+ Map<String, String> params = parseParameters(resolution);
+ BufferedImage img = ImageUtils.getImageForResolution(original, resolution, params);
+
try
{
+ float quality = 0.8F;
+ if (StringUtils.isNotEmpty(params.get("quality")))
+ {
+ try
+ {
+ quality = NumberUtils.toFloat(params.get("quality"));
+ if (quality > 1.0F)
+ {
+ quality = 1.0F;
+ }
+ }
+ catch (NumberFormatException ex)
+ {
+ log.error("quality parameter must be a float number but was {}", params.get("quality"));
+ }
+ }
+ boolean forceProgressive = false;
+ if (StringUtils.isNotEmpty(params.get("progressive")))
+ {
+ forceProgressive = true;
+ }
if ("thumbnail".equals(resolutionTarget) || "preview".equals(resolutionTarget))
{
- ImageUtils.saveResolution(img, node, resolutionTarget, extension);
+ ImageUtils
+ .saveResolution(img, node, resolutionTarget, extension, quality, forceProgressive);
}
else
{
- ImageUtils.saveResolution(img, node, resolutionName, extension);
+ ImageUtils.saveResolution(img, node, resolutionName, extension, quality, forceProgressive);
}
}
catch (RepositoryException e)
@@ -617,28 +682,9 @@
return true;
}
- /**
- * Get image for a resolution
- * @param original original image
- * @param resolution resolution
- * @return new image
- */
- public static BufferedImage getImageForResolution(BufferedImage original, String resolution)
+ private static Map<String, String> parseParameters(String resolution)
{
- if (original == null)
- {
- throw new IllegalArgumentException("input image is null");
- }
- if (resolution == null || resolution.length() < 1)
- {
- throw new IllegalArgumentException("Invalid resolution: " + resolution);
- }
-
- BufferedImage img = null;
-
- resolution = StringUtils.lowerCase(resolution);
-
Map<String, String> params = new HashMap<String, String>();
if (StringUtils.contains(resolution, ";"))
{
@@ -659,7 +705,32 @@
}
}
}
+ return params;
+ }
+ /**
+ * Get image for a resolution
+ * @param original original image
+ * @param resolution resolution
+ * @return new image
+ */
+ public static BufferedImage getImageForResolution(BufferedImage original, String resolution,
+ Map<String, String> params)
+ {
+
+ if (original == null)
+ {
+ throw new IllegalArgumentException("input image is null");
+ }
+ if (resolution == null || resolution.length() < 1)
+ {
+ throw new IllegalArgumentException("Invalid resolution: " + resolution);
+ }
+
+ BufferedImage img = null;
+
+ resolution = StringUtils.lowerCase(resolution);
+
char controlChar = resolution.charAt(0);
Point size = parseForSize(resolution);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mol...@us...> - 2009-10-14 14:19:43
|
Revision: 1486
http://openutils.svn.sourceforge.net/openutils/?rev=1486&view=rev
Author: molaschi
Date: 2009-10-14 14:19:37 +0000 (Wed, 14 Oct 2009)
Log Message:
-----------
MEDIA-26 fix to make round corners antialiased
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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-10-14 14:18:03 UTC (rev 1485)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-10-14 14:19:37 UTC (rev 1486)
@@ -32,13 +32,13 @@
import info.magnolia.cms.util.ExclusiveWrite;
import info.magnolia.context.MgnlContext;
+import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.Transparency;
-import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.io.BufferedOutputStream;
@@ -293,36 +293,70 @@
public static BufferedImage addRoundedCorners(BufferedImage original, Color backgroundColor, int radius)
{
- BufferedImage resizedImage;
+ int originalImageType = getType(original.getColorModel());
+ int roundedCornersImageType = BufferedImage.TYPE_4BYTE_ABGR;
+
+ if (originalImageType != BufferedImage.TYPE_4BYTE_ABGR)
+ {
+ if (originalImageType != BufferedImage.TYPE_4BYTE_ABGR_PRE)
+ {
+ // the image has not alpha channel so fill background
+ if (backgroundColor == null)
+ {
+ backgroundColor = Color.WHITE;
+ }
+ }
+ else
+ {
+ roundedCornersImageType = BufferedImage.TYPE_4BYTE_ABGR_PRE;
+ }
+ }
+
+ // use a 4 byte image type to create antialiased rounded corners
+ BufferedImage roundedImage;
try
{
- resizedImage = new BufferedImage(original.getWidth(), original.getHeight(), getType(original
- .getColorModel()));
+ roundedImage = new BufferedImage(original.getWidth(), original.getHeight(), roundedCornersImageType);
}
catch (NegativeArraySizeException e)
{
- throw new RuntimeException("NegativeArraySizeException caught when resizing image]");
+ throw new RuntimeException("NegativeArraySizeException caught when adding rounded corners");
}
- Graphics2D graphics2D = resizedImage.createGraphics();
- graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
+ Graphics2D roundedGraphics2D = roundedImage.createGraphics();
+ roundedGraphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ roundedGraphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
- if (original.getColorModel().getTransparency() == Transparency.OPAQUE && backgroundColor == null)
- {
- backgroundColor = Color.WHITE;
- }
+ roundedGraphics2D.setColor(Color.WHITE);
+ roundedGraphics2D.fillRoundRect(0, 0, original.getWidth(), original.getHeight(), radius, radius);
+ roundedGraphics2D.setComposite(AlphaComposite.SrcIn);
+ roundedGraphics2D.drawImage(original, 0, 0, original.getWidth(), original.getHeight(), null);
+
if (backgroundColor != null)
{
- graphics2D.setBackground(backgroundColor);
+
+ BufferedImage destImage;
+ try
+ {
+ destImage = new BufferedImage(original.getWidth(), original.getHeight(), originalImageType);
+ }
+ catch (NegativeArraySizeException e)
+ {
+ throw new RuntimeException("NegativeArraySizeException caught when resizing image]");
+ }
+ // draw new image
+ Graphics2D destImageGraphics2D = destImage.createGraphics();
+ destImageGraphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ destImageGraphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
+
+ destImageGraphics2D.setBackground(backgroundColor);
+ destImageGraphics2D.clearRect(0, 0, original.getWidth(), original.getHeight());
+ // destImageGraphics2D.setComposite(AlphaComposite.DstIn);
+ destImageGraphics2D.drawImage(roundedImage, 0, 0, original.getWidth(), original.getHeight(), null);
+ return destImage;
}
- graphics2D.clearRect(0, 0, original.getWidth(), original.getHeight());
- graphics2D
- .setClip(new RoundRectangle2D.Double(0, 0, original.getWidth(), original.getHeight(), radius, radius));
- graphics2D.drawImage(original, 0, 0, original.getWidth(), original.getHeight(), null);
-
- return resizedImage;
+ return roundedImage;
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mol...@us...> - 2009-10-14 15:07:50
|
Revision: 1488
http://openutils.svn.sourceforge.net/openutils/?rev=1488&view=rev
Author: molaschi
Date: 2009-10-14 15:07:43 +0000 (Wed, 14 Oct 2009)
Log Message:
-----------
fix issue on png compression. maybe we have to use jai?
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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-10-14 14:25:35 UTC (rev 1487)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-10-14 15:07:43 UTC (rev 1488)
@@ -479,20 +479,26 @@
// Get Default parameters
params = imageWriter.getDefaultWriteParam();
- // Define compression mode
- params.setCompressionMode(javax.imageio.ImageWriteParam.MODE_EXPLICIT);
+ try
+ {
+ // Define compression mode
+ params.setCompressionMode(javax.imageio.ImageWriteParam.MODE_EXPLICIT);
+ // Define compression quality
+ params.setCompressionQuality(quality);
- // Define compression quality
- params.setCompressionQuality(quality);
-
- // Define progressive mode
- if (forceProgressive)
- {
- params.setProgressiveMode(javax.imageio.ImageWriteParam.MODE_DEFAULT);
+ // Define progressive mode
+ if (forceProgressive)
+ {
+ params.setProgressiveMode(javax.imageio.ImageWriteParam.MODE_DEFAULT);
+ }
+ else
+ {
+ params.setProgressiveMode(javax.imageio.ImageWriteParam.MODE_COPY_FROM_METADATA);
+ }
}
- else
+ catch (UnsupportedOperationException e)
{
- params.setProgressiveMode(javax.imageio.ImageWriteParam.MODE_COPY_FROM_METADATA);
+ // go on
}
// Deine destination type - used the ColorModel and SampleModel of the Input Image
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fg...@us...> - 2009-12-20 20:23:52
|
Revision: 1512
http://openutils.svn.sourceforge.net/openutils/?rev=1512&view=rev
Author: fgiust
Date: 2009-12-20 20:23:46 +0000 (Sun, 20 Dec 2009)
Log Message:
-----------
MEDIA-38 better compatibility with magnolia 4.2 (4.2.2 already works, but navigation tag is buggy)
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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-12-14 10:22:42 UTC (rev 1511)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-12-20 20:23:46 UTC (rev 1512)
@@ -30,7 +30,9 @@
import info.magnolia.cms.core.HierarchyManager;
import info.magnolia.cms.core.NodeData;
import info.magnolia.cms.util.ExclusiveWrite;
+import info.magnolia.context.Context;
import info.magnolia.context.MgnlContext;
+import info.magnolia.context.MgnlContext.SystemContextOperation;
import java.awt.AlphaComposite;
import java.awt.Color;
@@ -562,7 +564,7 @@
try
{
- MgnlContext.doInSystemContext(new MgnlContext.SystemContextOperation()
+ ImageUtils.doInSystemContext(new MgnlContext.SystemContextOperation()
{
/**
@@ -856,4 +858,18 @@
return size;
}
+ private static void doInSystemContext(SystemContextOperation op)
+ {
+ final Context originalCtx = MgnlContext.hasInstance() ? MgnlContext.getInstance() : null;
+ try
+ {
+ MgnlContext.setInstance(MgnlContext.getSystemContext());
+ op.exec();
+ }
+ finally
+ {
+ MgnlContext.setInstance(originalCtx);
+ }
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fg...@us...> - 2009-12-30 19:12:43
|
Revision: 1561
http://openutils.svn.sourceforge.net/openutils/?rev=1561&view=rev
Author: fgiust
Date: 2009-12-30 19:12:37 +0000 (Wed, 30 Dec 2009)
Log Message:
-----------
MEDIA-41 "No compression type set" error while loading zip archives
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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-12-30 17:23:35 UTC (rev 1560)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-12-30 19:12:37 UTC (rev 1561)
@@ -453,11 +453,24 @@
try
{
- // Define compression mode
- params.setCompressionMode(javax.imageio.ImageWriteParam.MODE_EXPLICIT);
- // Define compression quality
- params.setCompressionQuality(quality);
+ String[] compressionTypes = params.getCompressionTypes();
+
+ if (compressionTypes != null && compressionTypes.length > 0)
+ {
+ // Define compression mode
+ params.setCompressionMode(javax.imageio.ImageWriteParam.MODE_EXPLICIT);
+
+ params.setCompressionType(compressionTypes[0]);
+
+ // Define compression quality
+ params.setCompressionQuality(quality);
+ }
+ else
+ {
+ params.setCompressionMode(javax.imageio.ImageWriteParam.MODE_COPY_FROM_METADATA);
+ }
+
// Define progressive mode
if (forceProgressive)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fg...@us...> - 2009-12-30 19:22:47
|
Revision: 1562
http://openutils.svn.sourceforge.net/openutils/?rev=1562&view=rev
Author: fgiust
Date: 2009-12-30 19:22:33 +0000 (Wed, 30 Dec 2009)
Log Message:
-----------
never try to resize an image to a width or height = 0
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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-12-30 19:12:37 UTC (rev 1561)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-12-30 19:22:33 UTC (rev 1562)
@@ -168,6 +168,27 @@
public static BufferedImage resizeImage(BufferedImage original, int x, int y, int canvasX, int canvasY,
Color background)
{
+ if (x <= 0)
+ {
+ x = 1;
+ // throw new IllegalArgumentException("x=" + x + " (must be >0)");
+ }
+ if (y <= 0)
+ {
+ y = 1;
+ // throw new IllegalArgumentException("y=" + y + " (must be >0)");
+ }
+ if (canvasX <= 0)
+ {
+ canvasX = 1;
+ // throw new IllegalArgumentException("canvasX=" + canvasX + " (must be >0)");
+ }
+ if (canvasY <= 0)
+ {
+ canvasY = 1;
+ // throw new IllegalArgumentException("canvasY=" + canvasY + " (must be >0)");
+ }
+
BufferedImage resizedImage;
try
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fg...@us...> - 2009-12-30 21:43:07
|
Revision: 1565
http://openutils.svn.sourceforge.net/openutils/?rev=1565&view=rev
Author: fgiust
Date: 2009-12-30 21:42:59 +0000 (Wed, 30 Dec 2009)
Log Message:
-----------
optimizations related to MEDIA-33
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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-12-30 21:41:27 UTC (rev 1564)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-12-30 21:42:59 UTC (rev 1565)
@@ -380,45 +380,65 @@
public static void saveResolution(BufferedImage image, Content saveTo, String name, String extension,
float quality, boolean forceProgressive) throws RepositoryException, IOException
{
- Content resolutions = saveTo.getChildByName("resolutions");
- if (resolutions == null)
- {
- resolutions = saveTo.createContent("resolutions", MediaConfigurationManager.RESOLUTIONS);
- }
- String resolution = name;
- if (resolution == null)
+ InputStream stream = null;
+
+ try
{
- resolution = "res-" + image.getWidth() + "x" + image.getHeight();
- }
+ stream = getStream(image, extension, quality, forceProgressive);
- String originalRes = resolution;
- resolution = getResolutionPath(resolution);
+ if (stream == null)
+ {
+ throw new IllegalArgumentException("Stream is null");
+ }
- synchronized (ExclusiveWrite.getInstance())
- {
+ Content resolutions = saveTo.getChildByName("resolutions");
+ if (resolutions == null)
+ {
+ resolutions = saveTo.createContent("resolutions", MediaConfigurationManager.RESOLUTIONS);
+ }
- if (resolutions.hasNodeData(resolution))
+ String resolution = name;
+ if (resolution == null)
{
- NodeData nd = resolutions.getNodeData(resolution);
- nd.delete();
+ resolution = "res-" + image.getWidth() + "x" + image.getHeight();
}
- NodeData nd = resolutions.createNodeData(resolution, PropertyType.BINARY);
- nd.setValue(getStream(image, extension, quality, forceProgressive));
- String mimetype = "image/" + extension;
- if ("jpg".equals(extension))
+ String originalRes = resolution;
+ resolution = getResolutionPath(resolution);
+
+ synchronized (ExclusiveWrite.getInstance())
{
- mimetype = "image/jpeg";
+
+ if (resolutions.hasNodeData(resolution))
+ {
+ NodeData nd = resolutions.getNodeData(resolution);
+ nd.delete();
+ }
+
+ NodeData nd = resolutions.createNodeData(resolution, PropertyType.BINARY);
+
+ log.info("setting value to {}", nd.getHandle());
+ nd.setValue(stream);
+ String mimetype = "image/" + extension;
+ if ("jpg".equals(extension))
+ {
+ mimetype = "image/jpeg";
+ }
+ nd.setAttribute(ImageUtils.RESOLUTION_PROPERTY, originalRes);
+ nd.setAttribute(FileProperties.PROPERTY_EXTENSION, extension);
+ nd.setAttribute(FileProperties.PROPERTY_FILENAME, "data");
+ nd.setAttribute(FileProperties.PROPERTY_CONTENTTYPE, mimetype);
+ nd.setAttribute(FileProperties.PROPERTY_LASTMODIFIED, "" + new Date().getTime());
+ nd.setAttribute(FileProperties.PROPERTY_WIDTH, "" + image.getWidth());
+ nd.setAttribute(FileProperties.PROPERTY_HEIGHT, "" + image.getHeight());
+
}
- nd.setAttribute(ImageUtils.RESOLUTION_PROPERTY, originalRes);
- nd.setAttribute(FileProperties.PROPERTY_EXTENSION, extension);
- nd.setAttribute(FileProperties.PROPERTY_FILENAME, "data");
- nd.setAttribute(FileProperties.PROPERTY_CONTENTTYPE, mimetype);
- nd.setAttribute(FileProperties.PROPERTY_LASTMODIFIED, "" + new Date().getTime());
- nd.setAttribute(FileProperties.PROPERTY_WIDTH, "" + image.getWidth());
- nd.setAttribute(FileProperties.PROPERTY_HEIGHT, "" + image.getHeight());
}
+ finally
+ {
+ IOUtils.closeQuietly(stream);
+ }
}
/**
@@ -507,20 +527,24 @@
// go on
}
- // Deine destination type - used the ColorModel and SampleModel of the Input Image
+ // Define destination type - used the ColorModel and SampleModel of the Input Image
params.setDestinationType(new ImageTypeSpecifier(image.getColorModel(), image.getSampleModel()));
- // Set the output stream to Second Argument
- // imageOutputStream = ImageIO.createImageOutputStream( new FileOutputStream(args[1]) );
imageOutputStream = ImageIO.createImageOutputStream(out);
imageWriter.setOutput(imageOutputStream);
- // Write the changed Image
- imageWriter.write(null, new IIOImage(image, null, null), params);
-
- // Close the streams
- imageOutputStream.close();
- imageWriter.dispose();
+ try
+ {
+ // Write the changed Image
+ IIOImage iioimage = new IIOImage(image, null, null);
+ imageWriter.write(null, iioimage, params);
+ }
+ finally
+ {
+ // Close the streams
+ imageOutputStream.close();
+ imageWriter.dispose();
+ }
}
else
{
@@ -533,7 +557,14 @@
throw ex;
}
- return new ByteArrayInputStream(bos.toByteArray());
+ byte[] byteArray = bos.toByteArray();
+
+ if (byteArray.length == 0)
+ {
+ return null;
+ }
+
+ return new ByteArrayInputStream(byteArray);
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fg...@us...> - 2009-12-30 22:45:06
|
Revision: 1567
http://openutils.svn.sourceforge.net/openutils/?rev=1567&view=rev
Author: fgiust
Date: 2009-12-30 22:44:55 +0000 (Wed, 30 Dec 2009)
Log Message:
-----------
use less memory, write to temporary files instead of byte arrays
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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-12-30 22:31:48 UTC (rev 1566)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-12-30 22:44:55 UTC (rev 1567)
@@ -43,9 +43,11 @@
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
+import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
@@ -469,9 +471,12 @@
public static InputStream getStream(BufferedImage image, String extension, float quality, boolean forceProgressive)
throws IOException
{
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- BufferedOutputStream out = new BufferedOutputStream(bos);
+ final File tempFile = File.createTempFile("image-", "." + extension);
+ FileOutputStream fos = new FileOutputStream(tempFile);
+
+ BufferedOutputStream out = new BufferedOutputStream(fos);
+
try
{
@@ -568,14 +573,22 @@
throw ex;
}
- byte[] byteArray = bos.toByteArray();
-
- if (byteArray.length == 0)
+ out.flush();
+ IOUtils.closeQuietly(out);
+ return new BufferedInputStream(new FileInputStream(tempFile)
{
- return null;
- }
- return new ByteArrayInputStream(byteArray);
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void close() throws IOException
+ {
+ tempFile.delete();
+ super.close();
+ }
+
+ });
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mol...@us...> - 2010-01-13 15:08:30
|
Revision: 1633
http://openutils.svn.sourceforge.net/openutils/?rev=1633&view=rev
Author: molaschi
Date: 2010-01-13 15:08:23 +0000 (Wed, 13 Jan 2010)
Log Message:
-----------
MEDIA-57 fix for JR 2.0
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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 2010-01-12 11:17:46 UTC (rev 1632)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2010-01-13 15:08:23 UTC (rev 1633)
@@ -47,6 +47,7 @@
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
+import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -426,7 +427,8 @@
nd.setAttribute(FileProperties.PROPERTY_EXTENSION, extension);
nd.setAttribute(FileProperties.PROPERTY_FILENAME, "data");
nd.setAttribute(FileProperties.PROPERTY_CONTENTTYPE, mimetype);
- nd.setAttribute(FileProperties.PROPERTY_LASTMODIFIED, "" + new Date().getTime());
+ nd.setAttribute(FileProperties.PROPERTY_LASTMODIFIED, GregorianCalendar.getInstance(TimeZone
+ .getDefault()));
nd.setAttribute(FileProperties.PROPERTY_WIDTH, "" + image.getWidth());
nd.setAttribute(FileProperties.PROPERTY_HEIGHT, "" + image.getHeight());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <die...@us...> - 2010-02-01 11:01:51
|
Revision: 1730
http://openutils.svn.sourceforge.net/openutils/?rev=1730&view=rev
Author: diego_schivo
Date: 2010-02-01 11:01:45 +0000 (Mon, 01 Feb 2010)
Log Message:
-----------
MEDIA-66 "broken image" displayed also for 0 byte files
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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 2010-02-01 10:39:24 UTC (rev 1729)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2010-02-01 11:01:45 UTC (rev 1730)
@@ -702,10 +702,8 @@
if (image.getContentLength() == 0)
{
- log.error(
- "Invalid image nodedata " + image.getHandle() + ", size " + image.getContentLength(),
- new Exception());
- return;
+ throw new RuntimeException("Invalid image nodedata " + image.getHandle()
+ + ", size " + image.getContentLength());
}
String extension = image.getAttribute(FileProperties.PROPERTY_EXTENSION);
@@ -728,7 +726,15 @@
Map<String, String> params = parseParameters(resolution);
- BufferedImage img = ImageUtils.getImageForResolution(original, resolution, params);
+ BufferedImage img;
+ try
+ {
+ img = ImageUtils.getImageForResolution(original, resolution, params);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new RuntimeException(e);
+ }
try
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mol...@us...> - 2010-11-18 15:08:29
|
Revision: 3146
http://openutils.svn.sourceforge.net/openutils/?rev=3146&view=rev
Author: molaschi
Date: 2010-11-18 15:08:23 +0000 (Thu, 18 Nov 2010)
Log Message:
-----------
MEDIA-195 fix black line
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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 2010-11-17 14:35:03 UTC (rev 3145)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2010-11-18 15:08:23 UTC (rev 3146)
@@ -219,12 +219,12 @@
if (canvasX > x)
{
graphics2D.fillRect(0, 0, (canvasX - x) / 2, canvasY);
- graphics2D.fillRect(canvasX - (canvasX - x) / 2, 0, canvasX, canvasY);
+ graphics2D.fillRect(x + (canvasX - x) / 2, 0, canvasX, canvasY);
}
if (canvasY > y)
{
graphics2D.fillRect(0, 0, canvasX, (canvasY - y) / 2);
- graphics2D.fillRect(0, canvasY - (canvasY - y) / 2, canvasX, canvasY);
+ graphics2D.fillRect(0, y + (canvasY - y) / 2, canvasX, canvasY);
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mol...@us...> - 2010-12-28 14:33:38
|
Revision: 3196
http://openutils.svn.sourceforge.net/openutils/?rev=3196&view=rev
Author: molaschi
Date: 2010-12-28 14:33:32 +0000 (Tue, 28 Dec 2010)
Log Message:
-----------
MEDIA-196 fix count bug
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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 2010-12-28 13:13:55 UTC (rev 3195)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2010-12-28 14:33:32 UTC (rev 3196)
@@ -1063,41 +1063,13 @@
* {@inheritDoc}
*/
@Override
- public synchronized int read() throws IOException
- {
- count++;
- return super.read();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public synchronized void reset() throws IOException
- {
- count = 0;
- super.reset();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int read(byte[] b) throws IOException
- {
- int read = super.read(b);
- count += read;
- return read;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
public synchronized int read(byte[] b, int off, int len) throws IOException
{
int read = super.read(b, off, len);
- count += read;
+ if (read > 0)
+ {
+ count += read;
+ }
return read;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fg...@us...> - 2011-01-23 17:56:22
|
Revision: 3258
http://openutils.svn.sourceforge.net/openutils/?rev=3258&view=rev
Author: fgiust
Date: 2011-01-23 17:56:15 +0000 (Sun, 23 Jan 2011)
Log Message:
-----------
MEDIA-195 In images resulting from fitbands resize sometimes there is a black line between image and band (left side or bottom side)
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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 2011-01-21 13:40:40 UTC (rev 3257)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2011-01-23 17:56:15 UTC (rev 3258)
@@ -351,16 +351,16 @@
* Save a resolution for an image to a node (in resolutions/res-[width]x[height]/data.jpg)
* @param image image to save
* @param saveTo node to save to
- * @param outputformat extension
+ * @param extension extension
* @param quality image quality
* @param forceProgressive true to force progressive mode
* @throws RepositoryException exception in jcr operations
* @throws IOException exception converting image to jpg
*/
- public static void saveResolution(BufferedImage image, Content saveTo, String outputformat, float quality,
+ public static void saveResolution(BufferedImage image, Content saveTo, String extension, float quality,
boolean forceProgressive) throws RepositoryException, IOException
{
- saveResolution(image, saveTo, null, outputformat, quality, forceProgressive);
+ saveResolution(image, saveTo, null, extension, quality, forceProgressive);
}
/**
@@ -368,13 +368,13 @@
* @param image image to save
* @param saveTo node to save to
* @param name name for this resolution
- * @param outputformat extension
+ * @param extension extension
* @param quality image quality
* @param forceProgressive true to force progressive mode
* @throws RepositoryException exception in jcr operations
* @throws IOException exception converting image to jpg
*/
- public static void saveResolution(BufferedImage image, Content saveTo, String name, String outputformat,
+ public static void saveResolution(BufferedImage image, Content saveTo, String name, String extension,
float quality, boolean forceProgressive) throws RepositoryException, IOException
{
@@ -382,7 +382,7 @@
try
{
- stream = new CountBytesBufferedInputStream(getStream(image, outputformat, quality, forceProgressive));
+ stream = new CountBytesBufferedInputStream(getStream(image, extension, quality, forceProgressive));
if (stream == null)
{
@@ -419,20 +419,23 @@
log.info("setting value to {}", nd.getHandle());
nd.setValue(stream);
- String mimetype = "image/" + outputformat;
- if ("jpg".equals(outputformat))
+ String mimetype = "image/" + extension;
+ if ("jpg".equals(extension))
{
mimetype = "image/jpeg";
}
nd.setAttribute(ImageUtils.RESOLUTION_PROPERTY, originalRes);
- nd.setAttribute(FileProperties.PROPERTY_EXTENSION, outputformat);
+ nd.setAttribute(FileProperties.PROPERTY_EXTENSION, extension);
nd.setAttribute(FileProperties.PROPERTY_FILENAME, saveTo.getName());
nd.setAttribute(FileProperties.PROPERTY_CONTENTTYPE, mimetype);
- nd.setAttribute(FileProperties.PROPERTY_LASTMODIFIED, GregorianCalendar.getInstance(TimeZone
- .getDefault()));
+ nd.setAttribute(
+ FileProperties.PROPERTY_LASTMODIFIED,
+ GregorianCalendar.getInstance(TimeZone.getDefault()));
nd.setAttribute(FileProperties.PROPERTY_WIDTH, "" + image.getWidth());
nd.setAttribute(FileProperties.PROPERTY_HEIGHT, "" + image.getHeight());
+
nd.setAttribute(FileProperties.PROPERTY_SIZE, "" + stream.getCount());
+
}
}
finally
@@ -528,7 +531,7 @@
}
else
{
- params.setProgressiveMode(javax.imageio.ImageWriteParam.MODE_COPY_FROM_METADATA);
+ params.setProgressiveMode(javax.imageio.ImageWriteParam.MODE_DISABLED);
}
}
catch (UnsupportedOperationException e)
@@ -597,7 +600,7 @@
/**
* Check if the resolution for a media is already present. Otherwise create it
- * @param media media to check the resolution on
+ * @param media media to check the resolutoin on
* @param resolutionTarget target resolution
* @return false if resolution doesn't exist and there is a problem in generate it; true otherwise
*/
@@ -609,7 +612,7 @@
/**
* Check if the resolution for a media is already present. Otherwise create it
- * @param media media to check the resolutoin on
+ * @param media media to check the resolution on
* @param resolutionTarget target resolution
* @param nodeDataName nodedata where the image to resize is stored
* @return false if resolution doesn't exist and there is a problem in generate it; true otherwise
@@ -715,10 +718,18 @@
+ image.getContentLength());
}
- String outputextension = image.getAttribute(FileProperties.PROPERTY_EXTENSION);
- if (!Arrays.asList(extensions).contains(outputextension))
+ String extension = image.getAttribute(FileProperties.PROPERTY_EXTENSION);
+ if (!Arrays.asList(extensions).contains(extension))
{
- outputextension = "png";
+ try
+ {
+ image.setAttribute(FileProperties.PROPERTY_EXTENSION, "jpg");
+ }
+ catch (RepositoryException e)
+ {
+ throw new RuntimeException(e);
+ }
+ extension = "jpg";
}
BufferedImage original = createBufferedImage(image);
@@ -762,23 +773,12 @@
}
if ("thumbnail".equals(resolutionTarget) || "preview".equals(resolutionTarget))
{
- ImageUtils.saveResolution(
- img,
- node,
- resolutionTarget,
- outputextension,
- quality,
- forceProgressive);
+ ImageUtils
+ .saveResolution(img, node, resolutionTarget, extension, quality, forceProgressive);
}
else
{
- ImageUtils.saveResolution(
- img,
- node,
- resolutionName,
- outputextension,
- quality,
- forceProgressive);
+ ImageUtils.saveResolution(img, node, resolutionName, extension, quality, forceProgressive);
}
}
catch (RepositoryException e)
@@ -895,11 +895,10 @@
if (ImageProcessorsManager.getInstance().isValidControlChar(controlChar))
{
- img = ImageProcessorsManager.getInstance().getImageResolutionProcessor(controlChar).getImageForResolution(
- original,
- size.x,
- size.y,
- params);
+ img = ImageProcessorsManager
+ .getInstance()
+ .getImageResolutionProcessor(controlChar)
+ .getImageForResolution(original, size.x, size.y, params);
}
else if (controlChar < '0' || controlChar > '9')
{
@@ -907,11 +906,10 @@
}
else
{
- img = ImageProcessorsManager.getInstance().getDefaultImageResolutionProcessor().getImageForResolution(
- original,
- size.x,
- size.y,
- params);
+ img = ImageProcessorsManager
+ .getInstance()
+ .getDefaultImageResolutionProcessor()
+ .getImageForResolution(original, size.x, size.y, params);
}
for (ImagePostProcessor ipp : ImageProcessorsManager.getInstance().getImagePostProcessorsList())
@@ -952,40 +950,22 @@
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);
- String ext = image.getAttribute(FileProperties.EXTENSION);
-
- if (StringUtils.equalsIgnoreCase(ext, "jpg") || StringUtils.equalsIgnoreCase(ext, "jpeg"))
+ if (result == null)
{
- try
- {
- return JpegUtils.processNonStandardImage(image);
- }
- catch (Throwable e)
- {
- // sun classes may not be available or other errors occurred, try with the standard ImageIO
- log
- .debug(
- "Unable to process image " + image.getHandle() + " using JpegUtils: " + e.getMessage(),
- e);
- }
+ // throw the original exception back
+ throw new BadImageFormatException("Unable to handle " + image.getHandle(), e);
}
- else if (StringUtils.equalsIgnoreCase(ext, "ico") || StringUtils.equalsIgnoreCase(ext, "bmp"))
- {
- BufferedImage buffered = IcoUtils.createBufferedImage(image);
- if (buffered != null)
- {
- return buffered;
- }
- }
+ return result;
- return ImageIO.read(is);
}
- catch (IOException e)
- {
- // throw the original exception back
- throw new BadImageFormatException("Unable to handle " + image.getHandle(), e);
- }
finally
{
IOUtils.closeQuietly(is);
@@ -993,7 +973,7 @@
}
/**
- * Parse resolution string for required size
+ * Parse resolution string for required sizesuper.read(b);
* @param res resolution string
* @return required size parsed from given resolution string
*/
@@ -1083,5 +1063,4 @@
}
}
-
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fg...@us...> - 2011-01-23 17:59:38
|
Revision: 3259
http://openutils.svn.sourceforge.net/openutils/?rev=3259&view=rev
Author: fgiust
Date: 2011-01-23 17:59:32 +0000 (Sun, 23 Jan 2011)
Log Message:
-----------
MEDIA-206 Better logging: avoid stacktraces for invalid binaries
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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 2011-01-23 17:56:15 UTC (rev 3258)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2011-01-23 17:59:32 UTC (rev 3259)
@@ -803,6 +803,18 @@
});
}
+ catch (BadImageFormatException e)
+ {
+ if (e.getCause() != null)
+ {
+ log.warn(e.getMessage(), e.getCause());
+ }
+ else
+ {
+ log.warn("Unable to extract a valid image from " + media.getHandle() + " (no message)");
+ }
+ return false;
+ }
catch (RuntimeException ex)
{
log.error(ClassUtils.getShortClassName(ex.getClass())
@@ -950,7 +962,15 @@
InputStream is = image.getStream();
try
{
- return ImageIO.read(is);
+ BufferedImage result = ImageIO.read(is);
+
+ // yes, ImageIO can return null without throwing any exception
+ if (result == null)
+ {
+ throw new BadImageFormatException("Unable to handle " + image.getHandle() + " (no message)");
+ }
+
+ return result;
}
catch (IOException e)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fg...@us...> - 2011-01-23 19:59:29
|
Revision: 3276
http://openutils.svn.sourceforge.net/openutils/?rev=3276&view=rev
Author: fgiust
Date: 2011-01-23 19:59:23 +0000 (Sun, 23 Jan 2011)
Log Message:
-----------
added back support for ico files, lost in recent commits :/
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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 2011-01-23 19:50:05 UTC (rev 3275)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2011-01-23 19:59:23 UTC (rev 3276)
@@ -96,7 +96,7 @@
*/
public static String RESOLUTION_PROPERTY = "resolution";
- private static final String[] extensions = new String[]{"jpg", "gif", "png" };
+ private static final String[] extensions = new String[]{"jpg", "jpeg", "gif", "png" };
static
{
@@ -960,8 +960,21 @@
public static BufferedImage createBufferedImage(NodeData image)
{
InputStream is = image.getStream();
+
+ String ext = image.getAttribute(FileProperties.EXTENSION);
+
try
{
+
+ if (StringUtils.equalsIgnoreCase(ext, "ico") || StringUtils.equalsIgnoreCase(ext, "bmp"))
+ {
+ BufferedImage buffered = IcoUtils.createBufferedImage(image);
+ if (buffered != null)
+ {
+ return buffered;
+ }
+ }
+
BufferedImage result = ImageIO.read(is);
// yes, ImageIO can return null without throwing any exception
@@ -971,6 +984,7 @@
}
return result;
+
}
catch (IOException e)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fg...@us...> - 2011-06-16 10:57:06
|
Revision: 3538
http://openutils.svn.sourceforge.net/openutils/?rev=3538&view=rev
Author: fgiust
Date: 2011-06-16 10:57:00 +0000 (Thu, 16 Jun 2011)
Log Message:
-----------
cleanup handling of "thumbnail" and "preview" resolutions
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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 2011-06-16 10:51:10 UTC (rev 3537)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2011-06-16 10:57:00 UTC (rev 3538)
@@ -85,6 +85,26 @@
{
/**
+ * Size for the "preview" resolution.
+ */
+ private static final String RESOLUTION_PREVIEW_SIZE = "l450x350";
+
+ /**
+ * Size for the "thumbnail" resolution.
+ */
+ private static final String RESOLUTION_THUMBNAIL_SIZE = "l100x100";
+
+ /**
+ * Name for the "preview" resolution.
+ */
+ private static final String RESOLUTION_PREVIEW = "preview";
+
+ /**
+ * Name for the "thumbnail" resolution.
+ */
+ private static final String RESOLUTION_THUMBNAIL = "thumbnail";
+
+ /**
* Logger.
*/
private static Logger log = LoggerFactory.getLogger(ImageUtils.class);
@@ -625,7 +645,7 @@
String resolution = resolutionTarget;
- if (!"thumbnail".equals(resolutionTarget) && !"preview".equals(resolutionTarget))
+ if (!RESOLUTION_THUMBNAIL.equals(resolutionTarget) && !RESOLUTION_PREVIEW.equals(resolutionTarget))
{
resolution = "res-" + resolutionTarget;
}
@@ -689,13 +709,13 @@
HierarchyManager hm = MgnlContext.getHierarchyManager(MediaModule.REPO);
String resolution = resolutionTarget;
- if ("thumbnail".equals(resolution))
+ if (RESOLUTION_THUMBNAIL.equals(resolution))
{
- resolution = "l100x100";
+ resolution = RESOLUTION_THUMBNAIL_SIZE;
}
- if ("preview".equals(resolution))
+ if (RESOLUTION_PREVIEW.equals(resolution))
{
- resolution = "l450x350";
+ resolution = RESOLUTION_PREVIEW_SIZE;
}
Content node;
@@ -771,7 +791,8 @@
{
forceProgressive = true;
}
- if ("thumbnail".equals(resolutionTarget) || "preview".equals(resolutionTarget))
+ if (RESOLUTION_THUMBNAIL.equals(resolutionTarget)
+ || RESOLUTION_PREVIEW.equals(resolutionTarget))
{
ImageUtils
.saveResolution(img, node, resolutionTarget, extension, quality, forceProgressive);
@@ -1006,6 +1027,23 @@
}
}
+ private static String normalizeResolutionString(String res)
+ {
+
+ String resolution = StringUtils.lowerCase(res);
+
+ if (RESOLUTION_THUMBNAIL.equals(resolution))
+ {
+ return RESOLUTION_THUMBNAIL_SIZE;
+ }
+ if (RESOLUTION_PREVIEW.equals(resolution))
+ {
+ return RESOLUTION_PREVIEW_SIZE;
+ }
+
+ return resolution;
+ }
+
/**
* Parse resolution string for required sizesuper.read(b);
* @param res resolution string
@@ -1014,7 +1052,7 @@
public static java.awt.Point parseForSize(String res)
{
Point size = new Point();
- String resolution = StringUtils.lowerCase(res);
+ String resolution = normalizeResolutionString(res);
if (StringUtils.contains(resolution, ";"))
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fg...@us...> - 2011-06-23 10:11:36
|
Revision: 3547
http://openutils.svn.sourceforge.net/openutils/?rev=3547&view=rev
Author: fgiust
Date: 2011-06-23 10:11:29 +0000 (Thu, 23 Jun 2011)
Log Message:
-----------
MEDIA-237 improved execution speed by using AffineTransform and avoiding filesystem usage
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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 2011-06-22 16:12:27 UTC (rev 3546)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2011-06-23 10:11:29 UTC (rev 3547)
@@ -31,19 +31,18 @@
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
-import java.awt.Image;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.Transparency;
+import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
-import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.GregorianCalendar;
@@ -75,7 +74,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.sun.image.codec.jpeg.JPEGEncodeParam;
+import com.sun.image.codec.jpeg.JPEGImageEncoder;
+
/**
* Main utility class that works with images and media nodes
* @author molaschi
@@ -249,21 +251,100 @@
}
}
+ graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
+
+ AffineTransform at = new AffineTransform();
+ double delta = ((double) x) / original.getWidth();
if (x > original.getWidth())
{
- graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
- graphics2D.drawImage(original, (canvasX - x) / 2, (canvasY - y) / 2, x, y, background, null);
+ at.scale(delta, delta);
+ at.translate((canvasX - x) / (2 * delta), (canvasY - y) / (2 * delta));
}
- else
+ else if (x < original.getWidth())
{
- Image scaledInstance = original.getScaledInstance(x, y, Image.SCALE_SMOOTH);
- graphics2D.drawImage(scaledInstance, (canvasX - x) / 2, (canvasY - y) / 2, x, y, background, null);
+ original = getScaledInstance(original, x, y, RenderingHints.VALUE_INTERPOLATION_BILINEAR, true);
+ at.translate((canvasX - x) / 2.0, (canvasY - y) / 2.0);
}
+ graphics2D.drawImage(original, at, null);
+ graphics2D.dispose();
+
return resizedImage;
}
/**
+ * Convenience method that returns a scaled instance of the provided {@code BufferedImage}.
+ * @param img the original image to be scaled
+ * @param targetWidth the desired width of the scaled instance, in pixels
+ * @param targetHeight the desired height of the scaled instance, in pixels
+ * @param hint one of the rendering hints that corresponds to {@code RenderingHints.KEY_INTERPOLATION} (e.g.
+ * {@code RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR}, {@code RenderingHints.VALUE_INTERPOLATION_BILINEAR},
+ * {@code RenderingHints.VALUE_INTERPOLATION_BICUBIC})
+ * @param higherQuality if true, this method will use a multi-step scaling technique that provides higher quality
+ * than the usual one-step technique (only useful in downscaling cases, where {@code targetWidth} or
+ * {@code targetHeight} is smaller than the original dimensions, and generally only when the {@code BILINEAR} hint
+ * is specified)
+ * @return a scaled version of the original {@code BufferedImage}
+ */
+ public static BufferedImage getScaledInstance(BufferedImage img, int targetWidth, int targetHeight, Object hint,
+ boolean higherQuality)
+ {
+ int type = (img.getTransparency() == Transparency.OPAQUE)
+ ? BufferedImage.TYPE_INT_RGB
+ : BufferedImage.TYPE_INT_ARGB;
+ BufferedImage ret = img;
+ int w, h;
+ if (higherQuality)
+ {
+ // Use multi-step technique: start with original size, then
+ // scale down in multiple passes with drawImage()
+ // until the target size is reached
+ w = img.getWidth();
+ h = img.getHeight();
+ }
+ else
+ {
+ // Use one-step technique: scale directly from original
+ // size to target size with a single drawImage() call
+ w = targetWidth;
+ h = targetHeight;
+ }
+
+ do
+ {
+ if (higherQuality && w > targetWidth)
+ {
+ w /= 2;
+
+ if (w < targetWidth)
+ {
+ w = targetWidth;
+ }
+ }
+
+ if (higherQuality && h > targetHeight)
+ {
+ h /= 2;
+ if (h < targetHeight)
+ {
+ h = targetHeight;
+ }
+ }
+
+ BufferedImage tmp = new BufferedImage(w, h, type);
+ Graphics2D g2 = tmp.createGraphics();
+ g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint);
+ g2.drawImage(ret, 0, 0, w, h, null);
+ g2.dispose();
+
+ ret = tmp;
+ }
+ while (w != targetWidth || h != targetHeight);
+
+ return ret;
+ }
+
+ /**
* Crop an image from left, top for width, height
* @param original original image
* @param left start crop point left
@@ -277,18 +358,14 @@
BufferedImage resizedImage = new BufferedImage(width, height, getType(original.getColorModel()));
Graphics2D graphics2D = resizedImage.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-
- if (width > original.getWidth())
- {
- graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
- }
- else
- {
- graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
- }
+ graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT);
- graphics2D.drawImage(original, 0, 0, width, height, left, top, width + left, height + top, null);
+ AffineTransform at = new AffineTransform();
+ at.translate(-left, -top);
+ graphics2D.drawImage(original, at, null);
+ graphics2D.dispose();
+
return resizedImage;
}
@@ -398,70 +475,90 @@
float quality, boolean forceProgressive) throws RepositoryException, IOException
{
- CountBytesBufferedInputStream stream = null;
+ Content resolutions = getResolutionsNode(saveTo);
+ if (resolutions == null)
+ {
+ resolutions = saveTo.createContent("resolutions", MediaConfigurationManager.RESOLUTIONS);
+ resolutions.getMetaData().setModificationDate();
+ }
- try
+ String resolution = name;
+ if (resolution == null)
{
- stream = new CountBytesBufferedInputStream(getStream(image, extension, quality, forceProgressive));
+ resolution = "res-" + image.getWidth() + "x" + image.getHeight();
+ }
- if (stream == null)
- {
- throw new IllegalArgumentException("Stream is null");
- }
+ String originalRes = resolution;
+ resolution = getResolutionPath(resolution);
- Content resolutions = getResolutionsNode(saveTo);
- if (resolutions == null)
- {
- resolutions = saveTo.createContent("resolutions", MediaConfigurationManager.RESOLUTIONS);
- resolutions.getMetaData().setModificationDate();
- }
+ synchronized (ExclusiveWrite.getInstance())
+ {
- String resolution = name;
- if (resolution == null)
+ if (resolutions.hasNodeData(resolution))
{
- resolution = "res-" + image.getWidth() + "x" + image.getHeight();
+ NodeData nd = resolutions.getNodeData(resolution);
+ nd.delete();
}
- String originalRes = resolution;
- resolution = getResolutionPath(resolution);
+ // don't remove deprecated method call, needed for magnolia 4.0 compatibility
+ final NodeData nd = resolutions.createNodeData(resolution, PropertyType.BINARY);
+ final PipedInputStream stream = new PipedInputStream();
+ PipedOutputStream outputstream = new PipedOutputStream(stream);
- synchronized (ExclusiveWrite.getInstance())
+ log.info("setting value to {}", nd.getHandle());
+
+ Thread t = new Thread(new Runnable()
{
- if (resolutions.hasNodeData(resolution))
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void run()
{
- NodeData nd = resolutions.getNodeData(resolution);
- nd.delete();
+ try
+ {
+ nd.setValue(stream);
+ }
+ catch (RepositoryException e)
+ {
+ // TODO Auto-generated catch block
+ log.error(e.getMessage(), e);
+ }
}
- // don't remove deprecated method call, needed for magnolia 4.0 compatibility
- NodeData nd = resolutions.createNodeData(resolution, PropertyType.BINARY);
+ });
+ t.start();
- log.info("setting value to {}", nd.getHandle());
- nd.setValue(stream);
- String mimetype = "image/" + extension;
- if ("jpg".equals(extension))
- {
- mimetype = "image/jpeg";
- }
- nd.setAttribute(ImageUtils.RESOLUTION_PROPERTY, originalRes);
- nd.setAttribute(FileProperties.PROPERTY_EXTENSION, extension);
- nd.setAttribute(FileProperties.PROPERTY_FILENAME, saveTo.getName());
- nd.setAttribute(FileProperties.PROPERTY_CONTENTTYPE, mimetype);
- nd.setAttribute(
- FileProperties.PROPERTY_LASTMODIFIED,
- GregorianCalendar.getInstance(TimeZone.getDefault()));
- nd.setAttribute(FileProperties.PROPERTY_WIDTH, "" + image.getWidth());
- nd.setAttribute(FileProperties.PROPERTY_HEIGHT, "" + image.getHeight());
+ long count = getStream(image, extension, quality, forceProgressive, outputstream);
+ IOUtils.closeQuietly(outputstream);
+ try
+ {
+ t.join();
+ }
+ catch (InterruptedException e)
+ {
+ log.warn(e.getMessage(), e);
+ }
- nd.setAttribute(FileProperties.PROPERTY_SIZE, "" + stream.getCount());
+ IOUtils.closeQuietly(stream);
+ String mimetype = "image/" + extension;
+ if ("jpg".equals(extension))
+ {
+ mimetype = "image/jpeg";
}
+ nd.setAttribute(ImageUtils.RESOLUTION_PROPERTY, originalRes);
+ nd.setAttribute(FileProperties.PROPERTY_EXTENSION, extension);
+ nd.setAttribute(FileProperties.PROPERTY_FILENAME, saveTo.getName());
+ nd.setAttribute(FileProperties.PROPERTY_CONTENTTYPE, mimetype);
+ nd.setAttribute(FileProperties.PROPERTY_LASTMODIFIED, GregorianCalendar.getInstance(TimeZone.getDefault()));
+ nd.setAttribute(FileProperties.PROPERTY_WIDTH, "" + image.getWidth());
+ nd.setAttribute(FileProperties.PROPERTY_HEIGHT, "" + image.getHeight());
+
+ nd.setAttribute(FileProperties.PROPERTY_SIZE, "" + count);
}
- finally
- {
- IOUtils.closeQuietly(stream);
- }
+
}
/**
@@ -489,110 +586,116 @@
* @return inputstream
* @throws IOException
*/
- public static InputStream getStream(BufferedImage image, String extension, float quality, boolean forceProgressive)
- throws IOException
+ public static long getStream(BufferedImage image, String extension, float quality, boolean forceProgressive,
+ PipedOutputStream outputstream) throws IOException
{
- // don't write ico file, use png
- if (StringUtils.equalsIgnoreCase(extension, "ico"))
- {
- extension = "png";
- }
+ CountBytesBufferedOutputStream out = new CountBytesBufferedOutputStream(outputstream);
- final File tempFile = File.createTempFile("image-", "." + extension);
- FileOutputStream fos = new FileOutputStream(tempFile);
-
- BufferedOutputStream out = new BufferedOutputStream(fos);
-
try
{
-
- Iterator<ImageWriter> writers;
- ImageOutputStream imageOutputStream;
- ImageWriteParam params;
- ImageWriter imageWriter;
-
- writers = ImageIO.getImageWritersBySuffix(extension);
-
- if (writers != null && writers.hasNext())
+ if (extension.equals("jpg"))
{
- // Fetch the first writer in the list
- imageWriter = writers.next();
+ JPEGImageEncoder encoder = com.sun.image.codec.jpeg.JPEGCodec.createJPEGEncoder(out);
+ if (quality != 1.0f)
+ {
+ JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(image);
+ param.setQuality(quality, true);
+ encoder.setJPEGEncodeParam(param);
+ }
+ encoder.encode(image);
+ }
+ else
+ {
- // Specify the parameters according to those the output file will be written
+ Iterator<ImageWriter> writers;
+ ImageOutputStream imageOutputStream;
+ ImageWriteParam params;
+ ImageWriter imageWriter;
- // Get Default parameters
- params = imageWriter.getDefaultWriteParam();
+ // don't use "ico" as output format
+ writers = ImageIO.getImageWritersBySuffix(extension.equals("ico") ? "png" : extension);
- try
+ if (writers != null && writers.hasNext())
{
+ // Fetch the first writer in the list
+ imageWriter = writers.next();
- String[] compressionTypes = params.getCompressionTypes();
+ // Specify the parameters according to those the output file will be written
- if (compressionTypes != null && compressionTypes.length > 0)
+ // Get Default parameters
+ params = imageWriter.getDefaultWriteParam();
+
+ try
{
- // Define compression mode
- params.setCompressionMode(javax.imageio.ImageWriteParam.MODE_EXPLICIT);
- params.setCompressionType(compressionTypes[0]);
+ String[] compressionTypes = params.getCompressionTypes();
- // Define compression quality
- params.setCompressionQuality(quality);
- }
- else
- {
- params.setCompressionMode(javax.imageio.ImageWriteParam.MODE_COPY_FROM_METADATA);
- }
+ if (compressionTypes != null && compressionTypes.length > 0)
+ {
+ // Define compression mode
+ params.setCompressionMode(javax.imageio.ImageWriteParam.MODE_EXPLICIT);
- // Define progressive mode
- if (forceProgressive)
- {
- params.setProgressiveMode(javax.imageio.ImageWriteParam.MODE_DEFAULT);
+ params.setCompressionType(compressionTypes[0]);
+
+ // Define compression quality
+ params.setCompressionQuality(quality);
+ }
+ else
+ {
+ params.setCompressionMode(javax.imageio.ImageWriteParam.MODE_COPY_FROM_METADATA);
+ }
+
+ // Define progressive mode
+ if (forceProgressive)
+ {
+ params.setProgressiveMode(javax.imageio.ImageWriteParam.MODE_DEFAULT);
+ }
+ else
+ {
+ params.setProgressiveMode(javax.imageio.ImageWriteParam.MODE_DISABLED);
+ }
}
- else
+ catch (UnsupportedOperationException e)
{
- params.setProgressiveMode(javax.imageio.ImageWriteParam.MODE_DISABLED);
+ // go on
}
- }
- catch (UnsupportedOperationException e)
- {
- // go on
- }
- // Define destination type - used the ColorModel and SampleModel of the Input Image
- params.setDestinationType(new ImageTypeSpecifier(image.getColorModel(), image.getSampleModel()));
+ // Define destination type - used the ColorModel and SampleModel of the Input Image
+ params.setDestinationType(new ImageTypeSpecifier(image.getColorModel(), image.getSampleModel()));
- imageOutputStream = ImageIO.createImageOutputStream(out);
- imageWriter.setOutput(imageOutputStream);
+ imageOutputStream = ImageIO.createImageOutputStream(out);
+ imageWriter.setOutput(imageOutputStream);
- IIOImage iioimage = new IIOImage(image, null, null);
+ IIOImage iioimage = new IIOImage(image, null, null);
- try
- {
- // Write the changed Image
- imageWriter.write(null, iioimage, params);
- }
- catch (NullPointerException e)
- {
- // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6287936
- // GIF writer is buggy for totally transparent gifs
+ try
+ {
+ // Write the changed Image
+ imageWriter.write(null, iioimage, params);
+ }
+ catch (NullPointerException e)
+ {
+ // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6287936
+ // GIF writer is buggy for totally transparent gifs
- // workaround: draw a point!
- image.createGraphics().drawRect(0, 0, 1, 1);
- imageWriter.write(null, iioimage, params);
+ // workaround: draw a point!
+ image.createGraphics().drawRect(0, 0, 1, 1);
+ imageWriter.write(null, iioimage, params);
+ }
+ finally
+ {
+ // Close the streams
+ imageOutputStream.close();
+ imageWriter.dispose();
+ }
}
- finally
+ else
{
- // Close the streams
- imageOutputStream.close();
- imageWriter.dispose();
+ ImageIO.write(image, extension, out);
}
}
- else
- {
- ImageIO.write(image, extension, out);
- }
}
catch (IOException ex)
{
@@ -600,22 +703,7 @@
throw ex;
}
- out.flush();
- IOUtils.closeQuietly(out);
- return new FileInputStream(tempFile)
- {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void close() throws IOException
- {
- tempFile.delete();
- super.close();
- }
-
- };
+ return out.count;
}
/**
@@ -758,6 +846,8 @@
Map<String, String> params = parseParameters(resolution);
+ long t = System.currentTimeMillis();
+
BufferedImage img;
try
{
@@ -820,6 +910,8 @@
throw new RuntimeException(e);
}
+ log.debug("Resized {} in: {}ms", finalNodeDataName, System.currentTimeMillis() - t);
+
}
});
@@ -1087,7 +1179,7 @@
}
}
- static class CountBytesBufferedInputStream extends BufferedInputStream
+ static class CountBytesBufferedOutputStream extends BufferedOutputStream
{
private int count = 0;
@@ -1096,43 +1188,39 @@
* @param in
* @param size
*/
- public CountBytesBufferedInputStream(InputStream in, int size)
+ public CountBytesBufferedOutputStream(OutputStream out, int size)
{
- super(in, size);
+ super(out, size);
count = 0;
}
/**
* @param in
*/
- public CountBytesBufferedInputStream(InputStream in)
+ public CountBytesBufferedOutputStream(OutputStream in)
{
super(in);
count = 0;
}
/**
- * {@inheritDoc}
+ * Returns the count.
+ * @return the count
*/
- @Override
- public synchronized int read(byte[] b, int off, int len) throws IOException
+ public int getCount()
{
- int read = super.read(b, off, len);
- if (read > 0)
- {
- count += read;
- }
- return read;
+ return count;
}
/**
- * Returns the count.
- * @return the count
+ * {@inheritDoc}
*/
- public int getCount()
+ @Override
+ public synchronized void write(byte[] b, int off, int len) throws IOException
{
- return count;
+ count += len;
+ super.write(b, off, len);
}
}
-}
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fg...@us...> - 2011-06-25 11:42:14
|
Revision: 3564
http://openutils.svn.sourceforge.net/openutils/?rev=3564&view=rev
Author: fgiust
Date: 2011-06-25 11:42:08 +0000 (Sat, 25 Jun 2011)
Log Message:
-----------
better logging
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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 2011-06-23 12:22:43 UTC (rev 3563)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2011-06-25 11:42:08 UTC (rev 3564)
@@ -505,7 +505,7 @@
final PipedInputStream stream = new PipedInputStream();
PipedOutputStream outputstream = new PipedOutputStream(stream);
- log.info("setting value to {}", nd.getHandle());
+ log.debug("setting value to {}", nd.getHandle());
Thread t = new Thread(new Runnable()
{
@@ -782,7 +782,7 @@
log.warn(e2.getMessage(), e2);
}
- final String finalNodeDataName = nodeDataName;
+ final String originalNodeDataName = nodeDataName;
try
{
@@ -794,18 +794,26 @@
*/
public void exec()
{
+ long timestart = System.currentTimeMillis();
+
HierarchyManager hm = MgnlContext.getHierarchyManager(MediaModule.REPO);
- String resolution = resolutionTarget;
+ String resolutionstring = resolutionTarget;
- if (RESOLUTION_THUMBNAIL.equals(resolution))
+ if (RESOLUTION_THUMBNAIL.equals(resolutionstring))
{
- resolution = RESOLUTION_THUMBNAIL_SIZE;
+ resolutionstring = RESOLUTION_THUMBNAIL_SIZE;
}
- if (RESOLUTION_PREVIEW.equals(resolution))
+ if (RESOLUTION_PREVIEW.equals(resolutionstring))
{
- resolution = RESOLUTION_PREVIEW_SIZE;
+ resolutionstring = RESOLUTION_PREVIEW_SIZE;
}
+ String resolutioNodeName = "res-" + resolutionstring;
+ if (RESOLUTION_THUMBNAIL.equals(resolutionTarget) || RESOLUTION_PREVIEW.equals(resolutionTarget))
+ {
+ resolutioNodeName = resolutionTarget;
+ }
+
Content node;
try
{
@@ -816,7 +824,7 @@
throw new RuntimeException(e);
}
- NodeData image = node.getNodeData(finalNodeDataName);
+ NodeData image = node.getNodeData(originalNodeDataName);
if (image.getContentLength() == 0)
{
@@ -842,16 +850,12 @@
BufferedImage original = createBufferedImage(image);
- String resolutionName = "res-" + resolution;
+ Map<String, String> params = parseParameters(resolutionstring);
- Map<String, String> params = parseParameters(resolution);
-
- long t = System.currentTimeMillis();
-
BufferedImage img;
try
{
- img = ImageUtils.getImageForResolution(original, resolution, params);
+ img = ImageUtils.getImageForResolution(original, resolutionstring, params);
}
catch (IllegalArgumentException e)
{
@@ -881,16 +885,8 @@
{
forceProgressive = true;
}
- if (RESOLUTION_THUMBNAIL.equals(resolutionTarget)
- || RESOLUTION_PREVIEW.equals(resolutionTarget))
- {
- ImageUtils
- .saveResolution(img, node, resolutionTarget, extension, quality, forceProgressive);
- }
- else
- {
- ImageUtils.saveResolution(img, node, resolutionName, extension, quality, forceProgressive);
- }
+
+ ImageUtils.saveResolution(img, node, resolutioNodeName, extension, quality, forceProgressive);
}
catch (RepositoryException e)
{
@@ -910,8 +906,10 @@
throw new RuntimeException(e);
}
- log.debug("Resized {} in: {}ms", finalNodeDataName, System.currentTimeMillis() - t);
-
+ log.info("Generated {} for {} in {} milliseconds", new Object[]{
+ resolutioNodeName,
+ node.getHandle(),
+ System.currentTimeMillis() - timestart });
}
});
@@ -926,6 +924,16 @@
{
log.warn("Unable to extract a valid image from " + media.getHandle() + " (no message)");
}
+
+ try
+ {
+ media.setNodeData("bad_image_marker", media.getNodeData("bad_image_marker").getLong() + 1);
+ media.save();
+ }
+ catch (RepositoryException e1)
+ {
+ // ignore
+ }
return false;
}
catch (RuntimeException ex)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fg...@us...> - 2011-07-03 15:41:54
|
Revision: 3575
http://openutils.svn.sourceforge.net/openutils/?rev=3575&view=rev
Author: fgiust
Date: 2011-07-03 15:41:48 +0000 (Sun, 03 Jul 2011)
Log Message:
-----------
better variable name, for clarity
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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 2011-07-03 15:35:14 UTC (rev 3574)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2011-07-03 15:41:48 UTC (rev 3575)
@@ -832,10 +832,10 @@
throw new ZeroSizeImageException(image.getHandle());
}
- String extension = image.getAttribute(FileProperties.PROPERTY_EXTENSION);
- if (!Arrays.asList(extensions).contains(extension))
+ String outputextension = image.getAttribute(FileProperties.PROPERTY_EXTENSION);
+ if (!Arrays.asList(extensions).contains(outputextension))
{
- extension = "jpg";
+ outputextension = "jpg";
}
BufferedImage original = createBufferedImage(image);
@@ -876,7 +876,7 @@
forceProgressive = true;
}
- ImageUtils.saveResolution(img, node, resolutioNodeName, extension, quality, forceProgressive);
+ ImageUtils.saveResolution(img, node, resolutioNodeName, outputextension, quality, forceProgressive);
}
catch (RepositoryException e)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fg...@us...> - 2011-11-06 16:57:10
|
Revision: 3681
http://openutils.svn.sourceforge.net/openutils/?rev=3681&view=rev
Author: fgiust
Date: 2011-11-06 16:57:03 +0000 (Sun, 06 Nov 2011)
Log Message:
-----------
MEDIA-264 Output resolutions in png format when input image is gif
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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 2011-10-31 15:26:36 UTC (rev 3680)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2011-11-06 16:57:03 UTC (rev 3681)
@@ -614,8 +614,15 @@
ImageWriteParam params;
ImageWriter imageWriter;
+ String outputextension = extension;
+ if (StringUtils.equals(extension, "ico") || StringUtils.equals(extension, "gif"))
+ {
+ // gif and ico are remapped to png
+ outputextension = "png";
+ }
+
// don't use "ico" as output format
- writers = ImageIO.getImageWritersBySuffix(extension.equals("ico") ? "png" : extension);
+ writers = ImageIO.getImageWritersBySuffix(outputextension);
if (writers != null && writers.hasNext())
{
@@ -694,7 +701,7 @@
}
else
{
- ImageIO.write(image, extension, out);
+ ImageIO.write(image, outputextension, out);
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fg...@us...> - 2011-11-06 17:48:17
|
Revision: 3691
http://openutils.svn.sourceforge.net/openutils/?rev=3691&view=rev
Author: fgiust
Date: 2011-11-06 17:48:11 +0000 (Sun, 06 Nov 2011)
Log Message:
-----------
MEDIA-266 Avoid usage of ExclusiveWrite and use node-scoped locks when saving resolutions - to be tested carefully
Modified Paths:
--------------
trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java
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 2011-11-06 17:21:20 UTC (rev 3690)
+++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2011-11-06 17:48:11 UTC (rev 3691)
@@ -23,7 +23,6 @@
import info.magnolia.cms.core.Content;
import info.magnolia.cms.core.HierarchyManager;
import info.magnolia.cms.core.NodeData;
-import info.magnolia.cms.util.ExclusiveWrite;
import info.magnolia.context.Context;
import info.magnolia.context.MgnlContext;
import info.magnolia.context.MgnlContext.SystemContextOperation;
@@ -60,6 +59,7 @@
import javax.imageio.stream.ImageOutputStream;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
+import javax.jcr.lock.Lock;
import net.sourceforge.openutils.mgnlmedia.media.configuration.ImageProcessorsManager;
import net.sourceforge.openutils.mgnlmedia.media.configuration.MediaConfigurationManager;
@@ -481,6 +481,7 @@
{
resolutions = saveTo.createContent("resolutions", MediaConfigurationManager.RESOLUTIONS);
resolutions.getMetaData().setModificationDate();
+ saveTo.save();
}
String resolution = name;
@@ -492,13 +493,17 @@
String originalRes = resolution;
resolution = getResolutionPath(resolution);
- synchronized (ExclusiveWrite.getInstance())
+ // max wait 5 secs
+ Lock lock = resolutions.lock(false, true, 5000);
+
+ try
{
if (resolutions.hasNodeData(resolution))
{
NodeData nd = resolutions.getNodeData(resolution);
nd.delete();
+ resolutions.save();
}
// don't remove deprecated method call, needed for magnolia 4.0 compatibility
@@ -514,7 +519,6 @@
/**
* {@inheritDoc}
*/
- @Override
public void run()
{
try
@@ -558,7 +562,13 @@
nd.setAttribute(FileProperties.PROPERTY_HEIGHT, "" + image.getHeight());
nd.setAttribute(FileProperties.PROPERTY_SIZE, "" + count);
+
+ resolutions.save();
}
+ finally
+ {
+ resolutions.unlock();
+ }
}
@@ -883,7 +893,13 @@
forceProgressive = true;
}
- ImageUtils.saveResolution(img, node, resolutioNodeName, outputextension, quality, forceProgressive);
+ ImageUtils.saveResolution(
+ img,
+ node,
+ resolutioNodeName,
+ outputextension,
+ quality,
+ forceProgressive);
}
catch (RepositoryException e)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|