mm2 / Little-CMS

A free, open source, CMM engine. It provides fast transforms between ICC profiles.
https://www.littlecms.com
MIT License
549 stars 174 forks source link

The fast float plugin doesn't premultiply alpha #430

Closed pjanx closed 8 months ago

pjanx commented 8 months ago

LittleCMS 2.15, 2.16

#include <stdint.h>

#include <lcms2.h>
#include <lcms2_fast_float.h>

int main()
{
#if 1
    cmsPlugin(cmsFastFloatExtensions());
#endif

    uint8_t BGRA8[4] = {255, 192, 160, 128};
    uint8_t bgrA8[4] = {0, 32, 64, 96};

    cmsHPROFILE srgb1 = cmsCreate_sRGBProfile();
    cmsHPROFILE srgb2 = cmsCreate_sRGBProfile();

    cmsHTRANSFORM xform = cmsCreateTransform(
            srgb1, TYPE_BGRA_8,
            srgb2, TYPE_BGRA_8_PREMUL,
            INTENT_PERCEPTUAL, cmsFLAGS_COPY_ALPHA);

    cmsCloseProfile(srgb1);
    cmsCloseProfile(srgb2);

    cmsDoTransform(xform, BGRA8, bgrA8, 1);
    cmsDeleteTransform(xform);

    printf("%3u %3u %3u %3u\n", BGRA8[0], BGRA8[1], BGRA8[2], BGRA8[3]);
    printf("%3u %3u %3u %3u\n", bgrA8[0], bgrA8[1], bgrA8[2], bgrA8[3]);
    return 0;
}
CPPFLAGS = `pkg-config --cflags lcms2` -Wall -Wextra
LDFLAGS = `pkg-config --libs lcms2`

test: test.c
mm2 commented 8 months ago

Should be fixed by 261376fc126f0b11ab56e8288ecc0a92666f01f3 Thanks for reporting!