-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmerger.js
More file actions
114 lines (114 loc) · 4.36 KB
/
merger.js
File metadata and controls
114 lines (114 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
function load_json(event) {
const fr = new FileReader();
fr.onload = event => {
const data = JSON.parse(event.target.result);
const slices=data.slices;
if(slices.length !== images.length) {
alert(`Series mismatch: ${slices.length} vs ${images.length} sections.\nProcessing aborts now.`);
return;
}
const checks=new Set;
const mapped=new Map;
for(const image of images) {
const m=image.filename.match(/.*(_s\d+[a-zA-Z]?)/);
if(!m){
alert("This function can not yet deal with series without section numbers.\nProblematic section: "+image.filename+"\nProcessing aborts now.");
return;
}
if(checks.has(m[1])){
alert("Duplicate section number:\n"+image.filename+"\nProcessing aborts now.");
return;
}
checks.add(m[1]);
mapped.set(m[1],image);
}
if(checks.size !== images.length){
alert(`${checks.size} individual section numbers are found for ${images.length} sections.\nProcessing aborts now.`);
return;
}
for(const slice of slices){
const m=slice.filename.match(/.*(_s\d+[a-zA-Z]?)/);
if(!m) {
alert("This function can not yet deal with series without section numbers.\nProblematic section: "+slice.filename+"\nProcessing aborts now.");
return;
}
if(!checks.has(m[1])) {
alert("Can not find matching section for\n"+slice.filename+"\nProcessing aborts now.");
return;
}
checks.delete(m[1]);
}
for(const slice of slices){
const m=slice.filename.match(/.*(_s\d+[a-zA-Z]?)/);
const image=mapped.get(m[1]);
if(slice.anchoring){
image.ouv=slice.anchoring;
image.wadone=true;
}else{
image.anchored=false;
image.wadone=false;
}
const section=series.sections[images.indexOf(image)];
if(slice.markers){
image.wwdone=true;
section.wwdone=true;
section.markers=slice.markers.map(coords=>[
coords[0]*section.width/slice.width,
coords[1]*section.height/slice.height,
coords[2]*section.width/slice.width,
coords[3]*section.height/slice.height
]);
}else{
delete image.wwdone;
delete section.wwdone;
delete section.markers;
}
}
propagate();
activateslice(series.current);
};
fr.readAsText(event.target.files[0]);
}
//let json_process;
//function load_json(event) {
// const fr = new FileReader();
// fr.onload = event => {
// const data = JSON.parse(event.target.result);
// json_process = data;
// transform_json();
// };
// fr.readAsText(event.target.files[0]);
//}
//function transform_json() {
// const apply=document.getElementById("apply_json");
// apply.disabled=true;
// const trf = document.getElementById("json_trf").value;
// const parts = trf.split(",").map(part => part.split("="));
// let done=true;
// let rows = "";
// for (const va of json_process.slices) {
// let name=va.filename;
// if (parts)
// for (const part of parts)
// name = name.replaceAll(part[0], part.length > 1 ? part[1] : "");
// const _s = name.match(/(_s\d+)/);
// let pair = "?";
//
// if (_s) {
// for (const wa of images)
// if (wa.filename.includes(_s[0]))
// pair = wa.filename;
// }
// let match = 0;
// while (match < name.length && match < pair.length && name[match] === pair[match])
// match++;
// rows += `<tr><td>${name.substring(0, match)}<span style="font-weight:bold;color:red">${name.substring(match)}</span></td>
// <td>${pair.substring(0, match)}<span style="font-weight:bold;color:red">${pair.substring(match)}</span></td></tr>`;
// if(name!==pair)done=false;
// }
// apply.disabled=!done;
// document.getElementById("json_pairs").innerHTML = rows;
//}
//function apply_json(){
//
//}