1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * filename: m-global.c                                                    *
3  *                                                                         *
4  * UTIL C-source: Medical Image Conversion Utility                         *
5  *                                                                         *
6  * purpose      : define global variables                                  *
7  *                                                                         *
8  * project      : (X)MedCon by Erik Nolf                                   *
9  *                                                                         *
10  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
11 /*
12  */
13 
14 /*
15    Copyright (C) 1997-2021 by Erik Nolf
16 
17    This program is free software; you can redistribute it and/or modify it
18    under the terms of the GNU General Public License as published by the
19    Free Software Foundation; either version 2, or (at your option) any later
20    version.
21 
22    This program is distributed in the hope that it will be useful, but
23    WITHOUT ANY WARRANTY; without even the implied warranty of
24    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
25    Public License for more details.
26 
27    You should have received a copy of the GNU General Public License along
28    with this program; if not, write to the Free Software Foundation, Inc.,
29    59 Place - Suite 330, Boston, MA 02111-1307, USA.  */
30 
31 /****************************************************************************
32                               H E A D E R S
33 ****************************************************************************/
34 
35 
36 #include <stdio.h>
37 #include "m-defs.h"
38 
39 /****************************************************************************
40                               D E F I N E S
41 ****************************************************************************/
42 
43 /* all our version constants */
44 const char  *MDC_MAJOR = XMEDCON_MAJOR;
45 const char  *MDC_MINOR = XMEDCON_MINOR;
46 const char  *MDC_MICRO = XMEDCON_MICRO;
47 const char  *MDC_PRGR  = XMEDCON_PRGR;
48 const char  *MDC_DATE  = XMEDCON_DATE;
49 const char  *MDC_VERSION = XMEDCON_VERSION;
50 const char  *MDC_LIBVERS = XMEDCON_LIBVERS;
51 
52 /* fill in host endian and default write endian */
53 Int8 MDC_HOST_ENDIAN = -1;
54 Int8 MDC_WRITE_ENDIAN= -1;
55 Int8 MDC_FILE_ENDIAN = -1;
56 
57 Int8 MDC_BLOCK_MESSAGES = MDC_NO;
58 
59 /* globally available variables */
60 char prefix[MDC_MAX_PREFIX + 1]="eNlf-"; /* 15 + '\O' */
61 char *mdcbasename=NULL;                  /* new base  */
62 
63 /* global arrays for argument handling */
64 char *mdc_arg_files[MDC_MAX_FILES];    /* pointers to filenames         */
65 int   mdc_arg_convs[MDC_MAX_FRMTS];    /* counter for each conversion   */
66 int   mdc_arg_total[2];                /* totals for files & conversion */
67 
68 /* format support compiled in */
69 Int8 FrmtSupported[MDC_MAX_FRMTS] = {
70     0,                  /* MDC_FRMT_NONE  */
71     1,                  /* MDC_FRMT_RAW   */
72     1,                  /* MDC_FRMT_ASCII */
73     MDC_INCLUDE_GIF,    /* MDC_FRMT_GIF   */
74     MDC_INCLUDE_ACR,    /* MDC_FRMT_ACR   */
75     MDC_INCLUDE_INW,    /* MDC_FRMT_INW   */
76     MDC_INCLUDE_ECAT,   /* MDC_FRMT_ECAT6 */
77     MDC_INCLUDE_ECAT,   /* MDC_FRMT_ECAT7 */
78     MDC_INCLUDE_INTF,   /* MDC_FRMT_INTF  */
79     MDC_INCLUDE_ANLZ,   /* MDC_FRMT_ANLZ  */
80     MDC_INCLUDE_DICM,   /* MDC_FRMT_DICM  */
81     MDC_INCLUDE_PNG,    /* MDC_FRMT_PNG   */
82     MDC_INCLUDE_CONC,   /* MDC_FRMT_CONC  */
83     MDC_INCLUDE_NIFTI   /* MDC_FRMT_NIFTI */
84   /*.................                     */
85 };
86 
87 /* format name */
88 char FrmtString[MDC_MAX_FRMTS][15]= {
89     "Unknown      ",    /* MDC_FRMT_NONE  */
90     "Raw Binary   ",    /* MDC_FRMT_RAW   */
91     "Raw Ascii    ",    /* MDC_FRMT_ASCII */
92     "Gif89a       ",    /* MDC_FRMT_GIF   */
93     "Acr/Nema     ",    /* MDC_FRMT_ACR   */
94     "INW (RUG)    ",    /* MDC_FRMT_INW   */
95     "CTI ECAT 6   ",    /* MDC_FRMT_ECAT6 */
96     "CTI ECAT 7   ",    /* MDC_FRMT_ECAT7 */
97     "InterFile    ",    /* MDC_FRMT_INTF  */
98     "Analyze      ",    /* MDC_FRMT_ANLZ  */
99     "DICOM        ",    /* MDC_FRMT_DICM  */
100     "PNG          ",    /* MDC_FRMT_PNG   */
101     "Concorde/uPET",    /* MDC_FRMT_CONC  */
102     "NIfTI        "     /* MDC_FRMT_NIFTI */
103   /*"............."                       */
104 };
105 
106 /* format extension */
107 char FrmtExt[MDC_MAX_FRMTS][8] = {
108     "???",    /* MDC_FRMT_NONE  */
109     "bin",    /* MDC_FRMT_RAW   */
110     "asc",    /* MDC_FRMT_ASCII */
111     "gif",    /* MDC_FRMT_GIF   */
112     "ima",    /* MDC_FRMT_ACR   */
113     "im",     /* MDC_FRMT_INW   */
114     "img",    /* MDC_FRMT_ECAT6 */
115     "v",      /* MDC_FRMT_ECAT7 */
116     "h33",    /* MDC_FRMT_INTF  */
117     "hdr",    /* MDC_FRMT_ANLZ  */
118     "dcm",    /* MDC_FRMT_DICM  */
119     "png",    /* MDC_FRMT_PNG   */
120     "img.hdr",/* MDC_FRMT_CONC  */
121     "nii"     /* MDC_FRMT_NIFTI */
122   /*"..."                       */
123 };
124 
125 char mdcbufr[MDC_2KB_OFFSET+1]; /* 2KB global buffer */
126 char errmsg[MDC_1KB_OFFSET+1];  /* 1KB error  buffer */
127 
128 /* user specified slope/intercept */
129 float mdc_si_slope     = 1.;
130 float mdc_si_intercept = 0.;
131 
132 /* user specified window center/width */
133 float mdc_cw_centre    = 0.;
134 float mdc_cw_width     = 0.;
135 
136 /* predefined mosaic stamps layout */
137 Uint32 mdc_mosaic_width = 0;
138 Uint32 mdc_mosaic_height= 0;
139 Uint32 mdc_mosaic_number= 0;
140 Int8   mdc_mosaic_interlaced = MDC_NO;
141 
142 /* crop settings */
143 Uint32 mdc_crop_xoffset = 0;
144 Uint32 mdc_crop_yoffset = 0;
145 Uint32 mdc_crop_width   = 0;
146 Uint32 mdc_crop_height  = 0;
147 
148 /* flags & options */
149 char MDC_INSTITUTION[MDC_MAXSTR]="NucMed"; /* name of institution           */
150 
151 Int8 MDC_COLOR_MODE=  MDC_COLOR_RGB;    /* default color mode               */
152 Int8 MDC_COLOR_MAP =  MDC_MAP_GRAY;     /* gray color palette selected      */
153 
154 Int8 MDC_PADDING_MODE= MDC_PAD_BOTTOM_RIGHT; /* resized image padding mode */
155 
156 Int8 MDC_ANLZ_SPM  =  MDC_NO;           /* Analyze/SPM with scaling factor  */
157 Int8 MDC_ANLZ_OPTIONS = MDC_NO;         /* Analyze/SPM request parameters   */
158 
159 Int8 MDC_DICOM_MOSAIC_ENABLED = MDC_NO;    /* DICOM: mosaic support enabled   */
160 Int8 MDC_DICOM_MOSAIC_FORCED  = MDC_NO;    /* DICOM: mosaic preset  forced    */
161 Int8 MDC_DICOM_MOSAIC_DO_INTERL = MDC_NO;  /* DICOM: mosaic forced interlaced */
162 Int8 MDC_DICOM_MOSAIC_FIX_VOXEL = MDC_NO;  /* DICOM: mosaic fix voxel sizes   */
163 Int8 MDC_DICOM_WRITE_IMPLICIT = MDC_NO;    /* DICOM: write little implicit    */
164 Int8 MDC_DICOM_WRITE_NOMETA = MDC_NO;      /* DICOM: write without meta header*/
165 
166 Int8 MDC_FORCE_RESCALE = MDC_NO;        /* user specified slope/intercept   */
167 Int8 MDC_FORCE_CONTRAST= MDC_NO;        /* user specified center/width      */
168 
169 Int8 MDC_INFO = MDC_YES;                /* default print header info        */
170 Int8 MDC_INTERACTIVE = MDC_NO;          /* interactive read of raw file     */
171 Int8 MDC_CONVERT = MDC_NO;              /* image conversion requested       */
172 Int8 MDC_EXTRACT = MDC_NO;              /* extract images                   */
173 Int8 MDC_RENAME = MDC_NO;               /* rename base filename             */
174 Int8 MDC_ECHO_ALIAS = MDC_NO;           /* echo alias name based on ID's    */
175 Int8 MDC_EDIT_FI = MDC_NO;              /* edit FILEINFO struct             */
176 
177 Int8 MDC_PIXELS = MDC_NO;               /* print specified pix values       */
178 Int8 MDC_PIXELS_PRINT_ALL = MDC_NO;     /* print    all    pix values       */
179 
180 Int8 MDC_NEGATIVE = MDC_NO;             /* allow negative pixel values      */
181 Int8 MDC_QUANTIFY = MDC_NO;             /* quantitation with one factor     */
182 Int8 MDC_CALIBRATE = MDC_NO;            /* quantitation with two factors    */
183 Int8 MDC_CONTRAST_REMAP = MDC_NO;       /* apply contrast remapping         */
184 
185 Int8 MDC_DEBUG = MDC_NO;                /* give debug info                  */
186 Int8 MDC_VERBOSE = MDC_NO;              /* run in verbose mode              */
187 
188 Int8 MDC_GIF_OPTIONS = MDC_NO;          /* request for extra GIF options    */
189 
190 Int8 MDC_MAKE_GRAY = MDC_NO;            /* forced remap color to gray scale */
191 Int8 MDC_DITHER_COLOR = MDC_NO;         /* apply dither on color reduction  */
192 
193 Int8 MDC_NORM_OVER_FRAMES = MDC_NO;     /* normalize over images in a frame */
194                                         /* instead of all images            */
195 Int8 MDC_SKIP_PREVIEW = MDC_NO;         /* skip the first (preview) slice   */
196 Int8 MDC_IGNORE_PATH = MDC_NO;          /* ignore path in INTF data fname   */
197 Int8 MDC_SINGLE_FILE = MDC_NO;          /* write INTF as single file        */
198 Int8 MDC_FORCE_INT = MDC_NO;            /* force integer pixels             */
199 Int8 MDC_INT16_BITS_USED = 16;          /* bits to use for Int16 type       */
200 Int8 MDC_TRUE_GAP = MDC_NO;             /* spacing = true gap/overlap       */
201 Int8 MDC_ALIAS_NAME = MDC_NO;           /* use  alias name based on ID's    */
202 Int8 MDC_PREFIX_DISABLED = MDC_NO;      /* prevent the prefix in names      */
203 Int8 MDC_PREFIX_ACQ = MDC_NO;           /* use acquisition number as prefix */
204 Int8 MDC_PREFIX_SER = MDC_NO;           /* use series      number as prefix */
205 
206 Int8 MDC_PATIENT_ANON = MDC_NO;         /* make patient anonymous           */
207 Int8 MDC_PATIENT_IDENT = MDC_NO;        /* give patient identification      */
208 Int8 MDC_FILE_OVERWRITE = MDC_NO;       /* allow file overwriting           */
209 Int8 MDC_FILE_STDIN  = MDC_NO;          /* input from stdin  stream         */
210 Int8 MDC_FILE_STDOUT = MDC_NO;          /* output  to stdout stream         */
211 Int8 MDC_FILE_SPLIT  = MDC_NO;          /* split up file in parts           */
212 Int8 MDC_FILE_STACK  = MDC_NO;          /* stack up files                   */
213 
214 Int8 MDC_FLIP_HORIZONTAL = MDC_NO;      /* flip horizontal   (x)            */
215 Int8 MDC_FLIP_VERTICAL   = MDC_NO;      /* flip vertical     (y)            */
216 Int8 MDC_SORT_REVERSE    = MDC_NO;      /* reverse   sorting                */
217 Int8 MDC_SORT_CINE_APPLY = MDC_NO;      /* cine apply sorting               */
218 Int8 MDC_SORT_CINE_UNDO  = MDC_NO;      /* cine undo  sorting               */
219 Int8 MDC_MAKE_SQUARE     = MDC_NO;      /* make square image                */
220 Int8 MDC_CROP_IMAGES     = MDC_NO;      /* crop image dimensions            */
221 Int8 MDC_RESLICE = MDC_NO;              /* reslice images (tra, sag, cor)   */
222 
223 Int8 MDC_FRMT_INPUT = MDC_FRMT_NONE;    /* format used for stdin            */
224 Int8 MDC_ECAT6_SORT = MDC_ANATOMICAL;   /* ECAT sort order                  */
225 
226 #if   MDC_INCLUDE_DICM                  /* fallback read format             */
227 Int8 MDC_FALLBACK_FRMT = MDC_FRMT_DICM;
228 #elif MDC_INCLUDE_ECAT
229 Int8 MDC_FALLBACK_FRMT = MDC_FRMT_ECAT6;
230 #elif MDC_INCLUDE_ANLZ
231 Int8 MDC_FALLBACK_FRMT = MDC_FRMT_ANLZ;
232 #elif MDC_INCLUDE_CONC
233 Int8 MDC_FALLBACK_FRMT = MDC_FRMT_CONC;
234 #else
235 Int8 MDC_FALLBACK_FRMT = MDC_FRMT_NONE;
236 #endif
237 
238 /* undocumented options, for debugging purposes only */
239 Int8 MDC_MY_DEBUG=MDC_NO;               /* give even more debug info        */
240 Int8 MDC_INFO_DB=MDC_NO;                /* just print short database info   */
241 Int8 MDC_HACK_ACR=MDC_NO;               /* try to find acrnema tags         */
242 
243 /* XMedCon - GUI*/
244 Int8 XMDC_GUI=MDC_NO;                   /* is program the GUI part?         */
245 Int8 XMDC_WRITE_FRMT = MDC_FRMT_RAW;    /* default format to save           */
246