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.

The shelf's film samples on every camera, no-darkroom builds included

Claude3706d108394f
diff --git a/docs/MANUAL.th.md b/docs/MANUAL.th.md
index 3ad17a6..dc60a1e 100644
--- a/docs/MANUAL.th.md
+++ b/docs/MANUAL.th.md
@@ -37,7 +37,7 @@
แบบเดียวกับที่ Darkrooms บนคอมใช้ (`tools/genfilms.py`) กล้องจึงไม่ต้องสร้างเอง
- รูปตัวอย่าง (PLAY บนชั้นวาง): รูปเดียว (`ml-dev/films/sample/SAMPLE.CR2`) ล้างด้วยทุกฟิล์มตอน build
ด้วยตัวล้างและตารางสีเดียวกับในกล้อง ได้ `ML/SAMPLES/Fnnn.BMP` (ฟิล์มละไฟล์ ราว 26 MB ทั้งหมด)
- ตอนนี้มีเฉพาะ build ของ EOS M เปลี่ยนรูปได้โดยวาง CR2 จาก EOS M ไฟล์ใหม่แทนแล้ว build ใหม่
+ ทุกรุ่นได้ชุดเดียวกัน (รวม build ที่ไม่มีห้องมืด) เปลี่ยนรูปได้โดยวาง CR2 จาก EOS M ไฟล์ใหม่แทนแล้ว build ใหม่
### สนับสนุน
System > Support M·FILM แสดง QR code ของลิงก์โดเนท (สูงสุด 2 อัน) ใส่ลิงก์ใน `ml-dev/donate.txt`
diff --git a/ml-dev/build_fork.sh b/ml-dev/build_fork.sh
index bf134d0..34cd128 100644
--- a/ml-dev/build_fork.sh
+++ b/ml-dev/build_fork.sh
@@ -76,30 +76,31 @@ python3 "$F/tools/genfilms.py" "$OUT/ML/data/FOSFILMS.BIN"
python3 -c "import segno" 2>/dev/null || pip install -q segno
python3 "$F/tools/genqr.py" "$HERE/donate.txt" "$OUT/ML/data/FOSQR.BIN"
-# with no darkroom, nothing below is used: the card is done
-if [ -n "$NODARK" ]; then
- echo "== card files in $OUT (no darkroom) =="
- (cd "$OUT" && find . -maxdepth 3 | sort | head -60)
- exit 0
-fi
-
# every film's colour table, so the darkroom never spends its first
# develop of a film mixing one (the camera checks they match its looks):
# mixed from the look, then baked from the film's LUT where it has one
# (films/getluts.py fetches the Film-Luts ones; your own go in films/luts/)
[ -d "$HERE/films/luts/filmluts" ] || python3 "$HERE/films/getluts.py"
gcc -O2 -std=gnu99 -DFOS_DEV_TEST -I"$F" -o "$HOME/ml/devtest" "$F"/sim/devtest.c "$F"/sim/port_files.c \
- "$F"/sim/films.c "$F"/fos_dev.c "$F"/fos_looks.c "$F"/fos_film.c "$F"/fos_gfx.c "$F"/fos_jpeg.c -lm
+ "$F"/sim/films.c "$F"/fos_dev.c "$F"/fos_print.c "$F"/fos_looks.c "$F"/fos_film.c "$F"/fos_gfx.c "$F"/fos_jpeg.c -lm
mkdir -p "$OUT/ML/DARKROOM"
FOS_FILMS="$OUT/ML/data/FOSFILMS.BIN" "$HOME/ml/devtest" -T "$OUT/ML/DARKROOM"
python3 "$F/tools/genfilms.py" "$OUT/ML/data/FOSFILMS.BIN" --tables "$OUT/ML/DARKROOM"
# the shelf's samples (PLAY on the shelf): one photo developed with every
-# film, with the tables above, as the camera's darkroom would. EOS M only for now.
-if [ "$PLAT" = "EOSM.202" ]; then
- mkdir -p "$OUT/ML/SAMPLES"
- FOS_FILMS="$OUT/ML/data/FOSFILMS.BIN" FOS_LUT_DIR="$OUT/ML/DARKROOM" \
- "$HOME/ml/devtest" -S "$HERE/films/sample/SAMPLE.CR2" "$OUT/ML/SAMPLES"
+# film, with the tables above, as the camera's darkroom would. The prints
+# don't depend on the camera, so every camera gets the same ones.
+mkdir -p "$OUT/ML/SAMPLES"
+FOS_FILMS="$OUT/ML/data/FOSFILMS.BIN" FOS_LUT_DIR="$OUT/ML/DARKROOM" \
+ "$HOME/ml/devtest" -S "$HERE/films/sample/SAMPLE.CR2" "$OUT/ML/SAMPLES"
+
+# with no darkroom, the colour tables were only for the samples: the card is done
+if [ -n "$NODARK" ]; then
+ rm -rf "$OUT/ML/DARKROOM"
+ python3 "$F/tools/genfilms.py" "$OUT/ML/data/FOSFILMS.BIN"
+ echo "== card files in $OUT (no darkroom) =="
+ (cd "$OUT" && find . -maxdepth 3 | sort | head -60)
+ exit 0
fi
echo "== card files in $OUT =="
(cd "$OUT" && find . -maxdepth 3 | sort | head -60)
diff --git a/ml-dev/filmos/fos_dev.c b/ml-dev/filmos/fos_dev.c
index e6b0350..b57aa84 100644
--- a/ml-dev/filmos/fos_dev.c
+++ b/ml-dev/filmos/fos_dev.c
@@ -1403,26 +1403,15 @@ static __attribute__((noinline)) int nearest(struct fos_dev *d, int cell)
/* ---------------------------------------------------------------- files */
-/* A print is an 8-bit BMP, so it also opens on a PC: the file and info
- * headers, 256 palette entries (1..240 the print's), our own header with
- * the frame's details, the pixels top row first, then the thumbnail. */
-#define BMP_PAL (14 + 40)
-#define BMP_META (BMP_PAL + 256 * 4)
-#define META_SIZE 64
-#define BMP_PIXELS (BMP_META + META_SIZE)
-#define BMP_THUMB (BMP_PIXELS + FOS_PRINT_W * FOS_PRINT_H)
-#define THUMB_SIZE (FOS_THUMB_W * FOS_THUMB_H * 3)
-#define BMP_SIZE (BMP_THUMB + THUMB_SIZE)
-
static int write_print(const char *path, int film, int frame, const char *when, const char *fstop,
const uint8_t pal[][3], int npal, const uint8_t *px, const uint8_t *thumb, int x0, int w)
{
- static uint8_t h[BMP_PIXELS];
+ static uint8_t h[FOS_BMP_PIXELS];
memset(h, 0, sizeof(h));
h[0] = 'B'; h[1] = 'M';
- put32(h + 2, BMP_SIZE);
- put32(h + 10, BMP_PIXELS);
+ put32(h + 2, FOS_BMP_SIZE);
+ put32(h + 10, FOS_BMP_PIXELS);
put32(h + 14, 40);
put32(h + 18, FOS_PRINT_W);
put32(h + 22, (uint32_t) -FOS_PRINT_H); /* top-down */
@@ -1432,10 +1421,10 @@ static int write_print(const char *path, int film, int frame, const char *when,
put32(h + 46, 256);
for (int i = 0; i < npal && i < FOS_PRINT_COLOURS; i++)
{
- uint8_t *q = h + BMP_PAL + 4 * (i + 1);
+ uint8_t *q = h + FOS_BMP_PAL + 4 * (i + 1);
q[0] = pal[i][2]; q[1] = pal[i][1]; q[2] = pal[i][0];
}
- uint8_t *m = h + BMP_META;
+ uint8_t *m = h + FOS_BMP_META;
memcpy(m, "FOP2", 4);
m[4] = (uint8_t) film;
m[6] = (uint8_t) frame; m[7] = (uint8_t) (frame >> 8);
@@ -1446,66 +1435,13 @@ static int write_print(const char *path, int film, int frame, const char *when,
void *f = fos_port_open(path, 1);
if (!f) return 0;
- int ok = fos_port_write(f, h, BMP_PIXELS) == BMP_PIXELS
+ int ok = fos_port_write(f, h, FOS_BMP_PIXELS) == FOS_BMP_PIXELS
&& fos_port_write(f, px, FOS_PRINT_W * FOS_PRINT_H) == FOS_PRINT_W * FOS_PRINT_H
- && fos_port_write(f, thumb, THUMB_SIZE) == THUMB_SIZE;
- fos_port_close(f);
- return ok;
-}
-
-static int is_print(const uint8_t *h)
-{
- return h[0] == 'B' && h[1] == 'M' && u32le(h + 10) == BMP_PIXELS && u32le(h + 18) == FOS_PRINT_W
- && !memcmp(h + BMP_META, "FOP2", 4);
-}
-
-int fos_print_thumb(const char *path, uint8_t *thumb)
-{
- void *f = fos_port_open(path, 0);
- if (!f) return 0;
- static uint8_t h[BMP_PIXELS];
- int ok = fos_port_read(f, h, BMP_PIXELS) == BMP_PIXELS && is_print(h)
- && fos_port_seek(f, BMP_THUMB) >= 0 && fos_port_read(f, thumb, THUMB_SIZE) == THUMB_SIZE;
- fos_port_close(f);
- return ok;
-}
-
-int fos_print_load(const char *path, struct fos_print *p)
-{
- memset(p, 0, sizeof(*p));
- void *f = fos_port_open(path, 0);
- if (!f) return 0;
- static uint8_t h[BMP_PIXELS];
- int ok = fos_port_read(f, h, BMP_PIXELS) == BMP_PIXELS && is_print(h);
- if (ok)
- {
- const uint8_t *m = h + BMP_META;
- p->film = m[4];
- p->frame = u16le(m + 6);
- memcpy(p->when, m + 8, 19);
- memcpy(p->fstop, m + 28, 7);
- p->x0 = u16le(m + 36);
- p->w = u16le(m + 38);
- if (!p->w || p->x0 + p->w > FOS_PRINT_W) p->x0 = 0, p->w = FOS_PRINT_W;
- for (int i = 0; i < FOS_PRINT_COLOURS; i++)
- {
- const uint8_t *q = h + BMP_PAL + 4 * (i + 1);
- p->pal[i][0] = q[2]; p->pal[i][1] = q[1]; p->pal[i][2] = q[0];
- }
- p->px = fos_port_alloc(FOS_PRINT_W * FOS_PRINT_H);
- ok = p->px && fos_port_read(f, p->px, FOS_PRINT_W * FOS_PRINT_H) == FOS_PRINT_W * FOS_PRINT_H;
- }
+ && fos_port_write(f, thumb, FOS_THUMB_SIZE) == FOS_THUMB_SIZE;
fos_port_close(f);
- if (!ok) fos_print_free(p);
return ok;
}
-void fos_print_free(struct fos_print *p)
-{
- fos_port_free(p->px);
- p->px = 0;
-}
-
/* ---------------------------------------------------------------- quantize an RGB print */
/* histogram, palette, error diffusion: rows y0..y1-1 of the dithering per
diff --git a/ml-dev/filmos/fos_dev.h b/ml-dev/filmos/fos_dev.h
index 6393835..9403bf9 100644
--- a/ml-dev/filmos/fos_dev.h
+++ b/ml-dev/filmos/fos_dev.h
@@ -66,6 +66,18 @@ enum { PX_BLACK = FOS_FIXED_BASE, PX_PANEL, PX_G1, PX_G2, PX_G3, PX_G4, PX_G5, P
PX_AMBER, PX_AMBER2, PX_RED, PX_LINE, PX_DIM, PX_SPARE };
extern const uint8_t fos_fixed_rgb[FOS_FIXED_N][3];
+/* A print is an 8-bit BMP, so it also opens on a PC: the file and info
+ * headers, 256 palette entries (1..240 the print's), our own header with
+ * the frame's details, the pixels top row first, then the thumbnail. */
+#define FOS_BMP_PAL (14 + 40)
+#define FOS_BMP_META (FOS_BMP_PAL + 256 * 4)
+#define FOS_META_SIZE 64
+#define FOS_BMP_PIXELS (FOS_BMP_META + FOS_META_SIZE)
+#define FOS_BMP_THUMB (FOS_BMP_PIXELS + FOS_PRINT_W * FOS_PRINT_H)
+#define FOS_THUMB_SIZE (FOS_THUMB_W * FOS_THUMB_H * 3)
+#define FOS_BMP_SIZE (FOS_BMP_THUMB + FOS_THUMB_SIZE)
+
+/* in fos_print.c, which every build has (the shelf's samples are prints too) */
int fos_print_load(const char *path, struct fos_print *p); /* allocates p->px; 0 on failure */
void fos_print_free(struct fos_print *p);
int fos_print_thumb(const char *path, uint8_t *thumb); /* FOS_THUMB_W x FOS_THUMB_H RGB */
diff --git a/ml-dev/filmos/fos_nodark.c b/ml-dev/filmos/fos_nodark.c
index c84a054..595b475 100644
--- a/ml-dev/filmos/fos_nodark.c
+++ b/ml-dev/filmos/fos_nodark.c
@@ -4,7 +4,7 @@
* (fos_dark.c, fos_dev.c, fos_lab.c, fos_looks.c, fos_jpeg.c: about 60 KB).
* Built with build_fork.sh --no-darkroom, those are replaced by this: the
* Darkroom and Prints screens say where the rolls are developed instead
- * (Darkrooms, on a computer), and the shelf has no sample prints.
+ * (Darkrooms, on a computer). The shelf's samples still show (fos_print.c).
*/
#include "fos_ui.h"
@@ -59,7 +59,3 @@ void prints_leave() {}
void prints_key(int k) { nd_key(k); }
int prints_update(int dt) { return 0; }
void prints_draw() { nd_draw(); }
-
-/* the shelf's sample prints are made by the darkroom's code */
-int fos_print_load(const char *path, struct fos_print *p) { return 0; }
-void fos_print_free(struct fos_print *p) {}
diff --git a/ml-dev/filmos/fos_print.c b/ml-dev/filmos/fos_print.c
new file mode 100644
index 0000000..38c5d50
--- /dev/null
+++ b/ml-dev/filmos/fos_print.c
@@ -0,0 +1,65 @@
+/* fos_print: reading a print (the BMP the darkroom writes, fos_dev.c).
+ *
+ * Kept apart from the darkroom so every build can show prints: the shelf's
+ * sample of each film is one, also in builds made --no-darkroom.
+ */
+
+#include "fos.h"
+#include "fos_dev.h"
+#include <string.h>
+
+static int u16le(const uint8_t *p) { return p[0] | p[1] << 8; }
+static unsigned u32le(const uint8_t *p) { return p[0] | p[1] << 8 | p[2] << 16 | (unsigned) p[3] << 24; }
+
+static int is_print(const uint8_t *h)
+{
+ return h[0] == 'B' && h[1] == 'M' && u32le(h + 10) == FOS_BMP_PIXELS && u32le(h + 18) == FOS_PRINT_W
+ && !memcmp(h + FOS_BMP_META, "FOP2", 4);
+}
+
+int fos_print_thumb(const char *path, uint8_t *thumb)
+{
+ void *f = fos_port_open(path, 0);
+ if (!f) return 0;
+ static uint8_t h[FOS_BMP_PIXELS];
+ int ok = fos_port_read(f, h, FOS_BMP_PIXELS) == FOS_BMP_PIXELS && is_print(h)
+ && fos_port_seek(f, FOS_BMP_THUMB) >= 0 && fos_port_read(f, thumb, FOS_THUMB_SIZE) == FOS_THUMB_SIZE;
+ fos_port_close(f);
+ return ok;
+}
+
+int fos_print_load(const char *path, struct fos_print *p)
+{
+ memset(p, 0, sizeof(*p));
+ void *f = fos_port_open(path, 0);
+ if (!f) return 0;
+ static uint8_t h[FOS_BMP_PIXELS];
+ int ok = fos_port_read(f, h, FOS_BMP_PIXELS) == FOS_BMP_PIXELS && is_print(h);
+ if (ok)
+ {
+ const uint8_t *m = h + FOS_BMP_META;
+ p->film = m[4];
+ p->frame = u16le(m + 6);
+ memcpy(p->when, m + 8, 19);
+ memcpy(p->fstop, m + 28, 7);
+ p->x0 = u16le(m + 36);
+ p->w = u16le(m + 38);
+ if (!p->w || p->x0 + p->w > FOS_PRINT_W) p->x0 = 0, p->w = FOS_PRINT_W;
+ for (int i = 0; i < FOS_PRINT_COLOURS; i++)
+ {
+ const uint8_t *q = h + FOS_BMP_PAL + 4 * (i + 1);
+ p->pal[i][0] = q[2]; p->pal[i][1] = q[1]; p->pal[i][2] = q[0];
+ }
+ p->px = fos_port_alloc(FOS_PRINT_W * FOS_PRINT_H);
+ ok = p->px && fos_port_read(f, p->px, FOS_PRINT_W * FOS_PRINT_H) == FOS_PRINT_W * FOS_PRINT_H;
+ }
+ fos_port_close(f);
+ if (!ok) fos_print_free(p);
+ return ok;
+}
+
+void fos_print_free(struct fos_print *p)
+{
+ fos_port_free(p->px);
+ p->px = 0;
+}
diff --git a/ml-dev/filmos/sim/Makefile b/ml-dev/filmos/sim/Makefile
index 147d78e..6660afe 100644
--- a/ml-dev/filmos/sim/Makefile
+++ b/ml-dev/filmos/sim/Makefile
@@ -1,5 +1,5 @@
# film OS simulator: make && ./out/sim scenes/shelf.txt out/frames/shelf
-SRC = sim.c port_files.c fonts.c films.c ../fos_gfx.c ../fos_film.c ../fos_ui.c ../fos_shelf.c ../fos_pages.c ../fos_hud.c \
+SRC = sim.c port_files.c fonts.c films.c ../fos_gfx.c ../fos_film.c ../fos_ui.c ../fos_shelf.c ../fos_pages.c ../fos_hud.c ../fos_print.c \
../fos_dark.c ../fos_dev.c ../fos_lab.c ../fos_looks.c ../fos_jpeg.c
CFLAGS = -O2 -g -Wall -Wextra -Wno-unused-parameter -Wdouble-promotion -std=gnu99
# M-Film's version, as the camera build gets it (VERSION at the top of the repository)
@@ -25,7 +25,7 @@ clean:
rm -rf out
# developing film: ./out/devtest [-f film] [-r raw.u16] in.CR2 out.FOP out.ppm
-DEV = devtest.c port_files.c films.c ../fos_dev.c ../fos_looks.c ../fos_film.c ../fos_gfx.c ../fos_jpeg.c
+DEV = devtest.c port_files.c films.c ../fos_dev.c ../fos_print.c ../fos_looks.c ../fos_film.c ../fos_gfx.c ../fos_jpeg.c
out/devtest: $(DEV) ../*.h out/FOSFILMS.BIN
mkdir -p out
$(CC) $(CFLAGS) -DFOS_DEV_TEST -o $@ $(DEV) -lm
diff --git a/ml-dev/fork/apply_fork.py b/ml-dev/fork/apply_fork.py
index dc47e5a..e12d265 100644
--- a/ml-dev/fork/apply_fork.py
+++ b/ml-dev/fork/apply_fork.py
@@ -111,7 +111,7 @@ def platform(name):
# our objects. Rewritten every time (older versions of this fork
# listed only filmroll.o), so the list always matches the sources.
# (no fos_font: the fonts go on the card as ML/DATA/FOSFONT.BIN, see fos_gfx.h)
- FOS_OBJS = ["filmroll", "fos_gfx", "fos_film", "fos_ui", "fos_shelf", "fos_pages", "fos_hud"]
+ FOS_OBJS = ["filmroll", "fos_gfx", "fos_film", "fos_ui", "fos_shelf", "fos_pages", "fos_hud", "fos_print"]
FOS_OBJS += ["fos_nodark"] if NO_DARKROOM else ["fos_dark", "fos_dev", "fos_lab", "fos_looks", "fos_jpeg"]
p = root / f"platform/{name}/Makefile"
lines = p.read_text().split("\n")