VIVO-848 move the image processing code behind an interface
This commit is contained in:
parent
c1bb928096
commit
c751ecdc6d
9 changed files with 266 additions and 161 deletions
|
@ -1,6 +1,6 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
||||
package edu.cornell.mannlib.vitro.webapp.imageprocessor.jai;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.controller.freemarker.ImageUploadController.THUMBNAIL_HEIGHT;
|
||||
import static edu.cornell.mannlib.vitro.webapp.controller.freemarker.ImageUploadController.THUMBNAIL_WIDTH;
|
||||
|
@ -17,7 +17,6 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.media.jai.JAI;
|
||||
import javax.media.jai.RenderedOp;
|
||||
import javax.media.jai.operator.StreamDescriptor;
|
||||
|
||||
|
@ -26,7 +25,9 @@ import org.apache.log4j.Logger;
|
|||
|
||||
import com.sun.media.jai.codec.MemoryCacheSeekableStream;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.ImageUploadHelper.NonNoisyImagingListener;
|
||||
import edu.cornell.mannlib.vitro.webapp.imageprocessor.jai.JaiImageProcessor;
|
||||
import edu.cornell.mannlib.vitro.webapp.modules.imageProcessor.ImageProcessor.CropRectangle;
|
||||
import edu.cornell.mannlib.vitro.webapp.modules.imageProcessor.ImageProcessor.Dimensions;
|
||||
|
||||
/**
|
||||
* This is not a unit test, so it is not named BlahBlahTest.
|
||||
|
@ -38,14 +39,13 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.ImageUploadHelper.
|
|||
* This is especially true because the images on the screen look color-correct,
|
||||
* but when viewed in the browser, they might not be.
|
||||
*/
|
||||
public class ImageUploaderThumbnailerTester extends Frame {
|
||||
static {
|
||||
JAI.getDefaultInstance().setImagingListener(
|
||||
new NonNoisyImagingListener());
|
||||
}
|
||||
public class JaiImageProcessorTester extends Frame {
|
||||
|
||||
/** Big enough to hold the JPEG file, certainly. */
|
||||
private final static int BUFFER_SIZE = 200 * 200 * 4;
|
||||
|
||||
private final static Dimensions THUMBNAIL_SIZE = new Dimensions(
|
||||
THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
|
||||
|
||||
private final static ImageCropData[] THUMBNAIL_DATA = new ImageCropData[] {
|
||||
new ImageCropData("/Users/jeb228/Pictures/JimBlake_20010915.jpg",
|
||||
|
@ -56,11 +56,10 @@ public class ImageUploaderThumbnailerTester extends Frame {
|
|||
new ImageCropData("/Users/jeb228/Pictures/DSC04203w-trans.gif",
|
||||
400, 1200, 800) };
|
||||
|
||||
private final ImageUploadThumbnailer thumbnailer = new ImageUploadThumbnailer(
|
||||
THUMBNAIL_HEIGHT, THUMBNAIL_WIDTH);
|
||||
private final JaiImageProcessor thumbnailer = new JaiImageProcessor();
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private ImageUploaderThumbnailerTester() {
|
||||
private JaiImageProcessorTester() {
|
||||
setTitle("Alpha Killer Test");
|
||||
addWindowListener(new CloseWindowListener());
|
||||
setLayout(createLayout());
|
||||
|
@ -68,7 +67,7 @@ public class ImageUploaderThumbnailerTester extends Frame {
|
|||
try {
|
||||
InputStream mainStream = new FileInputStream(icd.filename);
|
||||
File thumbFile = writeToTempFile(thumbnailer.cropAndScale(
|
||||
mainStream, icd.crop));
|
||||
mainStream, icd.crop, THUMBNAIL_SIZE));
|
||||
System.out.println(thumbFile.getAbsolutePath());
|
||||
|
||||
MemoryCacheSeekableStream thumbFileStream = new MemoryCacheSeekableStream(
|
||||
|
@ -108,18 +107,19 @@ public class ImageUploaderThumbnailerTester extends Frame {
|
|||
return layout;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void main(String[] args) {
|
||||
Logger.getLogger(ImageUploadThumbnailer.class).setLevel(Level.DEBUG);
|
||||
new ImageUploaderThumbnailerTester();
|
||||
Logger.getLogger(JaiImageProcessor.class).setLevel(Level.DEBUG);
|
||||
new JaiImageProcessorTester();
|
||||
}
|
||||
|
||||
private static class ImageCropData {
|
||||
final String filename;
|
||||
final ImageUploadController.CropRectangle crop;
|
||||
final CropRectangle crop;
|
||||
|
||||
ImageCropData(String filename, int x, int y, int size) {
|
||||
this.filename = filename;
|
||||
this.crop = new ImageUploadController.CropRectangle(x, y, size,
|
||||
this.crop = new CropRectangle(x, y, size,
|
||||
size);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
||||
package edu.cornell.mannlib.vitro.webapp.imageprocessor.jai;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
|
@ -35,9 +35,10 @@ import org.apache.log4j.PatternLayout;
|
|||
|
||||
import com.sun.media.jai.codec.MemoryCacheSeekableStream;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.ImageUploadController.CropRectangle;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.ImageUploadHelper.NonNoisyImagingListener;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.ImageUploaderThumbnailerTester_2.CropDataSet.CropData;
|
||||
import edu.cornell.mannlib.vitro.webapp.imageprocessor.jai.JaiImageProcessorTester2.CropDataSet.CropData;
|
||||
import edu.cornell.mannlib.vitro.webapp.imageprocessor.jai.JaiImageProcessor.NonNoisyImagingListener;
|
||||
import edu.cornell.mannlib.vitro.webapp.modules.imageProcessor.ImageProcessor.CropRectangle;
|
||||
import edu.cornell.mannlib.vitro.webapp.modules.imageProcessor.ImageProcessor.Dimensions;
|
||||
|
||||
/**
|
||||
* This is not a unit test, so it is not named BlahBlahTest.
|
||||
|
@ -49,14 +50,16 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.ImageUploaderThumb
|
|||
* one or more black edges on the thumbnails.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ImageUploaderThumbnailerTester_2 extends Frame {
|
||||
public class JaiImageProcessorTester2 extends Frame {
|
||||
private static final Log log = LogFactory
|
||||
.getLog(ImageUploaderThumbnailerTester_2.class);
|
||||
.getLog(JaiImageProcessorTester2.class);
|
||||
|
||||
private static final int ROWS = 6;
|
||||
private static final int COLUMNS = 9;
|
||||
|
||||
private static final int EDGE_THRESHOLD = 6000;
|
||||
|
||||
private static final Dimensions THUMBNAIL_SIZE = new Dimensions(200, 200);
|
||||
|
||||
/** Keep things quiet. */
|
||||
static {
|
||||
|
@ -65,12 +68,12 @@ public class ImageUploaderThumbnailerTester_2 extends Frame {
|
|||
}
|
||||
|
||||
private final String imagePath;
|
||||
private final ImageUploadThumbnailer thumbnailer;
|
||||
private final JaiImageProcessor thumbnailer;
|
||||
|
||||
public ImageUploaderThumbnailerTester_2(String imagePath,
|
||||
public JaiImageProcessorTester2(String imagePath,
|
||||
CropDataSet cropDataSet) {
|
||||
this.imagePath = imagePath;
|
||||
this.thumbnailer = new ImageUploadThumbnailer(200, 200);
|
||||
this.thumbnailer = new JaiImageProcessor();
|
||||
|
||||
setTitle("Cropping edging test");
|
||||
addWindowListener(new CloseWindowListener());
|
||||
|
@ -119,7 +122,7 @@ public class ImageUploaderThumbnailerTester_2 extends Frame {
|
|||
CropRectangle rectangle = new CropRectangle(cropData.left,
|
||||
cropData.top, cropData.size, cropData.size);
|
||||
InputStream thumbnailStream = thumbnailer.cropAndScale(mainStream,
|
||||
rectangle);
|
||||
rectangle, THUMBNAIL_SIZE);
|
||||
|
||||
return StreamDescriptor.create(new MemoryCacheSeekableStream(
|
||||
thumbnailStream), null, null);
|
||||
|
@ -200,8 +203,8 @@ public class ImageUploaderThumbnailerTester_2 extends Frame {
|
|||
.nextElement();
|
||||
appender.setLayout(new PatternLayout("%-5p [%c{1}] %m%n"));
|
||||
|
||||
Logger.getLogger(ImageUploadThumbnailer.class).setLevel(Level.DEBUG);
|
||||
Logger.getLogger(ImageUploaderThumbnailerTester_2.class).setLevel(
|
||||
Logger.getLogger(JaiImageProcessor.class).setLevel(Level.DEBUG);
|
||||
Logger.getLogger(JaiImageProcessorTester2.class).setLevel(
|
||||
Level.INFO);
|
||||
|
||||
CropDataSet cropDataSet = new CropDataSet();
|
||||
|
@ -210,7 +213,7 @@ public class ImageUploaderThumbnailerTester_2 extends Frame {
|
|||
cropDataSet.add(0, 0, 201 + i);
|
||||
}
|
||||
|
||||
new ImageUploaderThumbnailerTester_2(
|
||||
new JaiImageProcessorTester2(
|
||||
"C:/Users/jeb228/Pictures/wheel.png", cropDataSet);
|
||||
|
||||
// new ImageUploaderThumbnailerTester_2(
|
|
@ -8,6 +8,7 @@ import javax.servlet.ServletContext;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.modules.Application;
|
||||
import edu.cornell.mannlib.vitro.webapp.modules.imageProcessor.ImageProcessor;
|
||||
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine;
|
||||
|
||||
/**
|
||||
|
@ -58,4 +59,11 @@ public class ApplicationStub implements Application {
|
|||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public ImageProcessor getImageProcessor() {
|
||||
throw new RuntimeException(
|
||||
"ApplicationStub.getImageProcessor() not implemented.");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue