001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.tests.embedded;
034:
035: import com.flexive.core.IMParser;
036: import com.flexive.shared.FxSharedUtils;
037: import com.flexive.shared.media.FxImageMetadata;
038: import com.flexive.shared.media.FxMediaEngine;
039: import com.flexive.shared.media.FxMediaType;
040: import com.flexive.shared.media.FxMetadata;
041: import org.testng.Assert;
042: import org.testng.annotations.Test;
043:
044: import java.io.ByteArrayInputStream;
045: import java.io.File;
046:
047: /**
048: * Test for ImageMagick/ImageParser
049: *
050: * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
051: */
052: @Test(groups={"image","imageParser"})
053: public class ImageParserTest {
054:
055: private static String testData = "Image: IMG_0048.JPG\n"
056: + " Format: JPEG (Joint Photographic Experts Group JFIF format)\n"
057: + " Class: DirectClass\n"
058: + " Geometry: 2048x1536+0+0\n"
059: + " Type: TrueColor\n"
060: + " Endianess: Undefined\n"
061: + " Colorspace: RGB\n"
062: + " Channel depth:\n"
063: + " Red: 8-bit\n"
064: + " Green: 8-bit\n"
065: + " Blue: 8-bit\n"
066: + " Channel statistics:\n"
067: + " Red:\n"
068: + " Min: 0 (0)\n"
069: + " Max: 255 (1)\n"
070: + " Mean: 115.399 (0.452545)\n"
071: + " Standard deviation: 88.9127 (0.348677)\n"
072: + " Green:\n"
073: + " Min: 0 (0)\n"
074: + " Max: 255 (1)\n"
075: + " Mean: 82.4621 (0.323381)\n"
076: + " Standard deviation: 60.6466 (0.23783)\n"
077: + " Blue:\n"
078: + " Min: 0 (0)\n"
079: + " Max: 255 (1)\n"
080: + " Mean: 66.7881 (0.261914)\n"
081: + " Standard deviation: 53.3319 (0.209145)\n"
082: + " Colors: 272549\n"
083: + " Rendering intent: Undefined\n"
084: + " Resolution: 180x180\n"
085: + " Units: PixelsPerInch\n"
086: + " Filesize: 840.578kb\n"
087: + " Interlace: None\n"
088: + " Background color: white\n"
089: + " Border color: rgb(223,223,223)\n"
090: + " Matte color: grey74\n"
091: + " Transparent color: black\n"
092: + " Page geometry: 2048x1536+0+0\n"
093: + " Dispose: Undefined\n"
094: + " Iterations: 0\n"
095: + " Compression: JPEG\n"
096: + " Quality: 90\n"
097: + " Orientation: TopLeft\n"
098: + " Exif:DateTime: 2006:08:07 22:27:24\n"
099: + " Exif:Make: Canon\n"
100: + " Exif:Model: Canon PowerShot A400\n"
101: + " Exif:Orientation: 1\n"
102: + " Exif:ResolutionUnit: 2\n"
103: + " Exif:XResolution: 180/1\n"
104: + " Exif:YCbCrPositioning: 1\n"
105: + " Exif:YResolution: 180/1\n"
106: + " Jpeg:colorspace: 2\n"
107: + " Jpeg:sampling-factor: 2x1,1x1,1x1\n"
108: + " Signature: 8af18c5d3e9992092fdf56d60bde44ba3380ff29aed343d8fa4eea33bb0af8ea\n"
109: + " Unknown: 196\n"
110: + " Profile-exif: 8700 bytes\n"
111: + " Tainted: False\n"
112: + " User time: 0.141u\n"
113: + " Elapsed time: 0:01\n"
114: + " Pixels per second: 14.7784mb\n"
115: + " Version: ImageMagick 6.3.4 05/11/07 Q16 http://www.imagemagick.org";
116:
117: private static final String TEST_RESULT = "<?xml version=\"1.0\" ?><Image source=\"IMG_0048.JPG\"><Format>JPEG (Joint Photographic Experts Group JFIF format)</Format><Class>DirectClass</Class><Geometry>2048x1536+0+0</Geometry><Type>TrueColor</Type><Endianess>Undefined</Endianess><Colorspace>RGB</Colorspace><Channel-depth><Red>8-bit</Red><Green>8-bit</Green><Blue>8-bit</Blue></Channel-depth><Channel-statistics><Red><Min>0 (0)</Min><Max>255 (1)</Max><Mean>115.399 (0.452545)</Mean><Standard-deviation>88.9127 (0.348677)</Standard-deviation></Red><Green><Min>0 (0)</Min><Max>255 (1)</Max><Mean>82.4621 (0.323381)</Mean><Standard-deviation>60.6466 (0.23783)</Standard-deviation></Green><Blue><Min>0 (0)</Min><Max>255 (1)</Max><Mean>66.7881 (0.261914)</Mean><Standard-deviation>53.3319 (0.209145)</Standard-deviation></Blue></Channel-statistics><Colors>272549</Colors><Rendering-intent>Undefined</Rendering-intent><Resolution>180x180</Resolution><Units>PixelsPerInch</Units><Filesize>840.578kb</Filesize><Interlace>None</Interlace><Background-color>white</Background-color><Border-color>rgb(223,223,223)</Border-color><Matte-color>grey74</Matte-color><Transparent-color>black</Transparent-color><Page-geometry>2048x1536+0+0</Page-geometry><Dispose>Undefined</Dispose><Iterations>0</Iterations><Compression>JPEG</Compression><Quality>90</Quality><Orientation>TopLeft</Orientation><Exif-DateTime>2006:08:07 22:27:24</Exif-DateTime><Exif-Make>Canon</Exif-Make><Exif-Model>Canon PowerShot A400</Exif-Model><Exif-Orientation>1</Exif-Orientation><Exif-ResolutionUnit>2</Exif-ResolutionUnit><Exif-XResolution>180/1</Exif-XResolution><Exif-YCbCrPositioning>1</Exif-YCbCrPositioning><Exif-YResolution>180/1</Exif-YResolution><Jpeg-colorspace>2</Jpeg-colorspace><Jpeg-sampling-factor>2x1,1x1,1x1</Jpeg-sampling-factor><Signature>8af18c5d3e9992092fdf56d60bde44ba3380ff29aed343d8fa4eea33bb0af8ea</Signature><Unknown>196</Unknown><Profile-exif>8700 bytes</Profile-exif><Tainted>False</Tainted><User-time>0.141u</User-time><Elapsed-time>0:01</Elapsed-time><Pixels-per-second>14.7784mb</Pixels-per-second><Version>ImageMagick 6.3.4 05/11/07 Q16 http://www.imagemagick.org</Version></Image>";
118: private static final String TEST_FILE_EXIF = "src"
119: + File.separatorChar + "framework" + File.separatorChar
120: + "testresources" + File.separatorChar + "image"
121: + File.separatorChar + "Exif.JPG";
122: private static final String TEST_FILE_GIF = "src"
123: + File.separatorChar + "framework" + File.separatorChar
124: + "testresources" + File.separatorChar + "image"
125: + File.separatorChar + "GIF_Image.GIF";
126:
127: @Test(dependsOnMethods={"identifyTest"})
128: public void parserTest() throws Exception {
129: if (!FxMediaEngine.isImageMagickIdentifySupported())
130: return;
131: assert IMParser.parse(
132: new ByteArrayInputStream(FxSharedUtils
133: .getBytes(testData))).startsWith(TEST_RESULT);
134: FxSharedUtils.ProcessResult res = FxSharedUtils.executeCommand(
135: "identify", "-verbose", TEST_FILE_EXIF);
136: String result = IMParser.parse(new ByteArrayInputStream(
137: FxSharedUtils.getBytes(res.getStdOut())));
138: assert result
139: .indexOf("<Profile-exif>4604 bytes</Profile-exif>") > 0;
140: assert result.indexOf("<Geometry>2048x1536+0+0</Geometry>") > 0;
141: assert result
142: .indexOf("<Channel-depth><Red>8-bit</Red><Green>8-bit</Green>") > 0;
143: res = FxSharedUtils.executeCommand("identify", "-verbose",
144: TEST_FILE_GIF);
145: result = IMParser.parse(new ByteArrayInputStream(FxSharedUtils
146: .getBytes(res.getStdOut())));
147: assert result
148: .indexOf("<Signature>2f0ab5863f31c675bab16309bfa161fd331e55e6c6781ec1f6cd0305f725cfa9</Signature>") > 0;
149: assert result.indexOf("<Compression>LZW</Compression>") > 0;
150: }
151:
152: @Test
153: public void identifyTest() throws Exception {
154: if (!FxMediaEngine.hasImageMagickInstalled())
155: return;
156: FxSharedUtils.ProcessResult res = FxSharedUtils.executeCommand(
157: "identify", "-version");
158: System.out.println("Commandline: [" + res.getCommandLine()
159: + "]");
160: System.out.println("ExitCode: " + res.getExitCode());
161: System.out.println("Error: [" + res.getStdErr() + "]");
162: System.out.println("Out: [" + res.getStdOut() + "]");
163: if (res.getExitCode() != 0
164: || res.getStdOut().indexOf("ImageMagick") <= 0) {
165: assert false : "Please install ImageMagick (and add it to your path) for imaging tests to work!";
166: }
167: }
168:
169: public void mediaEngine() throws Exception {
170: File exif = new File(TEST_FILE_EXIF);
171: /*Sanselan.getImageInfo(exif).dump();
172: ICC_Profile prof = Sanselan.getICCProfile(exif);
173: if (prof != null) {
174: System.out.println("We have an ICC profile");
175: } else
176: System.out.println("No ICC profile");
177: // Sanselan.getFormatCompliance(exif).dump();
178: IImageMetadata imageMetadata = Sanselan.getMetadata(exif);
179: for (Object o : imageMetadata.getItems())
180: System.out.println("Metadata: " + o);
181: */
182: FxMetadata md = FxMediaEngine.identify(null, exif);
183: System.out.println("mimeTyp: " + md.getMimeType());
184: System.out.println("Filename: " + md.getFilename());
185: System.out.println("mediaType: " + md.getMediaType());
186: if (md.getMediaType() == FxMediaType.Image) {
187: FxImageMetadata imd = md.asImageMetadata();
188: System.out.println("BPP: " + imd.getBitsPerPixel());
189: System.out.println("color type:" + imd.getColorType());
190: System.out.println("compression:"
191: + imd.getCompressionAlgorithm());
192: System.out.println("format:" + imd.getFormat());
193: System.out.println("format-desc:"
194: + imd.getFormatDescription());
195: System.out.println("height:" + imd.getHeight());
196: System.out.println("width:" + imd.getWidth());
197: System.out.println("x-res:" + imd.getXResolution());
198: System.out.println("y-res:" + imd.getYResolution());
199:
200: }
201: for (FxMetadata.FxMetadataItem i : md.getMetadata()) {
202: System.out.println("Metadata: [" + i.getKey() + "] -> ["
203: + i.getValue() + "]");
204: }
205: System.out.println("IM available: "
206: + FxMediaEngine.hasImageMagickInstalled());
207: if (FxMediaEngine.hasImageMagickInstalled()) {
208: System.out.println("IM version: "
209: + FxMediaEngine.getImageMagickVersion());
210: System.out.println("IM based identify possible: "
211: + FxMediaEngine.isImageMagickIdentifySupported());
212: }
213: Assert
214: .assertEquals(
215: md.toXML(),
216: "<?xml version=\"1.0\" ?><metadata mediatype=\"Image\" mimetype=\"image/jpeg\" filename=\"Exif.JPG\"><imageData><width>2048</width><height>1536</height><bpp>24</bpp><colorType><![CDATA[RGB]]></colorType><compressionAlgorithm><![CDATA[JPEG]]></compressionAlgorithm><format><![CDATA[JPEG]]></format><formatDescription><![CDATA[JPEG (Joint Photographic Experts Group) Format]]></formatDescription><xResolution>180.0</xResolution><yResolution>180.0</yResolution></imageData><meta key=\"Make\"><![CDATA[Canon]]></meta><meta key=\"Model\"><![CDATA[Canon PowerShot A70]]></meta><meta key=\"Orientation\"><![CDATA[1]]></meta><meta key=\"XResolution\"><![CDATA[180]]></meta><meta key=\"YResolution\"><![CDATA[180]]></meta><meta key=\"ResolutionUnit\"><![CDATA[2]]></meta><meta key=\"DateTime\"><![CDATA[2006-08-07T18:20:21.000+0200]]></meta><meta key=\"YCbCrPositioning\"><![CDATA[1]]></meta><meta key=\"Exif_IFD_Pointer\"><![CDATA[196]]></meta><meta key=\"ExposureTime\"><![CDATA[1/30]]></meta><meta key=\"FNumber\"><![CDATA[56/10]]></meta><meta key=\"ExifVersion\"><![CDATA[48, 50, 50, 48]]></meta><meta key=\"DateTimeOriginal\"><![CDATA[2006-08-07T18:20:21.000+0200]]></meta><meta key=\"DateTimeDigitized\"><![CDATA[2006-08-07T18:20:21.000+0200]]></meta><meta key=\"ComponentsConfiguration\"><![CDATA[1, 2, 3, 0]]></meta><meta key=\"CompressedBitsPerPixel\"><![CDATA[3]]></meta><meta key=\"ShutterSpeedValue\"><![CDATA[157/32]]></meta><meta key=\"ApertureValue\"><![CDATA[159/32]]></meta><meta key=\"ExposureBiasValue\"><![CDATA[0]]></meta><meta key=\"MaxApertureValue\"><![CDATA[145/32]]></meta><meta key=\"MeteringMode\"><![CDATA[5]]></meta><meta key=\"Flash\"><![CDATA[16]]></meta><meta key=\"FocalLength\"><![CDATA[519/32]]></meta><meta key=\"MakerNote\"><![CDATA[14, 0, 1, 0, 3, 0, 46, 0, 0, 0, 92, 4, 0, 0, 2, 0, 3, 0, 4, 0, 0, 0, -72, 4, 0, 0, 3, 0, 3, 0, 4, 0, 0, 0, -64, 4, 0, 0, 4, 0, 3, 0, 34, 0, 0, 0, -56, 4, 0, 0, 0... (574)]]></meta><meta key=\"UserComment\"><![CDATA[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0... (264)]]></meta><meta key=\"FlashpixVersion\"><![CDATA[48, 49, 48, 48]]></meta><meta key=\"ColorSpace\"><![CDATA[1]]></meta><meta key=\"PixelXDimension\"><![CDATA[2048]]></meta><meta key=\"PixelYDimension\"><![CDATA[1536]]></meta><meta key=\"Interoperability_IFD_Pointer\"><![CDATA[1540]]></meta><meta key=\"FocalPlaneXResolution\"><![CDATA[2048000/208]]></meta><meta key=\"FocalPlaneYResolution\"><![CDATA[1536000/156]]></meta><meta key=\"FocalPlaneResolutionUnit\"><![CDATA[2]]></meta><meta key=\"FileSource\"><![CDATA[3]]></meta><meta key=\"CustomRendered\"><![CDATA[0]]></meta><meta key=\"ExposureMode\"><![CDATA[0]]></meta><meta key=\"WhiteBalance\"><![CDATA[0]]></meta><meta key=\"DigitalZoomRatio\"><![CDATA[1]]></meta><meta key=\"SceneCaptureType\"><![CDATA[1]]></meta><meta key=\"GPSLatitudeRef\"><![CDATA[R98]]></meta><meta key=\"GPSLatitude\"><![CDATA[48, 49, 48, 48]]></meta><meta key=\"Compression\"><![CDATA[6]]></meta><meta key=\"XResolution\"><![CDATA[180]]></meta><meta key=\"YResolution\"><![CDATA[180]]></meta><meta key=\"ResolutionUnit\"><![CDATA[2]]></meta><meta key=\"JPEGInterchangeFormat\"><![CDATA[2036]]></meta><meta key=\"JPEGInterchangeFormatLength\"><![CDATA[2427]]></meta></metadata>");
217: }
218: }
|