This commit is contained in:
2017-01-17 13:57:53 +01:00
parent 8cb697eca5
commit 880b87edff
10 changed files with 369 additions and 233 deletions
+3 -169
View File
@@ -209,18 +209,12 @@ public class ScaleWorker extends Thread {
// Print the File Path
System.out.println(sourceFile.toString());
// Print the Sizes
System.out.println("Size now: " + sourceWidth + "px X " + sourceHeight + "px");
System.out.println("Size between: " + scaledSourceWidth + "px X " + scaledSourceHeight + "px");
System.out.println("Size after: " + targetWidth + "px X " + targetHeight + "px");
// SCALE -----------------------------------------------------------
// THE -------------------------------------------------------------
// SOURCE ----------------------------------------------------------
// Get the ImageIcon
Image sourceImageIconImage = sourceImageIcon.getImage();
System.out.println("Got the ImageIcon");
// Open a buffered Image in the specified size
// (with no data at this point --> black image)
@@ -229,29 +223,21 @@ public class ScaleWorker extends Thread {
scaledSourceHeight,
BufferedImage.TYPE_INT_RGB
);
System.out.println("Got the BufferedImage");
// Get the Graphics2D
scaledSourceGraphics = scaledSourceBufferedImage.createGraphics();
System.out.println("Got the Graphics2D");
// Set the Rendering hints
scaledSourceGraphics.setRenderingHint(
RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR
);
System.out.println("Rendering Hints Set");
// Actually Scale the Image
scaledSourceGraphics.drawImage(sourceImageIconImage, 0, 0, scaledSourceWidth, scaledSourceHeight, null);
System.out.println("IMAGE SCALED");
scaledSourceGraphics.dispose();
// System Resources Released
// TODO Can we use this for perormance??
System.out.println("Got the target Image Icon");
// Calculate the Offsets
int wOffset;
@@ -269,10 +255,6 @@ public class ScaleWorker extends Thread {
wOffset = 0;
}
System.out.println("Got the Offset for cropping");
System.out.println("Get the Crop Image Filter");
CropImageFilter cropimgf = new CropImageFilter(
// Crop by moving the image half the way
// it is wider to the left
@@ -285,30 +267,18 @@ public class ScaleWorker extends Thread {
targetHeight
);
System.out.println("Ready");
System.out.println("Get the Filtered image Source");
FilteredImageSource producer = new FilteredImageSource(
scaledSourceBufferedImage.getSource(),
cropimgf
);
System.out.println("Ready");
System.out.println("Get the target Image");
Image image = Toolkit.getDefaultToolkit().createImage(
producer
);
System.out.println("Ready");
System.out.println("Get the target image Icon");
targetImageIcon = new ImageIcon( // TODO Veeeery slow on raspberry
targetImageIcon = new ImageIcon(
image
);
System.out.println("Ready");
// TODO Check if there is something in the Image Icon on RPi
System.out.println("IMAGE CROPPED");
// save the smaller image
croppedBufferedImage = new BufferedImage(
@@ -317,38 +287,23 @@ public class ScaleWorker extends Thread {
BufferedImage.TYPE_INT_RGB
);
System.out.println("Got the BufferedImage after CROPPING");
croppedGraphics = croppedBufferedImage.getGraphics();
System.out.println("Got the Graphics");
croppedGraphics.drawImage(targetImageIcon.getImage(), 0, 0, null);
System.out.println("Graphics drawn");
// WRITE ---------------------------------------------------------------
// THE -----------------------------------------------------------------
// IMAGE ---------------------------------------------------------------
System.out.println("Writing Thumb");
System.out.println("Trying to write image to " + targetFile.toString());
System.out.println(croppedBufferedImage.toString());
// TODO Breaking up at this point on the RPi --> Look at older ScaleWorker
writeJPEG(targetFile, croppedBufferedImage);
System.out.println("Image Writer returned: "
// + iw
);
// UPDATE ---------------------------------------------------------------
// IMAGE ----------------------------------------------------------------
// STATE ----------------------------------------------------------------
somImage.updateImageState();
System.out.println("Image State Updated");
System.out.println("Image State Updated: Scaled");
// Clean up
croppedGraphics.dispose();
@@ -361,127 +316,6 @@ public class ScaleWorker extends Thread {
break;
}
case SOMConfig.SCALING_IMAGE_ICON: {
// // IMAGE ICON ----------------------------------------------------------
// // Generate an ImageIcon from the Source File
// sourceImage = new javafx.scene.image.Image(sourceFile.toString());
// // the sources original width and height
// sourceWidth = sourceImage.getWidth();
// sourceHeight = sourceImage.getHeight();
//
// // Calculate the aspect ratio before cropping
// sourceAspect = (sourceWidth) / (sourceHeight);
// // Calculate the ImageViews' cropped aspect ratio
// targetAspect = ((double) targetWidth) / ((double) targetHeight);
//
// // if picture is higher than frame
// if (sourceAspect < targetAspect) {
// scaledSourceHeight = (int) Math.ceil(targetWidth / sourceAspect);
// scaledSourceWidth = targetWidth;
// }
//
// // if Picture is narrower (or equal)
// else {
// scaledSourceWidth = (int) Math.ceil(targetHeight * sourceAspect);
// scaledSourceHeight = targetHeight;
// }
//
// //Way too slow for the RPi
// System.out.println("Scale with ImageIcon");
//
// // Scale to right size,
// // no cropping
// targetImageIcon = new ImageIcon(
// sourceImageIcon.getImage().getScaledInstance(
// scaledSourceWidth, scaledSourceHeight,
// Image.SCALE_FAST
// ));
//
//
// // Calculate the Offsets
// int wOffset;
// int hOffset;
//
// // ----------
// // Crop Image
// if (sourceAspect > targetAspect) {
// hOffset = 0;
// wOffset = (scaledSourceWidth - targetWidth) / 2;
// } else {
// hOffset = (scaledSourceHeight - targetHeight) / 2;
// wOffset = 0;
// }
//
// System.out.println("Got the Offset for cropping");
//
// System.out.println("Get the Crop Image Filter");
// CropImageFilter cropimgf = new CropImageFilter(
// // Crop by moving the image half the way
// // it is wider to the left
// wOffset,
// // Crop by moving the image half the way
// // it is higher to the top
// hOffset,
//
// targetWidth,
// targetHeight
// );
// System.out.println("Ready");
//
// System.out.println("Get the Filtered image Source");
// FilteredImageSource producer = new FilteredImageSource(
// sourceImageIcon.getImage().getSource(),
// cropimgf
// );
// System.out.println("Ready");
//
// System.out.println("Get the target Image");
// Image image = Toolkit.getDefaultToolkit().createImage(
// producer
// );
// System.out.println("Ready");
//
// System.out.println("Get the target image Icon");
// targetImageIcon = new ImageIcon( // TODO Veeeery slow on raspberry
// image
// );
// System.out.println("Ready");
// // TODO Check if there is something in the Image Icon on RPi
// System.out.println("IMAGE CROPPED");
//
// // save the smaller image
// BufferedImage bufferedImage = new BufferedImage(
// targetWidth,
// targetHeight,
// BufferedImage.TYPE_INT_RGB
// );
//
// System.out.println("Got the BufferedImage after CROPPING");
// croppedGraphics = bufferedImage.getGraphics();
// System.out.println("Got the Graphics");
//
// croppedGraphics.drawImage(targetImageIcon.getImage(), 0, 0, null);
//
// System.out.println("Graphics drawn");
//
// System.out.println("Writing Thumb");
//
// System.out.println("Trying to write image to " + targetFile.toString());
// System.out.println(bufferedImage.toString());
// // TODO Breaking up at this point on the RPi --> Look at older ScaleWorker
//
// writeJPEG(targetFile, bufferedImage);
//
// System.out.println("Image Writer returned: "
//// + iw
// );
// somImage.updateImageState();
//
// System.out.println("Image State Updated");
//
// somImage.updateImageState();
break;
}
// JAVAFX ----------------------------------------------------------
case SOMConfig.SCALING_JAVAFX: {
// Scale with javafx
@@ -493,7 +327,7 @@ public class ScaleWorker extends Thread {
somImage.updateImageState();
System.out.println("Image State Updated");
System.out.println("Image State Updated: Scaled");
somImage.updateImageState();
break;