1 /* ----------------------------- MNI Header -----------------------------------
2 @NAME       : acr_nema_io.h
3 @DESCRIPTION: Header file for acr_nema_io code.
4 @METHOD     :
5 @GLOBALS    :
6 @CREATED    : November 10, 1993 (Peter Neelin)
7 @MODIFIED   :
8  * $Log: acr_io.h,v $
9  * Revision 6.4  2008-08-12 05:00:23  rotor
10  *  * large number of changes from Claude (64 bit and updates)
11  *
12  * Revision 6.3  2005/03/04 00:08:08  bert
13  * Cleanup headers, mostly by getting rid of the infernal 'public' and using extern instead
14  *
15  * Revision 6.2  2000/04/28 15:03:11  neelin
16  * Added support for ignoring non-fatal protocol errors (cases where redundant
17  * information is inconsistent). In particular, it is possible to ignore
18  * differences between the group length element and the true group length.
19  *
20  * Revision 6.1  1999/10/29 17:51:50  neelin
21  * Fixed Log keyword
22  *
23  * Revision 6.0  1997/09/12 13:23:59  neelin
24  * Release of minc version 0.6
25  *
26  * Revision 5.1  1997/09/08  21:53:31  neelin
27  * Added status ACR_CONNECTION_TIMEDOUT.
28  *
29  * Revision 5.0  1997/08/21  13:25:00  neelin
30  * Release of minc version 0.5
31  *
32  * Revision 4.1  1997/07/10  17:14:38  neelin
33  * Added more status codes and function to return status string.
34  *
35  * Revision 4.0  1997/05/07  20:01:23  neelin
36  * Release of minc version 0.4
37  *
38  * Revision 3.1  1997/04/21  20:21:09  neelin
39  * Updated the library to handle dicom messages.
40  *
41  * Revision 3.0  1995/05/15  19:32:12  neelin
42  * Release of minc version 0.3
43  *
44  * Revision 2.0  1994/09/28  10:36:07  neelin
45  * Release of minc version 0.2
46  *
47  * Revision 1.8  94/09/28  10:35:40  neelin
48  * Pre-release
49  *
50  * Revision 1.7  94/05/18  08:48:17  neelin
51  * Changed some ACR_OTHER_ERROR's to ACR_ABNORMAL_END_OF_OUTPUT.
52  *
53  * Revision 1.6  94/04/07  10:23:28  neelin
54  * Added ACR_HIGH_LEVEL_ERROR.
55  *
56  * Revision 1.5  94/04/07  10:05:10  neelin
57  * Added status ACR_ABNORMAL_END_OF_INPUT and changed some ACR_PROTOCOL_ERRORs
58  * to that or ACR_OTHER_ERROR.
59  * Added #ifdef lint to DEFINE_ELEMENT.
60  *
61  * Revision 1.4  94/01/06  13:31:30  neelin
62  * Changed acr_need_invert to a public function.
63  *
64  * Revision 1.3  93/11/25  10:37:26  neelin
65  * Added byte-ordering test.
66  *
67  * Revision 1.2  93/11/24  11:26:22  neelin
68  * Changed short to unsigned short.
69  *
70  * Revision 1.1  93/11/19  12:50:15  neelin
71  * Initial revision
72  *
73 @COPYRIGHT  :
74               Copyright 1993 Peter Neelin, McConnell Brain Imaging Centre,
75               Montreal Neurological Institute, McGill University.
76               Permission to use, copy, modify, and distribute this
77               software and its documentation for any purpose and without
78               fee is hereby granted, provided that the above copyright
79               notice appear in all copies.  The author and McGill University
80               make no representations about the suitability of this
81               software for any purpose.  It is provided "as is" without
82               express or implied warranty.
83 ---------------------------------------------------------------------------- */
84 
85 /* Length of short and long for ACR-NEMA protocol */
86 #define ACR_SIZEOF_SHORT  2
87 #define ACR_SIZEOF_LONG   4
88 #define ACR_SIZEOF_FLOAT  4
89 #define ACR_SIZEOF_DOUBLE 8
90 
91 /* Define the C data types for ACR-NEMA protocol.
92    Note: "numeric" functions use the C double datatype directly. */
93 
94 typedef unsigned short Acr_Short;
95 typedef unsigned int Acr_Long;  /* 4 bytes in both 32 and 64 bits */
96 typedef float Acr_Float;
97 typedef double Acr_Double;
98 typedef char * Acr_String;
99 
100 /* Undefined element length value for VRs of SQ, OB, OW */
101 #define ACR_UNDEFINED_ELEMENT_LENGTH 0xFFFFFFFFU
102 
103 /* Tags for sequence items */
104 #define ACR_ITEM_GROUP 0xfffe
105 #define ACR_ITEM_TAG 0xe000
106 #define ACR_ITEM_DELIMITER 0xe00d
107 #define ACR_SEQ_DELIMITER 0xe0dd
108 
109 /* Flag for data length to indicate variable length elements */
110 #define ACR_VARIABLE_LENGTH -1
111 
112 /* Byte-ordering options */
113 typedef enum {
114    ACR_UNKNOWN_ENDIAN = 0,
115    ACR_LITTLE_ENDIAN,
116    ACR_BIG_ENDIAN
117 } Acr_byte_order;
118 
119 /* VR encoding options */
120 typedef enum {
121    ACR_UNKNOWN_VR = 0,
122    ACR_EXPLICIT_VR,
123    ACR_IMPLICIT_VR
124 } Acr_VR_encoding_type;
125 
126 /* Status for io */
127 typedef enum {
128    ACR_OK,
129    ACR_END_OF_INPUT,
130    ACR_PROTOCOL_ERROR,
131    ACR_OTHER_ERROR,
132    ACR_ABNORMAL_END_OF_INPUT,
133    ACR_HIGH_LEVEL_ERROR,
134    ACR_ABNORMAL_END_OF_OUTPUT,
135    ACR_REACHED_WATCHPOINT,
136    ACR_IO_ERROR,
137    ACR_NO_VR_SPECIFIED,
138    ACR_PDU_UID_TOO_LONG,
139    ACR_CONNECTION_TIMEDOUT
140 } Acr_Status;
141 
142 /* Functions */
143 extern void acr_set_byte_order(Acr_File *afp,
144                                Acr_byte_order byte_order);
145 extern Acr_byte_order acr_get_byte_order(Acr_File *afp);
146 extern int acr_get_machine_byte_order(void);
147 extern int acr_need_invert(Acr_byte_order byte_order);
148 extern void acr_set_vr_encoding(Acr_File *afp,
149                                 Acr_VR_encoding_type vr_encoding);
150 extern Acr_VR_encoding_type acr_get_vr_encoding(Acr_File *afp);
151 extern void acr_set_ignore_errors(Acr_File *afp,
152                                   int ignore_nonfatal_protocol_errors);
153 extern int acr_ignore_protocol_errors(Acr_File *afp);
154 extern void acr_reverse_byte_order(long nvals, size_t value_size,
155                                    void *input_values, void *output_values);
156 extern void acr_get_short(Acr_byte_order byte_order,
157                           long nvals, void *input_value,
158                           Acr_Short *mach_value);
159 extern void acr_get_long(Acr_byte_order byte_order,
160                          long nvals, void *input_value, Acr_Long *mach_value);
161 extern void acr_get_float(Acr_byte_order byte_order,
162                           long nvals, void *input_value, Acr_Float *mach_value);
163 extern void acr_get_double(Acr_byte_order byte_order,
164                            long nvals, void *input_value, Acr_Double *mach_value);
165 extern void acr_put_short(Acr_byte_order byte_order,
166                           long nvals, Acr_Short *mach_value,
167                           void *output_value);
168 extern void acr_put_long(Acr_byte_order byte_order,
169                          long nvals, Acr_Long *mach_value, void *output_value);
170 extern void acr_put_float(Acr_byte_order byte_order,
171                           long nvals, Acr_Float *mach_value, void *output_value);
172 extern void acr_put_double(Acr_byte_order byte_order,
173                            long nvals, Acr_Double *mach_value, void *output_value);
174 extern Acr_Status acr_skip_input_data(Acr_File *afp, long nbytes_to_skip);
175 extern Acr_Status acr_read_buffer(Acr_File *afp, unsigned char buffer[],
176                                   long nbytes_to_read, long *nbytes_read);
177 extern Acr_Status acr_unget_buffer(Acr_File *afp, unsigned char buffer[],
178                                    long nbytes_to_unget);
179 extern Acr_Status acr_write_buffer(Acr_File *afp, unsigned char buffer[],
180                                    long nbytes_to_write, long *nbytes_written);
181 extern Acr_Status acr_test_byte_order(Acr_File *afp);
182 extern void acr_copy_file_encoding(Acr_File *afp1, Acr_File *afp2);
183 extern int acr_get_element_header_size(char vr_name[2],
184                                        Acr_VR_encoding_type vr_encoding);
185 extern Acr_Status acr_peek_at_next_element_id(Acr_File *afp,
186                                               int *group_id, int *element_id);
187 extern Acr_Status acr_read_one_element(Acr_File *afp,
188                                        int *group_id, int *element_id,
189                                        char vr_name[],
190                                        long *data_length, char **data_pointer);
191 extern Acr_Status acr_write_one_element(Acr_File *afp,
192                                         int group_id, int element_id,
193                                         char vr_name[],
194                                         long data_length, char *data_pointer);
195 extern char *acr_status_string(Acr_Status status);
196