Skip to content

Commit

Permalink
fix: added check for primaries to write XYZE file
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregungory committed Mar 18, 2021
1 parent b314dc1 commit 488ee66
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/util/rmatrix.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef lint
static const char RCSid[] = "$Id: rmatrix.c,v 2.47 2021/01/22 16:19:15 greg Exp $";
static const char RCSid[] = "$Id: rmatrix.c,v 2.48 2021/03/18 00:34:31 greg Exp $";
#endif
/*
* General matrix operations.
Expand Down Expand Up @@ -398,6 +398,23 @@ rmx_write_rgbe(const RMATRIX *rm, FILE *fp)
return(1);
}

/* Check if CIE XYZ primaries were specified */
static int
findCIEprims(const char *info)
{
RGBPRIMS prims;

if (!info)
return(0);
info = strstr(info, PRIMARYSTR);
if (!info || !primsval(prims, info))
return(0);

return((prims[RED][CIEX] > .99) & (prims[RED][CIEY] < .01) &&
(prims[GRN][CIEX] < .01) & (prims[GRN][CIEY] > .99) &&
(prims[BLU][CIEX] < .01) & (prims[BLU][CIEY] < .01));
}

/* Write matrix to file type indicated by dtype */
int
rmx_write(const RMATRIX *rm, int dtype, FILE *fp)
Expand All @@ -415,7 +432,8 @@ rmx_write(const RMATRIX *rm, int dtype, FILE *fp)
fputs(rm->info, fp);
if (dtype == DTfromHeader)
dtype = rm->dtype;
else if ((dtype == DTrgbe) & (rm->dtype == DTxyze))
else if (dtype == DTrgbe && (rm->dtype == DTxyze ||
findCIEprims(rm->info)))
dtype = DTxyze;
else if ((dtype == DTxyze) & (rm->dtype == DTrgbe))
dtype = DTrgbe;
Expand Down

0 comments on commit 488ee66

Please sign in to comment.