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 22, 2023
1 parent 75acb35 commit 55fceef
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 32 deletions.
2 changes: 1 addition & 1 deletion PhotoSlide/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<mainClass>org.photoslide.App</mainClass>
<app.name>Photoslide</app.name>
<maven.build.timestamp.format>yy.ww.WWkkmm</maven.build.timestamp.format>
<app.version>1.3.6</app.version>
<app.version>1.3.7</app.version>
<jvm.modules>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</jvm.modules>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>21</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public GridCell<MediaFile> call(GridView<MediaFile> 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);
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 14 additions & 1 deletion PhotoSlide/src/main/java/org/photoslide/datamodel/MediaFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,21 @@ public class ExposureFilter implements ImageFilter {
private final String name;
private int pos;
private float[] values;
private byte[] buffer;
private ByteBuffer byteBuffer;
private PixelBuffer<ByteBuffer> pixelBuffer;
private int height;
private int width;
private float exposure;
protected int[] rTable, gTable, bTable;
private byte[] buffer;

public ExposureFilter() {
name = "ExposureFilter";
exposure = 1.0f;
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();
Expand All @@ -55,33 +54,23 @@ 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;
PixelReader pixelReader = image.getPixelReader();
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<PixelBuffer<ByteBuffer>, 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;
Expand All @@ -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();
Expand All @@ -114,17 +103,29 @@ 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;
this.exposure = values[0];
rTable = gTable = bTable = makeTable();
Platform.runLater(() -> {
pixelBuffer.updateBuffer(callback);
});
});
}

Callback<PixelBuffer<ByteBuffer>, 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;
Expand Down
10 changes: 10 additions & 0 deletions PhotoSlide/src/main/java/org/photoslide/imageops/GainFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ 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
* @return the WriteableImage which should be used in the @ImageView
*/
public Image load(Image img);

public Image loadIcon(Image img);

/**
*
* @return the original Image to reset the filter as Image object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}

0 comments on commit 55fceef

Please sign in to comment.