clone

a photo toolkit for your phone that never uploads: fuji film looks for raw files, social crops, error level analysis

main
gudpics / scripts / extract.py
extract.py 2.7K
1"""Reproducible extraction from the vendored, pinned darktable source.2Run from any directory. No network required. Changes documented in NOTICE.md.3SPDX-License-Identifier: AGPL-3.0-or-later4"""5from pathlib import Path67root = Path(__file__).resolve().parent.parent8src = (root / 'native/upstream/ashift.c').read_text()910def section(start, end):11 return src[src.index(start):src.index(end, src.index(start))]1213parts = [src[:src.index('#include')],14 '// Extracted and adapted for Upright, 2026-09-21. See NOTICE.md.\n',15 '#include "compat.h"\n',16 section('#define ROTATION_RANGE ', '// For line detection'),17 '#include "lsd.inc"\n#include "upstream/ashift_nmsimplex.c"\n',18 section('typedef enum dt_iop_ashift_method_t', 'typedef struct dt_iop_ashift_cropfit_params_t'),19 '''typedef struct {20 dt_iop_ashift_line_t *lines;21 int lines_count, lines_in_width, lines_in_height, lines_x_off, lines_y_off;22 int vertical_count, horizontal_count, lines_version, isflipped;23 float vertical_weight, horizontal_weight;24 float rotation_range, lensshift_v_range, lensshift_h_range, shear_range;25} dt_iop_ashift_gui_data_t;26typedef struct { dt_iop_ashift_gui_data_t *gui_data; } dt_iop_module_t;27''',28 section('// normalized product of two 3x1 vectors', 'static inline void _shadow_crop_box'),29 section('#define MAT3SWAP', '// check if module parameters'),30 section('static void rgb2grey256', '// sobel edge enhancement')]31detect = section('static gboolean line_detect(', '// get image from buffer')32start = detect.index(' // apply gamma correction')33end = detect.index(' // allocate intermediate buffers')34detect = detect[:start] + ' // Browser input is already display-referred; no RAW/detail preprocessing.\n' + detect[end:]35start = detect.index(' // if requested perform an additional edge')36end = detect.index(' // call the line segment detector')37detect = detect[:start] + detect[end:]38parts.append(detect)39fitting = section('static inline void swap(', '#ifdef ASHIFT_DEBUG\n// only used in development')40# Preserve one/two-line selections when RANSAC is deliberately skipped.41fitting = fitting.replace('inout_set[vnb] = 0;', 'inout_set[vnb] = 1;').replace('inout_set[hnb] = 0;', 'inout_set[hnb] = 1;')42parts.append(fitting)43(root / 'native/extracted.inc').write_text('\n'.join(parts))44lsd = (root / 'native/upstream/ashift_lsd.c').read_text()45lsd = lsd.replace('#include "common/math.h"', '// math helpers supplied by compat.h')46lsd = lsd.replace('dt_print(DT_DEBUG_ALWAYS,"LSD Error: %s",msg);', 'fprintf(stderr,"LSD Error: %s\\n",msg);')47(root / 'native/lsd.inc').write_text(lsd)48print('Extracted detector, classification, RANSAC, fit and homography.')