Skip to content

M-Film: film simulation for Canon EOS cameras with Magic Lantern. 72 film stocks (Portra, Velvia, Tri-X, CineStill…), a film-camera interface and an in-camera darkroom that develops your RAWs. 5D Mark III, 6D, 600D, 650D, 700D, EOS M and more.

Reports from testers: the 5D Mark II's empty darkroom, the film in the JPEG's keywords, the ARM read check

Clauded34776f0c615
diff --git a/README.md b/README.md
index f1040fd..169bc4b 100644
--- a/README.md
+++ b/README.md
@@ -177,6 +177,9 @@ The camera's own darkroom stays free and unlimited. Buy Darkrooms Full in the pr
### Download
+> **Not released yet.** Darkrooms comes out together with Darkrooms Full; until then the files below
+> aren't in the releases. The camera's own darkroom develops your rolls in the meantime.
+
| Your computer | Get | Open it |
|---|---|---|
| **Windows 10 / 11** | `Darkrooms-windows-x64.zip` | Unzip, run `Darkrooms.exe`. If Windows warns: *More info* → *Run anyway*. |
diff --git a/README.th.md b/README.th.md
index 4a7aeef..cd5838c 100644
--- a/README.th.md
+++ b/README.th.md
@@ -174,6 +174,9 @@ M-Film ทำบน EOS M และใช้ได้จริงบนรุ่
### ดาวน์โหลด
+> **ยังไม่ได้ปล่อย** Darkrooms จะออกพร้อม Darkrooms Full ระหว่างนี้ยังไม่มีไฟล์ด้านล่างใน release
+> ล้างม้วนด้วยห้องมืดในกล้องไปก่อนได้
+
| คอมของคุณ | ไฟล์ | เปิดยังไง |
|---|---|---|
| **Windows 10 / 11** | `Darkrooms-windows-x64.zip` | แตกไฟล์ แล้วเปิด `Darkrooms.exe` ถ้า Windows เตือน: *More info* → *Run anyway* |
diff --git a/ml-dev/filmos/fos_dev.c b/ml-dev/filmos/fos_dev.c
index b57aa84..32ea8d3 100644
--- a/ml-dev/filmos/fos_dev.c
+++ b/ml-dev/filmos/fos_dev.c
@@ -819,6 +819,20 @@ static int slow_symbol(const struct huff *h, uint32_t bitbuf, int vbits)
}
typedef uint32_t __attribute__((may_alias)) word;
+#ifdef FOS_ARM_UNALIGNED
+/* devtest -DFOS_ARM_UNALIGNED: a word load the way ARMv5 does one off its
+ * boundary (the aligned word, rotated), to find reads the PC gets right by luck */
+static uint32_t arm_load(const word *p)
+{
+ uintptr_t a = (uintptr_t) p;
+ uint32_t v = *(const word *) (a & ~(uintptr_t) 3);
+ int r = (int) (a & 3) * 8;
+ return r ? v >> r | v << (32 - r) : v;
+}
+#define LOADW(q, i) arm_load((q) + (i))
+#else
+#define LOADW(q, i) ((q)[i])
+#endif
/* a byte of w is 0xFF: a zero byte of ~w, (~w - 0x01010101) & w & 0x80808080,
* and ~w - k is ~(w + k) */
@@ -1061,10 +1075,10 @@ static __attribute__((noinline)) void sum_row(const uint16_t *v, const uint8_t *
uint32_t w = 0;
switch (k & 7)
{
- case 4: w += q[3]; /* fall through */
- case 3: w += q[2]; /* fall through */
- case 2: w += q[1]; /* fall through */
- case 1: w += q[0]; /* fall through */
+ case 4: w += LOADW(q, 3); /* fall through */
+ case 3: w += LOADW(q, 2); /* fall through */
+ case 2: w += LOADW(q, 1); /* fall through */
+ case 1: w += LOADW(q, 0); /* fall through */
default: break;
}
v += 2 * (k & 7);
diff --git a/ml-dev/filmos/fos_jpeg.c b/ml-dev/filmos/fos_jpeg.c
index a46bf4e..a2ec300 100644
--- a/ml-dev/filmos/fos_jpeg.c
+++ b/ml-dev/filmos/fos_jpeg.c
@@ -192,6 +192,33 @@ static void block(struct jw *w, int32_t *d, int t, int *dc_prev)
/* a tiny TIFF: IFD0 (description, make, model, software, date) and the
* EXIF IFD (date taken, f-number) */
+/* text for XML: the few characters that can't stand as they are */
+static int xml_text(char *out, int size, const char *s)
+{
+ int n = 0;
+ for (; *s && n < size - 6; s++)
+ {
+ const char *e = *s == '&' ? "&amp;" : *s == '<' ? "&lt;" : *s == '>' ? "&gt;" : 0;
+ if (e) { int l = (int) strlen(e); memcpy(out + n, e, l); n += l; }
+ else out[n++] = *s;
+ }
+ out[n] = 0;
+ return n;
+}
+
+static int xmp(char *out, int size, const char *film)
+{
+ char f[160];
+ xml_text(f, sizeof(f), film);
+ int n = snprintf(out, size,
+ "<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"><rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">"
+ "<rdf:Description rdf:about=\"\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">"
+ "<dc:description><rdf:Alt><rdf:li xml:lang=\"x-default\">%s</rdf:li></rdf:Alt></dc:description>"
+ "<dc:subject><rdf:Bag><rdf:li>%s</rdf:li><rdf:li>M-Film</rdf:li><rdf:li>film simulation</rdf:li></rdf:Bag></dc:subject>"
+ "</rdf:Description></rdf:RDF></x:xmpmeta>", f, f);
+ return n < size ? n : size - 1;
+}
+
static int exif(uint8_t *out, const struct fos_jpeg_meta *m)
{
char date[20] = "";
@@ -290,6 +317,18 @@ int fos_jpeg_write(const char *path, const uint8_t *rgb, int stride, int width,
static const uint8_t tag[6] = { 'E', 'x', 'i', 'f', 0, 0 };
for (int i = 0; i < 6; i++) put8(w, tag[i]);
for (int i = 0; i < n; i++) put8(w, ex[i]);
+ /* XMP: the film as the caption and as keywords, where photo apps
+ * (Lightroom, Photos, Bridge) look for them; EXIF's ImageDescription
+ * above is the same caption for the ones that read only EXIF */
+ if (meta->desc && *meta->desc)
+ {
+ static char x[1024];
+ int k = xmp(x, sizeof(x), meta->desc);
+ static const char ns[] = "http://ns.adobe.com/xap/1.0/";
+ put16(w, 0xFFE1); put16(w, 2 + (int) sizeof(ns) + k);
+ for (int i = 0; i < (int) sizeof(ns); i++) put8(w, (uint8_t) ns[i]); /* with its 0 */
+ for (int i = 0; i < k; i++) put8(w, (uint8_t) x[i]);
+ }
}
/* quantisation, frame, Huffman tables */
for (int t = 0; t < 2; t++)
diff --git a/ml-dev/filmos/fos_lab.c b/ml-dev/filmos/fos_lab.c
index b6a5312..7ce3a18 100644
--- a/ml-dev/filmos/fos_lab.c
+++ b/ml-dev/filmos/fos_lab.c
@@ -119,6 +119,12 @@ static void read_log(const char *path, const struct log_reader *r)
void *f = fos_port_open(path, 0);
int n = f ? fos_port_read(f, buf, LOG_MAX) : 0;
if (f) fos_port_close(f);
+ if (n <= 0)
+ {
+ char msg[96];
+ snprintf(msg, sizeof(msg), "lab: can't read %s (%s)", path, f ? "read failed" : "can't open");
+ fos_port_log(msg);
+ }
buf[n > 0 ? n : 0] = 0;
for (char *line = buf; *line; )
{
diff --git a/ml-dev/filmos/sim/Makefile b/ml-dev/filmos/sim/Makefile
index 6660afe..32c3f14 100644
--- a/ml-dev/filmos/sim/Makefile
+++ b/ml-dev/filmos/sim/Makefile
@@ -29,3 +29,9 @@ DEV = devtest.c port_files.c films.c ../fos_dev.c ../fos_print.c ../fos_looks.c
out/devtest: $(DEV) ../*.h out/FOSFILMS.BIN
mkdir -p out
$(CC) $(CFLAGS) -DFOS_DEV_TEST -o $@ $(DEV) -lm
+
+# the same, loading words off their boundary the way the camera's ARM does (rotated):
+# a print that differs from out/devtest's has a read the camera gets wrong (lines, #6)
+out/devtest-arm: $(DEV) ../*.h out/FOSFILMS.BIN
+ mkdir -p out
+ $(CC) $(CFLAGS) -DFOS_DEV_TEST -DFOS_ARM_UNALIGNED -o $@ $(DEV) -lm
diff --git a/ml-dev/fork/src/filmroll.c b/ml-dev/fork/src/filmroll.c
index 71944fe..77741e1 100644
--- a/ml-dev/fork/src/filmroll.c
+++ b/ml-dev/fork/src/filmroll.c
@@ -721,20 +721,33 @@ void *fos_port_open(const char *path, int write)
}
/* Canon reads files by DMA: into memory the CPU caches, it goes through
- * an uncached buffer */
+ * an uncached buffer. Taken at start (card_buffer), while there is memory
+ * for it: on a 5D Mark II, asked for only when the darkroom first read a
+ * roll's log, it wasn't there, and every read came back empty (#10). */
#define BOUNCE (64 * 1024)
+static uint8_t *bounce = 0;
+static int bounce_size = 0;
+
+static int card_buffer()
+{
+ for (int size = BOUNCE; !bounce && size >= 4096; size /= 4)
+ {
+ bounce = fio_malloc(size);
+ if (bounce) bounce_size = size;
+ else dbg("read: no %d-byte buffer for card reads", size);
+ }
+ return bounce != 0;
+}
int fos_port_read(void *f, void *buf, int size)
{
if (buf != CACHEABLE(buf))
return FIO_ReadFile(f, buf, size);
- static uint8_t *bounce = 0;
- if (!bounce) bounce = fio_malloc(BOUNCE);
- if (!bounce) return -1;
+ if (!card_buffer()) return -1;
int done = 0;
while (done < size)
{
- int n = MIN(size - done, BOUNCE);
+ int n = MIN(size - done, bounce_size);
int got = FIO_ReadFile(f, UNCACHEABLE(bounce), n);
if (got <= 0) break;
memcpy((uint8_t *) buf + done, UNCACHEABLE(bounce), got);
@@ -1351,6 +1364,7 @@ static void filmroll_task()
load_fonts();
load_films();
+ dbg("read: %s", card_buffer() ? "card buffer ready" : "no card buffer: the darkroom can't read the card");
startup_task();
film_capture_check();