Skip to content

Commit

Permalink
Fix a bug on saving tabulated linearization devicelinks
Browse files Browse the repository at this point in the history
- Fix the bug
- Add a new test case to make sure it is working
  • Loading branch information
mm2 committed Oct 15, 2023
1 parent 6c821b3 commit 32ded9e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/cmstypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2663,8 +2663,8 @@ cmsBool WriteSetOfCurves(struct _cms_typehandler_struct* self, cmsIOHANDLER* io,
// If this is a table-based curve, use curve type even on V4
CurrentType = Type;

if ((Curves[i] ->nSegments == 0)||
((Curves[i]->nSegments == 2) && (Curves[i] ->Segments[1].Type == 0)) )
if ((Curves[i] ->nSegments == 0) || // 16 bits tabulated
((Curves[i]->nSegments == 3) && (Curves[i] ->Segments[1].Type == 0)) ) // Floating-point tabulated
CurrentType = cmsSigCurveType;
else
if (Curves[i] ->Segments[0].Type < 0)
Expand Down
71 changes: 69 additions & 2 deletions testbed/testcms2.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//---------------------------------------------------------------------------------
//
// Little Color Management System
// Copyright (c) 1998-2021 Marti Maria Saguer
// Copyright (c) 1998-2023 Marti Maria Saguer
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -8678,6 +8678,72 @@ int CheckIntToFloatTransform(void)
return 0;
}

static
int CheckSaveLinearizationDevicelink(void)
{
const cmsFloat32Number table[] = { 0, 0.5f, 1.0f };

cmsToneCurve* tone = cmsBuildTabulatedToneCurveFloat(NULL, 3, table);

cmsToneCurve* rgb_curves[3] = { tone, tone, tone };

cmsHPROFILE hDeviceLink = cmsCreateLinearizationDeviceLink(cmsSigRgbData, rgb_curves);

cmsBool result;
cmsHTRANSFORM xform;
int i;

cmsFreeToneCurve(tone);

result = cmsSaveProfileToFile(hDeviceLink, "lin_rgb.icc");

cmsCloseProfile(hDeviceLink);

if (!result)
{
remove("lin_rgb.icc");
Fail("Couldn't save linearization devicelink");
}


hDeviceLink = cmsOpenProfileFromFile("lin_rgb.icc", "r");

if (hDeviceLink == NULL)
{
remove("lin_rgb.icc");
Fail("Could't open devicelink");
}

xform = cmsCreateTransform(hDeviceLink, TYPE_RGB_8, NULL, TYPE_RGB_8, INTENT_PERCEPTUAL, 0);
cmsCloseProfile(hDeviceLink);

for (i = 0; i < 256; i++)
{
cmsUInt8Number rgb_in[3] = { i, i, i };
cmsUInt8Number rgb_out[3];

cmsDoTransform(xform, rgb_in, rgb_out, 1);

if (rgb_in[0] != rgb_out[0] ||
rgb_in[1] != rgb_out[1] ||
rgb_in[2] != rgb_out[2])
{
remove("lin_rgb.icc");
Fail("Saved devicelink was not working");
}
}


cmsDeleteTransform(xform);
remove("lin_rgb.icc");

return 1;



}


// --------------------------------------------------------------------------------------------------
// P E R F O R M A N C E C H E C K S
// --------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -9403,7 +9469,7 @@ int main(int argc, char* argv[])
printf("Installing error logger ... ");
cmsSetLogErrorHandler(FatalErrorQuit);
printf("done.\n");

PrintSupportedIntents();

Check("Base types", CheckBaseTypes);
Expand Down Expand Up @@ -9613,6 +9679,7 @@ int main(int argc, char* argv[])
Check("Unbounded mode w/ integer output", CheckIntToFloatTransform);
Check("Corrupted built-in by using cmsWriteRawTag", CheckInducedCorruption);
Check("Bad CGATS file", CheckBadCGATS);
Check("Saving linearization devicelink", CheckSaveLinearizationDevicelink);
}

if (DoPluginTests)
Expand Down

0 comments on commit 32ded9e

Please sign in to comment.