/* Currently called by 1 function with i == pxformseq->numpxforms - 1 */ static int jas_cmpxformseq_delete(jas_cmpxformseq_t *pxformseq, int i) { jas_cmpxform_destroy(pxformseq->pxforms[i]); pxformseq->pxforms[i] = 0; --pxformseq->numpxforms; return 0; }
static int jas_cmpxformseq_delete(jas_cmpxformseq_t *pxformseq, int i) { assert(i >= 0 && i < pxformseq->numpxforms); if (i != pxformseq->numpxforms - 1) abort(); jas_cmpxform_destroy(pxformseq->pxforms[i]); pxformseq->pxforms[i] = 0; --pxformseq->numpxforms; return 0; }
static int mono(jas_iccprof_t *iccprof, int op, jas_cmpxformseq_t **retpxformseq) { jas_iccattrval_t *graytrc; jas_cmshapmat_t *shapmat; jas_cmpxform_t *pxform; jas_cmpxformseq_t *pxformseq; jas_cmshapmatlut_t lut; jas_cmshapmatlut_init(&lut); if (!(graytrc = jas_iccprof_getattr(iccprof, JAS_ICC_TAG_GRYTRC)) || graytrc->type != JAS_ICC_TYPE_CURV) goto error; if (!(pxform = jas_cmpxform_createshapmat())) goto error; shapmat = &pxform->data.shapmat; if (!(pxformseq = jas_cmpxformseq_create())) goto error; if (jas_cmpxformseq_insertpxform(pxformseq, -1, pxform)) goto error; pxform->numinchans = 1; pxform->numoutchans = 3; shapmat->mono = 1; shapmat->useluts = 1; shapmat->usemat = 1; if (!op) { shapmat->order = 0; shapmat->mat[0][0] = 0.9642; shapmat->mat[1][0] = 1.0; shapmat->mat[2][0] = 0.8249; if (jas_cmshapmatlut_set(&shapmat->luts[0], &graytrc->data.curv)) goto error; } else { shapmat->order = 1; shapmat->mat[0][0] = 1.0 / 0.9642; shapmat->mat[1][0] = 1.0; shapmat->mat[2][0] = 1.0 / 0.8249; jas_cmshapmatlut_init(&lut); if (jas_cmshapmatlut_set(&lut, &graytrc->data.curv)) goto error; if (jas_cmshapmatlut_invert(&shapmat->luts[0], &lut, lut.size)) goto error; jas_cmshapmatlut_cleanup(&lut); } jas_iccattrval_destroy(graytrc); jas_cmpxform_destroy(pxform); *retpxformseq = pxformseq; return 0; error: return -1; }
static jas_cmprof_t *jas_cmprof_createsycc() { jas_cmprof_t *prof; jas_cmpxform_t *fwdpxform; jas_cmpxform_t *revpxform; jas_cmshapmat_t *fwdshapmat; jas_cmshapmat_t *revshapmat; int i; int j; if (!(prof = jas_cmprof_createfromclrspc(JAS_CLRSPC_SRGB))) goto error; prof->clrspc = JAS_CLRSPC_SYCBCR; assert(prof->numchans == 3 && prof->numrefchans == 3); assert(prof->refclrspc == JAS_CLRSPC_CIEXYZ); if (!(fwdpxform = jas_cmpxform_createshapmat())) goto error; fwdpxform->numinchans = 3; fwdpxform->numoutchans = 3; fwdshapmat = &fwdpxform->data.shapmat; fwdshapmat->mono = 0; fwdshapmat->order = 0; fwdshapmat->useluts = 0; fwdshapmat->usemat = 1; fwdshapmat->mat[0][0] = 1.0; fwdshapmat->mat[0][1] = 0.0; fwdshapmat->mat[0][2] = 1.402; fwdshapmat->mat[1][0] = 1.0; fwdshapmat->mat[1][1] = -0.34413; fwdshapmat->mat[1][2] = -0.71414; fwdshapmat->mat[2][0] = 1.0; fwdshapmat->mat[2][1] = 1.772; fwdshapmat->mat[2][2] = 0.0; fwdshapmat->mat[0][3] = -0.5 * (1.402); fwdshapmat->mat[1][3] = -0.5 * (-0.34413 - 0.71414); fwdshapmat->mat[2][3] = -0.5 * (1.772); if (!(revpxform = jas_cmpxform_createshapmat())) goto error; revpxform->numinchans = 3; revpxform->numoutchans = 3; revshapmat = &revpxform->data.shapmat; revshapmat->mono = 0; revshapmat->order = 1; revshapmat->useluts = 0; revshapmat->usemat = 1; jas_cmshapmat_invmat(revshapmat->mat, fwdshapmat->mat); for (i = 0; i < JAS_CMXFORM_NUMINTENTS; ++i) { j = SEQFWD(i); if (prof->pxformseqs[j]) { if (jas_cmpxformseq_insertpxform(prof->pxformseqs[j], 0, fwdpxform)) goto error; } j = SEQREV(i); if (prof->pxformseqs[j]) { if (jas_cmpxformseq_insertpxform(prof->pxformseqs[j], -1, revpxform)) goto error; } } jas_cmpxform_destroy(fwdpxform); jas_cmpxform_destroy(revpxform); return prof; error: return 0; }
static int triclr(jas_iccprof_t *iccprof, int op, jas_cmpxformseq_t **retpxformseq) { int i; jas_iccattrval_t *trcs[3]; jas_iccattrval_t *cols[3]; jas_cmshapmat_t *shapmat; jas_cmpxform_t *pxform; jas_cmpxformseq_t *pxformseq; jas_cmreal_t mat[3][4]; jas_cmshapmatlut_t lut; pxform = 0; pxformseq = 0; for (i = 0; i < 3; ++i) { trcs[i] = 0; cols[i] = 0; } jas_cmshapmatlut_init(&lut); if (!(trcs[0] = jas_iccprof_getattr(iccprof, JAS_ICC_TAG_REDTRC)) || !(trcs[1] = jas_iccprof_getattr(iccprof, JAS_ICC_TAG_GRNTRC)) || !(trcs[2] = jas_iccprof_getattr(iccprof, JAS_ICC_TAG_BLUTRC)) || !(cols[0] = jas_iccprof_getattr(iccprof, JAS_ICC_TAG_REDMATCOL)) || !(cols[1] = jas_iccprof_getattr(iccprof, JAS_ICC_TAG_GRNMATCOL)) || !(cols[2] = jas_iccprof_getattr(iccprof, JAS_ICC_TAG_BLUMATCOL))) goto error; for (i = 0; i < 3; ++i) { if (trcs[i]->type != JAS_ICC_TYPE_CURV || cols[i]->type != JAS_ICC_TYPE_XYZ) goto error; } if (!(pxform = jas_cmpxform_createshapmat())) goto error; pxform->numinchans = 3; pxform->numoutchans = 3; shapmat = &pxform->data.shapmat; if (!(pxformseq = jas_cmpxformseq_create())) goto error; if (jas_cmpxformseq_insertpxform(pxformseq, -1, pxform)) goto error; shapmat->mono = 0; shapmat->useluts = 1; shapmat->usemat = 1; if (!op) { shapmat->order = 0; for (i = 0; i < 3; ++i) { shapmat->mat[0][i] = cols[i]->data.xyz.x / 65536.0; shapmat->mat[1][i] = cols[i]->data.xyz.y / 65536.0; shapmat->mat[2][i] = cols[i]->data.xyz.z / 65536.0; } for (i = 0; i < 3; ++i) shapmat->mat[i][3] = 0.0; for (i = 0; i < 3; ++i) { if (jas_cmshapmatlut_set(&shapmat->luts[i], &trcs[i]->data.curv)) goto error; } } else { shapmat->order = 1; for (i = 0; i < 3; ++i) { mat[0][i] = cols[i]->data.xyz.x / 65536.0; mat[1][i] = cols[i]->data.xyz.y / 65536.0; mat[2][i] = cols[i]->data.xyz.z / 65536.0; } for (i = 0; i < 3; ++i) mat[i][3] = 0.0; if (jas_cmshapmat_invmat(shapmat->mat, mat)) goto error; for (i = 0; i < 3; ++i) { jas_cmshapmatlut_init(&lut); if (jas_cmshapmatlut_set(&lut, &trcs[i]->data.curv)) goto error; if (jas_cmshapmatlut_invert(&shapmat->luts[i], &lut, lut.size)) goto error; jas_cmshapmatlut_cleanup(&lut); } } for (i = 0; i < 3; ++i) { jas_iccattrval_destroy(trcs[i]); jas_iccattrval_destroy(cols[i]); } jas_cmpxform_destroy(pxform); *retpxformseq = pxformseq; return 0; error: for (i = 0; i < 3; ++i) { if (trcs[i]) { jas_iccattrval_destroy(trcs[i]); } if (cols[i]) { jas_iccattrval_destroy(cols[i]); } } if (pxformseq) { jas_cmpxformseq_destroy(pxformseq); } if (pxform) { jas_cmpxform_destroy(pxform); } return -1; }