diff --git a/src/main/java/sections/automatedfilter/AutomatedFilterController.java b/src/main/java/sections/automatedfilter/AutomatedFilterController.java index d32ebe0..117b98c 100644 --- a/src/main/java/sections/automatedfilter/AutomatedFilterController.java +++ b/src/main/java/sections/automatedfilter/AutomatedFilterController.java @@ -68,7 +68,7 @@ void filterAndSavePress(ActionEvent event) { new Thread(() -> { Platform.runLater(() -> UserFeedback.popup("Poup will show up once PDF is filtered")); - PdfFilter.filter(openPdf, savePdf, false, scaleBrightness.isSelected(), brightnessSlider.getValue()/100.0, finalBlurPasses); + PdfFilter.filter(openPdf, savePdf, scaleBrightness.isSelected(), brightnessSlider.getValue()/100.0, finalBlurPasses); Platform.runLater(() -> UserFeedback.popup("Finished filtering pdf")); }).start(); } @@ -123,7 +123,7 @@ void previewPress(ActionEvent event) { lastImage = inputImage[0]; } UserFeedback.reportProgress("Filtering image..."); - var output = HighPassFilterConverter.convert(inputImage[0], finalBlurPasses, scaleBrightness.isSelected(), brightnessSlider.getValue()/100.0, false); + var output = HighPassFilterConverter.convert(inputImage[0], finalBlurPasses, scaleBrightness.isSelected(), brightnessSlider.getValue()/100.0); if (higherQualityPreview.isSelected()) { semaphore = new Semaphore(0); diff --git a/src/main/java/sections/automatedfilter/PdfFilter.java b/src/main/java/sections/automatedfilter/PdfFilter.java index 56f746a..1f5c4bf 100644 --- a/src/main/java/sections/automatedfilter/PdfFilter.java +++ b/src/main/java/sections/automatedfilter/PdfFilter.java @@ -7,14 +7,14 @@ import java.io.File; public class PdfFilter { - public static void filter(File inputFile, File outputFile, boolean highQuality, boolean scaleBrightness, double scaleBrightnessVal, int blurPasses) { + public static void filter(File inputFile, File outputFile, boolean scaleBrightness, double scaleBrightnessVal, int blurPasses) { int size = PdfIO.getNumberOfPages(inputFile); var document = PdfIO.createDocument(); for (int i = 0; i < size; i++) { UserFeedback.reportProgress((1.0*i)/size); UserFeedback.reportProgress("Progress: page " + (i + 1) + "/" + size + "."); var image = PdfIO.getPdfAsImage(inputFile, i); - var filteredImage = HighPassFilterConverter.convert(image, blurPasses, scaleBrightness, scaleBrightnessVal, highQuality); + var filteredImage = HighPassFilterConverter.convert(image, blurPasses, scaleBrightness, scaleBrightnessVal); PdfIO.addImage(document, filteredImage); } PdfIO.saveDocumentAndClose(outputFile, document); diff --git a/src/main/java/sections/highpassfilter/HighPassFilterController.java b/src/main/java/sections/highpassfilter/HighPassFilterController.java index 0ac2a8d..569e257 100644 --- a/src/main/java/sections/highpassfilter/HighPassFilterController.java +++ b/src/main/java/sections/highpassfilter/HighPassFilterController.java @@ -12,9 +12,11 @@ import sections.UserFeedback; import sections.main.MainViewController; import toolset.imagetools.BufferedImageConvert; +import toolset.imagetools.BufferedImageScale; import toolset.io.GuiFileIO; import java.awt.image.BufferedImage; +import java.util.concurrent.Semaphore; public final class HighPassFilterController { @@ -31,7 +33,7 @@ public final class HighPassFilterController { private CheckBox scaleBrightness; @FXML - private CheckBox higherQuality; + private CheckBox higherQualityPreview; @FXML @@ -82,18 +84,41 @@ void runButton(ActionEvent event) { //failed parsing } UserFeedback.reportProgress("Converting..."); - var output = HighPassFilterConverter.convert(inputImage, blurValue, scaleBrightness.isSelected(), brightnessSlider.getValue()/100.0, higherQuality.isSelected()); + var output = HighPassFilterConverter.convert(inputImage, blurValue, scaleBrightness.isSelected(), brightnessSlider.getValue()/100.0); processedImage = output; UserFeedback.reportProgress("Converted image!"); Platform.runLater(() -> setNewImage(output)); + + if (higherQualityPreview.isSelected()) { + semaphore = new Semaphore(0); + Platform.runLater(() -> setNewImage(output)); + UserFeedback.reportProgress("Generated preview. Scaling to fit window... Waiting for permit."); + try { + semaphore.acquire(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + UserFeedback.reportProgress("Generated preview. Scaling to fit window..."); + double width = imagePreview.getFitWidth(); + double height = imagePreview.getFitHeight(); + var scaledOutput = BufferedImageScale.getScaledImage(output, width, height); + Platform.runLater(() -> setNewImage(scaledOutput)); + UserFeedback.reportProgress("Generated scaled preview."); + } else { + Platform.runLater(() -> setNewImage(output)); + UserFeedback.reportProgress("Generated preview."); + } }).start(); } + Semaphore semaphore; + private void setNewImage(BufferedImage bufferedImage) { imagePreview.setImage(BufferedImageConvert.toFxImage(bufferedImage)); reAddNotifier(); MainViewController.forceOnWindowSizeChange(); + if (semaphore != null) semaphore.release(); } private void reAddNotifier() { diff --git a/src/main/java/sections/highpassfilter/HighPassFilterConverter.java b/src/main/java/sections/highpassfilter/HighPassFilterConverter.java index 3a853cc..89d9011 100644 --- a/src/main/java/sections/highpassfilter/HighPassFilterConverter.java +++ b/src/main/java/sections/highpassfilter/HighPassFilterConverter.java @@ -1,17 +1,16 @@ package sections.highpassfilter; -import toolset.imagetools.*; +import toolset.imagetools.BufferedImageBlur; +import toolset.imagetools.BufferedImageColorPalette; +import toolset.imagetools.BufferedImageLayers; +import toolset.imagetools.BufferedImageVarious; import java.awt.image.BufferedImage; import java.awt.image.Kernel; public final class HighPassFilterConverter { - public static BufferedImage convert(BufferedImage bufferedImage, int blurPasses, boolean scaleBrightness, double scaleBrightnessVal, boolean higherQuality) { - - if (higherQuality) blurPasses *= 2; - - if (higherQuality) bufferedImage = BufferedImageScale.getScaledImage(bufferedImage, 2); + public static BufferedImage convert(BufferedImage bufferedImage, int blurPasses, boolean scaleBrightness, double scaleBrightnessVal) { var blurredImage = BufferedImageVarious.copyImage(bufferedImage); @@ -23,7 +22,6 @@ public static BufferedImage convert(BufferedImage bufferedImage, int blurPasses, BufferedImageVarious.copyImage(bufferedImage), blurredImage); if (scaleBrightness) BufferedImageColorPalette.scaleAndCutoffBrightness(output, scaleBrightnessVal); - if (higherQuality) output = BufferedImageScale.getScaledImage(output, 0.5); return output; } diff --git a/src/main/java/sections/highpassfilter/highPassFilter.fxml b/src/main/java/sections/highpassfilter/highPassFilter.fxml index f420acd..01001cd 100644 --- a/src/main/java/sections/highpassfilter/highPassFilter.fxml +++ b/src/main/java/sections/highpassfilter/highPassFilter.fxml @@ -12,7 +12,7 @@ - + diff --git a/src/main/java/toolset/imagetools/BufferedImageScale.java b/src/main/java/toolset/imagetools/BufferedImageScale.java index 833fbd2..4a98460 100644 --- a/src/main/java/toolset/imagetools/BufferedImageScale.java +++ b/src/main/java/toolset/imagetools/BufferedImageScale.java @@ -9,13 +9,6 @@ public final class BufferedImageScale { - /** - * Scales down image - * - * @param source input BufferedImage - * @param SIZE size of scaled down image - * @return scaled down image - */ public static BufferedImage getComparableScaledDownImage(BufferedImage source, final int SIZE) { if (source == null) return null; @@ -35,21 +28,6 @@ public static BufferedImage getComparableScaledDownImage(BufferedImage source, f return newImage; } - public static BufferedImage getScaledImage(BufferedImage source, double scale) { - if (source == null) return null; - BufferedImage newImage = new BufferedImage((int) (source.getWidth() * scale), (int) (source.getHeight() * scale), BufferedImage.TYPE_INT_ARGB); - - Graphics2D graphics2D = (Graphics2D) newImage.getGraphics(); - - graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); - - AffineTransform affineTransform = new AffineTransform(); - affineTransform.scale(scale, scale); - graphics2D.drawImage(source, affineTransform, null); - graphics2D.dispose(); - - return newImage; - } public static BufferedImage getScaledImage(BufferedImage source, double width, double height) { if (source == null) return null;