/* ----------------------------- MNI Header ----------------------------------- @NAME : acr_write_one_element @INPUT : afp - Acr_File pointer from which to read group_id - ACR-NEMA group id element_id - ACR-NEMA element id data_length - length of data to follow data_pointer - pointer to data. @OUTPUT : (nothing) @RETURNS : Status. @DESCRIPTION: Routine to write out one ACR-NEMA element. @METHOD : @GLOBALS : @CALLS : @CREATED : November 10, 1993 (Peter Neelin) @MODIFIED : ---------------------------------------------------------------------------- */ Acr_Status acr_write_one_element(Acr_File *afp, int group_id, int element_id, long data_length, char *data_pointer) { int ch, i, buflen; unsigned char buffer[2*ACR_SIZEOF_SHORT+ACR_SIZEOF_LONG]; unsigned short grpid, elid; buflen = sizeof(buffer)/sizeof(buffer[0]); /* Write out group id, element id and length of data */ grpid = group_id; acr_put_short(1, &grpid, &buffer[0]); elid = element_id; acr_put_short(1, &elid, &buffer[2]); acr_put_long(1, &data_length, &buffer[4]); for (i=0; i < buflen; i++) { ch = acr_putc(buffer[i], afp); if (ch == EOF) { return ACR_OTHER_ERROR; } } /* Write out the data */ for (i=0; i < data_length; i++) { ch = acr_putc(data_pointer[i], afp); if (ch == EOF) { return ACR_OTHER_ERROR; } } return ACR_OK; }
/* ----------------------------- MNI Header ----------------------------------- @NAME : update_group_length_element @INPUT : group vr_encoding - ACR_IMPLICIT_VR or ACR_EXPLICIT_VR @OUTPUT : (none) @RETURNS : (nothing) @DESCRIPTION: Update the length element of the group according to the VR type @METHOD : @GLOBALS : @CALLS : @CREATED : February 14, 1997 (Peter Neelin) @MODIFIED : ---------------------------------------------------------------------------- */ static void update_group_length_element(Acr_Group group, Acr_VR_encoding_type vr_encoding) { Acr_Long group_length; Acr_Element length_element; void *group_length_data; /* Get the element */ length_element = group->list_head; if (length_element == NULL) return; if (acr_get_element_element(length_element) != ACR_EID_GRPLEN) return; /* Calculate the appropriate length */ if (vr_encoding == ACR_IMPLICIT_VR) { group_length = group->implicit_total_length - acr_get_element_total_length(length_element, ACR_IMPLICIT_VR); } else { group_length = group->explicit_total_length - acr_get_element_total_length(length_element, ACR_EXPLICIT_VR); } /* Update the element */ group_length_data = acr_get_element_data(length_element); acr_put_long(acr_get_element_byte_order(length_element), 1, &group_length, group_length_data); }
/* ----------------------------- MNI Header ----------------------------------- @NAME : acr_write_one_element @INPUT : afp - Acr_File pointer from which to read group_id - ACR-NEMA group id element_id - ACR-NEMA element id vr_name - 2 character string giving value representation. It is an error to pass in two NULs if explicit VR is used (ACR_NO_VR_SPECIFIED is returned). data_length - length of data to follow. If set to ACR_VARIABLE_LENGTH, then the data portion is not written out. data_pointer - pointer to data. If NULL, then no data is written. @OUTPUT : (nothing) @RETURNS : VIO_Status. @DESCRIPTION: Routine to write out one ACR-NEMA element. @METHOD : @GLOBALS : @CALLS : @CREATED : November 10, 1993 (Peter Neelin) @MODIFIED : January 29, 1997 (P.N.) ---------------------------------------------------------------------------- */ Acr_Status acr_write_one_element(Acr_File *afp, int group_id, int element_id, char vr_name[], long data_length, char *data_pointer) { long buflen; unsigned char buffer[2*ACR_SIZEOF_SHORT+2*ACR_SIZEOF_LONG]; Acr_Short grpid, elid, sval; Acr_Long datalen; int offset; Acr_byte_order byte_order; Acr_Status status; buflen = sizeof(buffer)/sizeof(buffer[0]) - ACR_SIZEOF_LONG; /* Get byte ordering */ byte_order = acr_get_byte_order(afp); /* Get the group id and element id */ offset = 0; grpid = (Acr_Short) group_id; acr_put_short(byte_order, 1, &grpid, &buffer[offset]); offset += ACR_SIZEOF_SHORT; elid = (Acr_Short) element_id; acr_put_short(byte_order, 1, &elid, &buffer[offset]); offset += ACR_SIZEOF_SHORT; /* Check data length */ if ((Acr_Long)data_length == ACR_VARIABLE_LENGTH) datalen = ACR_UNDEFINED_ELEMENT_LENGTH; else datalen = (Acr_Long)data_length; /* Check whether we need VR */ if (acr_get_vr_encoding(afp) == ACR_IMPLICIT_VR) { acr_put_long(byte_order, 1, &datalen, &buffer[offset]); offset += ACR_SIZEOF_LONG; } else { if (vr_name[0] == '\0') return ACR_NO_VR_SPECIFIED; buffer[offset++] = vr_name[0]; buffer[offset++] = vr_name[1]; if (!is_special_vr(vr_name)) { sval = (Acr_Short) datalen; acr_put_short(byte_order, 1, &sval, &buffer[offset]); offset += ACR_SIZEOF_SHORT; } else { sval = 0; acr_put_short(byte_order, 1, &sval, &buffer[offset]); offset += ACR_SIZEOF_SHORT; acr_put_long(byte_order, 1, &datalen, &buffer[offset]); offset += ACR_SIZEOF_LONG; buflen += ACR_SIZEOF_LONG; } } /* Write it out */ status = acr_write_buffer(afp, buffer, buflen, NULL); if (status != ACR_OK) return status; if ((data_length == ACR_VARIABLE_LENGTH) || (data_pointer == NULL)) { return ACR_OK; } /* Write out the data */ status = acr_write_buffer(afp, (unsigned char *) data_pointer, data_length, NULL); if (status != ACR_OK) return status; return ACR_OK; }