Skip to content

Commit

Permalink
PixelBuffer enhenced but not yet working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
lanthale committed Oct 28, 2023
1 parent 55fceef commit 5ef60ad
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,8 @@ protected Boolean call() throws Exception {
ObservableList<ImageFilter> filterList = mediaItem.getFilterListWithoutImageData();
Image imageWithFilters = img;
for (ImageFilter imageFilter : filterList) {
imageWithFilters = imageFilter.load(imageWithFilters);
imageFilter.filter(imageFilter.getValues());
imageWithFilters = imageFilter.loadIcon(imageWithFilters);
imageFilter.filterIcon(imageFilter.getValues());
}
img = imageWithFilters;
PixelReader reader = img.getPixelReader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ public void loadImage() throws MalformedURLException {
if ((Double) g1 == 1.0 && !img.isError()) {
lightController.getImageProgress().setVisible(false);
lightController.getImageView().setImage(img);
//imageWithFilters = img;
imageWithFilters = img;
filterList = selectedMediaItem.getFilterListWithoutImageData();
for (ImageFilter imageFilter : filterList) {
switch (imageFilter.getName()) {
Expand All @@ -529,13 +529,13 @@ public void loadImage() throws MalformedURLException {
metadataController.getBiasSlider().setValue(imageFilter.getValues()[1]);
}
}
imageWithFilters = imageFilter.load(img);
imageFilter.filter(imageFilter.getValues());
imageWithFilters = imageFilter.loadIcon(img);
imageFilter.filterIcon(imageFilter.getValues());
}
img = imageWithFilters;
img = imageWithFilters;
lightController.getImageView().setImage(img);
}
});
lightController.getImageView().setImage(img);

lightController.getImageView().setViewport(selectedCell.getItem().getCropView());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,20 +248,25 @@ public void initialize(URL url, ResourceBundle rb) {
if (exposerFilter == null) {
exposerFilter = new ExposureFilter();
actualMediaFile.addImageFilter(exposerFilter);
lightController.getImageView().setImage(exposerFilter.load(lightController.getImageView().getImage()));
}
double val = exposureSlider.getValue();
exposerFilter.filter(new float[]{(float) val});
ImageFilter filterForName = actualMediaFile.getFilterForName(exposerFilter.getName());
if (filterForName != null) {
filterForName.setValues(exposerFilter.getValues());
//lightController.getImageView().setImage(exposerFilter.loadGPU(lightController.getImageView().getImage()));
lightController.getImageView().setImage(exposerFilter.loadIcon(lightController.getImageView().getImage()));
} /*else {
if (((ExposureFilter) exposerFilter).isGpuInit() == false) {
lightController.getImageView().setImage(exposerFilter.loadGPU(lightController.getImageView().getImage()));
}
}*/
double val = exposureSlider.getValue();
/*exposerFilter.filterGPU(new float[]{(float) val});
ImageFilter filterForName = actualMediaFile.getFilterForName(exposerFilter.getName());
if (filterForName != null) {
filterForName.setValues(exposerFilter.getValues());
}*/
executorFilter.submit(() -> {
/*exposerFilter.filter(new float[]{(float) val});
exposerFilter.filterIcon(new float[]{(float) val});
ImageFilter filterForName = actualMediaFile.getFilterForName(exposerFilter.getName());
if (filterForName != null) {
filterForName.setValues(exposerFilter.getValues());
}*/
}
actualMediaFile.saveEdits();
});
});
Expand All @@ -271,13 +276,13 @@ public void initialize(URL url, ResourceBundle rb) {
if (gainFilter == null) {
gainFilter = new GainFilter();
actualMediaFile.addImageFilter(gainFilter);
lightController.getImageView().setImage(gainFilter.load(lightController.getImageView().getImage()));
lightController.getImageView().setImage(gainFilter.loadIcon(lightController.getImageView().getImage()));
}

double valGain = gainSlider.getValue();
double valBias = biasSlider.getValue();
executorFilter.submit(() -> {
gainFilter.filter(new float[]{(float) valGain, (float) valBias});
gainFilter.filterIcon(new float[]{(float) valGain, (float) valBias});
ImageFilter filterForName = actualMediaFile.getFilterForName(gainFilter.getName());
if (filterForName != null) {
filterForName.setValues(gainFilter.getValues());
Expand All @@ -289,13 +294,13 @@ public void initialize(URL url, ResourceBundle rb) {
if (gainFilter == null) {
gainFilter = new GainFilter();
actualMediaFile.addImageFilter(gainFilter);
lightController.getImageView().setImage(gainFilter.load(lightController.getImageView().getImage()));
lightController.getImageView().setImage(gainFilter.loadIcon(lightController.getImageView().getImage()));
}

double valGain = gainSlider.getValue();
double valBias = biasSlider.getValue();
executorFilter.submit(() -> {
gainFilter.filter(new float[]{(float) valGain, (float) valBias});
gainFilter.filterIcon(new float[]{(float) valGain, (float) valBias});
ImageFilter filterForName = actualMediaFile.getFilterForName(gainFilter.getName());
if (filterForName != null) {
filterForName.setValues(gainFilter.getValues());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ public Image setFilters() {
if (this.unModifiyAbleImage != null) {
Image imageWithFilters = getClonedImage(unModifiyAbleImage);
for (ImageFilter imageFilter : filterList) {
imageWithFilters = imageFilter.load(imageWithFilters);
imageFilter.filter(imageFilter.getValues());
imageWithFilters = imageFilter.loadIcon(imageWithFilters);
imageFilter.filterIcon(imageFilter.getValues());
}
return imageWithFilters;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ protected Boolean call() throws Exception {
imageWithFilters = img;
filterList = selectedMediaFile.getFilterListWithoutImageData();
for (ImageFilter imageFilter : filterList) {
imageWithFilters = imageFilter.load(imageWithFilters);
imageFilter.filter(imageFilter.getValues());
imageWithFilters = imageFilter.loadIcon(imageWithFilters);
imageFilter.filterIcon(imageFilter.getValues());
}
img = imageWithFilters;
mediaViewController.getEditorImageView().setImage(img);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ protected Boolean call() throws Exception {
imageWithFilters = img;
filterList = selectedMediaFile.getFilterListWithoutImageData();
for (ImageFilter imageFilter : filterList) {
imageWithFilters = imageFilter.load(imageWithFilters);
imageFilter.filter(imageFilter.getValues());
imageWithFilters = imageFilter.loadIcon(imageWithFilters);
imageFilter.filterIcon(imageFilter.getValues());
}
img = imageWithFilters;
editorImageView.setImage(img);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ protected Boolean call() throws Exception {
imageWithFilters = img;
filterList = selectedMediaFile.getFilterListWithoutImageData();
for (ImageFilter imageFilter : filterList) {
imageWithFilters = imageFilter.load(imageWithFilters);
imageFilter.filter(imageFilter.getValues());
imageWithFilters = imageFilter.loadIcon(imageWithFilters);
imageFilter.filterIcon(imageFilter.getValues());
}
img = imageWithFilters;
histogram = new Histogram(img);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;
import javafx.application.Platform;
import javafx.geometry.Rectangle2D;
import javafx.scene.image.Image;
Expand Down Expand Up @@ -37,6 +35,7 @@ public class ExposureFilter implements ImageFilter {
private float exposure;
protected int[] rTable, gTable, bTable;
private byte[] buffer;
private boolean gpuInit=false;

public ExposureFilter() {
name = "ExposureFilter";
Expand All @@ -57,7 +56,7 @@ public Image loadIcon(Image img) {
}

@Override
public Image load(Image img) {
public Image loadGPU(Image img) {
image = img;
PixelReader pixelReader = image.getPixelReader();
height = (int) image.getHeight();
Expand All @@ -68,6 +67,7 @@ public Image load(Image img) {
pixelBuffer = new PixelBuffer<>(width, height, byteBuffer, PixelFormat.getByteBgraPreInstance());
filteredImage = new WritableImage(pixelBuffer);
ByteBuffer.wrap(buffer);
gpuInit=true;
return filteredImage;
}

Expand Down Expand Up @@ -106,7 +106,7 @@ public void filterIcon(float[] values) {
}

@Override
public void filter(float[] values) {
public void filterGPU(float[] values) {
this.values = values;
this.exposure = values[0];
rTable = gTable = bTable = makeTable();
Expand Down Expand Up @@ -219,6 +219,12 @@ public boolean equals(Object obj) {
return true;
}

public boolean isGpuInit() {
return gpuInit;
}



@Override
public String toString() {
return "ExposureFilter{" + "name=" + name + ", pos=" + pos + ", values=" + values + ", exposure=" + exposure + '}';
Expand Down
26 changes: 14 additions & 12 deletions PhotoSlide/src/main/java/org/photoslide/imageops/GainFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public GainFilter() {
}

@Override
public Image load(Image img) {
public Image loadIcon(Image img) {
image = img;
PixelReader pixelReader = image.getPixelReader();
height = (int) image.getHeight();
Expand All @@ -54,6 +54,17 @@ public Image load(Image img) {
filteredImage = new WritableImage(pixelReader, width, height);
return filteredImage;
}

@Override
public void filterGPU(float[] values) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Image loadGPU(Image img) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}


@Override
public Image reset() {
Expand All @@ -74,7 +85,7 @@ public float[] getValues() {
}

@Override
public synchronized void filter(float[] values) {
public synchronized void filterIcon(float[] values) {
this.values = values;
this.gain = values[0];
this.bias = values[1];
Expand Down Expand Up @@ -195,14 +206,5 @@ 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
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public interface ImageFilter extends Cloneable {
*
* @param values filter with the given values
*/
public void filter(float[] values);
public void filterGPU(float[] values);

public void filterIcon(float[] values);

Expand All @@ -48,7 +48,7 @@ public interface ImageFilter extends Cloneable {
* @param img Image to be loaded into an byte array
* @return the WriteableImage which should be used in the @ImageView
*/
public Image load(Image img);
public Image loadGPU(Image img);

public Image loadIcon(Image img);

Expand Down
26 changes: 13 additions & 13 deletions PhotoSlide/src/main/java/org/photoslide/imageops/UnsharpFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public UnsharpFilter() {
}

@Override
public Image load(Image img) {
public Image loadIcon(Image img) {
image = img;
PixelReader pixelReader = image.getPixelReader();
height = (int) image.getHeight();
Expand All @@ -53,6 +53,16 @@ public Image load(Image img) {
filteredImage = new WritableImage(pixelReader, width, height);
return filteredImage;
}

@Override
public void filterGPU(float[] values) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Image loadGPU(Image img) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Image reset() {
Expand All @@ -73,7 +83,7 @@ public float[] getValues() {
}

@Override
public void filter(float[] values) {
public void filterIcon(float[] values) {
this.values = values;
this.amount = values[0];
this.threshold = (int) values[1];
Expand Down Expand Up @@ -197,16 +207,6 @@ public boolean equals(Object obj) {
@Override
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
}
}

}

0 comments on commit 5ef60ad

Please sign in to comment.