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.
C analog-photographycamera-firmwarecanoncanon-5d-mark-ivcanon-5dmark2canon-6dcanon-eoscr2darkroomeos-mfilm-emulationfilm-lookfilm-photographyfilm-simulationfujifilm-recipeskodak-portralutmagic-lanternphotographyraw
Delete roll: what couldn't go stays deletable; a roll developed again keeps its folder (#65)
Claude87021b8bd9a2
diff --git a/docs/MANUAL.th.md b/docs/MANUAL.th.mdindex 0fbb11b..f6c1198 100644--- a/docs/MANUAL.th.md+++ b/docs/MANUAL.th.md@@ -105,7 +105,8 @@ System > Support M·FILM แสดง QR code ของลิงก์โดเหาไฟล์แบบเดียวกับตอนล้าง: ชื่อที่กล้องตั้งจริง (`_MG_` ใน Adobe RGB, prefix ที่ตั้งเอง), JPG ถ้าถ่ายเป็น JPEG,และทุกโฟลเดอร์ใน DCIM ที่ม้วนข้ามไปหลัง IMG_9999 ม้วนที่ไม่มีภาพเลยจะข้ามไปถามยืนยันลบทั้งม้วนเลย- ไม่ลบไฟล์ที่ log ไม่ได้ระบุ (เช่น JPEG ที่กล้องเขียนคู่กับ RAW ตอนตั้ง RAW+JPEG ยังอยู่) และไม่ลบม้วนที่อยู่ในกล้อง- - ลบไม่ได้ครบ กล้องจะบอกจำนวนที่เหลือ รายละเอียดอยู่ใน log บรรทัด `lab: ...` (เปิด Debug log ไว้)+ - ถ้าลบได้ไม่ครบ กล้องจะขึ้นว่า *Not all of it could be deleted* (รายละเอียดอยู่ใน log บรรทัด `lab: ...` ถ้าเปิด Debug log ไว้)+ ไฟล์ที่ลบไม่ได้ทำให้ log ของม้วน (และไฟล์ ROLLnnn.TXT ในโฟลเดอร์ JPEG) ยังอยู่ ม้วนจึงยังอยู่ในรายการ ลบซ้ำได้### สีบนจอสีของ Film OS ส่งไปที่จอแบบเดียวกับที่ Canon แปลงสีของตัวเอง (BT.601 Y'CbCr, ขาวที่ระดับ 235)diff --git a/ml-dev/filmos/fos_lab.c b/ml-dev/filmos/fos_lab.cindex fe946c7..e021386 100644--- a/ml-dev/filmos/fos_lab.c+++ b/ml-dev/filmos/fos_lab.c@@ -107,13 +107,12 @@ int fos_lab_dcim_dir(char *buf, int size, int roll, int film, const char *when)film = fos_clamp(film, 0, fos_nfilms - 1);const char *film_name = fos_films[film].shortname ? fos_films[film].shortname : fos_films[film].key;/* developed before: its folder, long or short (so a card without long- * names doesn't get the long one tried again each time) */+ * names doesn't get the long one tried again each time), whichever of+ * the day's names it has: another roll deleted since leaves a gap */for (int k = 0; k < DAY_NAMES; k++){day_dir(buf, size, k, m, d, film_name);- if (dir_exists(buf)) { if (tagged(buf, roll)) return 0; }- else if (k < DAY_LONG) k = DAY_LONG - 1;- else break;+ if (dir_exists(buf) && tagged(buf, roll)) return 0;}/* else the first free name */for (int k = 0; k < DAY_NAMES; k++)@@ -474,10 +473,12 @@ int fos_lab_frames(int roll, struct fos_lab_frame *frames, int max)/* ---------------------------------------------------------------- deleting a roll *//* A folder of ours: the roll's prints (ML/DARKROOM/Rnnn: Fnn.BMP, SHEET.BMP),- * or its folder in DCIM (IMG_0102.JPG and the tag, ROLL012.TXT). Those files- * go, and the folder once nothing else is in it: one with anything left is- * never removed. The names are taken first and removed after, not while the- * folder is read. How many couldn't be removed. */+ * or its folder in DCIM (IMG_0102.JPG and the roll's tag, ROLL012.TXT).+ * Those files go, the tag last and only once the rest has (a folder that+ * couldn't all go is still the roll's, to delete again), then the folder+ * once nothing else is in it: one with anything left is never removed. The+ * names are taken first and removed after, not while the folder is read.+ * How many files couldn't be removed; a folder that stays adds to *dirs. */#define SWEEP_MAX (FOS_MAX_FRAMES + 2)struct sweep { int n; char names[SWEEP_MAX][13]; };@@ -486,25 +487,28 @@ static int sweep_entry(void *ctx, const char *name, int is_dir)struct sweep *s = ctx;int len = (int) strlen(name);if (!is_dir && len >= 5 && len <= 12 && s->n < SWEEP_MAX- && (!strcmp(name + len - 4, ".BMP") || !strcmp(name + len - 4, ".JPG") || !strncmp(name, "ROLL", 4)))+ && (!strcmp(name + len - 4, ".BMP") || !strcmp(name + len - 4, ".JPG")))memcpy(s->names[s->n++], name, len + 1);return 1;}-static int sweep(const char *dir)+static int sweep(const char *dir, int roll, int *dirs){struct sweep s;s.n = 0;fos_port_list(dir, sweep_entry, &s);char path[160];int failed = 0;- for (int i = 0; i < s.n; i++)+ for (int i = 0; i <= s.n; i++){- snprintf(path, sizeof(path), "%s/%s", dir, s.names[i]);+ if (i < s.n) snprintf(path, sizeof(path), "%s/%s", dir, s.names[i]);+ else if (failed) break;+ else snprintf(path, sizeof(path), "%s/ROLL%03d.TXT", dir, roll); /* none in Rnnn: nothing to do */failed += remove_logged(path);}int left = fos_port_list(dir, first_only, 0); /* < 0: there was none */- return failed + (left ? left > 0 : remove_logged(dir));+ *dirs += left ? left > 0 : remove_logged(dir);+ return failed;}/* the roll's logs, one in each DCIM folder it ran into */@@ -528,21 +532,24 @@ int fos_lab_delete(int roll, int whole, struct fos_lab_frame *frames)char dcim[64];snprintf(dcim, sizeof(dcim), "%sDCIM", fos_port_card());fos_port_list(dcim, jpeg_folder, &js);- int failed = 0;- for (int i = 0; i < f.n; i++) failed += sweep(f.paths[i]);+ int failed = 0, dirs = 0;+ for (int i = 0; i < f.n; i++) failed += sweep(f.paths[i], roll, &dirs);if (whole){/* its frames, only those its logs list, by the names the darkroom* finds them by (Canon's _MG_ in Adobe RGB, a JPEG where it was* shot as one, each in its folder across IMG_9999); then the logs,- * last, so a roll that couldn't all go is still there to delete */+ * last and only once every file has gone (an empty folder that+ * stays doesn't count), so a roll that couldn't all go is still+ * there to delete again */int n = fos_lab_frames(roll, frames, FOS_MAX_FRAMES);for (int i = 0; i < n; i++)if (!frames[i].missing || frames[i].jpeg) failed += remove_logged(frames[i].cr2);f.n = 0;- each_log(logs_log, &f);+ if (!failed) each_log(logs_log, &f);for (int i = 0; i < f.n; i++) failed += remove_logged(f.paths[i]);}+ failed += dirs;char msg[64];snprintf(msg, sizeof(msg), "lab: roll %03d: deleted %s, %d left", roll, whole ? "all" : "prints", failed);fos_port_log(msg);diff --git a/ml-dev/filmos/sim/cardtest.sh b/ml-dev/filmos/sim/cardtest.shindex bf5efe7..649e220 100755--- a/ml-dev/filmos/sim/cardtest.sh+++ b/ml-dev/filmos/sim/cardtest.sh@@ -1,8 +1,10 @@#!/usr/bin/env bash# The darkroom on a card of problem rolls (mkcard.sh --problems): it develops# what it can, and says why it can't the rest; Delete roll takes exactly-# what it says; a card that can't take long folder names keeps no empty-# ones (#65). Fails if a line is missing or a file is wrong.+# what it says, and what it couldn't is still there to delete again; a card+# that can't take long folder names keeps no empty ones (#65); a roll+# developed again keeps its folder. Fails if a line is missing or a file is+# wrong.# make && ./cardtest.shset -euo pipefailcd "$(dirname "$0")"@@ -36,11 +38,12 @@ for f in 1 2 3 4; do expect "9999 wrap: frame $f developed" "roll 008 frame $f d# Delete roll, on the card just developed: the files that go are exactly# the ones listed, and nothing else changeslisting() { (cd "$1" && find . | grep -v '/LOOK[0-9]*\.LUT$' | sort); }-deletes() { # deletes <what> <scene> <path that goes>...+dcard=out/cardp+deletes() { # deletes <what> <scene> <path that goes>... (on $dcard)local what=$1 scene=$2; shift 2- listing out/cardp > out/del-before.txt- FOS_CARD=out/cardp/ ./out/sim "scenes/$scene.txt" - >> "$log" 2>&1- listing out/cardp > out/del-after.txt+ listing $dcard > out/del-before.txt+ FOS_CARD=$dcard/ ./out/sim "scenes/$scene.txt" - >> "$log" 2>&1+ listing $dcard > out/del-after.txtprintf '%s\n' "$@" | sed '/^$/d' | sort > out/del-want.txtcomm -23 out/del-before.txt out/del-after.txt > out/del-gone.txtcomm -13 out/del-before.txt out/del-after.txt > out/del-new.txt@@ -60,14 +63,21 @@ deletes "Delete roll: prints only" delete_prints \./ML/DARKROOM/R007 ./ML/DARKROOM/R007/F01.BMP ./ML/DARKROOM/R007/F03.BMP ./ML/DARKROOM/R007/F04.BMP \./ML/DARKROOM/R007/SHEET.BMPexpect "Delete roll: prints only, logged" "lab: roll 007: deleted prints, 0 left"-# the whole roll (008, across IMG_9999): its RAWs and logs in both DCIM folders, and its prints-deletes "Delete roll: whole roll across IMG_9999" delete_whole \- ./DCIM/100CANON/IMG_9998.CR2 ./DCIM/100CANON/IMG_9999.CR2 ./DCIM/100CANON/ROLL_008.TXT \- ./DCIM/101CANON/IMG_0001.CR2 ./DCIM/101CANON/IMG_0002.CR2 ./DCIM/101CANON/ROLL_008.TXT \- "./DCIM/Oct1003 Gold200" "./DCIM/Oct1003 Gold200/IMG_0001.JPG" "./DCIM/Oct1003 Gold200/IMG_0002.JPG" \- "./DCIM/Oct1003 Gold200/IMG_9998.JPG" "./DCIM/Oct1003 Gold200/IMG_9999.JPG" "./DCIM/Oct1003 Gold200/ROLL008.TXT" \+# the whole roll (008, across IMG_9999) where IMG_9999's RAW and its print+# in DCIM can't be removed: the rest of it goes; its logs and the print+# folder's tag stay, so it is still there to delete again+FOS_KEEP=IMG_9999 deletes "Delete roll: whole roll, files that can't go" delete_whole \+ ./DCIM/100CANON/IMG_9998.CR2 ./DCIM/101CANON/IMG_0001.CR2 ./DCIM/101CANON/IMG_0002.CR2 \+ "./DCIM/Oct1003 Gold200/IMG_0001.JPG" "./DCIM/Oct1003 Gold200/IMG_0002.JPG" "./DCIM/Oct1003 Gold200/IMG_9998.JPG" \./ML/DARKROOM/R008 ./ML/DARKROOM/R008/F01.BMP ./ML/DARKROOM/R008/F02.BMP ./ML/DARKROOM/R008/F03.BMP \./ML/DARKROOM/R008/F04.BMP ./ML/DARKROOM/R008/SHEET.BMP+expect "Delete roll: the RAW that can't go is said" "lab: can't remove out/cardp/DCIM/100CANON/IMG_9999.CR2"+expect "Delete roll: ... and counted" "lab: roll 008: deleted all, 3 left"+# deleted again: the rest of it, the print folder and its tag, the RAW and+# its logs in both DCIM folders+deletes "Delete roll: whole roll across IMG_9999, again" delete_whole \+ "./DCIM/Oct1003 Gold200" "./DCIM/Oct1003 Gold200/IMG_9999.JPG" "./DCIM/Oct1003 Gold200/ROLL008.TXT" \+ ./DCIM/100CANON/IMG_9999.CR2 ./DCIM/100CANON/ROLL_008.TXT ./DCIM/101CANON/ROLL_008.TXT# the roll in the camera (006 here): nothing goesdeletes "Delete roll: never the roll in the camera" delete_loaded ""# the whole roll (007) once its prints are gone: straight to "sure?"; Canon's _MG_ names@@ -78,7 +88,8 @@ deletes "Delete roll: whole roll shot as JPEG" delete_whole \./DCIM/100CANON/IMG_0501.JPG ./DCIM/100CANON/IMG_0502.JPG ./DCIM/100CANON/IMG_0503.JPG \./DCIM/100CANON/IMG_0504.JPG ./DCIM/100CANON/ROLL_006.TXT \"./DCIM/Oct1001 Portra400" "./DCIM/Oct1001 Portra400/ROLL006.TXT" ./ML/DARKROOM/R006 ./ML/DARKROOM/R006/SHEET.BMP-reject "Delete roll: nothing it couldn't" "lab: can't remove|isn't empty"+n=$(grep -c "lab: can't remove" "$log" || true)+[ "$n" = 2 ] && echo "ok Delete roll: nothing else it couldn't" || { echo "FAIL Delete roll: $n \"can't remove\" lines, not 2"; fail=1; }# A card that makes a long-named folder but can't write into it (a 550D's# exFAT card, #65): the prints go in SEP0906-style folders, and no empty@@ -97,5 +108,27 @@ CARD=out/cardl ./mkcard.sh --problems >/dev/nullfor i in 1 2; do FOS_CARD=out/cardl/ FOS_LONG_DIRS_EMPTY=1 FOS_NO_RMDIR=1 ./out/sim scenes/darkroom_problems.txt - >> "$log" 2>&1; donen=$(long_dirs out/cardl)[ "$n" = 3 ] && echo "ok Long names fail, no folder removal: 3 left" || { echo "FAIL Long names fail, no folder removal: $n left, not 3"; fail=1; }+# there, Delete roll still takes every file of the whole roll (008) and its+# logs: only the folders stay, empty+dcard=out/cardl FOS_NO_RMDIR=1 deletes "Delete roll, no folder removal: every file" delete_whole \+ ./DCIM/100CANON/IMG_9998.CR2 ./DCIM/100CANON/IMG_9999.CR2 ./DCIM/100CANON/ROLL_008.TXT \+ ./DCIM/101CANON/IMG_0001.CR2 ./DCIM/101CANON/IMG_0002.CR2 ./DCIM/101CANON/ROLL_008.TXT \+ ./DCIM/OCT1003/IMG_0001.JPG ./DCIM/OCT1003/IMG_0002.JPG ./DCIM/OCT1003/IMG_9998.JPG ./DCIM/OCT1003/IMG_9999.JPG \+ ./DCIM/OCT1003/ROLL008.TXT ./ML/DARKROOM/R008/F01.BMP ./ML/DARKROOM/R008/F02.BMP ./ML/DARKROOM/R008/F03.BMP \+ ./ML/DARKROOM/R008/F04.BMP ./ML/DARKROOM/R008/SHEET.BMP+expect "Delete roll, no folder removal: the folders counted" "lab: roll 008: deleted all, 2 left"++# A roll developed again finds its folder whichever of the day's names it+# has: here "Oct1002 Ektar100 2", the first name free again (another roll+# of that day deleted since). No second folder, no frame developed again.+CARD=out/cardg ./mkcard.sh --problems >/dev/null+FOS_CARD=out/cardg/ ./out/sim scenes/darkroom_problems.txt - >> "$log" 2>&1+mv "out/cardg/DCIM/Oct1002 Ektar100" "out/cardg/DCIM/Oct1002 Ektar100 2"+FOS_CARD=out/cardg/ ./out/sim scenes/darkroom_problems.txt - > out/cardtest-gap.log 2>&1+cat out/cardtest-gap.log >> "$log"+grep -qF "darkroom: JPEGs in out/cardg/DCIM/Oct1002 Ektar100 2" out/cardtest-gap.log && [ ! -e "out/cardg/DCIM/Oct1002 Ektar100" ] \+ && echo "ok A gap in the day's names: its own folder" || { echo "FAIL A gap in the day's names: not its own folder"; fail=1; }+grep -qE "roll 007 frame [0-9]+ developed" out/cardtest-gap.log \+ && { echo "FAIL A gap in the day's names: frames developed again"; fail=1; } || echo "ok A gap in the day's names: nothing developed again"[ $fail = 0 ] && echo "cardtest: all passed" || { echo "cardtest: failed (log: sim/$log)"; exit 1; }diff --git a/ml-dev/filmos/sim/mkcard.sh b/ml-dev/filmos/sim/mkcard.shindex f982c39..e249f85 100755--- a/ml-dev/filmos/sim/mkcard.sh+++ b/ml-dev/filmos/sim/mkcard.sh@@ -7,8 +7,9 @@# CARD=out/cardp ./mkcard.sh --problems# instead, the rolls the darkroom has to find or explain (cardtest.sh):# shot as JPEG, Adobe RGB with a file deleted, across the IMG_9999 wrap;-# cardtest.sh then deletes them (Delete roll), and develops them on a card-# that takes no long folder names (FOS_LONG_DIRS_EMPTY, FOS_NO_RMDIR: port_files.c)+# cardtest.sh then deletes them (Delete roll; FOS_KEEP: a file that can't go),+# and develops them on a card that takes no long folder names+# (FOS_LONG_DIRS_EMPTY, FOS_NO_RMDIR: port_files.c)set -euo pipefailcd "$(dirname "$0")"mkdir -p outdiff --git a/ml-dev/filmos/sim/port_files.c b/ml-dev/filmos/sim/port_files.cindex 4611c3d..4fa56f0 100644--- a/ml-dev/filmos/sim/port_files.c+++ b/ml-dev/filmos/sim/port_files.c@@ -70,7 +70,9 @@ int fos_port_remove(const char *path){struct stat st;if (stat(path, &st)) return 0;- /* FOS_NO_RMDIR: a camera whose firmware removes files but not folders */- if (S_ISDIR(st.st_mode) && getenv("FOS_NO_RMDIR")) return -1;+ /* FOS_NO_RMDIR: a camera whose firmware removes files but not folders;+ * FOS_KEEP=text: a file whose path has text in it can't be removed */+ const char *keep = getenv("FOS_KEEP");+ if (S_ISDIR(st.st_mode) ? getenv("FOS_NO_RMDIR") != 0 : keep && strstr(path, keep)) return -1;return remove(path) ? -1 : 0;}diff --git a/ml-dev/filmos/sim/scenes/delete_loaded.txt b/ml-dev/filmos/sim/scenes/delete_loaded.txtindex d9e7f04..e462e0c 100644--- a/ml-dev/filmos/sim/scenes/delete_loaded.txt+++ b/ml-dev/filmos/sim/scenes/delete_loaded.txt@@ -1,7 +1,9 @@-# Delete roll (cardtest.sh): roll 006 is in the camera and can't be deleted+# Delete roll (cardtest.sh): roll 006 is in the camera and can't be deleted;+# LEFT, then SET twice would delete its prints if it could be askedroll 0 4 12 6open darkroom1500 down1900 left2700 set-3500 end+3500 set+6000 end