# Makefile for image processing pipeline # --- Configuration --- # Executables (assuming they are in the current directory or your PATH) FILMCOLOR_EXE := ./filmcolor FILMSCAN_EXE := ./filmscan FILMGRAIN_EXE := ./filmgrain # Fixed Paths for this project RAW_DIR := ./test_images/RAW SIM_DATA_FILE := ./sim_data/portra_400.json OUTPUT_BASE_DIR := ./test_images/v1.0output # Output subdirectory names (used to construct paths) FILMCOLOR_SUBDIR := filmcolor FILMSCAN_SUBDIR := filmscan FILMGRAIN_RGB_SUBDIR := filmgrainrgb FILMGRAIN_MONO_SUBDIR := filmgrainmono # --- Helper: Define all output directories --- # These are the actual directory paths DIR_FILMCOLOR := $(OUTPUT_BASE_DIR)/$(FILMCOLOR_SUBDIR) DIR_FILMSCAN := $(OUTPUT_BASE_DIR)/$(FILMSCAN_SUBDIR) DIR_FILMGRAIN_RGB := $(OUTPUT_BASE_DIR)/$(FILMGRAIN_RGB_SUBDIR) DIR_FILMGRAIN_MONO:= $(OUTPUT_BASE_DIR)/$(FILMGRAIN_MONO_SUBDIR) ALL_OUTPUT_DIRS := $(DIR_FILMCOLOR) $(DIR_FILMSCAN) $(DIR_FILMGRAIN_RGB) $(DIR_FILMGRAIN_MONO) # --- Input Handling for single DNG processing --- # INPUT_DNG_PATH is expected for targets like 'full_process' # It's not used directly by 'run_all_test_process' but by the targets it calls if you invoke them manually. # Derive BASENAME if INPUT_DNG_PATH is provided (for single image processing) # This block is evaluated if INPUT_DNG_PATH is set when make is invoked. ifdef INPUT_DNG_PATH # Check if the input DNG file exists (only if INPUT_DNG_PATH is provided) ifeq ($(wildcard $(INPUT_DNG_PATH)),) $(error Input DNG file not found: $(INPUT_DNG_PATH)) endif FILENAME_WITH_EXT_SINGLE := $(notdir $(INPUT_DNG_PATH)) BASENAME_SINGLE := $(basename $(FILENAME_WITH_EXT_SINGLE)) # e.g., "09" from "09.DNG" # Define specific output files for the single INPUT_DNG_PATH # These are used by 'full_process' target when INPUT_DNG_PATH is specified SPECIFIC_FILMCOLOR_OUT := $(DIR_FILMCOLOR)/$(BASENAME_SINGLE).tiff SPECIFIC_FILMSCAN_OUT := $(DIR_FILMSCAN)/$(BASENAME_SINGLE).tiff SPECIFIC_FILMGRAIN_RGB_OUT := $(DIR_FILMGRAIN_RGB)/$(BASENAME_SINGLE).tiff SPECIFIC_FILMGRAIN_MONO_OUT := $(DIR_FILMGRAIN_MONO)/$(BASENAME_SINGLE).tiff endif # --- Batch Processing: Find all DNGs and define their targets --- # Find all .DNG and .dng files in the RAW_DIR DNG_FILES_IN_RAW := $(wildcard $(RAW_DIR)/*.DNG) $(wildcard $(RAW_DIR)/*.dng) # Extract unique basenames from these DNG files (e.g., "09", "another_image") # $(notdir path/file.ext) -> file.ext # $(basename file.ext) -> file (or file.part if original was file.part.ext) # $(sort ... ) also removes duplicates ALL_BASENAMES := $(sort $(foreach dng_file,$(DNG_FILES_IN_RAW),$(basename $(notdir $(dng_file))))) # Generate lists of all final output files for the run_all_test_process target ALL_FINAL_RGB_OUTPUTS := $(foreach bn,$(ALL_BASENAMES),$(DIR_FILMGRAIN_RGB)/$(bn).tiff) ALL_FINAL_MONO_OUTPUTS := $(foreach bn,$(ALL_BASENAMES),$(DIR_FILMGRAIN_MONO)/$(bn).tiff) TARGETS_FOR_RUN_ALL := $(ALL_FINAL_RGB_OUTPUTS) $(ALL_FINAL_MONO_OUTPUTS) # --- Targets --- .DEFAULT_GOAL := help .PHONY: all full_process run_all_test_process create_dirs help .SECONDEXPANSION: # Allow use of $$(@F) etc. in static pattern rules if needed, though not strictly used here # Target to create all necessary output directories # This is a prerequisite for the first processing step. create_dirs: @echo "Creating output directories if they don't exist..." @mkdir -p $(ALL_OUTPUT_DIRS) @echo "Output directories ensured: $(ALL_OUTPUT_DIRS)" # --- Static Pattern Rules for image processing steps --- # These rules define how to build .tiff files in output directories from .DNG/.dng files in RAW_DIR # The '%' is a wildcard that matches the basename of the file. # 1. Filmcolor (handles both .DNG and .dng inputs) $(DIR_FILMCOLOR)/%.tiff: $(RAW_DIR)/%.DNG $(SIM_DATA_FILE) create_dirs @echo "--- [1. Filmcolor] ---" @echo " Input DNG: $<" @echo " Sim Data: $(SIM_DATA_FILE)" @echo " Output: $@" $(FILMCOLOR_EXE) "$<" "$(SIM_DATA_FILE)" "$@" $(DIR_FILMCOLOR)/%.tiff: $(RAW_DIR)/%.dng $(SIM_DATA_FILE) create_dirs @echo "--- [1. Filmcolor] ---" @echo " Input dng: $<" @echo " Sim Data: $(SIM_DATA_FILE)" @echo " Output: $@" $(FILMCOLOR_EXE) "$<" "$(SIM_DATA_FILE)" "$@" # 2. Filmscan $(DIR_FILMSCAN)/%.tiff: $(DIR_FILMCOLOR)/%.tiff @echo "--- [2. Filmscan] ---" @echo " Input: $<" @echo " Output: $@" $(FILMSCAN_EXE) "$<" "$@" # 3. Filmgrain RGB $(DIR_FILMGRAIN_RGB)/%.tiff: $(DIR_FILMSCAN)/%.tiff @echo "--- [3. Filmgrain RGB] ---" @echo " Input: $<" @echo " Output: $@" $(FILMGRAIN_EXE) "$<" "$@" # 4. Filmgrain Mono $(DIR_FILMGRAIN_MONO)/%.tiff: $(DIR_FILMSCAN)/%.tiff @echo "--- [4. Filmgrain Mono] ---" @echo " Input: $<" @echo " Output: $@" $(FILMGRAIN_EXE) "$<" "$@" --mono # --- Main User Targets --- # Process a single image specified by INPUT_DNG_PATH full_process: $(SPECIFIC_FILMGRAIN_RGB_OUT) $(SPECIFIC_FILMGRAIN_MONO_OUT) ifndef INPUT_DNG_PATH $(error INPUT_DNG_PATH must be set for 'make full_process'. Usage: make full_process INPUT_DNG_PATH=/path/to/image.DNG) endif @echo "----------------------------------------------------" @echo "SUCCESS: Full processing complete for $(BASENAME_SINGLE)" @echo "RGB Output: $(SPECIFIC_FILMGRAIN_RGB_OUT)" @echo "Mono Output: $(SPECIFIC_FILMGRAIN_MONO_OUT)" @echo "----------------------------------------------------" # Process all DNG images in test_images/RAW/ run_all_test_process: $(TARGETS_FOR_RUN_ALL) @echo "====================================================" @echo "SUCCESS: All test images in $(RAW_DIR) processed." @echo "Processed $(words $(ALL_BASENAMES)) images: $(ALL_BASENAMES)" @echo "====================================================" all: @echo "Common targets: 'make full_process INPUT_DNG_PATH=...', 'make run_all_test_process'" # Help message help: @echo "Makefile for Image Processing Pipeline" @echo "" @echo "Usage: make [INPUT_DNG_PATH=]" @echo "" @echo "Main Targets:" @echo " full_process - Run the entire pipeline for a single image." @echo " Requires: INPUT_DNG_PATH=./test_images/RAW/your_image.DNG" @echo " run_all_test_process - Run the entire pipeline for ALL .DNG/.dng images" @echo " found in $(RAW_DIR)/" @echo "" @echo "Other Targets:" @echo " create_dirs - Ensure all output directories exist." @echo " help - Show this help message." @echo "" @echo "Examples:" @echo " make full_process INPUT_DNG_PATH=./test_images/RAW/09.DNG" @echo " make run_all_test_process"