1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
|
/*
Copyright (C) 1993, 1994, RSNA and Washington University
The software and supporting documentation for the Radiological
Society of North America (RSNA) 1993, 1994 Digital Imaging and
Communications in Medicine (DICOM) Demonstration were developed
at the
Electronic Radiology Laboratory
Mallinckrodt Institute of Radiology
Washington University School of Medicine
510 S. Kingshighway Blvd.
St. Louis, MO 63110
as part of the 1993, 1994 DICOM Central Test Node project for, and
under contract with, the Radiological Society of North America.
THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND NEITHER RSNA NOR
WASHINGTON UNIVERSITY MAKE ANY WARRANTY ABOUT THE SOFTWARE, ITS
PERFORMANCE, ITS MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR
USE, FREEDOM FROM ANY COMPUTER DISEASES OR ITS CONFORMITY TO ANY
SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND PERFORMANCE OF
THE SOFTWARE IS WITH THE USER.
Copyright of the software and supporting documentation is
jointly owned by RSNA and Washington University, and free access
is hereby granted as a license to use this software, copy this
software and prepare derivative works based upon this software.
However, any distribution of this software source code or
supporting documentation or derivative works (source code and
supporting documentation) must include the three paragraphs of
the copyright notice.
*/
/* Copyright marker. Copyright will be inserted above. Do not remove */
/*
** DICOM 93
** Electronic Radiology Laboratory
** Mallinckrodt Institute of Radiology
** Washington University School of Medicine
**
** Module Name(s): ctndisp (main())
** Author, Date: David E. Beecher, 4-Jul-93
** Intent: DICOM Image display server.
** Last Update: $Author: smm $, $Date: 2002-12-13 15:18:24 $
** Source File: $RCSfile: ctndisp.c,v $
** Revision: $Revision: 1.13 $
** Status: $State: Exp $
*/
static char rcsid[] = "$Revision: 1.13 $ $RCSfile: ctndisp.c,v $";
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#ifdef X11
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
#include "dicom.h"
#include "condition.h"
#include "lst.h"
#include "dicom_objects.h"
#include "iqueues.h"
#include "gq.h"
#include "xutl.h"
#include "common_x.h"
#include "ctndisp.h"
#include "common_disp.h"
char *CTNDISP_usage = "CTNDISP Usage: ctndisp -n node -q queue_number [-w display_width -h display_height]\n";
/*
* This typedef and these function prototypes occur here because
* gcc can't handlel the X include libraries....this is the short
* answer...
*/
#ifdef SMM
typedef struct _XImageStruct {
XImage *x_image; /* the X image struct */
Window image_window; /* the window for display */
} XImageStruct;
#endif
void CTNDISP_AdjustImageDepth(ImageStruct * img);
void CTNDISP_DisplayImageData(ImageStruct * img, XImageStruct * ximg);
void CTNDISP_RefreshImageData(ImageStruct * img, XImageStruct * ximg);
/*
* Globals (preceded with G_)...declared extern in other files
*/
Window G_big_window;
#if 0
Display *G_display; /* Xstuff used all over... */
#endif
Visual *G_visual;
#if 0
Colormap G_cmap;
#endif
GC
G_gclargeT,
G_gcsmallT,
G_gclargeTred,
G_gclargeTgreen,
G_gcblack, /* Graphics contexts needed... */
G_gcred,
G_gcgreen;
int G_display_width,
G_display_height, /* Well known screen stuff... */
G_screen,
G_pixel_depth,
G_store_depth,
G_byte_order,
G_ncolors;
int G_FirstTime = TRUE;
char G_nodename[MAX_STRING_LENGTH];
char G_dpnname[MAX_STRING_LENGTH];
XUTL_STRUCT* G_xStruct = 0;
/*
* End Globals...
*/
ImageStruct cur_img,
next_img;
XImageStruct xcur_img,
xnext_img;
/*******************************************************************/
main(int argc, char **argv)
{
CONDITION
retval;
CTNDISP_Queue
element;
void
*data;
unsigned char
*new_data;
unsigned long
options;
int
count_args,
node_arg;
int
QueueElementSize,
diag_level,
image_Q_id = 0;
char
log_file[MAX_STRING_LENGTH];
QueueElementSize = sizeof(CTNDISP_Queue);
/*
* Get the input paramaters from command line
*/
if (argc < 3) {
COND_PushCondition(CTNDISP_CMDLINE, "%s", CTNDISP_usage);
COND_DumpConditions();
exit(-1);
}
count_args = node_arg = 0;
argc--;
argv++;
while (argc > 0) {
if ((strcmp(*argv, "-q")) == 0) {
argc--;
argv++;
if (!*argv) {
fprintf(stderr, "Missing required argument for option -q\n");
exit(-1);
}
image_Q_id = atoi(*argv);
if (image_Q_id < 0) {
COND_PushCondition(CTNDISP_CMDLINE,
"CTNDISP: Queue number must > 0");
COND_DumpConditions();
exit(-1);
}
argc--;
argv++;
} else if ((strcmp(*argv, "-w")) == 0) {
argc--;
argv++;
if (!*argv) {
fprintf(stderr, "Missing required argument for option -w\n");
exit(-1);
}
G_display_width = atoi(*argv);
if (G_display_width < MIN_DISPLAY_WIDTH) {
COND_PushCondition(CTNDISP_CMDLINE,
"CTNDISP: Display width must be > MIN_DISPLAY_WIDTH");
COND_DumpConditions();
exit(-1);
}
count_args++;
argc--;
argv++;
} else if ((strcmp(*argv, "-h")) == 0) {
argc--;
argv++;
if (!*argv) {
fprintf(stderr, "Missing required argument for option -h\n");
exit(-1);
}
G_display_height = atoi(*argv);
if (G_display_height < MIN_DISPLAY_HEIGHT) {
COND_PushCondition(CTNDISP_CMDLINE,
"CTNDISP: Display height must be > MIN_DISPLAY_HEIGHT");
COND_DumpConditions();
exit(-1);
}
count_args++;
argc--;
argv++;
} else if ((strcmp(*argv, "-n")) == 0) {
argc--;
argv++;
if (!*argv) {
fprintf(stderr, "Missing required argument for option -n\n");
exit(-1);
}
strcpy(G_nodename, *argv);
node_arg++;
argc--;
argv++;
} else {
COND_PushCondition(CTNDISP_CMDLINE, CTNDISP_usage);
COND_DumpConditions();
exit(-1);
}
}
/*
* -1's indicate to set the width and height to full screen
*/
if (count_args != 2)
G_display_width = G_display_height = -1;
if (node_arg == 0)
strcpy(G_nodename, "UNKNOWN");
/*
* Initialize the Generalized Queue for images and status messages
*/
if (GQ_GetQueue(image_Q_id, QueueElementSize) != GQ_NORMAL) {
if ((GQ_InitQueue(image_Q_id, QUEUE_SIZE, QueueElementSize)) != GQ_NORMAL) {
COND_PushCondition(CTNDISP_NOGQ, "CTNDISP: Not able to access Image Queue.");
COND_DumpConditions();
exit(-1);
}
if (GQ_GetQueue(image_Q_id, QueueElementSize) != GQ_NORMAL) {
COND_PushCondition(CTNDISP_NOGQ, "CTNDISP: Not able to get Image Queue.");
COND_DumpConditions();
exit(-1);
}
}
/*
* Initialize the X stuff, load gray-scale color table
*/
if ((CTNDISP_InitializeX(128)) != CTNDISP_NORMAL) {
COND_PushCondition(CTNDISP_NOXWINDOWS,
"CTNDISP: No Connection to X-Server.");
(void) GQ_KillQueue(image_Q_id);
COND_DumpConditions();
exit(-1);
}
/*
* Display node name and the status buttons...
*/
strcpy(G_dpnname, "none");
CTNDISP_CreateIncomingOutgoing();
CTNDISP_CheckStatus();
/*
* Main Control loop for ctndisp
*/
retval = GQ_Dequeue(image_Q_id, (void *) &element);
if (retval == GQ_NORMAL)
strcpy(G_dpnname, element.dpnid);
while (strcmp(element.imagefile, KILL_DISPLAY) != 0) {
if (retval == GQ_NORMAL) {
switch (element.connection) {
case CONN_INDISPLAY:
case CONN_OUTDISPLAY:
next_img.error_condition = FALSE;
options = DCM_ORDERLITTLEENDIAN;
data = GetDICOMData(element.imagefile, options, &next_img,
NO_OVERRIDE, NO_OVERRIDE, FALSE);
if (next_img.error_condition)
fprintf(stderr, "Error set after GetDICOMData: %s\n",
element.imagefile);
CTNDISP_CheckStatus();
if (data != NULL) {
new_data = ScaleImageData(data, &next_img);
if (new_data == NULL)
fprintf(stderr, "ScaleImageData returned NULL ptr\n");
COND_DumpConditions();
if (next_img.error_condition)
fprintf(stderr, "Error set after ScaleImageData: %s\n",
element.imagefile);
}
CTNDISP_CheckStatus();
CTNDISP_UnDisplayImageData(&cur_img, &xcur_img);
CTNDISP_AdjustImageDepth(&next_img);
if (next_img.error_condition)
fprintf(stderr, "Error set after AdjustImageDepth: %s\n",
element.imagefile);
CTNDISP_DisplayImageData(&next_img, &xnext_img);
cur_img = next_img;
xcur_img = xnext_img;
CTNDISP_CheckStatus();
break;
case CONN_INOPEN:
case CONN_INCLOSE:
case CONN_INXFER:
CTNDISP_ProcessIncoming(element.connection, element.inumber);
break;
case CONN_OUTOPEN:
case CONN_OUTCLOSE:
case CONN_OUTXFER:
CTNDISP_ProcessOutgoing(element.connection, element.inumber);
break;
default:
break;
}
}
retval = GQ_Dequeue(image_Q_id, (void *) &element);
if (retval == GQ_NORMAL)
strcpy(G_dpnname, element.dpnid);
else {
#ifdef IRIX
(void) sginap(50);
#elif defined (USLEEP)
(void) usleep(100000);
#else
(void) sleep(1);
#endif
}
CTNDISP_CheckStatus();
/*
* Clear the COND stack so it doesn't overflow...
COND_DumpConditions();
*/
COND_PopCondition(TRUE);
}
#ifdef MALLOC_DEBUG
malloc_verify(0);
malloc_shutdown();
#endif
return 0;
}
/*******************************************************************/
void
CTNDISP_CheckStatus()
{
CTNDISP_Queue
element;
XEvent
report;
unsigned long
mask_event;
CONDITION
val;
/*
* Check for X events that require redrawing the screen...
*/
mask_event = StructureNotifyMask | SubstructureNotifyMask | ExposureMask;
while (XCheckMaskEvent(G_xStruct->display, mask_event, &report) == True) {
CTNDISP_RefreshStatus();
if (G_FirstTime == FALSE)
CTNDISP_RefreshImageData(&cur_img, &xcur_img);
}
return;
}
#else
main()
{
fprintf(stderr, "ctndisp requires the X Window System\n");
fprintf(stderr, "This version was compiled without the proper MACRO\n");
fprintf(stderr, "defined to use X11. Please refer to the source code\n");
fprintf(stderr, "(and recompile) to use this application\n");
}
#endif
|