Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The cmsCreateMultiprofileTransform may modify the profile in some way #322

Open
mrserb opened this issue Jun 8, 2022 · 1 comment
Open

Comments

@mrserb
Copy link
Contributor

mrserb commented Jun 8, 2022

Hello.

This issue is continuation of this one: #273
That bug was caused by the "broken" PYCC.pf profile which did not include the "B" step. After the "B" was added to that profile the example code in that issue start to work fine.

The updated profile can be found here: https://bugs.openjdk.org/secure/attachment/99226/pycc2.icc
The icc inspector and ProfileDump mark this profile as "Valid".

Unfortunately I have found that the new updated profile can produce similar errors like before if cmsCreateTransform will be replaced by the cmsCreateMultiprofileTransform. So it cannot be saved to the memory if it was used by the cmsCreateMultiprofileTransform(). Tested on LittleCMS 2.12 and 2.13.

The test code:

#include "lcms2.h"
#include <stdlib.h>

void LogErrorHandler(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *Text){
    fprintf(stderr, "%s\n", Text);
}

void check(cmsHPROFILE hProfile) {
    cmsUInt32Number pfSize = 0;
    cmsHPROFILE pfSanity = NULL;
    if (cmsSaveProfileToMem(hProfile, NULL, &pfSize)) {
        void* buf = malloc((pfSize));
        if (buf != NULL) {
            if (cmsSaveProfileToMem(hProfile, buf, &pfSize)) {
                pfSanity = cmsOpenProfileFromMem(buf, pfSize);
                cmsCloseProfile(pfSanity);
                fprintf(stderr, "This step passed\n");
            }
            free(buf);
        }
    }
}

int main(void) {
    cmsSetLogErrorHandler(LogErrorHandler);
    cmsHPROFILE mid = cmsOpenProfileFromFile(".../.../PYCC.pf", "r");
    
    cmsHPROFILE input = cmsCreate_sRGBProfile();
    cmsHPROFILE output = cmsCreate_sRGBProfile();

    cmsHPROFILE _iccArray[20];
    int j = 0;
    _iccArray[j++] = input;

    _iccArray[j++] = mid;
    _iccArray[j++] = mid;

    // can the user request same profile again? skip it for now
    // _iccArray[j++] = mid;  
    // _iccArray[j++] = mid;

    _iccArray[j++] = output;
    // this transform works fine    
    cmsHTRANSFORM transform = cmsCreateTransform(mid, PT_ANY,
                                                  output, PT_ANY,
                                                  INTENT_PERCEPTUAL,
                                                  cmsFLAGS_COPY_ALPHA);
    cmsDeleteTransform(transform);

    //// Comment the block below to solve the error
    cmsHTRANSFORM hTransform = cmsCreateMultiprofileTransform(_iccArray, j,
        TYPE_RGB_8, TYPE_RGB_8, INTENT_PERCEPTUAL, cmsFLAGS_COPY_ALPHA);
    cmsDeleteTransform(hTransform);
    //// Comment the block above to solve the error

    check(input);
    check(mid);
    check(output);
    cmsCloseProfile(input);
    cmsCloseProfile(mid);
    cmsCloseProfile(output);

    return 0;
}

The code above will print:

LUT is not suitable to be saved as LutAToB
Couldn't write type 'mAB '

But if the block of code is commented out(or just remove the cmsCreateMultiprofileTransform and cmsDeleteTransform) in the example, then cmsSaveProfileToMem/cmsOpenProfileFromMem will work fine.

@mrserb
Copy link
Contributor Author

mrserb commented Jun 15, 2022

Looks like the problem is similar to the old one, the main method can be simplified:

int main(void) {
    cmsSetLogErrorHandler(LogErrorHandler);
    cmsHPROFILE mid = cmsOpenProfileFromFile(".../pycc2.icc", "r");
    cmsReadTag(mid, cmsSigBToA0Tag);
    check(mid);
    cmsCloseProfile(mid);
    return 0;
}

The issue is in the cmsReadTag(mid, cmsSigBToA0Tag); It decodes the tag and after that lcms cannot save the profile. If the tag is not decoded then the lcms can write it as a "raw" tag. So probably something still wrong with this profile, but for now I cannot say what exactly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant