Use calibration for preview
This commit is contained in:
62
src/dcp.c
62
src/dcp.c
@@ -1,8 +1,10 @@
|
||||
#include "dcp.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
unsigned int
|
||||
get_int32(const unsigned char *buffer, size_t offset)
|
||||
@@ -147,3 +149,63 @@ parse_calibration_file(const char *path)
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool
|
||||
find_calibration_by_model(char *conffile, char *model, const char *sensor)
|
||||
{
|
||||
// Check config/%model,%sensor.dcp in the current working directory
|
||||
sprintf(conffile, "config/%s,%s.dcp", model, sensor);
|
||||
if (access(conffile, F_OK) != -1) {
|
||||
printf("Found calibration file at %s\n", conffile);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check user overridden /etc/megapixels/config/%model,%sensor.dcp
|
||||
sprintf(conffile,
|
||||
"%s/megapixels/config/%s,%s.dcp",
|
||||
SYSCONFDIR,
|
||||
model,
|
||||
sensor);
|
||||
if (access(conffile, F_OK) != -1) {
|
||||
printf("Found calibration file at %s\n", conffile);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check packaged /usr/share/megapixels/config/%model,%sensor.ini
|
||||
sprintf(conffile, "%s/megapixels/config/%s,%s.dcp", DATADIR, model, sensor);
|
||||
if (access(conffile, F_OK) != -1) {
|
||||
printf("Found calibration file at %s\n", conffile);
|
||||
return true;
|
||||
}
|
||||
printf("No calibration found for %s,%s\n", model, sensor);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
find_calibration(char *conffile, const char *sensor)
|
||||
{
|
||||
char model[512];
|
||||
FILE *fp;
|
||||
|
||||
if (access("/proc/device-tree/compatible", F_OK) == -1) {
|
||||
return false;
|
||||
}
|
||||
fp = fopen("/proc/device-tree/compatible", "r");
|
||||
char *modelptr = model;
|
||||
while (1) {
|
||||
int c = fgetc(fp);
|
||||
if (c == EOF) {
|
||||
*(modelptr) = '\0';
|
||||
return find_calibration_by_model(conffile, model, sensor);
|
||||
}
|
||||
*(modelptr++) = (char)c;
|
||||
if (c == 0) {
|
||||
bool res =
|
||||
find_calibration_by_model(conffile, model, sensor);
|
||||
if (res) {
|
||||
return true;
|
||||
}
|
||||
modelptr = model;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user