added option to adjust brightness
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>BelegScanner</groupId>
|
||||
<artifactId>BelegScanner</artifactId>
|
||||
<version>1.0.9</version>
|
||||
<version>1.0.10</version>
|
||||
|
||||
<name>BelegScanner</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
Actions : Aktionen
|
||||
Adjusting brightness… : Helligkeitskorrektur…
|
||||
Adjustments : Verbesserungen
|
||||
Apps missing : Anwendungen fehlen
|
||||
Category : Kategorie
|
||||
CATEGORY : KATEGORIE
|
||||
Click here to open directory : Hier klicken, um das Verzeichnis zu öffnen
|
||||
Configuration problem : Konfigurations-Problem
|
||||
Conversion failed. : Konvertierung fehlgeschlagen.
|
||||
Converting to PDF… : Kovertiere zu PDF…
|
||||
current resolution : aktuelle Auflösung
|
||||
@@ -13,14 +16,19 @@ drop file : Datei löschen
|
||||
done : fertig
|
||||
Error code\: {} for {} : Fehlercode: {} für {}
|
||||
Finished text recognition. : Texterkennung beendet.
|
||||
German language support missing! : Unterstützung für deutsche Sprache fehlt!
|
||||
Height : Höhe
|
||||
Improve brightness : Helligkeit verbessern
|
||||
Joining PDFs… : Verbinde PDFs…
|
||||
join PDFs : PDFs zusammenführen
|
||||
Language support : Sprach-Unterstützung
|
||||
MONTH : MONAT
|
||||
OCR failed. : OCR fehlgeschlagen.
|
||||
open folder : Ordner öffnen
|
||||
Path '{}' does not exist! : Pfad '{}' existiert nicht!
|
||||
Path : Pfad
|
||||
Please install the package : Bitte installiere das Paket
|
||||
Please remove the line<br/><br/>policy<br/><br/>from 'file'. : Bitte entferne die Zeile<br/><br/>policy<br/><br/> aus 'file'.
|
||||
PDFs joined. : Zusammengefügt.
|
||||
Press Shift + Delete to remove an entry. : Drücken Sie Umschalt + Entf um einen Eintrag zu löschen
|
||||
Scan failed. : Scannen fehlgeschlagen.
|
||||
@@ -33,3 +41,4 @@ Text recognition… : Texterkennung…
|
||||
This application requires the following helper commands to be installed\: : Diese Anwendung erfordert es, dass auch die folgenden Hilfsprogramme installiert sind:
|
||||
Width : Breite
|
||||
YEAR : JAHR
|
||||
Your ImageMagick configuration prohibits conversion of jpg to pdf! : Deine ImageMagick-Konfiguration verbietet die Umwandlung von jpg zu PDF!
|
||||
|
||||
@@ -12,8 +12,11 @@ import java.awt.Dimension;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
@@ -68,6 +71,10 @@ public class MainFrame extends JFrame {
|
||||
|
||||
private static final String APP_Y = "app.main.position.y";
|
||||
|
||||
private static final String BAD_POLICY = "<policy domain=\"coder\" rights=\"none\" pattern=\"PDF\" />";
|
||||
|
||||
private static final String POLICY_FILE = "/etc/ImageMagick-6/policy.xml";
|
||||
|
||||
private StatusBar statusBar;
|
||||
private Toolbar toolbar;
|
||||
|
||||
@@ -156,10 +163,69 @@ public class MainFrame extends JFrame {
|
||||
};
|
||||
|
||||
public void checkDependencies() {
|
||||
List<String> missing = List.of("convert --version", "killall --version", "pdfsandwich -version", "pdftk --version", "scanimage --version",FILE_BROWSER+" --version").stream().map(this::appMissing).filter(app -> app != null).collect(Collectors.toList());
|
||||
List<String> missing = List.of("convert --version", "killall --version", "pdfsandwich -version", "pdftk --version", "scanimage --version",FILE_BROWSER+" --version")
|
||||
.stream().map(this::appMissing).filter(app -> app != null).collect(Collectors.toList());
|
||||
if (!missing.isEmpty()) notifyAppsMissing(missing);
|
||||
checkImageMagickPolicy();
|
||||
checkTesseractLang();
|
||||
}
|
||||
|
||||
private void checkTesseractLang() {
|
||||
List<String> cmd = List.of("tesseract","--list-langs");
|
||||
|
||||
try {
|
||||
Process process = new ProcessBuilder(cmd).start();
|
||||
process.waitFor();
|
||||
var bytes = new ByteArrayOutputStream();
|
||||
process.getInputStream().transferTo(bytes);
|
||||
var out = bytes.toString(StandardCharsets.UTF_8);
|
||||
if (!out.contains("deu")) {
|
||||
StringBuilder message = new StringBuilder();
|
||||
message.append("<html>")
|
||||
.append(t("German language support missing!"))
|
||||
.append("<br/>")
|
||||
.append(t("Please install the package"))
|
||||
.append("<br/><br/>tesseract-ocr-deu");
|
||||
|
||||
JOptionPane.showMessageDialog(this,
|
||||
message,
|
||||
t("Language support"),
|
||||
JOptionPane.WARNING_MESSAGE);
|
||||
System.exit(-1);
|
||||
|
||||
}
|
||||
} catch (IOException | InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void checkImageMagickPolicy() {
|
||||
var file = new File(POLICY_FILE);
|
||||
if (file.exists())
|
||||
try {
|
||||
var policy = Files.readString(file.toPath());
|
||||
if (policy.contains(BAD_POLICY)) {
|
||||
StringBuilder message = new StringBuilder();
|
||||
message.append("<html>")
|
||||
.append(t("Your ImageMagick configuration prohibits conversion of jpg to pdf!"))
|
||||
.append("<br/>")
|
||||
.append(t("Please remove the line<br/><br/>policy<br/><br/>from 'file'.").replace("policy",BAD_POLICY.replace("<", "<")).replace("file",POLICY_FILE));
|
||||
|
||||
JOptionPane.showMessageDialog(this,
|
||||
message,
|
||||
t("Configuration problem"),
|
||||
JOptionPane.WARNING_MESSAGE);
|
||||
System.exit(-1);
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String appMissing(String appTest){
|
||||
List<String> cmd = Arrays.asList(appTest.split(" "));
|
||||
|
||||
@@ -203,9 +269,9 @@ public class MainFrame extends JFrame {
|
||||
*/
|
||||
private void performScan(String path, Dimension dimension) {
|
||||
LOG.debug("performScan({})",path);
|
||||
/* We need to all required config values before starting to scan, because the might be changed during scanning */
|
||||
/* We need to save all required config values before starting to scan, because they might be changed during scanning */
|
||||
String target = config.getOrCreate(CONFIG_TARGET, "pdf");
|
||||
|
||||
|
||||
setScanning(true);
|
||||
|
||||
File folder = new File(path);
|
||||
@@ -217,6 +283,7 @@ public class MainFrame extends JFrame {
|
||||
docTable.add(path);
|
||||
|
||||
int resolution = toolbar.getResolution();
|
||||
boolean improbeBrightness = toolbar.getImproveBrightness();
|
||||
long timestamp = new Date().getTime();
|
||||
String raw = timestamp+".jpg";
|
||||
|
||||
@@ -251,6 +318,31 @@ public class MainFrame extends JFrame {
|
||||
LOG.error(t("{} terminated: "),builder,e);
|
||||
}
|
||||
setScanning(false);
|
||||
|
||||
if (improbeBrightness) {
|
||||
cmd = new Vector<>();
|
||||
cmd.add("mogrify");
|
||||
cmd.add("-contrast-stretch");
|
||||
cmd.add("0x60%");
|
||||
cmd.add(raw);
|
||||
builder = new ProcessBuilder(cmd);
|
||||
builder.directory(folder);
|
||||
try {
|
||||
Process process = builder.start();
|
||||
docTable.setState(path,t("Adjusting brightness…"));
|
||||
int errorCode = process.waitFor();
|
||||
if (errorCode != 0) {
|
||||
LOG.error(t("Error code: {} for {}"),errorCode,cmd);
|
||||
docTable.setState(path, t("Adjustment failed."));
|
||||
setScanning(false);
|
||||
return;
|
||||
}
|
||||
} catch (InterruptedException | IOException e) {
|
||||
LOG.error(t("{} terminated: "),builder,e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (JPG.equals(target)) {
|
||||
docTable.setState(path, t("Image scanned"));
|
||||
docTable.preview(path);
|
||||
@@ -471,7 +563,7 @@ public class MainFrame extends JFrame {
|
||||
config.set(prefix+"path",path);
|
||||
config.set(prefix+"size.w", dimension.width);
|
||||
config.set(prefix+"size.h", dimension.height);
|
||||
|
||||
|
||||
|
||||
Point loc = getLocation();
|
||||
config.set(APP_X, loc.x);
|
||||
|
||||
@@ -15,15 +15,7 @@ import java.util.List;
|
||||
import java.util.Vector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import org.json.JSONArray;
|
||||
@@ -38,6 +30,7 @@ import de.srsoftware.tools.gui.SelectComboBox;
|
||||
|
||||
import static de.srsoftware.belegscanner.Application.*;
|
||||
import static de.srsoftware.belegscanner.Constants.*;
|
||||
import static java.awt.BorderLayout.*;
|
||||
|
||||
/**
|
||||
* create the application's toolbar
|
||||
@@ -96,7 +89,7 @@ public class Toolbar extends JPanel {
|
||||
private JTextField height;
|
||||
private SelectComboBox catPicker;
|
||||
private int resolution = 150;
|
||||
|
||||
private boolean improveBrightness = false;
|
||||
/**
|
||||
* create toolbar
|
||||
* @param config
|
||||
@@ -109,6 +102,7 @@ public class Toolbar extends JPanel {
|
||||
add(input(t("Path"),pathPicker = pathPicker()));
|
||||
addFormatSelector();
|
||||
add(resolutionSelector());
|
||||
add(improveSelector());
|
||||
add(typeSelector());
|
||||
add(scanButton());
|
||||
add(Box.createGlue());
|
||||
@@ -173,8 +167,8 @@ public class Toolbar extends JPanel {
|
||||
dummy.setLayout(new BorderLayout());
|
||||
dummy.setMaximumSize(new Dimension(600, 40));
|
||||
|
||||
dummy.add(new JLabel(t("Width")+": "),BorderLayout.WEST);
|
||||
dummy.add(width = new JTextField(209+""),BorderLayout.CENTER);
|
||||
dummy.add(new JLabel(t("Width")+": "), WEST);
|
||||
dummy.add(width = new JTextField(209+""), CENTER);
|
||||
dummy.add(new JLabel("px"),BorderLayout.EAST);
|
||||
add(dummy);
|
||||
|
||||
@@ -182,8 +176,8 @@ public class Toolbar extends JPanel {
|
||||
dummy.setLayout(new BorderLayout());
|
||||
dummy.setMaximumSize(new Dimension(600, 40));
|
||||
|
||||
dummy.add(new JLabel(t("Height")+": "),BorderLayout.WEST);
|
||||
dummy.add(height = new JTextField(297+""),BorderLayout.CENTER);
|
||||
dummy.add(new JLabel(t("Height")+": "), WEST);
|
||||
dummy.add(height = new JTextField(297+""), CENTER);
|
||||
dummy.add(new JLabel("px"),BorderLayout.EAST);
|
||||
add(dummy);
|
||||
|
||||
@@ -294,7 +288,11 @@ public class Toolbar extends JPanel {
|
||||
public Date getDate() {
|
||||
return date.getSelectedDate();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean getImproveBrightness(){
|
||||
return improveBrightness;
|
||||
}
|
||||
/**
|
||||
* get resolution (set by resoultion form)
|
||||
* @return
|
||||
@@ -317,6 +315,23 @@ public class Toolbar extends JPanel {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set of checkboxes for adjustments
|
||||
* @return
|
||||
*/
|
||||
private JPanel improveSelector() {
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
JPanel adjustmentSelector = new JPanel(new BorderLayout());
|
||||
adjustmentSelector.add(new JLabel(t("Adjustments")), NORTH);
|
||||
var checkbox = new JCheckBox(t("Improve brightness"));
|
||||
adjustmentSelector.add(checkbox,WEST);
|
||||
adjustmentSelector.setMaximumSize(new Dimension(600,200));
|
||||
checkbox.addActionListener(e -> {
|
||||
improveBrightness = checkbox.isSelected();
|
||||
});
|
||||
return adjustmentSelector;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a labeled input field
|
||||
@@ -381,9 +396,9 @@ public class Toolbar extends JPanel {
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
JPanel resolutionSelector = new JPanel(new BorderLayout());
|
||||
JLabel label = new JLabel(t("current resolution")+": "+resolution+"px");
|
||||
resolutionSelector.add(label, BorderLayout.NORTH);
|
||||
resolutionSelector.add(resolutionButton(group,label,150),BorderLayout.WEST);
|
||||
resolutionSelector.add(resolutionButton(group,label,300),BorderLayout.CENTER);
|
||||
resolutionSelector.add(label, NORTH);
|
||||
resolutionSelector.add(resolutionButton(group,label,150), WEST);
|
||||
resolutionSelector.add(resolutionButton(group,label,300), CENTER);
|
||||
resolutionSelector.add(resolutionButton(group,label,600),BorderLayout.EAST);
|
||||
resolutionSelector.setMaximumSize(new Dimension(600,200));
|
||||
return resolutionSelector;
|
||||
@@ -433,9 +448,9 @@ public class Toolbar extends JPanel {
|
||||
JPanel typeSelector = new JPanel(new BorderLayout());
|
||||
JLabel label = new JLabel(t("Target type"));
|
||||
String target = config.getOrCreate(CONFIG_TARGET, PDF);
|
||||
typeSelector.add(label, BorderLayout.NORTH);
|
||||
typeSelector.add(typeButton(group,t(JPG),target),BorderLayout.WEST);
|
||||
typeSelector.add(typeButton(group,t(PDF),target),BorderLayout.CENTER);
|
||||
typeSelector.add(label, NORTH);
|
||||
typeSelector.add(typeButton(group,t(JPG),target), WEST);
|
||||
typeSelector.add(typeButton(group,t(PDF),target), CENTER);
|
||||
typeSelector.add(typeButton(group,t(OCR),target),BorderLayout.EAST);
|
||||
typeSelector.setMaximumSize(new Dimension(600,200));
|
||||
return typeSelector;
|
||||
|
||||
Reference in New Issue
Block a user