1 package kaka.cakelight;
3 import org.opencv.imgproc.Imgproc;
5 import java.io.FileInputStream;
6 import java.io.IOException;
7 import java.io.InputStream;
9 import java.util.stream.Collectors;
11 public class Configuration {
12 private List<Map.Entry<String, String>> settings = new ArrayList<>();
13 public VideoConfiguration video;
14 public LedConfiguration leds;
16 private Configuration(Properties prop) {
17 video = new VideoConfiguration(prop);
18 leds = new LedConfiguration(prop);
21 public static Configuration from(String propertiesFile) {
22 InputStream input = null;
24 input = new FileInputStream(propertiesFile);
25 Properties prop = new Properties();
27 return new Configuration(prop);
28 } catch (IOException ex) {
34 } catch (IOException e) {
42 private String get(Properties prop, String name) {
43 return addSetting(name, prop.getProperty(name));
46 private String get(Properties prop, String name, String dflt) {
47 return addSetting(name, prop.getProperty(name, dflt));
50 private String addSetting(String name, String value) {
51 settings.add(new AbstractMap.SimpleEntry<>(name, value));
56 public String toString() {
57 return settings.stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.joining("\n"));
60 public class VideoConfiguration {
65 public CropConfiguration crop;
67 private VideoConfiguration(Properties prop) {
68 width = Integer.parseInt(get(prop, "video.width", "720"));
69 height = Integer.parseInt(get(prop, "video.height", "576"));
70 bpp = Integer.parseInt(get(prop, "video.bpp", "2"));
71 switch (get(prop, "video.format", "").toUpperCase()) {
73 format = Imgproc.COLOR_YUV2RGB_YUYV;
76 format = Imgproc.COLOR_YUV2RGB_YVYU;
79 format = Imgproc.COLOR_YUV2RGB_UYVY;
81 crop = new CropConfiguration(prop);
84 public class CropConfiguration {
85 public int left, right, top, bottom;
87 private CropConfiguration(Properties prop) {
88 left = Integer.parseInt(get(prop, "video.crop.left", "0"));
89 right = Integer.parseInt(get(prop, "video.crop.right", "0"));
90 top = Integer.parseInt(get(prop, "video.crop.top", "0"));
91 bottom = Integer.parseInt(get(prop, "video.crop.bottom", "0"));
96 public class LedConfiguration {
100 private LedConfiguration(Properties prop) {
101 cols = Integer.parseInt(get(prop, "leds.cols"));
102 rows = Integer.parseInt(get(prop, "leds.rows"));