From 55fceefa8f064375104efcc9d19ccb19603f7ede Mon Sep 17 00:00:00 2001 From: lanthale Date: Sun, 22 Oct 2023 13:43:13 +0200 Subject: [PATCH] PixelBuffer enhenced but not yet working correctly --- PhotoSlide/pom.xml | 2 +- .../MediaGridCellFactory.java | 15 ++++--- .../org/photoslide/datamodel/MediaFile.java | 15 ++++++- .../photoslide/datamodel/MediaGridCell.java | 2 +- .../photoslide/imageops/ExposureFilter.java | 45 ++++++++++--------- .../org/photoslide/imageops/GainFilter.java | 10 +++++ .../org/photoslide/imageops/ImageFilter.java | 4 ++ .../photoslide/imageops/UnsharpFilter.java | 10 +++++ 8 files changed, 71 insertions(+), 32 deletions(-) diff --git a/PhotoSlide/pom.xml b/PhotoSlide/pom.xml index e1d115d..006a578 100644 --- a/PhotoSlide/pom.xml +++ b/PhotoSlide/pom.xml @@ -17,7 +17,7 @@ org.photoslide.App Photoslide yy.ww.WWkkmm - 1.3.6 + 1.3.7 java.base,jdk.management,java.naming,java.sql,java.transaction.xa,java.xml,jdk.unsupported,java.management,java.datatransfer,java.desktop,java.security.jgss,java.xml.crypto,jdk.javadoc,javafx.media,javafx.controls,javafx.fxml,javafx.graphics,javafx.base,javafx.swing,javafx.web,java.logging,jdk.charsets,java.se,java.net.http,java.prefs,jdk.crypto.ec,jdk.crypto.cryptoki,jdk.localedata,java.compiler,jdk.net,java.instrument,java.scripting,java.rmi UTF-8 21 diff --git a/PhotoSlide/src/main/java/org/photoslide/browserlighttable/MediaGridCellFactory.java b/PhotoSlide/src/main/java/org/photoslide/browserlighttable/MediaGridCellFactory.java index 9ada07e..029b289 100644 --- a/PhotoSlide/src/main/java/org/photoslide/browserlighttable/MediaGridCellFactory.java +++ b/PhotoSlide/src/main/java/org/photoslide/browserlighttable/MediaGridCellFactory.java @@ -193,7 +193,7 @@ public GridCell call(GridView p) { cell.itemProperty().addListener((ov, oldMediaItem, newMediaItem) -> { if (listFilesActive == false) { if (newMediaItem != null && oldMediaItem == null) { - if (newMediaItem.isLoading() == true) { + if (newMediaItem.isLoading() == true) { if (newMediaItem.getMediaType() == MediaFile.MediaTypes.IMAGE) { if (isCellVisible(cell)) { fileLoader.loadImage(newMediaItem); @@ -514,11 +514,10 @@ public void loadImage() throws MalformedURLException { img.progressProperty().addListener((ov, g, g1) -> { if ((Double) g1 == 1.0 && !img.isError()) { lightController.getImageProgress().setVisible(false); - imageWithFilters = img; + lightController.getImageView().setImage(img); + //imageWithFilters = img; filterList = selectedMediaItem.getFilterListWithoutImageData(); for (ImageFilter imageFilter : filterList) { - imageWithFilters = imageFilter.load(imageWithFilters); - imageFilter.filter(imageFilter.getValues()); switch (imageFilter.getName()) { case "ExposureFilter" -> { metadataController.setExposerFilter(imageFilter); @@ -530,12 +529,14 @@ public void loadImage() throws MalformedURLException { metadataController.getBiasSlider().setValue(imageFilter.getValues()[1]); } } + imageWithFilters = imageFilter.load(img); + imageFilter.filter(imageFilter.getValues()); } - img = imageWithFilters; - lightController.getImageView().setImage(img); + img = imageWithFilters; } }); lightController.getImageView().setImage(img); + lightController.getImageView().setViewport(selectedCell.getItem().getCropView()); if (selectedCell.getItem().getCropView() != null) { @@ -754,7 +755,7 @@ public void oneRowDown(MediaGridCell input, double cellHeight) { * @return true if cell is actual visible */ public boolean isCellVisible(MediaGridCell input) { - VirtualFlow vf = (VirtualFlow) grid.getChildrenUnmodifiable().get(0); + VirtualFlow vf = (VirtualFlow) grid.getChildrenUnmodifiable().get(0); boolean ret = false; if (vf.getFirstVisibleCell() == null) { return false; diff --git a/PhotoSlide/src/main/java/org/photoslide/datamodel/MediaFile.java b/PhotoSlide/src/main/java/org/photoslide/datamodel/MediaFile.java index ca945a9..f22ba6a 100644 --- a/PhotoSlide/src/main/java/org/photoslide/datamodel/MediaFile.java +++ b/PhotoSlide/src/main/java/org/photoslide/datamodel/MediaFile.java @@ -175,6 +175,19 @@ public Image setFilters() { return this.image; } } + + public Image setFiltersIcon() { + if (this.unModifiyAbleImage != null) { + Image imageWithFilters = getClonedImage(unModifiyAbleImage); + for (ImageFilter imageFilter : filterList) { + imageWithFilters = imageFilter.loadIcon(imageWithFilters); + imageFilter.filterIcon(imageFilter.getValues()); + } + return imageWithFilters; + } else { + return this.image; + } + } public void setImage(Image image) { this.image = image; @@ -664,7 +677,7 @@ public Image getClonedImage(Image img) { int width = (int) image.getWidth(); byte[] buffer = new byte[width * height * 4]; try { - pixelReader.getPixels(0, 0, width, height, PixelFormat.getByteBgraInstance(), buffer, 0, width * 4); + pixelReader.getPixels(0, 0, width, height, PixelFormat.getByteBgraInstance(), buffer, 0, width * 4); Image filteredImage = new WritableImage(pixelReader, width, height); return filteredImage; } catch (Exception e) { diff --git a/PhotoSlide/src/main/java/org/photoslide/datamodel/MediaGridCell.java b/PhotoSlide/src/main/java/org/photoslide/datamodel/MediaGridCell.java index 44d9bda..b6c31fa 100644 --- a/PhotoSlide/src/main/java/org/photoslide/datamodel/MediaGridCell.java +++ b/PhotoSlide/src/main/java/org/photoslide/datamodel/MediaGridCell.java @@ -180,7 +180,7 @@ public final void setImage(MediaFile item) { if (item.getUnModifiyAbleImage() == null) { item.setUnModifiyAbleImage(item.getClonedImage(item.getImage())); } - item.setImage(item.setFilters()); + item.setImage(item.setFiltersIcon()); rootPane.getChildren().clear(); rootPane.getChildren().add(imageView); if (item.getCropView() != null) { diff --git a/PhotoSlide/src/main/java/org/photoslide/imageops/ExposureFilter.java b/PhotoSlide/src/main/java/org/photoslide/imageops/ExposureFilter.java index 43dce11..3f3f45e 100644 --- a/PhotoSlide/src/main/java/org/photoslide/imageops/ExposureFilter.java +++ b/PhotoSlide/src/main/java/org/photoslide/imageops/ExposureFilter.java @@ -31,13 +31,12 @@ public class ExposureFilter implements ImageFilter { private final String name; private int pos; private float[] values; - private byte[] buffer; - private ByteBuffer byteBuffer; private PixelBuffer pixelBuffer; private int height; private int width; private float exposure; protected int[] rTable, gTable, bTable; + private byte[] buffer; public ExposureFilter() { name = "ExposureFilter"; @@ -45,8 +44,8 @@ public ExposureFilter() { rTable = gTable = bTable = makeTable(); } - /*@Override - public Image load(Image img) { + @Override + public Image loadIcon(Image img) { image = img; PixelReader pixelReader = image.getPixelReader(); height = (int) image.getHeight(); @@ -55,7 +54,8 @@ public Image load(Image img) { pixelReader.getPixels(0, 0, width, height, PixelFormat.getByteBgraInstance(), buffer, 0, width * 4); filteredImage = new WritableImage(pixelReader, width, height); return filteredImage; - }*/ + } + @Override public Image load(Image img) { image = img; @@ -63,25 +63,14 @@ public Image load(Image img) { height = (int) image.getHeight(); width = (int) image.getWidth(); buffer = new byte[width * height * 4]; - byteBuffer = ByteBuffer.allocateDirect(width * height * 4); + ByteBuffer byteBuffer = ByteBuffer.allocateDirect(width * height * 4); pixelReader.getPixels(0, 0, width, height, PixelFormat.getByteBgraPreInstance(), buffer, 0, width * 4); pixelBuffer = new PixelBuffer<>(width, height, byteBuffer, PixelFormat.getByteBgraPreInstance()); filteredImage = new WritableImage(pixelBuffer); - ByteBuffer.wrap(buffer); + ByteBuffer.wrap(buffer); return filteredImage; } - Callback, Rectangle2D> callback = pBuffer -> { - ByteBuffer bufferPB = pBuffer.getBuffer(); - // Update the buffer. - for (int i = 0; i < buffer.length; i++) { - int rgba = buffer[i]; - int res = filterRGB(rgba); - bufferPB.put(i, (byte) (res)); - } - return new Rectangle2D(0, 0, width, height); - }; - @Override public Image reset() { this.exposure = 1.0f; @@ -99,8 +88,8 @@ public float[] getValues() { return new float[]{exposure}; } - /*@Override - public void filter(float[] values) { + @Override + public void filterIcon(float[] values) { this.values = values; this.exposure = values[0]; rTable = gTable = bTable = makeTable(); @@ -114,7 +103,8 @@ public void filter(float[] values) { } pixelWriter.setPixels(0, 0, width, height, PixelFormat.getByteBgraInstance(), targetBuffer, 0, width * 4); }); - }*/ + } + @Override public void filter(float[] values) { this.values = values; @@ -122,9 +112,20 @@ public void filter(float[] values) { rTable = gTable = bTable = makeTable(); Platform.runLater(() -> { pixelBuffer.updateBuffer(callback); - }); + }); } + Callback, Rectangle2D> callback = pBuffer -> { + ByteBuffer bufferPB = pBuffer.getBuffer(); + // Update the buffer. + for (int i = 0; i < buffer.length; i++) { + int rgba = buffer[i]; + int res = filterRGB(rgba); + bufferPB.put(i, (byte) (res)); + } + return new Rectangle2D(0, 0, width, height); + }; + @Override public void setValues(float[] values) { this.values = values; diff --git a/PhotoSlide/src/main/java/org/photoslide/imageops/GainFilter.java b/PhotoSlide/src/main/java/org/photoslide/imageops/GainFilter.java index 643eb95..f717d8b 100644 --- a/PhotoSlide/src/main/java/org/photoslide/imageops/GainFilter.java +++ b/PhotoSlide/src/main/java/org/photoslide/imageops/GainFilter.java @@ -195,4 +195,14 @@ public String toString() { return "GainFilter{" + "name=" + name + ", pos=" + pos + ", values=" + values + ", gain=" + gain + ", bias=" + bias + '}'; } + @Override + public void filterIcon(float[] values) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public Image loadIcon(Image img) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + } diff --git a/PhotoSlide/src/main/java/org/photoslide/imageops/ImageFilter.java b/PhotoSlide/src/main/java/org/photoslide/imageops/ImageFilter.java index 7a5d7dd..2f7bc04 100644 --- a/PhotoSlide/src/main/java/org/photoslide/imageops/ImageFilter.java +++ b/PhotoSlide/src/main/java/org/photoslide/imageops/ImageFilter.java @@ -41,6 +41,8 @@ public interface ImageFilter extends Cloneable { */ public void filter(float[] values); + public void filterIcon(float[] values); + /** * * @param img Image to be loaded into an byte array @@ -48,6 +50,8 @@ public interface ImageFilter extends Cloneable { */ public Image load(Image img); + public Image loadIcon(Image img); + /** * * @return the original Image to reset the filter as Image object diff --git a/PhotoSlide/src/main/java/org/photoslide/imageops/UnsharpFilter.java b/PhotoSlide/src/main/java/org/photoslide/imageops/UnsharpFilter.java index 00e9de2..4cbee73 100644 --- a/PhotoSlide/src/main/java/org/photoslide/imageops/UnsharpFilter.java +++ b/PhotoSlide/src/main/java/org/photoslide/imageops/UnsharpFilter.java @@ -199,4 +199,14 @@ public String toString() { return "UnsharpFilter{" + "name=" + name + ", pos=" + pos + ", values=" + values + ", amount=" + amount + ", threshold=" + threshold + ", radius=" + radius + '}'; } + @Override + public void filterIcon(float[] values) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public Image loadIcon(Image img) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + }