From e722843e5197b8c54d6b8383d6f50a89a7eecf62 Mon Sep 17 00:00:00 2001 From: Bruce Grant Date: Thu, 22 Mar 2012 17:39:01 +0100 Subject: [PATCH] imaging changes --- .../pictures/tiles/magick/tiler/MagickTiler.java | 3 +- .../nuxeo/ecm/platform/picture/api/ImageInfo.java | 17 ++++++++++++++ .../api/adapters/AbstractPictureAdapter.java | 22 +++++++++++++++-- .../magick/utils/ImageCropperAndResizer.java | 11 ++++++++- .../picture/magick/utils/ImageIdentifier.java | 3 +- .../OSGI-INF/commandline-imagemagick-contrib.xml | 24 ++++++++++---------- .../picture/core/test/TestMagickExecutors.java | 4 +- 7 files changed, 64 insertions(+), 20 deletions(-) diff --git a/nuxeo-platform-imaging-tiling/nuxeo-platform-imaging-tiling/src/main/java/org/nuxeo/ecm/platform/pictures/tiles/magick/tiler/MagickTiler.java b/nuxeo-platform-imaging-tiling/nuxeo-platform-imaging-tiling/src/main/java/org/nuxeo/ecm/platform/pictures/tiles/magick/tiler/MagickTiler.java index 9ed1c43..b85e047 100644 --- a/nuxeo-platform-imaging-tiling/nuxeo-platform-imaging-tiling/src/main/java/org/nuxeo/ecm/platform/pictures/tiles/magick/tiler/MagickTiler.java +++ b/nuxeo-platform-imaging-tiling/nuxeo-platform-imaging-tiling/src/main/java/org/nuxeo/ecm/platform/pictures/tiles/magick/tiler/MagickTiler.java @@ -129,10 +129,11 @@ public class MagickTiler implements PictureTiler { String fileName = StringMaker.getTileFileName(xCenter, yCenter, lastModificationTime); String outputFilePath = new Path(outputDirPath).append(fileName).toString(); + // FEATURE-image_fixes: DBG: 2012.03.21: added additional param for colorModel try { ImageCropperAndResizer.cropAndResize(input.getFilePath(), outputFilePath, cropCoords[2], cropCoords[3], - cropCoords[0], cropCoords[1], cropCoords[6], cropCoords[7]); + cropCoords[0], cropCoords[1], cropCoords[6], cropCoords[7], input.getColorModel()); } catch (Exception e) { throw new ClientException(e); } diff --git a/nuxeo-platform-imaging/nuxeo-platform-imaging-api/src/main/java/org/nuxeo/ecm/platform/picture/api/ImageInfo.java b/nuxeo-platform-imaging/nuxeo-platform-imaging-api/src/main/java/org/nuxeo/ecm/platform/picture/api/ImageInfo.java index 425c96a..62c32fb 100644 --- a/nuxeo-platform-imaging/nuxeo-platform-imaging-api/src/main/java/org/nuxeo/ecm/platform/picture/api/ImageInfo.java +++ b/nuxeo-platform-imaging/nuxeo-platform-imaging-api/src/main/java/org/nuxeo/ecm/platform/picture/api/ImageInfo.java @@ -38,6 +38,15 @@ public class ImageInfo { protected String format; protected String filePath; + + // FEATURE-image_fixes: DBG: 2012.03.21: added additional property and constructor for colorModel + protected String colorModel; + + public ImageInfo(String width, String height, String format, String depth, String colorModel, String filePath) { + this(width, height, format, filePath); + this.depth = Integer.parseInt(depth); + this.colorModel = colorModel; + } public ImageInfo(String width, String height, String format, String filePath) { this.width = Integer.parseInt(width); @@ -97,4 +106,12 @@ public class ImageInfo { this.depth = depth; } + public String getColorModel() { + return colorModel; + } + + public void setColorModel(String colorModel) { + this.colorModel = colorModel; + } + } diff --git a/nuxeo-platform-imaging/nuxeo-platform-imaging-api/src/main/java/org/nuxeo/ecm/platform/picture/api/adapters/AbstractPictureAdapter.java b/nuxeo-platform-imaging/nuxeo-platform-imaging-api/src/main/java/org/nuxeo/ecm/platform/picture/api/adapters/AbstractPictureAdapter.java index 7d2af89..ebb338f 100644 --- a/nuxeo-platform-imaging/nuxeo-platform-imaging-api/src/main/java/org/nuxeo/ecm/platform/picture/api/adapters/AbstractPictureAdapter.java +++ b/nuxeo-platform-imaging/nuxeo-platform-imaging-api/src/main/java/org/nuxeo/ecm/platform/picture/api/adapters/AbstractPictureAdapter.java @@ -145,6 +145,9 @@ public abstract class AbstractPictureAdapter implements PictureResourceAdapter { protected Integer height; protected Integer depth; + + // FEATURE-image_fixes: DBG: 2012.03.21: get colorModel + protected String colorModel; protected String description; @@ -206,6 +209,8 @@ public abstract class AbstractPictureAdapter implements PictureResourceAdapter { width = imageInfo.getWidth(); height = imageInfo.getHeight(); depth = imageInfo.getDepth(); + // FEATURE-image_fixes: DBG: 2012.03.21: get colorModel + colorModel = imageInfo.getColorModel(); imageInfoUsed = true; } Map metadata = getImagingService().getImageMetadata( @@ -214,6 +219,8 @@ public abstract class AbstractPictureAdapter implements PictureResourceAdapter { if (!imageInfoUsed) { width = (Integer) metadata.get(META_WIDTH); height = (Integer) metadata.get(META_HEIGHT); + // FEATURE-image_fixes: DBG: 2012.03.21: fix for bad filename + colorModel = ""; } doc.setPropertyValue("picture:" + FIELD_BYLINE, (String) metadata.get(META_BY_LINE)); @@ -263,8 +270,9 @@ public abstract class AbstractPictureAdapter implements PictureResourceAdapter { (String) metadata.get(META_ISOSPEED)); doc.setPropertyValue("imd:focal_length", (Double) metadata.get(META_FOCALLENGTH)); - doc.setPropertyValue("imd:color_space", - (String) metadata.get(META_COLORSPACE)); + // FEATURE-image_fixes: DBG: 2012.03.21: fix for colormodel + doc.setPropertyValue("imd:color_space", colorModel); + // (String) metadata.get(META_COLORSPACE)); doc.setPropertyValue("imd:white_balance", (String) metadata.get(META_WHITEBALANCE)); ICC_Profile iccProfile = (ICC_Profile) metadata.get(META_ICCPROFILE); @@ -377,7 +385,8 @@ public abstract class AbstractPictureAdapter implements PictureResourceAdapter { Map map = new HashMap(); map.put("title", title); map.put("description", description); - map.put("filename", filename); + // FEATURE-image_fixes: DBG: 2012.03.21: fix for bad filename + //map.put("filename", filename); map.put("tag", tag); if ("Original".equals(title)) { map.put("width", width); @@ -385,6 +394,8 @@ public abstract class AbstractPictureAdapter implements PictureResourceAdapter { FileBlob fileBlob = new FileBlob(file, type); fileBlob.setFilename(title + "_" + filename); map.put("content", fileBlob); + // FEATURE-image_fixes: DBG: 2012.03.21: fix for bad filename + map.put("filename", filename); } else if ("OriginalJpeg".equals(title)) { map.put("width", width); map.put("height", height); @@ -402,6 +413,8 @@ public abstract class AbstractPictureAdapter implements PictureResourceAdapter { JPEG_CONVERSATION_FORMAT); blob.setFilename(title + "_" + viewFilename); map.put("content", blob); + // FEATURE-image_fixes: DBG: 2012.03.21: fix for bad filename + map.put("filename", viewFilename); } else { Point size = new Point(width, height); size = getSize(size, maxsize); @@ -424,6 +437,9 @@ public abstract class AbstractPictureAdapter implements PictureResourceAdapter { JPEG_CONVERSATION_FORMAT); blob.setFilename(title + "_" + viewFilename); map.put("content", blob); + // FEATURE-image_fixes: DBG: 2012.03.21: fix for bad filename + map.put("filename", viewFilename); + } Serializable views = doc.getPropertyValue(VIEWS_PROPERTY); List> viewsList = (List>) views; diff --git a/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/magick/utils/ImageCropperAndResizer.java b/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/magick/utils/ImageCropperAndResizer.java index 6d5399f..1a5ffe5 100644 --- a/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/magick/utils/ImageCropperAndResizer.java +++ b/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/magick/utils/ImageCropperAndResizer.java @@ -29,9 +29,10 @@ import org.nuxeo.ecm.platform.picture.magick.MagickExecutor; */ public class ImageCropperAndResizer extends MagickExecutor { + // FEATURE-image_fixes: DBG: 2012.03.21: added additional param for colorModel public static void cropAndResize(String inputFilePath, String outputFilePath, int tileWidth, int tileHeight, int offsetX, - int offsetY, int targetWidth, int targetHeight) throws Exception { + int offsetY, int targetWidth, int targetHeight, String colorModel) throws Exception { CmdParameters params = new CmdParameters(); params.addNamedParameter("tileWidth", String.valueOf(tileWidth)); params.addNamedParameter("tileHeight", String.valueOf(tileHeight)); @@ -41,6 +42,14 @@ public class ImageCropperAndResizer extends MagickExecutor { params.addNamedParameter("targetHeight", String.valueOf(targetHeight)); params.addNamedParameter("inputFilePath", inputFilePath); params.addNamedParameter("outputFilePath", outputFilePath); + + // DBG: imagemagick supports sRGB color model but stream/convert still require rgb as colorspace param + if ("srgb".equals(colorModel.toLowerCase())) { + params.addNamedParameter("colorModel", "rgb"); + } else { + params.addNamedParameter("colorModel", colorModel); + } + execCommand("cropAndResize", params); } diff --git a/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/magick/utils/ImageIdentifier.java b/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/magick/utils/ImageIdentifier.java index 1e6d692..f36bb2d 100644 --- a/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/magick/utils/ImageIdentifier.java +++ b/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/magick/utils/ImageIdentifier.java @@ -43,7 +43,8 @@ public class ImageIdentifier extends MagickExecutor { : 0); String[] res = out.split(" "); - return new ImageInfo(res[1], res[2], res[0], res[res.length - 1], + // FEATURE-image_fixes: DBG: 2012.03.21: added additional param for colorModel + return new ImageInfo(res[1], res[2], res[0], res[3], res[res.length - 1], inputFilePath); } diff --git a/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/resources/OSGI-INF/commandline-imagemagick-contrib.xml b/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/resources/OSGI-INF/commandline-imagemagick-contrib.xml index fd7c09c..06b548b 100644 --- a/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/resources/OSGI-INF/commandline-imagemagick-contrib.xml +++ b/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/resources/OSGI-INF/commandline-imagemagick-contrib.xml @@ -8,51 +8,51 @@ identify - -ping -format '%m %w %h %z' #{inputFilePath} - -ping -format "%m %w %h %z" #{inputFilePath} - You need to install ImageMagic. + -ping -format '%m %w %h %z %[colorspace]' #{inputFilePath} + -ping -format "%m %w %h %z %[colorspace]" #{inputFilePath} + You need to install ImageMagick. stream -map rgb -storage-type char -extract #{tileWidth}x#{tileHeight}+#{offsetX}+#{offsetY} #{inputFilePath}[0] - | convert -depth 8 -size #{tileWidth}x#{tileHeight} rgb:- #{outputFilePath} - You need to install ImageMagic. + You need to install ImageMagick. convert - -flatten -resize #{targetWidth}x#{targetHeight} -depth #{targetDepth} #{inputFilePath}[0] #{outputFilePath} - You need to install ImageMagic. + #{inputFilePath}[0] jpg:- | convert - -resize #{targetWidth}x#{targetHeight} -depth #{targetDepth} #{outputFilePath} + You need to install ImageMagick. convert #{inputFilePath} -coalesce -resize #{targetWidth}x#{targetHeight} -depth #{targetDepth} -deconstruct #{outputFilePath} - You need to install ImageMagic. + You need to install ImageMagick. convert -rotate #{angle} #{inputFilePath}[0] #{outputFilePath} - You need to install ImageMagic. + You need to install ImageMagick. stream - -map rgb -storage-type char -extract #{tileWidth}x#{tileHeight}+#{offsetX}+#{offsetY} #{inputFilePath} - | convert -depth 8 -size #{tileWidth}x#{tileHeight} -resize #{targetWidth}x#{targetHeight}! rgb:- #{outputFilePath} - You need to install ImageMagic. + -map #{colorModel} -storage-type char -extract #{tileWidth}x#{tileHeight}+#{offsetX}+#{offsetY} #{inputFilePath} - | convert -depth 8 -size #{tileWidth}x#{tileHeight} -resize #{targetWidth}x#{targetHeight}! #{colorModel}:- #{outputFilePath} + You need to install ImageMagick. convert -colorspace rgb #{inputFilePath}[0] #{outputFilePath} - You need to install ImageMagic. + You need to install ImageMagick. convert #{inputFilePath} -crop #{tileWidth}x#{tileHeight} + repage #{outputFilePath} - You need to install ImageMagic. + You need to install ImageMagick. diff --git a/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/test/java/org/nuxeo/ecm/platform/picture/core/test/TestMagickExecutors.java b/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/test/java/org/nuxeo/ecm/platform/picture/core/test/TestMagickExecutors.java index 0361bec..8e19d8c 100644 --- a/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/test/java/org/nuxeo/ecm/platform/picture/core/test/TestMagickExecutors.java +++ b/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/test/java/org/nuxeo/ecm/platform/picture/core/test/TestMagickExecutors.java @@ -94,9 +94,9 @@ public class TestMagickExecutors extends RepositoryOSGITestCase { + "/test_crop_resized.jpg"; File file = FileUtils.getResourceFileFromContext("images/test.jpg"); - + // FEATURE-image_fixes: DBG: 2012.03.21: set color model to RGB for test image ImageCropperAndResizer.cropAndResize(file.getAbsolutePath(), - outputFilePath, 255, 255, 10, 10, 200, 200); + outputFilePath, 255, 255, 10, 10, 200, 200, "rgb"); File out = new File(outputFilePath); assertTrue(out.exists()); -- 1.7.1