MCPcopy Index your code
hub / github.com/leslievan/semi-utils / start_process

Function start_process

processor/core.py:266–329  ·  view source on GitHub ↗

执行处理管道 Args: data: 处理器配置列表 input_path: 输入文件路径 output_path: 输出文件路径 initial_buffer: 初始图像缓冲区(可选,用于不从文件加载的情况)

(data: List[dict], input_path: str = None, output_path: str = None, initial_buffer: List = None)

Source from the content-addressed store, hash-verified

264
265
266def start_process(data: List[dict], input_path: str = None, output_path: str = None, initial_buffer: List = None):
267 """
268 执行处理管道
269
270 Args:
271 data: 处理器配置列表
272 input_path: 输入文件路径
273 output_path: 输出文件路径
274 initial_buffer: 初始图像缓冲区(可选,用于不从文件加载的情况)
275 """
276 nodes = [PipelineContext(datum) for datum in data]
277
278 # 设置初始 buffer
279 if initial_buffer is not None:
280 nodes[0].set("buffer", initial_buffer)
281 nodes[0].set("buffer_loaded", True)
282 elif input_path is not None:
283 nodes[0].set("buffer_path", [input_path])
284
285 # 填充 exif 信息
286 if input_path is not None:
287 exif = get_exif(input_path)
288 for node in nodes:
289 if 'exif' not in node:
290 node['exif'] = exif
291
292 # 所有处理器的输出, 0 被看作是头元素的输出
293 output = nodes[0].get_buffer()
294
295 all_buffer = [output]
296 last_merger_idx = -1
297
298 for idx, node in enumerate(nodes):
299 processor = get_processor(node.get_processor_name())
300 if processor is None:
301 raise RuntimeError(f"Processor '{node.get_processor_name()}' not found")
302
303 processor_instance: ImageProcessor = processor()
304 if 'select' in node:
305 indexes = json.loads(node['select'])
306 flattened = list(chain.from_iterable([all_buffer[i] for i in indexes]))
307 node.update_buffer(flattened)
308 else:
309 # 使用 category() 方法判断是否为 merger,避免导入 Merger 类
310 if processor_instance.category() != "merger":
311 node.update_buffer(output)
312 else:
313 # 收集下标从上一个 merger 之后, 到当前 idx 为止的 buffer
314 buffers_to_merge = all_buffer[last_merger_idx + 1:idx + 1]
315
316 # 将数组的数组展平为数组
317 flattened = list(chain.from_iterable(buffers_to_merge))
318 node.update_buffer(flattened)
319 last_merger_idx = idx
320
321 processor_instance.process(node)
322 output = node.get_buffer()
323 all_buffer.append(output)

Callers 4

process_single_fileFunction · 0.90
processMethod · 0.90
generateMethod · 0.90
processMethod · 0.90

Calls 13

get_exifFunction · 0.90
load_configFunction · 0.90
PipelineContextClass · 0.85
get_processorFunction · 0.85
setMethod · 0.80
get_bufferMethod · 0.80
get_processor_nameMethod · 0.80
update_bufferMethod · 0.80
successMethod · 0.80
save_bufferMethod · 0.80
getintMethod · 0.80
categoryMethod · 0.45

Tested by

no test coverage detected