Changeset 659
- Timestamp:
- 02/07/12 09:50:21 (3 months ago)
- Location:
- Core/trunk
- Files:
-
- 3 added
- 3 deleted
- 5 edited
-
.classpath (modified) (1 diff)
-
.project (modified) (1 diff)
-
.settings/org.eclipse.core.resources.prefs (deleted)
-
.settings/org.eclipse.jdt.core.prefs (added)
-
.settings/org.eclipse.m2e.core.prefs (added)
-
build.xml (deleted)
-
pom.xml (added)
-
src/main/java/corinis/util/FileUtils.java (modified) (1 diff)
-
src/main/java/corinis/util/images/MediaConverter.java (modified) (4 diffs)
-
src/main/java/corinis/util/images/Quant.java (deleted)
-
src/main/java/corinis/util/images/Thumbnailer.java (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Core/trunk/.classpath
r586 r659 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <classpath> 3 <classpathentry kind="src" path="src"/> 4 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> 5 <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/corinis"/> 3 <classpathentry kind="src" output="target/classes" path="src/main/java"/> 4 <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/> 5 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> 6 <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/> 6 7 <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v6.0"/> 7 <classpathentry combineaccessrules="false" kind="src" path="/XMLUtils"/> 8 <classpathentry kind="output" path="bin"/> 8 <classpathentry kind="output" path="target/classes"/> 9 9 </classpath> -
Core/trunk/.project
r586 r659 11 11 </arguments> 12 12 </buildCommand> 13 <buildCommand> 14 <name>org.eclipse.m2e.core.maven2Builder</name> 15 <arguments> 16 </arguments> 17 </buildCommand> 13 18 </buildSpec> 14 19 <natures> 20 <nature>org.eclipse.m2e.core.maven2Nature</nature> 15 21 <nature>org.eclipse.jdt.core.javanature</nature> 16 22 </natures> -
Core/trunk/src/main/java/corinis/util/FileUtils.java
r531 r659 369 369 370 370 // character replaces... better this way 371 case ' Ä':372 case ' Â':373 case ' À':374 case ' Á':371 case '\u00c4': 372 case '\u00c2': 373 case '\u00c0': 374 case '\u00c1': 375 375 placeHolder = false; 376 376 sb.append('A'); 377 377 break; 378 378 379 case ' ä':380 case ' â':381 case ' á':382 case ' à':379 case '\u00e4': 380 case '\u00e2': 381 case '\u00e1': 382 case '\u00e0': 383 383 placeHolder = false; 384 384 sb.append('a'); 385 385 break; 386 case ' Ö':387 case ' Ò':388 case ' Ó':389 case ' Ô':386 case '\u00d6': 387 case '\u00d2': 388 case '\u00d3': 389 case '\u00d4': 390 390 placeHolder = false; 391 391 sb.append('O'); 392 392 break; 393 case ' ö':394 case ' ô':395 case ' ó':396 case ' ò':393 case '\u00f6': 394 case '\u00f4': 395 case '\u00f3': 396 case '\u00f2': 397 397 placeHolder = false; 398 398 sb.append('o'); 399 399 break; 400 case ' Ü':401 case ' Û':402 case ' Ú':403 case ' Ù':400 case '\u00dc': 401 case '\u00db': 402 case '\u00da': 403 case '\u00d9': 404 404 placeHolder = false; 405 405 sb.append('U'); 406 406 break; 407 case ' ü':408 case ' û':409 case ' ú':410 case ' ù':407 case '\u00fc': 408 case '\u00fb': 409 case '\u00fa': 410 case '\u00f9': 411 411 placeHolder = false; 412 412 sb.append('u'); 413 413 break; 414 case ' î':415 case ' ì':416 case ' í':414 case '\u00ee': 415 case '\u00ec': 416 case '\u00ed': 417 417 placeHolder = false; 418 418 sb.append('i'); 419 419 break; 420 case ' Î':421 case ' Í':422 case ' Ì':420 case '\u00ce': 421 case '\u00cd': 422 case '\u00cc': 423 423 placeHolder = false; 424 424 sb.append('I'); 425 425 break; 426 case ' ß':426 case '\u00df': 427 427 placeHolder = false; 428 428 sb.append('s'); -
Core/trunk/src/main/java/corinis/util/images/MediaConverter.java
r596 r659 26 26 public static final int TYPE_DOCUMENT = 1; 27 27 28 28 29 29 /** The type is an image 30 30 */ … … 56 56 /** xls (Excel) files 57 57 */ 58 public static final int TYPE_FILE_XLS = 10;58 public static final int TYPE_FILE_XLS = 10; 59 59 /** xls (Excel) files 60 60 */ 61 public static final int TYPE_FILE_PPT = 11;61 public static final int TYPE_FILE_PPT = 11; 62 62 /** video 63 63 */ 64 public static final int TYPE_FILE_VIDEO = 12;65 64 public static final int TYPE_FILE_VIDEO = 12; 65 66 66 /** The type is an unknown file 67 67 */ 68 68 public static final int TYPE_FILEUNKNOWN = 2; 69 69 70 70 public static final int ROTATE_NONE = -1; 71 71 public static final int ROTATE_AUTO = 0; … … 86 86 if (!original.isFile()) 87 87 return null; 88 88 89 89 // generate the converted path: 90 90 // /originalfolder/originalfilename-w-h-orient-x-y-cx-cy.ext 91 91 String paths[] = original.getAbsolutePath().replace('\\', '/').split("/"); 92 92 93 93 String ext = paths[paths.length].substring(paths[paths.length].lastIndexOf('.')); 94 94 StringBuffer path = new StringBuffer('/'); … … 104 104 path.append(orientation); 105 105 path.append(ext); 106 107 106 107 108 108 File target = new File(core.getConfigurator().getMediaConverterPath() + path); 109 109 110 110 // lets do something with the original 111 111 if (!target.exists()) 112 112 { 113 int type = TYPE_FILEUNKNOWN; //unknown114 String imgtype = null;115 int width = -1;116 int height = -1;117 118 // only display images, no other junk119 if (ext.equalsIgnoreCase("jpg") || ext.equalsIgnoreCase("jpeg"))120 {121 type = TYPE_FILE_IMAGE; // image122 imgtype = Thumbnailer.TYPE_JPEG;123 ext = "jpg";124 } else if (ext.equalsIgnoreCase("gif"))125 {126 type = TYPE_FILE_IMAGE; // image127 imgtype = Thumbnailer.TYPE_GIF;128 ext = "gif";129 } else if (ext.equalsIgnoreCase("png"))130 {131 type = TYPE_FILE_IMAGE; // image132 imgtype = Thumbnailer.TYPE_PNG;133 ext = "png";134 } else if (ext.equalsIgnoreCase("avi"))135 {136 type = TYPE_FILE_VIDEO;137 imgtype = Thumbnailer.TYPE_VIDEO;138 ext = "avi";139 } else if (ext.equalsIgnoreCase("mov"))140 {141 type = TYPE_FILE_VIDEO;142 imgtype = Thumbnailer.TYPE_VIDEO;143 ext = "mov";144 } else if (ext.equalsIgnoreCase("wmv"))145 {146 type = TYPE_FILE_VIDEO;147 imgtype = Thumbnailer.TYPE_VIDEO;148 ext = "wmv";149 } else if (ext.equalsIgnoreCase("fla"))150 {151 type = TYPE_FILE_FLASH; // flash152 ext = "fla";153 } else if (ext.equalsIgnoreCase("dcr"))154 type = TYPE_FILE_SHOCKWAVE; // shockwave155 else if (ext.equalsIgnoreCase("pdf"))156 type = TYPE_FILE_PDF; // pdf157 else if (ext.equalsIgnoreCase("doc"))158 type = TYPE_FILE_DOC; // avi159 else if (ext.equalsIgnoreCase("zip"))160 type = TYPE_FILE_ZIP; // quicktime161 else162 type = TYPE_FILEUNKNOWN;163 164 // get the width/height of the file165 if (type == TYPE_FILE_FLASH || type == TYPE_FILE_VIDEO || type == TYPE_FILE_IMAGE)166 {167 ImageInfo ii = new ImageInfo();168 ii.setInput(new FileInputStream(original));169 if (ii.check())170 {171 width = ii.getWidth();172 height = ii.getHeight();173 }174 175 if (width <= 0)176 width = 0;177 if (height <= 0)178 height = 0;179 180 }181 182 try183 {184 // we have written the file, lets find out information about it185 // and convert/thumbnail it :)186 switch (type)187 {188 case TYPE_FILE_IMAGE:189 // jpeg is a special case - imageinfo might fail190 if (imgtype.equals(Thumbnailer.TYPE_JPEG))191 {192 Metadata metadata = JpegMetadataReader.readMetadata(original);193 Directory exif = metadata.getDirectory(ExifDirectory.class);194 Directory jpeg = metadata.getDirectory(JpegDirectory.class);195 // for later?196 if (orientation == ROTATE_AUTO)197 if (exif.containsTag(ExifDirectory.TAG_ORIENTATION))198 orientation = exif.getInt(ExifDirectory.TAG_ORIENTATION );199 200 if (jpeg.containsTag(JpegDirectory.TAG_JPEG_IMAGE_WIDTH))201 width = jpeg.getInt(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);202 if (jpeg.containsTag(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT))203 height = jpeg.getInt(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);204 }205 206 break;207 case TYPE_FILE_VIDEO:208 break;209 }210 }211 catch (Exception e)212 {213 // these errors should be caught but are not necessary abort-level214 core.printLog("Problem with file" + original.getAbsolutePath(), e, Core.LOG_WARNING);215 }216 217 // create the cache directory (where the flv, thumbnails etc are stored) if not existant218 if (!target.getParentFile().isDirectory())219 {220 if (!target.getParentFile().mkdirs())221 {222 core.printLog("Unable to create: " + target.getParentFile().getAbsolutePath(), null, Core.LOG_ERROR);223 return null;224 }225 }226 227 String rotate = "";228 switch (orientation)229 {230 case 1: break; // nothing231 case 2: rotate = " -flip "; break;232 case 3: rotate = " -rotate 180 "; break;233 case 4: rotate = " -flop "; break;234 case 5: rotate = " -rotate 270 -flip "; break;235 case 6: rotate = " -rotate 90 "; break;236 case 7: rotate = " -rotate 270 -flip "; break;237 case 8: rotate = " -rotate 270 "; break;238 }239 240 // create the thumbnail if possible241 if (imgtype != null)242 {243 String runme = core.getConfigurator().getImageMagickConvert() + " " + original.getAbsolutePath() + " -resize ";244 runme += resizeW + "x" + resizeH + "! -crop ";245 runme += w + "x" + h + "+" + x + "+" + y;246 runme += rotate;247 runme += " +repage " + target.getAbsolutePath();248 try249 {250 Process p = Runtime.getRuntime().exec(runme);251 if (wait)252 p.waitFor();253 }254 catch (Exception e) {255 // Print out Error if available256 System.err.println(runme);257 e.printStackTrace();258 }259 }113 int type = TYPE_FILEUNKNOWN; //unknown 114 String imgtype = null; 115 int width = -1; 116 int height = -1; 117 118 // only display images, no other junk 119 if (ext.equalsIgnoreCase("jpg") || ext.equalsIgnoreCase("jpeg")) 120 { 121 type = TYPE_FILE_IMAGE; // image 122 imgtype = Thumbnailer.TYPE_JPEG; 123 ext = "jpg"; 124 } else if (ext.equalsIgnoreCase("gif")) 125 { 126 type = TYPE_FILE_IMAGE; // image 127 imgtype = Thumbnailer.TYPE_GIF; 128 ext = "gif"; 129 } else if (ext.equalsIgnoreCase("png")) 130 { 131 type = TYPE_FILE_IMAGE; // image 132 imgtype = Thumbnailer.TYPE_PNG; 133 ext = "png"; 134 } else if (ext.equalsIgnoreCase("avi")) 135 { 136 type = TYPE_FILE_VIDEO; 137 imgtype = Thumbnailer.TYPE_VIDEO; 138 ext = "avi"; 139 } else if (ext.equalsIgnoreCase("mov")) 140 { 141 type = TYPE_FILE_VIDEO; 142 imgtype = Thumbnailer.TYPE_VIDEO; 143 ext = "mov"; 144 } else if (ext.equalsIgnoreCase("wmv")) 145 { 146 type = TYPE_FILE_VIDEO; 147 imgtype = Thumbnailer.TYPE_VIDEO; 148 ext = "wmv"; 149 } else if (ext.equalsIgnoreCase("fla")) 150 { 151 type = TYPE_FILE_FLASH; // flash 152 ext = "fla"; 153 } else if (ext.equalsIgnoreCase("dcr")) 154 type = TYPE_FILE_SHOCKWAVE; // shockwave 155 else if (ext.equalsIgnoreCase("pdf")) 156 type = TYPE_FILE_PDF; // pdf 157 else if (ext.equalsIgnoreCase("doc")) 158 type = TYPE_FILE_DOC; // avi 159 else if (ext.equalsIgnoreCase("zip")) 160 type = TYPE_FILE_ZIP; // quicktime 161 else 162 type = TYPE_FILEUNKNOWN; 163 164 // get the width/height of the file 165 if (type == TYPE_FILE_FLASH || type == TYPE_FILE_VIDEO || type == TYPE_FILE_IMAGE) 166 { 167 ImageInfo ii = new ImageInfo(); 168 ii.setInput(new FileInputStream(original)); 169 if (ii.check()) 170 { 171 width = ii.getWidth(); 172 height = ii.getHeight(); 173 } 174 175 if (width <= 0) 176 width = 0; 177 if (height <= 0) 178 height = 0; 179 180 } 181 182 try 183 { 184 // we have written the file, lets find out information about it 185 // and convert/thumbnail it :) 186 switch (type) 187 { 188 case TYPE_FILE_IMAGE: 189 // jpeg is a special case - imageinfo might fail 190 if (imgtype.equals(Thumbnailer.TYPE_JPEG)) 191 { 192 Metadata metadata = JpegMetadataReader.readMetadata(original); 193 Directory exif = metadata.getDirectory(ExifDirectory.class); 194 Directory jpeg = metadata.getDirectory(JpegDirectory.class); 195 // for later? 196 if (orientation == ROTATE_AUTO) 197 if (exif.containsTag(ExifDirectory.TAG_ORIENTATION)) 198 orientation = exif.getInt(ExifDirectory.TAG_ORIENTATION ); 199 200 if (jpeg.containsTag(JpegDirectory.TAG_JPEG_IMAGE_WIDTH)) 201 width = jpeg.getInt(JpegDirectory.TAG_JPEG_IMAGE_WIDTH); 202 if (jpeg.containsTag(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT)) 203 height = jpeg.getInt(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT); 204 } 205 206 break; 207 case TYPE_FILE_VIDEO: 208 break; 209 } 210 } 211 catch (Exception e) 212 { 213 // these errors should be caught but are not necessary abort-level 214 core.printLog("Problem with file" + original.getAbsolutePath(), e, Core.LOG_WARNING); 215 } 216 217 // create the cache directory (where the flv, thumbnails etc are stored) if not existant 218 if (!target.getParentFile().isDirectory()) 219 { 220 if (!target.getParentFile().mkdirs()) 221 { 222 core.printLog("Unable to create: " + target.getParentFile().getAbsolutePath(), null, Core.LOG_ERROR); 223 return null; 224 } 225 } 226 227 String rotate = ""; 228 switch (orientation) 229 { 230 case 1: break; // nothing 231 case 2: rotate = " -flip "; break; 232 case 3: rotate = " -rotate 180 "; break; 233 case 4: rotate = " -flop "; break; 234 case 5: rotate = " -rotate 270 -flip "; break; 235 case 6: rotate = " -rotate 90 "; break; 236 case 7: rotate = " -rotate 270 -flip "; break; 237 case 8: rotate = " -rotate 270 "; break; 238 } 239 240 // create the thumbnail if possible 241 if (imgtype != null) 242 { 243 String runme = core.getConfigurator().getImageMagickConvert() + " " + original.getAbsolutePath() + " -resize "; 244 runme += resizeW + "x" + resizeH + "! -crop "; 245 runme += w + "x" + h + "+" + x + "+" + y; 246 runme += rotate; 247 runme += " +repage " + target.getAbsolutePath(); 248 try 249 { 250 Process p = Runtime.getRuntime().exec(runme); 251 if (wait) 252 p.waitFor(); 253 } 254 catch (Exception e) { 255 // Print out Error if available 256 System.err.println(runme); 257 e.printStackTrace(); 258 } 259 } 260 260 } 261 261 return core.getConfigurator().getMediaConverterUrl() + path; -
Core/trunk/src/main/java/corinis/util/images/Thumbnailer.java
r570 r659 3 3 4 4 import java.awt.Dimension; 5 import java.awt.Frame;6 5 import java.awt.Graphics; 7 6 import java.awt.GraphicsConfiguration; … … 14 13 import java.awt.image.ColorModel; 15 14 import java.awt.image.PixelGrabber; 16 import java.io.ByteArrayInputStream;17 import java.io.ByteArrayOutputStream;18 15 import java.io.File; 19 import java.io.FileOutputStream;20 import java.io.InputStream;21 16 22 17 import javax.swing.ImageIcon; 23 24 import Acme.JPM.Encoders.GifEncoder;25 18 26 19 import com.drew.metadata.Directory; 27 20 import com.drew.metadata.Metadata; 28 21 import com.drew.metadata.exif.ExifDirectory; 29 import com.sun.jimi.core.ImageAccessException;30 import com.sun.jimi.core.Jimi;31 import com.sun.jimi.core.raster.JimiRasterImage;32 22 33 23 /** … … 36 26 * Version History 37 27 * --------------- 28 * 1.4 Niko Berger 29 * - removed "qunat" support -use imagemagick 30 * 38 31 * 1.3 Niko Berger 39 32 * - Added support for imagemagick … … 148 141 } 149 142 150 public static Image createThumbnailImage(Image image, Dimension size) throws Exception {151 Frame fr = new Frame();152 153 return fr.createImage(createThumbnail(image, size).getImageProducer());154 }155 143 156 144 public static String getImageTypeFromExt (String ext) … … 169 157 return null; 170 158 } 171 /** 172 * @param image the image object 173 * @param size the size the thumbnail should be 174 * @return a scaled JimiRasterImage object 175 * @throws Exception 176 */ 177 public static JimiRasterImage createThumbnail(Image image, Dimension size) throws Exception { 178 return Jimi.createRasterImage( 179 image.getScaledInstance(size.width, size.height, Image.SCALE_SMOOTH) 180 .getSource()); 181 } 182 183 /** 184 * creates an jpeg input stream 185 * @param image the original image object 186 * @param size the desired thumbnail size 187 * @return an inputstream that includes the thumbnail data in jpeg 188 * @throws Exception 189 */ 190 public static InputStream createThumbnailInputStream(Image image, Dimension size) throws Exception{ 191 JimiRasterImage raster = createThumbnail(image, size); 192 ByteArrayOutputStream out = new ByteArrayOutputStream(); 193 Jimi.putImage("image/jpeg", raster, out); 194 out.close(); 195 byte it[] = out.toByteArray(); 196 return new ByteArrayInputStream(it); 197 } 198 199 /** 200 * @param file the source file 201 * @param maxDim the maximum dimension 202 * @return a thumbnail of the the source 203 * @throws Exception 204 */ 205 public static Image createThumbnail (File file, int maxDim) throws Exception 206 { 207 Image ii = getImage (file); 208 return createThumbnailImage(ii, getThumbnailSize(ii, maxDim)); 209 } 210 211 /** 212 * @param file the source file 213 * @param maxDim the maximum dimension 214 * @return a stream for the jpeg of the thumbnail 215 * @throws Exception 216 */ 217 public static InputStream createThumbnailInputStream (File file, int maxDim) throws Exception 218 { 219 Image ii = getImage (file); 220 return createThumbnailInputStream(ii, getThumbnailSize(ii, maxDim)); 221 } 222 223 /** 224 * Creates a new thumbnail of the original file 225 * @param in the source file 226 * @param out the destination file 227 * @param maxDim the maximum dimension(width/height, resize wont change the proportion) 228 * @param type the type of the image (example: image/jpeg) 229 * @throws Exception 230 */ 231 public static void createThumbnail (File in, int maxDim, File out, String type) throws Exception 232 { 233 Image iin = getImage (in); 234 Dimension d = getThumbnailSize(iin, maxDim); 235 createThumbnail(iin, d, out, type); 236 } 159 237 160 238 161 … … 273 196 } 274 197 else{ 275 Image iin = getImage (in); 276 Dimension d = getThumbnailSize(iin, maxDim); 277 createThumbnail(iin, d, out, type); 198 throw new RuntimeException("Imagemagick not configured - please check your configuration!"); 278 199 } 279 200 } … … 354 275 } 355 276 else{ 356 Image iin = getImage (in); 357 createThumbnail(iin, new Dimension(width, height), out, type); 277 throw new RuntimeException("Imagemagick not configured - please check your configuration!"); 358 278 } 359 279 } … … 377 297 378 298 /** 379 *380 * @param image the image to take the pixels from381 * @return an array of pixels382 * @throws ImageAccessException383 */384 static int[][] getPixels(JimiRasterImage image) throws ImageAccessException {385 int w = image.getWidth();386 int h = image.getHeight();387 388 int pixels[][] = new int[w][h];389 for (int x = w; x-- > 0; ) {390 for (int y = h; y-- > 0; ) {391 pixels[x][y] = image.getPixelRGB(x, y);392 }393 }394 395 return pixels;396 }397 398 /**399 * Writes a image scaled to a file400 * @param image the original image401 * @param size the new size402 * @param outputFile the output file403 * @param type the type of the image404 * @throws Exception405 */406 public static void createThumbnail(Image image, Dimension size, File outputFile, String type) throws Exception{407 if (TYPE_GIF.equalsIgnoreCase(type))408 {409 JimiRasterImage raster = createThumbnail(image, size);410 FileOutputStream out = new FileOutputStream(outputFile);411 412 // change the raster image to 256 colors413 Quant q = new Quant(raster);414 q.init();415 BufferedImage iout = new BufferedImage(raster.getWidth(), raster.getHeight(), BufferedImage.TYPE_3BYTE_BGR);416 417 int w = raster.getWidth();418 int h = raster.getHeight();419 420 int pixels[][] = getPixels(raster);421 for (int x = w; x-- > 0; ) {422 for (int y = h; y-- > 0; ) {423 iout.setRGB(x, y, q.convert(pixels[x][y]));424 }425 }426 427 GifEncoder ge = new GifEncoder(iout, out);428 ge.encode();429 }430 else431 {432 JimiRasterImage raster = createThumbnail(image, size);433 FileOutputStream fos = new FileOutputStream(outputFile);434 Jimi.putImage(type, raster, fos);435 fos.flush();436 fos.close();437 }438 }439 440 /**441 * Create a Thumbnail out of an file with a fixed dimension442 * @param image The original image443 * @param size the thumbnail size444 * @param outputFile the output file445 * @param type the type of the image (example: image/jpeg)446 * @throws Exception447 */448 public static void createThumbnail(File image, Dimension size, File outputFile, String type) throws Exception{449 createThumbnail(new ImageIcon(image.getPath()).getImage(), size, outputFile, type);450 }451 452 453 /**454 299 * @param image the original file 455 300 * @return an image object
Note: See TracChangeset
for help on using the changeset viewer.
