Giter Club home page Giter Club logo

Comments (6)

JimBobSquarePants avatar JimBobSquarePants commented on May 22, 2024

From @voidstar69 on January 23, 2016 14:27

@JimBobSquarePants is this the sort of change that you are looking for?

Changing Color.Lerp from this:

    public static Color Lerp(Color from, Color to, float amount)
    {
        amount = amount.Clamp(0f, 1f);

        if (Math.Abs(from.A - 1) < Epsilon && Math.Abs(to.A - 1) < Epsilon)
        {
            return from + (to - from) * amount;
        }

        // Premultiplied.
        return from * (1 - amount) + to;
    }

to this:

    public static Color Lerp(Color from, Color to, float amount)
    {
        amount = amount.Clamp(0f, 1f);

        if (Math.Abs(from.A - 1) < Epsilon && Math.Abs(to.A - 1) < Epsilon)
        {
            return Vector4.Lerp(from, to, amount);
        }

        // Premultiplied.
        // TODO: not sure how to use Vector4.Lerp here
        return from * (1 - amount) + to;
    }

might improve performance by making use of the Vector4.Lerp method (need to measure performance to be certain).

from imagesharp.

JimBobSquarePants avatar JimBobSquarePants commented on May 22, 2024

You're absolutely correct. I can use the built in Vector4.Lerp in that situation. The Color minus operator utilizes the backing vector but we might as well cut out the middle man.

The code, I believe, would be:

return Vector4.Lerp(from.backingVector, to.backingVector, amount);

For premultiplied alpha we'd probably have to fall back to the non SIMD approach.

I'd imagine it would be a very tiny performance improvement but every little most certainly helps.

from imagesharp.

olivif avatar olivif commented on May 22, 2024

I see usage of Vector4 in a bunch of places now, are there any remaining areas which we need to convert? 😄

from imagesharp.

JimBobSquarePants avatar JimBobSquarePants commented on May 22, 2024

I think it might be possible to vectorize bits and bobs throughout, maybe in colorspace conversions or running through lists. I know the subsampling scaling in jpeg decoder is vectorised in libjpeg turbo also.

I just don't know the Numerics API's well enough though to figure out what could benefit.

from imagesharp.

antonfirsov avatar antonfirsov commented on May 22, 2024

Subsampling is not an issue, the only test input where it goes over 1% is the cmyk watch:
jpegcmykwatchprofile

from imagesharp.

JimBobSquarePants avatar JimBobSquarePants commented on May 22, 2024

Closing this. @antonfirsov has done incredible work to implement vectorization throughout the library.

from imagesharp.

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.