/* use PTRefNum1 and PTRefNum2 to propagate attributes to PTRefNumR */ PTErr_t ComposeAttrFut( PTRefNum_t PTRefNum1, PTRefNum_t PTRefNum2, PTRefNum_t PTRefNumR) { PTErr_t errnum = KCP_SUCCESS; KpInt8_t strInSpace[KCM_MAX_ATTRIB_VALUE_LENGTH+1]; KpInt8_t strOutSpace[KCM_MAX_ATTRIB_VALUE_LENGTH+1]; KpInt32_t inspace, outspace, attrSize; /* get 1st PT */ attrSize = KCM_MAX_ATTRIB_VALUE_LENGTH; errnum = PTGetAttribute(PTRefNum1, KCM_SPACE_OUT, &attrSize, strOutSpace); if (errnum == KCP_SUCCESS) { outspace = KpAtoi(strOutSpace); /* get 2nd PT */ attrSize = KCM_MAX_ATTRIB_VALUE_LENGTH; errnum = PTGetAttribute(PTRefNum2, KCM_SPACE_IN, &attrSize, strInSpace); if (errnum == KCP_SUCCESS) { inspace = KpAtoi(strInSpace); if ((outspace == KCM_UNKNOWN) && (inspace != KCM_UNKNOWN)) { errnum = moveAttrList (PTRefNum2, 0, propIAttrF, 0, PTRefNumR); if (errnum == KCP_SUCCESS) { errnum = moveAttrList (PTRefNum2, 0, propOAttrF, 0, PTRefNumR); } return (errnum); } else { if ((outspace != KCM_UNKNOWN) && (inspace == KCM_UNKNOWN)) { errnum = moveAttrList (PTRefNum1, 0, propIAttrF, 0, PTRefNumR); if (errnum == KCP_SUCCESS) { errnum = moveAttrList (PTRefNum1, 0, propOAttrF, 0, PTRefNumR); } return (errnum); } } } } errnum = moveAttrList (PTRefNum1, 0, propIAttrF, 0, PTRefNumR); /* propagate "input" attributes */ if (errnum == KCP_SUCCESS) { errnum = moveAttrList (PTRefNum2, 0, propOAttrF, 0, PTRefNumR); /* propagate "output" attributes */ } return (errnum); }
PTErr_t initAttrib (PTRefNum_t PTRefNum) { PTErr_t errnum = KCP_SUCCESS; KpInt32_t attrSize, year; KpChar_t attrBuf[KCM_MAX_ATTRIB_VALUE_LENGTH+1], yearStr[10]; kpTm_t currentTime; /* If the copyright string isn't there, then generate it */ attrSize = KCM_MAX_ATTRIB_VALUE_LENGTH; errnum = PTGetAttribute (PTRefNum, KCM_COPYRIGHT, &attrSize, attrBuf); if (errnum == KCP_INVAL_PTA_TAG) { KpGetLocalTime(¤tTime); /* get the current time, which has the current year */ year = currentTime.year + 1900; /* add 1900 to get the actual year */ KpItoa (year, yearStr); strcpy (attrBuf, FUT_COPYRIGHT_PREFIX); /* make the copyright string. */ strcat (attrBuf, yearStr); strcat (attrBuf, FUT_COPYRIGHT_SUFFIX); errnum = PTSetAttribute (PTRefNum, KCM_COPYRIGHT, attrBuf); } return errnum; }
/* Set KCM_EFFECT_TYPE attribute, which use a default if the attribute is * present in both PTs but with different values */ static PTErr_t setEFFECTstate (PTRefNum_t PTRefNum1, PTRefNum_t PTRefNum2, PTRefNum_t PTRefNumR) { KpChar_t attrStr[KCM_MAX_ATTRIB_VALUE_LENGTH+1]; KpChar_t attrStr1[KCM_MAX_ATTRIB_VALUE_LENGTH+1], attrStr2[KCM_MAX_ATTRIB_VALUE_LENGTH+1]; PTErr_t PTErr, errnum1, errnum2; KpInt32_t attrSize; PTErr = KCP_FAILURE; /* attribute not yet written */ KpItoa (KCM_EFFECT_MULTIPLE, attrStr); /* initialize to default */ attrSize = KCM_MAX_ATTRIB_VALUE_LENGTH; /* get attribute from 1st PT */ errnum1 = PTGetAttribute (PTRefNum1, KCM_EFFECT_TYPE, &attrSize, attrStr1); attrSize = KCM_MAX_ATTRIB_VALUE_LENGTH; /* get attribute from 2nd PT */ errnum2 = PTGetAttribute (PTRefNum2, KCM_EFFECT_TYPE, &attrSize, attrStr2); if (errnum1 == KCP_SUCCESS) { if ((errnum2 != KCP_SUCCESS) || /* if attribute is not in 2nd */ (strcmp (attrStr1, attrStr2) == 0)) { /* or attribute values are the same */ strcpy (attrStr, attrStr1); /* use attribute in 1st PT */ } } else { if (errnum2 == KCP_SUCCESS) { /* if attribute is in 2nd */ strcpy (attrStr, attrStr2); /* use it */ } else { PTErr = KCP_SUCCESS; /* not in either PT, do not write attribute */ } } if (PTErr != KCP_SUCCESS) { /* write to destination PT */ PTErr = PTSetAttribute (PTRefNumR, KCM_EFFECT_TYPE, attrStr); } return (PTErr); }
/*-------------------------------------------------------------------- * DESCRIPTION * This function obtains the number of input and output * channels of a PT * * AUTHOR * PGT * * DATE CREATED * May 11, 1994 *--------------------------------------------------------------------*/ static PTErr_t getNumChans ( PTRefNum_t RefNum, KpInt32_p numOutChan, KpInt32_p numInVar) { KpInt32_t attrib[FUT_NOCHAN] = {KCM_NUM_VAR_1_IN, KCM_NUM_VAR_2_IN, KCM_NUM_VAR_3_IN, KCM_NUM_VAR_4_IN, KCM_NUM_VAR_5_IN, KCM_NUM_VAR_6_IN, KCM_NUM_VAR_7_IN, KCM_NUM_VAR_8_IN}; KpInt32_t i, nOutChan; PTErr_t PTErr; KpChar_t AttrValue [10]; KpInt32_t AttrSize; /* get number of output variables and the number of input variables for each output variable */ AttrSize = sizeof (AttrValue); PTErr = PTGetAttribute (RefNum, KCM_NUM_VAR_OUT, &AttrSize, AttrValue); if (PTErr != KCP_SUCCESS) { return PTErr; } nOutChan = KpAtoi (AttrValue); *numOutChan = nOutChan; if (nOutChan > FUT_NOCHAN) { nOutChan = FUT_NOCHAN; } for (i = 0; i < nOutChan; i++) { AttrSize = sizeof (AttrValue); PTErr = PTGetAttribute(RefNum, attrib[i], &AttrSize, AttrValue); if (KCP_SUCCESS != PTErr) { numInVar [i] = 0; } else { numInVar [i] = KpAtoi (AttrValue); } } return KCP_SUCCESS; }
/*-------------------------------------------------------------------- * DESCRIPTION * Get the number of input and output channels for a Transform. * * AUTHOR * mjb * * DATE CREATED * October 17, 1995 *------------------------------------------------------------------*/ SpStatus_t KSPAPI SpXformGetChannels ( SpXform_t Xform, KpInt32_t FAR *In, KpInt32_t FAR *Out) { PTRefNum_t refNum; KpChar_t attribute [KCM_MAX_ATTRIB_VALUE_LENGTH+1]; KpInt32_t inChans, outChans, temp, size, attribId, index; SpStatus_t spStatus; PTErr_t ptErr; /* Get the PTRefNum for the transform */ spStatus = SpXformGetRefNum (Xform, &refNum); if (SpStatSuccess != spStatus) { return spStatus; } /* Start by determining the number of output channels */ size = sizeof (attribute); ptErr = PTGetAttribute (refNum, KCM_NUM_VAR_OUT, &size, attribute); if (KCP_SUCCESS != ptErr) { return SpStatBadXform; } outChans = KpAtoi (attribute); /* Check that we didn't exceed the maximum output channels */ if (outChans > SpMaxComponents) { return SpStatBadXform; } /* For each output channel get the number of input channels. The number of input channels must be the same for each output channel. */ inChans = -1; for (index = 0, attribId = KCM_NUM_VAR_1_IN; index < outChans; index++, attribId++) { size = sizeof (attribute); ptErr = PTGetAttribute (refNum, attribId, &size, attribute); if (KCP_SUCCESS != ptErr) { return SpStatBadXform; } temp = KpAtoi (attribute); if (-1 == inChans) { inChans = temp; } else { if (temp != inChans) { return SpStatBadXform; } } } /* return the number of input and output channels */ *In = inChans; *Out = outChans; return SpStatSuccess; }
/* PTActivate reads the PT data from an external memory block and * sets up the technology specific PT memory structures. Before loading * the PT, check to make sure that it matches the "checked in" info. */ PTErr_t PTActivate( PTRefNum_t PTRefNum, KpInt32_t mBlkSize, PTAddr_t PTAddr) { PTErr_t errnum; KpFd_t fd; KpHandle_t PTHdr, PTData, PTHdr2; fut_hdr_p futp; #if !defined KCMS_NO_CRC KpChar_t strCRCmade[KCM_MAX_ATTRIB_VALUE_LENGTH+1]; KpChar_t strCRCfound[KCM_MAX_ATTRIB_VALUE_LENGTH+1]; KpInt32_t crcAttrSize, crc32; #endif KpInt32_t attrSize; PTType_t format; errnum = getPTStatus (PTRefNum); if (errnum != KCP_PT_INACTIVE) { goto ErrOut1; } /* initialize memory file manager */ if (KpOpen (NULL, "m", &fd, NULL, (KpGenericPtr_t)PTAddr, mBlkSize) != KCMS_IO_SUCCESS) { errnum = KCP_SYSERR_1; goto ErrOut1; } /* read in the encoded header, verify that its the same as the original, then discard */ errnum = TpReadHdr (&fd, &PTHdr2, &format); if (errnum != KCP_SUCCESS ) { goto ErrOut2; } #if defined KCP_DIAG_LOG {KpChar_t string[256]; sprintf (string, "\nPTActivate\n PTRefNum %x, mBlkSize %d, PTAddr %x, format %x\n", PTRefNum, mBlkSize, PTAddr, format); kcpDiagLog (string);} #endif /* get and save size of attributes */ futp = lockBuffer (PTHdr2); attrSize = futp->idstr_len; unlockBuffer (PTHdr2); PTHdr = getPTHdr (PTRefNum); /* get the original PT header */ /* make sure the PT header and checkin info match */ errnum = TpCompareHdr (PTHdr, PTHdr2); (void) TpFreeHdr (PTHdr2); /* free the header */ if (errnum != KCP_SUCCESS) { /* then check for an error in hdrVerify */ goto ErrOut2; } #if !defined KCP_ICC_ONLY switch (format) { case PTTYPE_FUTF: /* discard the attribute info */ if (Kp_skip (&fd, attrSize) != KCMS_IO_SUCCESS){ /* may have been setAttribute after checkin */ errnum = KCP_PTERR_3; goto ErrOut2; } break; default: break; } #endif errnum = TpReadData (&fd, format, PTRefNum, PTHdr, &PTData); /* get the PT data */ if (errnum == KCP_SUCCESS) { if (PTMemTest () == 0) { /* enough memory to continue operations? */ errnum = KCP_NO_ACTIVATE_MEM; goto ErrOut3; } #if !defined KCMS_NO_CRC errnum = TpCalCrc (PTHdr, PTData, &crc32); /* calculate the CRC */ if (errnum == KCP_SUCCESS) { KpItoa(crc32, strCRCmade); crcAttrSize = KCM_MAX_ATTRIB_VALUE_LENGTH; errnum = PTGetAttribute(PTRefNum, KCM_CRC, &crcAttrSize, strCRCfound); if (errnum == KCP_INVAL_PTA_TAG) { /* if not present, just set it */ PTSetAttribute(PTRefNum, KCM_CRC, strCRCmade); errnum = KCP_SUCCESS; } else { /* if ((errnum == KCP_SUCCESS)*/ /* if present, must match */ /* && (strcmp (strCRCmade, strCRCfound) != 0)) { */ /* errnum = KCP_INCON_PT; */ /* goto ErrOut3; */ /* } */ } } #endif } if (errnum == KCP_SUCCESS) { /* Everything's OK, now activate */ makeActive (PTRefNum, PTData); } ErrOut2: (void) Kp_close (&fd); ErrOut1: return (errnum); ErrOut3: (void) TpFreeData (PTData); /* Release the PT memory */ goto ErrOut2; }
/*-------------------------------------------------------------------- * DESCRIPTION * This function checks to determine if the PT can be inverted * * AUTHOR * PGT * * DATE CREATED * May 11, 1994 *--------------------------------------------------------------------*/ static KpBool_t InvertOk ( PTRefNum_t RefNum, KpInt32_t senseAttrib) { KpInt32_t sense; KpInt32_t invertAttrib; PTErr_t PTErr; KpChar_t AttrValue [10]; KpInt32_t AttrSize; /* See if the attribute is the right type */ switch (senseAttrib) { case KCM_MEDIUM_SENSE_IN: invertAttrib = KCM_SENSE_INVERTIBLE_IN; break; case KCM_MEDIUM_SENSE_OUT: invertAttrib = KCM_SENSE_INVERTIBLE_OUT; break; default: return KPFALSE; } /* If the sense attribute is not in this PT, then this PT cannot be * inverted for that sense because it is a color space for which * inverting is not appropriate (e.g., RCS) */ AttrSize = sizeof(AttrValue); PTErr = PTGetAttribute (RefNum, senseAttrib, &AttrSize, AttrValue); if (PTErr != KCP_SUCCESS) { return KPFALSE; } sense = KpAtoi (AttrValue); if (KCM_UNKNOWN == sense) { return KPFALSE; } /* Make sure that the PT is allowed to be inverted: * if the attribute KCM_SENSE_INVERTIBLE==KCM_IS_INVERTIBLE * if KCM_SENSE_INVERTIBLE is missing and KCM_CLASS==KCM_OUTPUT_CLASS */ AttrSize = sizeof(AttrValue); PTErr = PTGetAttribute (RefNum, invertAttrib, &AttrSize, AttrValue); /* If attribute not set, OK to invert */ if (PTErr == KCP_SUCCESS) { switch ( KpAtoi (AttrValue)) { case KCM_IS_NOT_INVERTIBLE: return KPFALSE; case KCM_IS_INVERTIBLE: return KPTRUE; } } AttrSize = sizeof(AttrValue); PTErr = PTGetAttribute (RefNum, KCM_CLASS, &AttrSize, AttrValue); if (PTErr != KCP_SUCCESS) { return KPFALSE; } if (KCM_OUTPUT_CLASS == KpAtoi(AttrValue)) { return KPTRUE; } return KPFALSE; }