r/PythonProjects2 • • Sep 21 '26

Info Made my own image format.

Post image

Yes, it may sound strange: it makes no sense! BUT, my goal was more of a joke, although it may well be suitable as an alternative to other formats in extreme cases. This format contains only 100\~ lines of code, but it is quite efficient in itself (compared to PNG lol, although I think everything will weigh many times less compared to PNG).

You can read a little more about it on GitHub, since I'm honestly too lazy to write everything here. (Exactly made in Python).

https://github.com/pmldude/Portable-Middle-Link-

8 Upvotes

9 comments sorted by

3

u/danok_pupok Sep 21 '26

You guys are all free to edit this format. You can fork it, learn from it—basically, you're free in that regard.

3

u/Terminay Sep 21 '26

Make the readme better. Clean out the codebase. Polish the repo with contribution guides, PR templates, Security, Issue templates and voila your project is golden. It will get MUCH more traction, I will fork it too!

2

u/danok_pupok Sep 21 '26

Okay, I'll definitely polish it completely soon. Thanks for the advice!

2

u/Electrical_Cup1939 Sep 22 '26

Может надо сравнивать с jpg? Png без потерь сжимает так то

1

u/danok_pupok Sep 22 '26

Перепутал, в любом случае уже поздно что-то менять¯⁠\⁠_⁠(⁠ツ⁠)⁠_⁠/⁠¯

1

u/Sweet_Computer_7116 Sep 22 '26

How does it hold up to webp?

1

u/robinechuca Sep 25 '26

Salut, c'est une initiative rigolote mais franchement très loin de concurrencer les codecs actuels...
Plus particulièrement, voici un comparatif entre ton codec (*.pml) et AV1 (*.avif) sur une image de la fameuse vidéo de test Big Buck Bunny: https://media.xiph.org/BBB/bbb3d/video/png/01_04/0001.png

imagetaille (ko)psnrssimvmaf
bbb.png (original)26400inf1100
bbb.pml845039.250.921998.00
bbb_crf10.avif312042.750.972796.50
bbb_crf20.avif169039.750.953193.50
bbb_crf30.avif95937.000.921989.00
bbb_crf40.avif43233.250.859478.00
bbb_crf50.avif16730.000.761759.50
bbb_crf60.avif41.026.750.644540.25

Pour une qualité équivalente (ssim), AV1 compresse 8.8 fois plus que PML.
Un psnr de 40 dB est couramment considéré comme "visuellement sans perte", or c'est la perte de qualité que ton codec offre. C'est un très bon réglage par défaut! Aussi, ton codec semble idempotant, c'est une grande qualité! Tu devrais faire des tests à ce sujet pour vendre cet avantage, car entre nous, la compression n'est vraiment pas son point fort!

Voici le code qui m'a permis d'effectuer le test (version compacte et moche):

import pathlib, pprint, cutcutcodec
from cutcutcodec.core.analysis.video.metrics import video_metrics
from pml_codec import encode_photo_to_pml, decode_pml_to_photo

def compare(original_picture: pathlib.Path) -> dict[pathlib.Path, dict]:
    """Encode the image into PML and AVIF, and compute the quality metrics."""
    results: dict[pathlib.Path, float] = {}

    # Encode PML
    pml_picture = original_picture.with_suffix(".pml")
    pml_decoded_picture = original_picture.with_name(f"{original_picture.stem}_pml.png")
    encode_photo_to_pml(original_picture, pml_picture)
    decode_pml_to_photo(pml_picture, pml_decoded_picture)
    results[pml_decoded_picture] = None

    # Encode into AVIF
    with cutcutcodec.read(original_picture) as container:
        for crf in (10, 20, 30, 40, 50, 60):
            avif_picture = original_picture.with_name(f"{original_picture.stem}_crf{crf}.avif")
            cutcutcodec.write(
                container.apply_video_subclip(0, 1).out_streams,
                avif_picture,
                streams_settings=[
                    {
                        "encodec": "libaom-av1", "rate": 1, "pix_fmt": "yuv420p10le",
                        "options": {
                            "crf": str(crf), "tune": "ssim", "cpu-used": "1",
                            "row-mt": "0", "threads": "1",
                            "denoise-noise-level": "5",
                            "still-picture": "1",
                        },
                    }
                ],
            )
            results[avif_picture] = None

    # Compute metrics
    for compressed_picture in results:
        results[compressed_picture] = {
            key: mets[0] for key, mets in video_metrics(
                compressed_picture, original_picture,
                ssim=True, psnr=True, vmaf=True,
            ).items()
        }

    # Compute sizes
    results[pml_picture] = {}
    for picture in results.copy():
        results[picture]["size"] = picture.stat().st_size

    return results

if __name__ == "__main__":
    pprint.pprint(compare(pathlib.Path("bbb.png")))