summaryrefslogtreecommitdiff
path: root/src/cmstypes.c
diff options
context:
space:
mode:
authorMarti Maria <marti.maria@littlecms.com>2021-10-24 11:42:33 +0200
committerMarti Maria <marti.maria@littlecms.com>2021-10-24 11:42:33 +0200
commit0b845e907e63129110e2ce5ee2e4476e7b6efd08 (patch)
tree3e0347056407873864f2d741eeb38ab7a1b69791 /src/cmstypes.c
parent4f2d13b069feb8001beb50870e9297d07de4a53b (diff)
downloadlcms2-0b845e907e63129110e2ce5ee2e4476e7b6efd08.tar.gz
Fix for #287
Fix for #286 Multiprocessor elements sampled curves missing node
Diffstat (limited to 'src/cmstypes.c')
-rw-r--r--src/cmstypes.c70
1 files changed, 42 insertions, 28 deletions
diff --git a/src/cmstypes.c b/src/cmstypes.c
index 6512683..e20c362 100644
--- a/src/cmstypes.c
+++ b/src/cmstypes.c
@@ -3967,41 +3967,44 @@ cmsToneCurve* ReadSegmentedCurve(struct _cms_typehandler_struct* self, cmsIOHAND
switch (ElementSig) {
- case cmsSigFormulaCurveSeg: {
+ case cmsSigFormulaCurveSeg: {
- cmsUInt16Number Type;
- cmsUInt32Number ParamsByType[] = {4, 5, 5 };
+ cmsUInt16Number Type;
+ cmsUInt32Number ParamsByType[] = { 4, 5, 5 };
- if (!_cmsReadUInt16Number(io, &Type)) goto Error;
- if (!_cmsReadUInt16Number(io, NULL)) goto Error;
+ if (!_cmsReadUInt16Number(io, &Type)) goto Error;
+ if (!_cmsReadUInt16Number(io, NULL)) goto Error;
- Segments[i].Type = Type + 6;
- if (Type > 2) goto Error;
+ Segments[i].Type = Type + 6;
+ if (Type > 2) goto Error;
- for (j=0; j < ParamsByType[Type]; j++) {
+ for (j = 0; j < ParamsByType[Type]; j++) {
- cmsFloat32Number f;
- if (!_cmsReadFloat32Number(io, &f)) goto Error;
- Segments[i].Params[j] = f;
- }
- }
- break;
+ cmsFloat32Number f;
+ if (!_cmsReadFloat32Number(io, &f)) goto Error;
+ Segments[i].Params[j] = f;
+ }
+ }
+ break;
- case cmsSigSampledCurveSeg: {
- cmsUInt32Number Count;
+ case cmsSigSampledCurveSeg: {
+ cmsUInt32Number Count;
- if (!_cmsReadUInt32Number(io, &Count)) goto Error;
+ if (!_cmsReadUInt32Number(io, &Count)) goto Error;
- Segments[i].nGridPoints = Count;
- Segments[i].SampledPoints = (cmsFloat32Number*) _cmsCalloc(self ->ContextID, Count, sizeof(cmsFloat32Number));
- if (Segments[i].SampledPoints == NULL) goto Error;
+ // The first point is implicit in the last stage, we allocate an extra note to be populated latter on
+ Count++;
+ Segments[i].nGridPoints = Count;
+ Segments[i].SampledPoints = (cmsFloat32Number*)_cmsCalloc(self->ContextID, Count, sizeof(cmsFloat32Number));
+ if (Segments[i].SampledPoints == NULL) goto Error;
- for (j=0; j < Count; j++) {
- if (!_cmsReadFloat32Number(io, &Segments[i].SampledPoints[j])) goto Error;
- }
- }
- break;
+ Segments[i].SampledPoints[0] = 0;
+ for (j = 1; j < Count; j++) {
+ if (!_cmsReadFloat32Number(io, &Segments[i].SampledPoints[j])) goto Error;
+ }
+ }
+ break;
default:
{
@@ -4021,6 +4024,17 @@ cmsToneCurve* ReadSegmentedCurve(struct _cms_typehandler_struct* self, cmsIOHAND
if (Segments[i].SampledPoints) _cmsFree(self ->ContextID, Segments[i].SampledPoints);
}
_cmsFree(self ->ContextID, Segments);
+
+ // Explore for missing implicit points
+ for (i = 0; i < nSegments; i++) {
+
+ // If sampled curve, fix it
+ if (Curve->Segments[i].Type == 0) {
+
+ Curve->Segments[i].SampledPoints[0] = cmsEvalToneCurveFloat(Curve, Curve->Segments[i].x0);
+ }
+ }
+
return Curve;
Error:
@@ -4115,12 +4129,12 @@ cmsBool WriteSegmentedCurve(cmsIOHANDLER* io, cmsToneCurve* g)
if (ActualSeg -> Type == 0) {
- // This is a sampled curve
+ // This is a sampled curve. First point is implicit in the ICC format, but not in our representation
if (!_cmsWriteUInt32Number(io, (cmsUInt32Number) cmsSigSampledCurveSeg)) goto Error;
if (!_cmsWriteUInt32Number(io, 0)) goto Error;
- if (!_cmsWriteUInt32Number(io, ActualSeg -> nGridPoints)) goto Error;
+ if (!_cmsWriteUInt32Number(io, ActualSeg -> nGridPoints - 1)) goto Error;
- for (j=0; j < g ->Segments[i].nGridPoints; j++) {
+ for (j=1; j < g ->Segments[i].nGridPoints; j++) {
if (!_cmsWriteFloat32Number(io, ActualSeg -> SampledPoints[j])) goto Error;
}