code wiki / (root) / nx_revimg_crawl.nx

nx_revimg_crawl.nx source

↩ module page · 42 lines · 2308 B

1// nx_revimg_crawl.nx -- the DISCOVERY DRIVER: turns real image files (a crawl's fetched media) into the 2// fingerprint corpus that nx_revimg_discover reasons over. This is the glue that makes the reverse-image 3// discovery loop run on REAL media: each candidate image is decoded through the shared nx_img_to_gray 4// (PNG today, JPEG since the FF-D8-FF wiring -- so real web media works), perceptually hashed (nx_phash 5// dHash), and appended to the (site, fingerprint, path-id) corpus. Undecodable/unsupported files are 6// SKIPPED (graceful degradation, never fatal -- one bad image can't abort a crawl). 7// 8// The network I/O (fetch HTML, extract <img> via nx_html_extract_imgs, fetch each image to a local file) 9// is the operator-driven half wired to nx_https_get; this driver is the pure decode->fingerprint->corpus 10// half, so it is fully gateable against local fixtures and identical whether the bytes came from disk or 11// the live web. Composes nx_img_to_gray + nx_phash + nx_revimg_discover -- ZERO new logic. ORIGINAL 12import "nx_image_gray.nx" 13import "nx_phash.nx" 14import "nx_revimg_discover.nx" 15 16// fingerprint one image FILE (decode -> Rec.709 gray -> dHash). returns the 64-bit dHash, or 0 if the 17// file is undecodable (caller treats 0 as "could not seed from this file"). 18func nx_revimg_seed_file(path: *u8) -> i64 { 19 let wh: *i64 = sys_mmap(16) as *i64 20 let gray: *u8 = nx_img_to_gray(path, wh) 21 if gray == (0 as *u8) { return 0 } 22 if wh[0] <= 0 { return 0 } 23 if wh[1] <= 0 { return 0 } 24 return nx_phash_dhash(gray, wh[0], wh[1]) 25} 26 27// ingest one image FILE into the corpus: decode -> dHash -> append (site_id, fp, path_id). returns the 28// new corpus count (== n unchanged if the file could not be decoded -- graceful skip). 29func nx_revimg_ingest_file(path: *u8, site_id: i64, path_id: i64, 30 corpus_fp: *i64, corpus_site: *i64, corpus_pid: *i64, 31 n: i64, cap: i64) -> i64 { 32 if n >= cap { return n } 33 let wh: *i64 = sys_mmap(16) as *i64 34 let gray: *u8 = nx_img_to_gray(path, wh) 35 if gray == (0 as *u8) { return n } 36 if wh[0] <= 0 { return n } 37 if wh[1] <= 0 { return n } 38 corpus_fp[n] = nx_phash_dhash(gray, wh[0], wh[1]) 39 corpus_site[n] = site_id 40 corpus_pid[n] = path_id 41 return n + 1 42}