1

我有一个应用程序,我想在 JPEG 中执行无损交换切片,从而生成如下文件:交换了瓷砖的图像 为此,我已经能够制作一个概念验证 python 脚本,该脚本重复调用已修补的具有裁剪和删除支持的 jpegtran,如下所示:

# Export tiles
for i, swap in enumerate(swaps):
    if i > 0:
        continue
    commanda = [
        jtp,
        "-crop", "{}x{}+{}+{}".format(dividerWidth, dividerHeight, swap["sx"], swap["sy"]),
        "-outfile", "tmp/s{}s.jpg".format(i),
        "original.jpg"
    ]
    commandb = [
        jtp,
        "-crop", "{}x{}+{}+{}".format(dividerWidth, dividerHeight, swap["dx"], swap["dy"]),
        "-outfile", "tmp/s{}d.jpg".format(i),
        "original.jpg"
    ]
    print(list2cmdline(commanda))
    call(commanda)
    print(list2cmdline(commandb))
    call(commandb)


# Then drop them on the original
for i, swap in enumerate(swaps):
    command = [jtp]
    if i == len(swaps) - 1:
        command.append("-optimize")

    source = "mixed.jpg"
    if i == 0:
        source = "original.jpg"

    commanda = command.copy()
    commanda.extend([
        "-drop", "+{}+{}".format(swap["dx"], swap["dy"]),
        "tmp/s{}s.jpg".format(i),
        "-outfile", "mixed.jpg",
        source
    ])

    commandb = command.copy()
    commandb.extend([
        "-drop", "+{}+{}".format(swap["sx"], swap["sy"]),
        "tmp/s{}d.jpg".format(i),
        "-outfile", "mixed.jpg",
        "mixed.jpg"
    ])
    print(list2cmdline(commanda))
    call(commanda)
    print(list2cmdline(commandb))
    call(commandb)

然而,这是非常低效和缓慢的。我开始尝试制作一个受 jpegtrans 源代码(已修补的版本)启发的版本,但无济于事。我不明白在执行 (jtransform_execute_transformation) 之后如何拍摄裁剪后的图像(在 jpeg_compress_struct 中),然后将其放到图像上。我似乎可以只用内存中整个图像的一个副本来做到这一点,然后裁剪部分并将它们放在其他地方,但我不知道该怎么做。

4

0 回答 0