Giter Site home page Giter Site logo

Comments (12)

etemesi254 avatar etemesi254 commented on June 15, 2024 1

Is there a way to toggle which decoders are compiled, or some way to toggle them at runtime?

In many cases it would be nice to disable PSD support either to reduce attack surface (e.g. an image format converter accepting untrusted input) or just not to advertise support for a format that is not complete (e.g. in a desktop image viewer). PSD is an immensely complex format, and full support for it is a multi-year effort.

Added is_experimental method to DecoderTrait, (DecoderTrait allows unanimous image decoding from multiple formats into a single image, i.e. implemented for all image decoders).

And added an --experimental flag in the command line, this adds a guard on all decoders which are experimental(currently farbfeld and psd) to require --experimental flag in the command line before decoding.

from zune-image.

etemesi254 avatar etemesi254 commented on June 15, 2024 1

@Shnatsel , Finished a simple PNG decoder.

Doesn't do a lot yet, only works with 8 bpp pixel images but I think you'll love the speeds at
https://github.com/etemesi254/zune-image/blob/main/zune-png/Benches.md

Uses a custom zlib decoder at zune-inflate which is as fast as zlib-ng (for the tests I've done, which is extracting delfate chunks from a png image of your AI upscaled image from before, running decode on it) and about 20Mb/s faster than miniz-oxide(using the same procedure).

The speedups actually don't even come from that.
They come from a carefully written filter algorithm which the compiler can optimize, and that's pretty sweet(will probably write a blog post about it soon) but for now that's all.

Will work on finishing this and the jpeg decoder for now

from zune-image.

etemesi254 avatar etemesi254 commented on June 15, 2024

cc @Shnatsel , PSD decoding landed(limited in scope, not fully working), thought you might be interested.

from zune-image.

Shnatsel avatar Shnatsel commented on June 15, 2024

Is there a way to toggle which decoders are compiled, or some way to toggle them at runtime?

In many cases it would be nice to disable PSD support either to reduce attack surface (e.g. an image format converter accepting untrusted input) or just not to advertise support for a format that is not complete (e.g. in a desktop image viewer). PSD is an immensely complex format, and full support for it is a multi-year effort.

from zune-image.

Shnatsel avatar Shnatsel commented on June 15, 2024

PNG also has an animated variant, APNG, which is now supported by all web browsers as well as the Rust png and image crates. It would be nice to support that as well eventually.

from zune-image.

etemesi254 avatar etemesi254 commented on June 15, 2024

from zune-image.

etemesi254 avatar etemesi254 commented on June 15, 2024

Is there a way to toggle which decoders are compiled, or some way to toggle them at runtime?

In many cases it would be nice to disable PSD support either to reduce attack surface (e.g. an image format converter accepting untrusted input) or just not to advertise support for a format that is not complete (e.g. in a desktop image viewer). PSD is an immensely complex format, and full support for it is a multi-year effort.

zune-image supports ability to disable , I'm yet to add that to the binary.

For PSD complexity you make an interesing case,

Just found out ffmpeg supports PSD files, i.e https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/psd.c that's their implementation.
ImageMagick's one is longer since it supports more features i.e

https://github.com/ImageMagick/ImageMagick/blob/31176f90be5bb143302d2a7a2746a601dc9e2ac0/coders/psd.c

The I was using stb as a basis for my PSD implementation. about 246 LOC at https://github.com/nothings/stb/blob/8b5f1f37b5b75829fc72d38e7b5d4bcbf8a26d55/stb_image.h#L6002-L6248.

Currently we throw out a lot of data we don't need, i.e layers and such to just get the image, the same with ffmpeg and stb. Imagemagick does not do this, and the features it implements aren't

I'd rather not disable it, for the command line and add it under a feature , say --unsafe is needed to decode PSD files since it's experimental at best than trying to chase perfection since that will mean this library will never be ready for any real world decoding.

from zune-image.

Shnatsel avatar Shnatsel commented on June 15, 2024

Is the BMP format in scope? It should be relatively trivial, but I don't see it mentioned explicitly.

from zune-image.

etemesi254 avatar etemesi254 commented on June 15, 2024

Hi, BMP support is planned.

The plan is to support at least anything image-rs supports first.(Like farbfeld decode support landed but can't currently be encoded, working on that one over the weekend).

This issue should probably be restructured in the way it is(I.e tracking image status and planned times )

from zune-image.

Shnatsel avatar Shnatsel commented on June 15, 2024

That's excellent news, thanks for sharing!

I'm curious, how does zune-inflate compare to libdeflate performance-wise?

Also, I should have mentioned it earlier, but WUFFS has a fast PNG decoder and detailed explanation of why it's fast, and there's also libspng that beats libpng. You might be able to lift some tricks from those and push performance even further.

from zune-image.

etemesi254 avatar etemesi254 commented on June 15, 2024

Perfomance wise with libdeflate, zune-inflate is probably a 1 to 1 translation of libdeflate with some small language differences, will put up performance comparisions soon, but in face value I expect libdeflate to be slightly faster because it can take advantage of some C properties like incrementing pointers,unbound checks,some union hackery and some wrapping subtractions on steroids, which I didn't implement as it made some asserts hard to do in some places.

Didn't know about libspng let me check it out.
Also looking at wuffs.

Will cc you when I think it's ready for fuzz-testing

from zune-image.

Shnatsel avatar Shnatsel commented on June 15, 2024

FWIW what I've been doing so far is testing on real-world images instead of fuzz testing. Fuzzing produces random/invalid data to trigger unexpected codepaths, like panics or memory safety bugs.

Fuzzing usually finds a large amount of rather boring panics, so I've put it off until the correctness on real-world images is established.

from zune-image.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.