add skip process image when in known

This commit is contained in:
Mateusz Kowalczyk 2020-01-23 23:30:35 +01:00
parent 1923ec1801
commit 360f663119
3 changed files with 63 additions and 16 deletions

View File

@ -7,6 +7,7 @@ import dev.mateuszkowalczyk.ffm.image.ThumbnailService;
import dev.mateuszkowalczyk.ffm.utils.PropertiesLoader;
import dev.mateuszkowalczyk.ffm.utils.Property;
import javafx.application.Platform;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.image.PixelWriter;
import javafx.scene.image.WritableImage;
@ -36,34 +37,46 @@ public class DirectoryScanner implements Runnable {
.filter(Files::isRegularFile)
.forEach(path -> {
String filename = path.getFileName().toString();
ImageView imageView;
if(this.isImagePath(filename) && !path.toString().contains(".cache")) {
Photo photo = new Photo();
photo.setPath(path.toString());
photo.setFileName(filename);
Photo photo;
BufferedImage image = this.thumbnailService.createThumbnail(photo);
this.photoDAO.save(photo);
photo = this.photoDAO.findByPath(path.toString());
WritableImage wr = null;
if (image != null) {
wr = new WritableImage(image.getWidth(), image.getHeight());
PixelWriter pw = wr.getPixelWriter();
for (int x = 0; x < image.getWidth(); x++) {
for (int y = 0; y < image.getHeight(); y++) {
pw.setArgb(x, y, image.getRGB(x, y));
if (photo == null) {
photo = new Photo();
photo.setPath(path.toString());
photo.setFileName(filename);
BufferedImage image = this.thumbnailService.createThumbnail(photo);
this.photoDAO.save(photo);
WritableImage wr = null;
if (image != null) {
wr = new WritableImage(image.getWidth(), image.getHeight());
PixelWriter pw = wr.getPixelWriter();
for (int x = 0; x < image.getWidth(); x++) {
for (int y = 0; y < image.getHeight(); y++) {
pw.setArgb(x, y, image.getRGB(x, y));
}
}
}
}
// new Thread(
// new FaceDetector(photo)
// ).start();
new FaceDetector(photo).run();
new FaceDetector(photo).run();
ImageView imageView = new ImageView(wr);
imageViews.add(imageView);
imageView = new ImageView(wr);
imageViews.add(imageView);
} else {
Image image = new Image("file:" + photo.getCachedPath());
imageView = new ImageView(image);
}
Platform.runLater(() -> WorkspaceService.getInstance().getMainPageController().addImage(imageView));
}
});

View File

@ -4,6 +4,9 @@ import dev.mateuszkowalczyk.ffm.data.database.annotation.Column;
import dev.mateuszkowalczyk.ffm.data.database.annotation.PrimaryKey;
import dev.mateuszkowalczyk.ffm.data.database.annotation.Table;
import java.sql.ResultSet;
import java.sql.SQLException;
@Table(name = "photos")
public class Photo {
@ -17,6 +20,17 @@ public class Photo {
@Column
private String cachedPath;
public Photo() {
}
public Photo(ResultSet resultSet) throws SQLException {
this.id = resultSet.getInt("id");
this.path = resultSet.getString("path");
this.fileName = resultSet.getString("fileName");
this.cachedPath = resultSet.getString("cachedPath");
}
public String getFileName() {
return fileName;
}

View File

@ -53,6 +53,26 @@ public class PhotoDAO implements Dao<Photo> {
}
public Photo findByPath(String path) {
String sql = "SELECT * FROM photos WHERE path = ?";
Photo photo = null;
try {
PreparedStatement preparedStatement = this.databaseService.getConnection().prepareStatement(sql);
preparedStatement.setString(1, path);
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
photo = new Photo(resultSet);
}
} catch (SQLException e) {
e.printStackTrace();
}
return photo;
}
@Override
public void update(Photo photo) {