/work/dcmtk-install/include/dcmtk/dcmimgle/dimoimg.h
Line | Count | Source |
1 | | /* |
2 | | * |
3 | | * Copyright (C) 1996-2022, OFFIS e.V. |
4 | | * All rights reserved. See COPYRIGHT file for details. |
5 | | * |
6 | | * This software and supporting documentation were developed by |
7 | | * |
8 | | * OFFIS e.V. |
9 | | * R&D Division Health |
10 | | * Escherweg 2 |
11 | | * D-26121 Oldenburg, Germany |
12 | | * |
13 | | * |
14 | | * Module: dcmimgle |
15 | | * |
16 | | * Author: Joerg Riesmeier |
17 | | * |
18 | | * Purpose: DicomMonochromeImage (Header) |
19 | | * |
20 | | */ |
21 | | |
22 | | |
23 | | #ifndef DIMOIMG_H |
24 | | #define DIMOIMG_H |
25 | | |
26 | | #include "dcmtk/config/osconfig.h" |
27 | | |
28 | | #include "dcmtk/ofstd/ofcast.h" |
29 | | |
30 | | #include "dcmtk/dcmimgle/diimage.h" |
31 | | #include "dcmtk/dcmimgle/dimopx.h" |
32 | | #include "dcmtk/dcmimgle/dimoopx.h" |
33 | | #include "dcmtk/dcmimgle/didispfn.h" |
34 | | |
35 | | |
36 | | /*------------------------* |
37 | | * forward declarations * |
38 | | *------------------------*/ |
39 | | |
40 | | class DiColorImage; |
41 | | |
42 | | |
43 | | /*---------------------* |
44 | | * class declaration * |
45 | | *---------------------*/ |
46 | | |
47 | | /** Base class for monochrome images |
48 | | */ |
49 | | class DCMTK_DCMIMGLE_EXPORT DiMonoImage |
50 | | : public DiImage |
51 | | { |
52 | | |
53 | | public: |
54 | | |
55 | | /** constructor |
56 | | * |
57 | | ** @param docu pointer to the DICOM document |
58 | | * @param status status of the image object |
59 | | */ |
60 | | DiMonoImage(const DiDocument *docu, |
61 | | const EI_Status status); |
62 | | |
63 | | /** constructor, rescale |
64 | | * |
65 | | ** @param docu pointer to the DICOM document |
66 | | * @param status status of the image object |
67 | | * @param slope rescale slope |
68 | | * @param intercept rescale intercept |
69 | | */ |
70 | | DiMonoImage(const DiDocument *docu, |
71 | | const EI_Status status, |
72 | | const double slope, |
73 | | const double intercept); |
74 | | |
75 | | /** constructor, modality LUT |
76 | | * |
77 | | ** @param docu pointer to the DICOM document |
78 | | * @param status status of the image object |
79 | | * @param data element containing the modality LUT data |
80 | | * @param descriptor element containing the modality LUT descriptor |
81 | | * @param explanation element containing the modality LUT explanation (optional) |
82 | | */ |
83 | | DiMonoImage(const DiDocument *docu, |
84 | | const EI_Status status, |
85 | | const DcmUnsignedShort &data, |
86 | | const DcmUnsignedShort &descriptor, |
87 | | const DcmLongString *explanation); |
88 | | |
89 | | /** destructor |
90 | | */ |
91 | | virtual ~DiMonoImage(); |
92 | | |
93 | | /** process next couple of frames |
94 | | * |
95 | | ** @param fcount number of frames to be processed (0 = same number as before) |
96 | | * |
97 | | ** @return status, true if successful, false otherwise |
98 | | */ |
99 | | virtual int processNextFrames(const unsigned long fcount); |
100 | | |
101 | | /** get minimum and maximum pixel values. |
102 | | * the resulting pixel values are stored in 'double' variables to avoid problems |
103 | | * with different number ranges, limited to monochrome images |
104 | | * |
105 | | ** @param min minimum pixel value (reference parameter) |
106 | | * @param max maximum pixel value (reference parameter) |
107 | | * @param mode 0 = min/max 'used' pixel values, |
108 | | * 1 = min/max 'possible' pixel values (absolute min/max) |
109 | | * |
110 | | ** @return status code (true if successful) |
111 | | */ |
112 | | int getMinMaxValues(double &min, |
113 | | double &max, |
114 | | const int mode) const; |
115 | | |
116 | | /** get display function |
117 | | * |
118 | | ** @return pointer to current display function, NULL if absent |
119 | | */ |
120 | | DiDisplayFunction *getDisplayFunction() const |
121 | 0 | { |
122 | 0 | return DisplayFunction; |
123 | 0 | } |
124 | | |
125 | | /** set display function |
126 | | * |
127 | | ** @param display object describing the output device characteristic (only referenced!) |
128 | | * |
129 | | ** @return true if successful, false otherwise |
130 | | */ |
131 | | int setDisplayFunction(DiDisplayFunction *display); |
132 | | |
133 | | /** set no display function. |
134 | | * disables display function transformation, object is not deleted! |
135 | | * |
136 | | ** @return true if successful (1 = disabled current function, |
137 | | * 2 = there was no function to disable) |
138 | | * false otherwise |
139 | | */ |
140 | | int setNoDisplayFunction(); |
141 | | |
142 | | /** unset all VOI transformations (windows and LUTs). |
143 | | * only applicable for monochrome images |
144 | | * |
145 | | ** @return true if successful (1 = previous window/LUT has been valid, |
146 | | * 2 = otherwise), |
147 | | * false otherwise (image is invalid or not monochrome) |
148 | | */ |
149 | | int setNoVoiTransformation(); |
150 | | |
151 | | /** delete specified display LUT(s) |
152 | | * |
153 | | ** @param bits parameter of LUT to be deleted (0 = all) |
154 | | * |
155 | | ** @return true if successful, false otherwise |
156 | | */ |
157 | | inline int deleteDisplayLUT(const int bits) |
158 | 0 | { |
159 | 0 | return (DisplayFunction != NULL) ? DisplayFunction->deleteLookupTable(bits) : 0; |
160 | 0 | } |
161 | | |
162 | | /** check whether given output value is unused |
163 | | * |
164 | | ** @param value output value to be checked |
165 | | * |
166 | | ** @return status, true if unused (1 = within output range, 2 = out of range), false otherwise |
167 | | */ |
168 | | inline int isValueUnused(const unsigned long value) |
169 | 0 | { |
170 | 0 | return (OutputData != NULL) ? OutputData->isUnused(value) : 0; |
171 | 0 | } |
172 | | |
173 | | /** convert P-value to DDL. |
174 | | * conversion uses display LUT if present, linear scaling otherwise. |
175 | | * |
176 | | ** @param pvalue P-value to be converted (0..65535) |
177 | | * @param ddl reference to resulting DDL |
178 | | * @param bits number of bits for output |
179 | | * |
180 | | ** @return true if successful (1 = display function transformation, |
181 | | * 2 = linear scaling), |
182 | | * false otherwise |
183 | | */ |
184 | | int convertPValueToDDL(const Uint16 pvalue, |
185 | | Uint16 &ddl, |
186 | | const int bits); |
187 | | |
188 | | /** set automatically calculated minimum/maximum window. |
189 | | * possibly active VOI LUT is implicitly disabled. |
190 | | * |
191 | | ** @param idx ignore global min/max values if false (0) |
192 | | * |
193 | | ** @return true if successful (1 = window has changed, |
194 | | * 2 = new window is the same as previous one), |
195 | | * false otherwise |
196 | | */ |
197 | | int setMinMaxWindow(const int idx = 1); |
198 | | |
199 | | /** set automatically calculated VOI window for the specified Region of Interest (ROI). |
200 | | * The ROI is specified by means of a rectangle (left_pos, top_pos, width, height). |
201 | | * Possibly active VOI LUT is implicitly disabled. |
202 | | * |
203 | | ** @param left_pos x-coordinate of the top left-hand corner of the ROI (starting from 0) |
204 | | * @param top_pos y-coordinate of the top left-hand corner of the ROI (starting from 0) |
205 | | * @param width width in pixels of the rectangular ROI (minimum: 1) |
206 | | * @param height height in pixels of the rectangular ROI (minimum: 1) |
207 | | * @param frame index of the frame to be used for the calculation |
208 | | * |
209 | | ** @return true if successful (1 = window has changed, |
210 | | * 2 = new window is the same as previous one), |
211 | | * false otherwise |
212 | | */ |
213 | | int setRoiWindow(const unsigned long left_pos, |
214 | | const unsigned long top_pos, |
215 | | const unsigned long width, |
216 | | const unsigned long height, |
217 | | const unsigned long frame); |
218 | | |
219 | | /** set automatically calculated histogram window. |
220 | | * possibly active VOI LUT is implicitly disabled. |
221 | | * |
222 | | ** @param thresh threshold value specifying percentage of histogram border which shall be ignored |
223 | | * |
224 | | ** @return true if successful, false otherwise |
225 | | */ |
226 | | int setHistogramWindow(const double thresh); |
227 | | |
228 | | /** set specified window (given by index to window width/center sequence stored in image file). |
229 | | * possibly active VOI LUT is implicitly disabled. |
230 | | * |
231 | | ** @param pos index to window width/center sequence |
232 | | * |
233 | | ** @return true if successful, false otherwise |
234 | | */ |
235 | | int setWindow(const unsigned long pos = 0); |
236 | | |
237 | | /** set specified window (given by window width and center). |
238 | | * possibly active VOI LUT is implicitly disabled. |
239 | | * |
240 | | ** @param center center of specified window |
241 | | * @param width width of specified window |
242 | | * @param explanation window explanation (optional) |
243 | | * |
244 | | ** @return true if successful (1 = window has changed, |
245 | | * 2 = new window is the same as previous one), |
246 | | * false otherwise |
247 | | */ |
248 | | int setWindow(const double center, |
249 | | const double width, |
250 | | const char *explanation = NULL); |
251 | | |
252 | | /** get current window center and width values |
253 | | * |
254 | | ** @param center return current window center value |
255 | | * @param width return current window width value |
256 | | * |
257 | | ** @return true if successful, false otherwise |
258 | | */ |
259 | | int getWindow(double ¢er, |
260 | | double &width); |
261 | | |
262 | | /** get number of VOI windows (stored in image file) |
263 | | * |
264 | | ** @return number of VOI windows |
265 | | */ |
266 | | inline unsigned long getWindowCount() const |
267 | 0 | { |
268 | 0 | return WindowCount; |
269 | 0 | } |
270 | | |
271 | | /** get VOI LUT function. |
272 | | * possible values are: EFV_Default, EFV_Linear, EFV_Sigmoid. |
273 | | * |
274 | | ** @return currently active VOI LUT function |
275 | | */ |
276 | | EF_VoiLutFunction getVoiLutFunction() const; |
277 | | |
278 | | /** set VOI LUT function |
279 | | * |
280 | | ** @param function type of VOI LUT function (default, linear or sigmoid). |
281 | | * 'default' basically means the same as 'linear'. |
282 | | * |
283 | | ** @return true if successful (1 = function has changed, |
284 | | * 2 = function has not changed) |
285 | | * false otherwise |
286 | | */ |
287 | | int setVoiLutFunction(const EF_VoiLutFunction function); |
288 | | |
289 | | /** set VOI LUT (given by dcmdata elements). |
290 | | * possibly active window/center is implicitly disabled. |
291 | | * |
292 | | ** @param data contains LUT data |
293 | | * @param descriptor describes LUT structure |
294 | | * @param explanation free form description of VOI LUT (optional) |
295 | | * @param descripMode mode specifying the use of the bits per table entry value |
296 | | * |
297 | | ** @return true if successful, false otherwise |
298 | | */ |
299 | | int setVoiLut(const DcmUnsignedShort &data, |
300 | | const DcmUnsignedShort &descriptor, |
301 | | const DcmLongString *explanation, |
302 | | const EL_BitsPerTableEntry descripMode = ELM_UseValue); |
303 | | |
304 | | /** set VOI LUT (given by index to VOI LUT sequence stored in image file). |
305 | | * possibly active window/center is implicitly disabled. |
306 | | * |
307 | | ** @param pos index to VOI LUT sequence |
308 | | * @param descripMode mode specifying the use of the bits per table entry value |
309 | | * |
310 | | ** @return true if successful, false otherwise |
311 | | */ |
312 | | int setVoiLut(const unsigned long pos, |
313 | | const EL_BitsPerTableEntry descripMode = ELM_UseValue); |
314 | | |
315 | | /** get number of VOI LUTs (stored in image file) |
316 | | * |
317 | | ** @return number of VOI LUTs |
318 | | */ |
319 | | inline unsigned long getVoiLutCount() const |
320 | 0 | { |
321 | 0 | return VoiLutCount; |
322 | 0 | } |
323 | | |
324 | | /** get description of active VOI transformation |
325 | | * |
326 | | ** @return pointer to description text (NULL if absent) |
327 | | */ |
328 | | inline const char *getVoiTransformationExplanation() const |
329 | 0 | { |
330 | 0 | return VoiExplanation.c_str(); |
331 | 0 | } |
332 | | |
333 | | /** get description of specified VOI window (stored in the image file) |
334 | | * |
335 | | ** @param pos index of the stored VOI window (0..n-1) |
336 | | * @param explanation variable in which the result text is stored |
337 | | * |
338 | | ** @return pointer to description text (NULL if absent or index invalid) |
339 | | */ |
340 | | const char *getVoiWindowExplanation(const unsigned long pos, |
341 | | OFString &explanation) const; |
342 | | |
343 | | /** get description of specified VOI LUT (stored in the image file) |
344 | | * |
345 | | ** @param pos index of the stored VOI LUT (0..n-1) |
346 | | * @param explanation variable in which the result text is stored |
347 | | * |
348 | | ** @return pointer to description text (NULL if absent or index invalid) |
349 | | */ |
350 | | const char *getVoiLutExplanation(const unsigned long pos, |
351 | | OFString &explanation) const; |
352 | | |
353 | | /** get description of performed modality LUT transformation |
354 | | * |
355 | | ** @return pointer to description text (NULL if absent) |
356 | | */ |
357 | | inline const char *getModalityLutExplanation() const |
358 | 0 | { |
359 | 0 | return (InterData != NULL) ? InterData->getModalityLutExplanation() : OFstatic_cast(const char *, NULL); |
360 | 0 | } |
361 | | |
362 | | /** set hardcopy parameters. (used to display LinOD images) |
363 | | * |
364 | | ** @param min minimum density of the print-out (in hundreds of Optical Density, e.g. 150 means 1.5 OD) |
365 | | * @param max maximum density of the print-out (ditto) |
366 | | * @param reflect reflected ambient light (in candela per square meter - cd/m^2) |
367 | | * @param illumin illumination (ditto) |
368 | | * |
369 | | ** @return true if successful (1 = at least one of the parameters has changed, |
370 | | * 2 = no parameter has changed) |
371 | | * false otherwise |
372 | | */ |
373 | | int setHardcopyParameters(const unsigned int min, |
374 | | const unsigned int max, |
375 | | const unsigned int reflect, |
376 | | const unsigned int illumin); |
377 | | |
378 | | /** get shape for presentation transformation. |
379 | | * possible values are: ESP_Default, ESP_Identity, ESP_Inverse, ESP_LinOD |
380 | | * If a presentation LUT is currently active ESP_Default is always returned. |
381 | | * |
382 | | ** @return currently active presentation LUT shape |
383 | | */ |
384 | | ES_PresentationLut getPresentationLutShape() const; |
385 | | |
386 | | /** set shape for presentation transformation. |
387 | | * possibly active presentation LUT is implicitly disabled. |
388 | | * |
389 | | ** @param shape presentation LUT shape (default, identity or inverse). |
390 | | * 'default' means that the output data is always created with 0 for black |
391 | | * and maxvalue for white (i.e. monochrome2 data is created for output). |
392 | | * |
393 | | ** @return true if successful (1 = shape has changed, |
394 | | * 2 = shape has not changed) |
395 | | * false otherwise |
396 | | */ |
397 | | int setPresentationLutShape(const ES_PresentationLut shape); |
398 | | |
399 | | /** set LUT for presentation transformation. |
400 | | * possibly active presentation LUT is implicitly disabled. |
401 | | * |
402 | | ** @param data contains LUT data |
403 | | * @param descriptor describes LUT structure |
404 | | * @param explanation free form description of presentation LUT (optional) |
405 | | * @param descripMode mode specifying the use of the bits per table entry value |
406 | | * |
407 | | ** @return true if successful, false otherwise |
408 | | */ |
409 | | int setPresentationLut(const DcmUnsignedShort &data, |
410 | | const DcmUnsignedShort &descriptor, |
411 | | const DcmLongString *explanation = NULL, |
412 | | const EL_BitsPerTableEntry descripMode = ELM_UseValue); |
413 | | |
414 | | /** set inverse LUT for presentation transformation. |
415 | | * this LUT transform is e.g. used for DICOM print (12->8, 8->12 bit) |
416 | | * possibly active presentation LUT will not be considered ! |
417 | | * |
418 | | ** @param data contains LUT data |
419 | | * @param descriptor describes LUT structure |
420 | | * @param descripMode mode specifying the use of the bits per table entry value |
421 | | * |
422 | | ** @return true if successful, false otherwise |
423 | | */ |
424 | | int setInversePresentationLut(const DcmUnsignedShort &data, |
425 | | const DcmUnsignedShort &descriptor, |
426 | | const EL_BitsPerTableEntry descripMode = ELM_UseValue); |
427 | | |
428 | | /** get description of active presentation LUT |
429 | | * |
430 | | ** @return pointer to description text (NULL if absent) |
431 | | */ |
432 | | inline const char *getPresentationLutExplanation() const |
433 | 0 | { |
434 | 0 | return (PresLutData != NULL) ? PresLutData->getExplanation() : OFstatic_cast(const char *, NULL); |
435 | 0 | } |
436 | | |
437 | | /** add specified plane to group of additional overlay planes. |
438 | | * replaces old overlay plane if group number already exists. |
439 | | * |
440 | | ** @param group group number (0x60nn) of overlay plane |
441 | | * @param left_pos x coordinate of plane origin (referring to image origin) |
442 | | * @param top_pos y coordinate of plane origin |
443 | | * @param columns width of overlay plane (in pixels) |
444 | | * @param rows height of overlay plane (in pixels) |
445 | | * @param data overlay plane data (dcmdata element) |
446 | | * @param label overlay plane label |
447 | | * @param description overlay plane description |
448 | | * @param mode display mode (see 'diutils.h') |
449 | | * |
450 | | ** @return false (0) if an error occurred, true otherwise (1 = added new plane, |
451 | | * 2 = replaced existing plane) |
452 | | */ |
453 | | int addOverlay(const unsigned int group, |
454 | | const signed int left_pos, |
455 | | const signed int top_pos, |
456 | | const unsigned int columns, |
457 | | const unsigned int rows, |
458 | | const DcmOverlayData &data, |
459 | | const DcmLongString &label, |
460 | | const DcmLongString &description, |
461 | | const EM_Overlay mode); |
462 | | |
463 | | /** remove all additional overlay planes |
464 | | * |
465 | | ** @return false (0) if an error occurred, true otherwise |
466 | | */ |
467 | | int removeAllOverlays(); |
468 | | |
469 | | /** get pointer to specified overlay managing object |
470 | | * |
471 | | ** @param idx index of overlay group (0 = dataset, 1 = additional) |
472 | | * |
473 | | ** @return pointer to overlay managing object (NULL if absent or invalid) |
474 | | */ |
475 | | inline DiOverlay *getOverlayPtr(const unsigned int idx) |
476 | | { |
477 | | return (idx < 2) ? Overlays[idx] : OFstatic_cast(DiOverlay *, NULL); |
478 | | } |
479 | | |
480 | | /** get pointer to current monochrome image (this) |
481 | | * |
482 | | ** @return pointer to this object |
483 | | */ |
484 | | inline DiMonoImage *getMonoImagePtr() |
485 | | { |
486 | | return this; |
487 | | } |
488 | | |
489 | | /** flip current image (horizontally and/or vertically) |
490 | | * |
491 | | ** @param horz flip horizontally if true |
492 | | * @param vert flip vertically if true |
493 | | * |
494 | | ** @return true if successful (1 = flipped at least direction, |
495 | | * 2 = not flipped, because of image resolution - width and/or height equal to 1), |
496 | | * false otherwise |
497 | | */ |
498 | | int flip(const int horz, |
499 | | const int vert); |
500 | | |
501 | | /** rotate current image (by steps of 90 degrees) |
502 | | * |
503 | | ** @param degree angle by which the image shall be rotated (-360, -270, -180, -90, 0, 90, 180, 270, 360) |
504 | | * |
505 | | ** @return true if successful (1 = rotated by at least 90 degrees, |
506 | | * 2 = not rotated, because of image resolution or angle), |
507 | | * false otherwise |
508 | | */ |
509 | | int rotate(const int degree); |
510 | | |
511 | | /** get number of bits per sample. |
512 | | * If the optional parameter is specified the value will be checked and in any case |
513 | | * a valid value will be returned. |
514 | | * |
515 | | ** @param bits value to be returned (if less than 1 or greater than the maximum (32) |
516 | | * the default value will be used which is equal to the bits per sample |
517 | | * value stored in the DICOM dataset) |
518 | | * |
519 | | ** @return status, true if successful, false otherwise |
520 | | */ |
521 | | virtual int getBits(const int bits = 0) const |
522 | | { |
523 | | return (((bits < 1) || (bits > MAX_BITS)) && (bits != MI_PastelColor)) ? BitsPerSample : bits; |
524 | | } |
525 | | |
526 | | /** get number of bytes required for the rendered output of a single frame |
527 | | * |
528 | | * @param bits number of bits for the output pixel data (depth) |
529 | | * |
530 | | ** @return number of bytes if successful, 0 otherwise |
531 | | */ |
532 | | virtual unsigned long getOutputDataSize(const int bits = 0) const; |
533 | | |
534 | | /** get pixel data with specified format. |
535 | | * (memory is handled internally) |
536 | | * |
537 | | ** @param frame number of frame to be rendered |
538 | | * @param bits number of bits for the output pixel data (depth) |
539 | | * @param planar flag, only useful for multi-planar images (color) |
540 | | * |
541 | | ** @return untyped pointer to the pixel data if successful, NULL otherwise |
542 | | */ |
543 | | virtual const void *getOutputData(const unsigned long frame, |
544 | | const int bits, |
545 | | const int planar = 0) = 0; |
546 | | |
547 | | /** get pixel data with specified format. |
548 | | * (memory is handled externally) |
549 | | * |
550 | | ** @param buffer untyped pointer to the externally allocated memory buffer |
551 | | * @param size size of the memory buffer in bytes (will be checked) |
552 | | * @param frame number of frame to be rendered |
553 | | * @param bits number of bits for the output pixel data (depth) |
554 | | * @param planar flag, only useful for multi-planar images (color) |
555 | | * |
556 | | ** @return status, true if successful, false otherwise |
557 | | */ |
558 | | virtual int getOutputData(void *buffer, |
559 | | const unsigned long size, |
560 | | const unsigned long frame, |
561 | | const int bits, |
562 | | const int planar = 0) = 0; |
563 | | |
564 | | /** get pixel data of specified plane. |
565 | | * (memory is handled internally) |
566 | | * |
567 | | ** @param dummy (not used) |
568 | | * |
569 | | ** @return untyped pointer to the pixel data if successful, NULL otherwise |
570 | | */ |
571 | | const void *getOutputPlane(const int dummy) const; |
572 | | |
573 | | /** delete internally handled output memory buffer |
574 | | * Save memory if data is no longer needed. |
575 | | */ |
576 | | void deleteOutputData(); |
577 | | |
578 | | /** create bitmap for specified overlay plane. |
579 | | * (up to 16 bits per pixel with two values: fore and back) |
580 | | * |
581 | | ** @param frame index of frame used for output |
582 | | * @param plane number (0..15) or group number (0x60nn) of overlay plane |
583 | | * @param left_pos returns x coordinate of plane's origin |
584 | | * @param top_pos returns y coordinate of plane's origin |
585 | | * @param width returns width of overlay plane (in pixels) |
586 | | * @param height returns height of overlay plane (in pixels) |
587 | | * @param mode return display mode (see 'diutils.h') |
588 | | * @param idx index of overlay group (0 = dataset, 1 = additional, 2 = '1' plane hides '0' plane) |
589 | | * @param bits number of bits (stored) in the resulting array, default: 8 |
590 | | * @param fore foreground color to be set in bitmap, default: 255 |
591 | | * @param back background color to be set in bitmap (transparent), default: 0 |
592 | | * |
593 | | ** @return pointer to overlay plane data (internal memory buffer) |
594 | | */ |
595 | | const void *getOverlayData(const unsigned long frame, |
596 | | const unsigned int plane, |
597 | | unsigned int &left_pos, |
598 | | unsigned int &top_pos, |
599 | | unsigned int &width, |
600 | | unsigned int &height, |
601 | | EM_Overlay &mode, |
602 | | const unsigned int idx, |
603 | | const int bits = 8, |
604 | | const Uint16 fore = 0xff, |
605 | | const Uint16 back = 0x0); |
606 | | |
607 | | /** create bitmap for specified overlay plane. |
608 | | * (up to 16 bits per pixel with two values: fore and back) |
609 | | * |
610 | | ** @param frame index of frame used for output |
611 | | * @param plane number (0..15) or group number (0x60nn) of overlay plane |
612 | | * @param width returns width of overlay plane (in pixels) |
613 | | * @param height returns height of overlay plane (in pixels) |
614 | | * @param idx index of overlay group (0 = dataset, 1 = additional, 2 = '1' plane hides '0' plane) |
615 | | * @param bits number of bits (stored) in the resulting array, default: 8 |
616 | | * @param fore foreground color to be set in bitmap, default: 255 |
617 | | * @param back background color to be set in bitmap (transparent), default: 0 |
618 | | * |
619 | | ** @return pointer to overlay plane data (internal memory buffer) |
620 | | */ |
621 | | const void *getFullOverlayData(const unsigned long frame, |
622 | | const unsigned int plane, |
623 | | unsigned int &width, |
624 | | unsigned int &height, |
625 | | const unsigned int idx, |
626 | | const int bits = 8, |
627 | | const Uint16 fore = 0xff, |
628 | | const Uint16 back = 0x0); |
629 | | |
630 | | /** delete buffer for overlay plane data. |
631 | | * Save memory if data is no longer needed. |
632 | | */ |
633 | | void deleteOverlayData(); |
634 | | |
635 | | /** create bitmap for specified overlay plane and store it in (6xxx,3000) format. |
636 | | * (1 bit allocated and stored, foreground color is 1, background color is 0, |
637 | | * data is 16 bit padded - even length) |
638 | | * memory is not handled internally - must be deleted from calling program. |
639 | | * |
640 | | ** @param buffer stores pointer to overlay data (memory is allocated internally) |
641 | | * @param plane number (0..15) or group number (0x60nn) of overlay plane |
642 | | * @param width returns width of overlay plane (in pixels) |
643 | | * @param height returns height of overlay plane (in pixels) |
644 | | * @param frames returns number of frames (multiple overlay frames possible!) |
645 | | * @param idx index of overlay group (0 = dataset, planes stored in the image dataset; |
646 | | * 1 = additional, planes added by addOverlay()), |
647 | | * default: 0 |
648 | | * |
649 | | ** @return number of bytes allocated for the 'buffer' if successful, 0 otherwise |
650 | | */ |
651 | | unsigned long create6xxx3000OverlayData(Uint8 *&buffer, |
652 | | const unsigned int plane, |
653 | | unsigned int &width, |
654 | | unsigned int &height, |
655 | | unsigned long &frames, |
656 | | const unsigned int idx = 0); |
657 | | |
658 | | /** get pointer to intermediate pixel data representation |
659 | | * |
660 | | ** @return pointer to intermediate pixel data |
661 | | */ |
662 | | const DiPixel *getInterData() const |
663 | | { |
664 | | return InterData; |
665 | | } |
666 | | |
667 | | /** get pointer to intermediate pixel data representation |
668 | | * |
669 | | ** @return pointer to intermediate pixel data |
670 | | */ |
671 | | const DiMonoPixel *getMonoInterData() const |
672 | 0 | { |
673 | 0 | return InterData; |
674 | 0 | } |
675 | | |
676 | | /** create true color (24/32 bit) or palette (8 bit) bitmap for MS Windows. |
677 | | * memory is not handled internally - must be deleted from calling program. |
678 | | * |
679 | | ** @param data untyped pointer memory buffer (set to NULL if not allocated externally) |
680 | | * @param size size of the memory buffer in bytes (if 0 'data' is set to NULL) |
681 | | * @param frame index of frame to be converted (starting from 0) |
682 | | * @param bits number of bits per pixel used for the output bitmap (8, 24 or 32) |
683 | | * @param upsideDown specifies the order of lines in the images (0 = top-down, bottom-up otherwise) |
684 | | * @param padding align each line to a 32-bit address if true (default) |
685 | | * |
686 | | ** @return number of bytes allocated by the bitmap, or 0 if an error occurred |
687 | | */ |
688 | | unsigned long createDIB(void *&data, |
689 | | const unsigned long size, |
690 | | const unsigned long frame, |
691 | | const int bits, |
692 | | const int upsideDown, |
693 | | const int padding = 1); |
694 | | |
695 | | /** create true color (32 bit) or palette (8 bit) bitmap for Java (AWT default format). |
696 | | * Memory is not handled internally - must be deleted from calling program. |
697 | | * |
698 | | ** @param data resulting pointer to bitmap data (set to NULL if an error occurred) |
699 | | * @param frame index of frame to be converted (starting from 0) |
700 | | * @param bits number of bits per pixel used for the output bitmap (8 or 32) |
701 | | * |
702 | | ** @return number of bytes allocated by the bitmap, or 0 if an error occurred |
703 | | */ |
704 | | unsigned long createAWTBitmap(void *&data, |
705 | | const unsigned long frame, |
706 | | const int bits); |
707 | | |
708 | | /** create packed bitmap (e.g. 12/16 bit -> 12/12 bit for DICOM printers). |
709 | | * Memory is not handled internally - must be deleted from calling program. |
710 | | * |
711 | | ** @param buffer pointer to input memory buffer |
712 | | * @param size size of memory buffer (will be checked whether it is sufficient) |
713 | | * @param count number of entries (pixels) in input buffer |
714 | | * @param alloc number of bits allocated for the pixels stored in the buffer (e.g. 16) |
715 | | * @param stored number of bits stored for the pixels stored in the buffer (e.g. 12) |
716 | | * |
717 | | ** @return pointer to memory buffer containing the packed output bitmap data (NULL if an error occurred) |
718 | | */ |
719 | | static void *createPackedBitmap(const void *buffer, |
720 | | const unsigned long size, |
721 | | const unsigned long count, |
722 | | const int alloc, |
723 | | const int stored); |
724 | | |
725 | | /** create new single frame DiImage with applied grayscale transformations. |
726 | | * The method getOutputData() is used internally for the new bitmap. |
727 | | * |
728 | | ** @param frame index of frame to be converted |
729 | | * @param bits number of bits per pixel used for the output bitmap |
730 | | * |
731 | | ** @return pointer to new DiImage object (NULL if an error occurred) |
732 | | */ |
733 | | DiImage *createOutputImage(const unsigned long frame, |
734 | | const int bits); |
735 | | |
736 | | /** write current image and related attributes to DICOM dataset. |
737 | | * |
738 | | ** @param dataset reference to DICOM dataset where the image attributes are stored |
739 | | * @param mode 0 = determine value of BitsStored from 'used' pixel values, |
740 | | * 1 = determine value of BitsStored from 'possible' pixel values |
741 | | * @param planar dummy parameter (only used for color images) |
742 | | * |
743 | | ** @return true if successful, false otherwise |
744 | | */ |
745 | | int writeImageToDataset(DcmItem &dataset, |
746 | | const int mode, |
747 | | const int planar); |
748 | | |
749 | | /** write pixel data to PPM file. |
750 | | * pixel data is written in ASCII format. |
751 | | * |
752 | | ** @param stream open C++ output stream |
753 | | * @param frame index of frame used for output |
754 | | * @param bits number of bits used for output of pixel data |
755 | | * |
756 | | ** @return true if successful, false otherwise |
757 | | */ |
758 | | int writePPM(STD_NAMESPACE ostream& stream, |
759 | | const unsigned long frame, |
760 | | const int bits); |
761 | | |
762 | | /** write pixel data to PPM file. |
763 | | * pixel data is written in ASCII format. |
764 | | * |
765 | | ** @param stream open C output stream |
766 | | * @param frame index of frame used for output |
767 | | * @param bits number of bits used for output of pixel data |
768 | | * |
769 | | ** @return true if successful, false otherwise |
770 | | */ |
771 | | int writePPM(FILE *stream, |
772 | | const unsigned long frame, |
773 | | const int bits); |
774 | | |
775 | | /** write pixel data to raw PPM file |
776 | | * |
777 | | ** @param stream open C output stream |
778 | | * @param frame index of frame used for output |
779 | | * @param bits number of bits used for output of pixel data |
780 | | * |
781 | | ** @return true if successful, false otherwise |
782 | | */ |
783 | | int writeRawPPM(FILE *stream, |
784 | | const unsigned long frame, |
785 | | const int bits); |
786 | | |
787 | | /** write pixel data to BMP file |
788 | | * |
789 | | ** @param stream open C output stream |
790 | | * @param frame index of frame used for output (default: first frame = 0) |
791 | | * @param bits number of bits used for output of pixel data (8, 24 or 32, default (0) = 8) |
792 | | * |
793 | | ** @return true if successful, false otherwise |
794 | | */ |
795 | | int writeBMP(FILE *stream, |
796 | | const unsigned long frame, |
797 | | const int bits); |
798 | | |
799 | | |
800 | | protected: |
801 | | |
802 | | /** constructor |
803 | | * |
804 | | ** @param image pointer to dataset (encapsulated) |
805 | | * @param status current image status |
806 | | * @param dummy (necessary to be different from another constructor) |
807 | | */ |
808 | | DiMonoImage(const DiDocument *image, |
809 | | const EI_Status status, |
810 | | const char dummy); |
811 | | |
812 | | /** constructor, copy |
813 | | * |
814 | | ** @param image pointer to reference image |
815 | | * @param fstart first frame to be processed |
816 | | * @param fcount number of frames |
817 | | */ |
818 | | DiMonoImage(const DiMonoImage *image, |
819 | | const unsigned long fstart, |
820 | | const unsigned long fcount); |
821 | | |
822 | | /** constructor, convert color images to monochrome |
823 | | * |
824 | | ** @param image pointer to reference image |
825 | | * @param red coefficient by which the red component is weighted |
826 | | * @param green coefficient by which the green component is weighted |
827 | | * @param blue coefficient by which the blue component is weighted |
828 | | * |
829 | | ** @return pointer to new DiImage object (NULL if an error occurred) |
830 | | */ |
831 | | DiMonoImage(const DiColorImage *image, |
832 | | const double red, |
833 | | const double green, |
834 | | const double blue); |
835 | | |
836 | | /** constructor, scale/clip |
837 | | * |
838 | | ** @param image pointer to reference image |
839 | | * @param left_pos x coordinate of top left corner of area to be scaled |
840 | | * (referring to image origin, negative values create a border around the image) |
841 | | * @param top_pos y coordinate of top left corner of area to be scaled |
842 | | * @param src_cols width of area to be scaled |
843 | | * @param src_rows height of area to be scaled |
844 | | * @param dest_cols width of scaled image (in pixels) |
845 | | * @param dest_rows height of scaled image (in pixels) |
846 | | * @param interpolate specifies whether scaling algorithm should use interpolation (if necessary). |
847 | | * default: no interpolation (0), preferred interpolation algorithm (if applicable): |
848 | | * 1 = pbmplus algorithm, 2 = c't algorithm, 3 = bilinear magnification, |
849 | | * 4 = bicubic magnification |
850 | | * @param aspect specifies whether pixel aspect ratio should be taken into consideration |
851 | | * (if true, width OR height should be 0, i.e. this component will be calculated |
852 | | * automatically) |
853 | | * @param pvalue P-value used for the border outside the image (0..65535) |
854 | | */ |
855 | | DiMonoImage(const DiMonoImage *image, |
856 | | const signed long left_pos, |
857 | | const signed long top_pos, |
858 | | const Uint16 src_cols, |
859 | | const Uint16 src_rows, |
860 | | const Uint16 dest_cols, |
861 | | const Uint16 dest_rows, |
862 | | const int interpolate, |
863 | | const int aspect, |
864 | | const Uint16 pvalue); |
865 | | |
866 | | /** constructor, flip |
867 | | * |
868 | | ** @param image pointer to reference image |
869 | | ** @param horz flip horizontally if true |
870 | | * @param vert flip vertically if true |
871 | | */ |
872 | | DiMonoImage(const DiMonoImage *image, |
873 | | const int horz, |
874 | | const int vert); |
875 | | |
876 | | /** constructor, rotate |
877 | | * |
878 | | ** @param image pointer to reference image |
879 | | * @param degree angle by which the image shall be rotated |
880 | | */ |
881 | | DiMonoImage(const DiMonoImage *image, |
882 | | const int degree); |
883 | | |
884 | | /** constructor, createMonoOutput |
885 | | * |
886 | | ** @param image pointer to reference image |
887 | | * @param pixel pointer to output pixel data used for the new image |
888 | | * @param frame number of frame stored in the new image object |
889 | | * @param stored number of bits stored |
890 | | * @param alloc number of bits allocated |
891 | | */ |
892 | | DiMonoImage(const DiMonoImage *image, |
893 | | DiMonoOutputPixel *pixel, |
894 | | const unsigned long frame, |
895 | | const int stored, |
896 | | const int alloc); |
897 | | |
898 | | /** initialize internal data structures and member variables |
899 | | * |
900 | | ** @param modality pointer to object handling the modality transform |
901 | | * @param reuse reuse particular information determined in a previous call |
902 | | */ |
903 | | void Init(DiMonoModality *modality, |
904 | | const OFBool reuse = OFFalse); |
905 | | |
906 | | /** initialize internal data structures (for Uint8) |
907 | | * |
908 | | ** @param modality pointer to object handling the modality transform |
909 | | */ |
910 | | void InitUint8(DiMonoModality *modality); |
911 | | |
912 | | /** initialize internal data structures (for Sint8) |
913 | | * |
914 | | ** @param modality pointer to object handling the modality transform |
915 | | */ |
916 | | void InitSint8(DiMonoModality *modality); |
917 | | |
918 | | /** initialize internal data structures (for Uint16) |
919 | | * |
920 | | ** @param modality pointer to object handling the modality transform |
921 | | */ |
922 | | void InitUint16(DiMonoModality *modality); |
923 | | |
924 | | /** initialize internal data structures (for Sint16) |
925 | | * |
926 | | ** @param modality pointer to object handling the modality transform |
927 | | */ |
928 | | void InitSint16(DiMonoModality *modality); |
929 | | |
930 | | /** initialize internal data structures (for Uint32) |
931 | | * |
932 | | ** @param modality pointer to object handling the modality transform |
933 | | */ |
934 | | void InitUint32(DiMonoModality *modality); |
935 | | |
936 | | /** initialize internal data structures (for Sint32) |
937 | | * |
938 | | ** @param modality pointer to object handling the modality transform |
939 | | */ |
940 | | void InitSint32(DiMonoModality *modality); |
941 | | |
942 | | /** check intermediate pixel representation for consistency |
943 | | * |
944 | | ** @param mode check number of pixels stored in the dataset if true |
945 | | * |
946 | | ** @return status, true if successful, false otherwise |
947 | | */ |
948 | | int checkInterData(const int mode = 1); |
949 | | |
950 | | /** update Image Pixel Module attributes in the given dataset. |
951 | | * Removes possibly existing embedded overlay planes and replaces any |
952 | | * present modality transformation by a linear rescale/slope. |
953 | | * Used in writeXXXToDataset() routines. |
954 | | * |
955 | | ** @param dataset reference to DICOM image dataset |
956 | | */ |
957 | | virtual void updateImagePixelModuleAttributes(DcmItem &dataset); |
958 | | |
959 | | /** get pixel data with specified format. |
960 | | * (memory is handled externally) |
961 | | * |
962 | | ** @param buffer untyped pointer to the externally allocated memory buffer |
963 | | * @param size size of the memory buffer in bytes (will be checked) |
964 | | * @param frame number of frame to be rendered |
965 | | * @param bits number of bits for the output pixel data (depth) |
966 | | * @param planar flag, only useful for multi-planar images (color) |
967 | | * @param negative invert pixel data if true |
968 | | * |
969 | | ** @return untyped pointer to the pixel data if successful, NULL otherwise |
970 | | */ |
971 | | const void *getData(void *buffer, |
972 | | const unsigned long size, |
973 | | const unsigned long frame, |
974 | | int bits, |
975 | | const int planar, |
976 | | const int negative); |
977 | | |
978 | | /** get pixel data with specified format for Uint8 input (helper function). |
979 | | * (memory is handled externally) |
980 | | * |
981 | | ** @param buffer untyped pointer to the externally allocated memory buffer |
982 | | * @param disp pointer to current display function object |
983 | | * @param samples number of samples per pixel |
984 | | * @param frame number of frame to be rendered |
985 | | * @param bits number of bits for the output pixel data (depth) |
986 | | * @param low output pixel value to which 0 is mapped (min) |
987 | | * @param high output pixel value to which 2^bits-1 is mapped (max) |
988 | | */ |
989 | | void getDataUint8(void *buffer, |
990 | | DiDisplayFunction *disp, |
991 | | const int samples, |
992 | | const unsigned long frame, |
993 | | const int bits, |
994 | | const Uint32 low, |
995 | | const Uint32 high); |
996 | | |
997 | | /** get pixel data with specified format for Sint8 input (helper function). |
998 | | * (memory is handled externally) |
999 | | * |
1000 | | ** @param buffer untyped pointer to the externally allocated memory buffer |
1001 | | * @param disp pointer to current display function object |
1002 | | * @param samples number of samples per pixel |
1003 | | * @param frame number of frame to be rendered |
1004 | | * @param bits number of bits for the output pixel data (depth) |
1005 | | * @param low output pixel value to which 0 is mapped (min) |
1006 | | * @param high output pixel value to which 2^bits-1 is mapped (max) |
1007 | | */ |
1008 | | void getDataSint8(void *buffer, |
1009 | | DiDisplayFunction *disp, |
1010 | | const int samples, |
1011 | | const unsigned long frame, |
1012 | | const int bits, |
1013 | | const Uint32 low, |
1014 | | const Uint32 high); |
1015 | | |
1016 | | /** get pixel data with specified format for Uint16 input (helper function). |
1017 | | * (memory is handled externally) |
1018 | | * |
1019 | | ** @param buffer untyped pointer to the externally allocated memory buffer |
1020 | | * @param disp pointer to current display function object |
1021 | | * @param samples number of samples per pixel |
1022 | | * @param frame number of frame to be rendered |
1023 | | * @param bits number of bits for the output pixel data (depth) |
1024 | | * @param low output pixel value to which 0 is mapped (min) |
1025 | | * @param high output pixel value to which 2^bits-1 is mapped (max) |
1026 | | */ |
1027 | | void getDataUint16(void *buffer, |
1028 | | DiDisplayFunction *disp, |
1029 | | const int samples, |
1030 | | const unsigned long frame, |
1031 | | const int bits, |
1032 | | const Uint32 low, |
1033 | | const Uint32 high); |
1034 | | |
1035 | | /** get pixel data with specified format for Sint16 input (helper function). |
1036 | | * (memory is handled externally) |
1037 | | * |
1038 | | ** @param buffer untyped pointer to the externally allocated memory buffer |
1039 | | * @param disp pointer to current display function object |
1040 | | * @param samples number of samples per pixel |
1041 | | * @param frame number of frame to be rendered |
1042 | | * @param bits number of bits for the output pixel data (depth) |
1043 | | * @param low output pixel value to which 0 is mapped (min) |
1044 | | * @param high output pixel value to which 2^bits-1 is mapped (max) |
1045 | | */ |
1046 | | void getDataSint16(void *buffer, |
1047 | | DiDisplayFunction *disp, |
1048 | | const int samples, |
1049 | | const unsigned long frame, |
1050 | | const int bits, |
1051 | | const Uint32 low, |
1052 | | const Uint32 high); |
1053 | | |
1054 | | /** get pixel data with specified format for Uint32 input (helper function). |
1055 | | * (memory is handled externally) |
1056 | | * |
1057 | | ** @param buffer untyped pointer to the externally allocated memory buffer |
1058 | | * @param disp pointer to current display function object |
1059 | | * @param samples number of samples per pixel |
1060 | | * @param frame number of frame to be rendered |
1061 | | * @param bits number of bits for the output pixel data (depth) |
1062 | | * @param low output pixel value to which 0 is mapped (min) |
1063 | | * @param high output pixel value to which 2^bits-1 is mapped (max) |
1064 | | */ |
1065 | | void getDataUint32(void *buffer, |
1066 | | DiDisplayFunction *disp, |
1067 | | const int samples, |
1068 | | const unsigned long frame, |
1069 | | const int bits, |
1070 | | const Uint32 low, |
1071 | | const Uint32 high); |
1072 | | |
1073 | | /** get pixel data with specified format for Sint32 input (helper function). |
1074 | | * (memory is handled externally) |
1075 | | * |
1076 | | ** @param buffer untyped pointer to the externally allocated memory buffer |
1077 | | * @param disp pointer to current display function object |
1078 | | * @param samples number of samples per pixel |
1079 | | * @param frame number of frame to be rendered |
1080 | | * @param bits number of bits for the output pixel data (depth) |
1081 | | * @param low output pixel value to which 0 is mapped (min) |
1082 | | * @param high output pixel value to which 2^bits-1 is mapped (max) |
1083 | | */ |
1084 | | void getDataSint32(void *buffer, |
1085 | | DiDisplayFunction *disp, |
1086 | | const int samples, |
1087 | | const unsigned long frame, |
1088 | | const int bits, |
1089 | | const Uint32 low, |
1090 | | const Uint32 high); |
1091 | | |
1092 | | /** create a presentation look-up table converting the pixel data which is linear to |
1093 | | * Optical Density to DDLs of the softcopy device (used to display print images on screen). |
1094 | | * |
1095 | | ** @param count number of LUT entries |
1096 | | * @param bits number of bits per entry |
1097 | | * |
1098 | | ** @return true if successful, false otherwise |
1099 | | */ |
1100 | | int createLinODPresentationLut(const unsigned long count, const int bits); |
1101 | | |
1102 | | /// center of current VOI-window |
1103 | | double WindowCenter; |
1104 | | /// width of current VOI-window |
1105 | | double WindowWidth; |
1106 | | /// number of stored VOI-windows |
1107 | | unsigned long WindowCount; |
1108 | | /// number of stored VOU-LUTs |
1109 | | unsigned long VoiLutCount; |
1110 | | |
1111 | | /// true, if current VOI-window is valid |
1112 | | int ValidWindow; |
1113 | | |
1114 | | /// free text explanation of current VOI transformation |
1115 | | OFString VoiExplanation; |
1116 | | /// VOI LUT function (linear or sigmoid) |
1117 | | EF_VoiLutFunction VoiLutFunction; |
1118 | | /// presentation LUT shape (identity, inverse or lin od) |
1119 | | ES_PresentationLut PresLutShape; |
1120 | | |
1121 | | /// minimum density of a print-out (in hundreds of Optical Density) |
1122 | | unsigned int MinDensity; |
1123 | | /// maximum density of a print-out (ditto) |
1124 | | unsigned int MaxDensity; |
1125 | | /// reflected ambient light (in candela per square meter) |
1126 | | unsigned int Reflection; |
1127 | | /// illumination (ditto) |
1128 | | unsigned int Illumination; |
1129 | | |
1130 | | /// points to associated overlay-objects ([0] = built-in, [1] = additional) |
1131 | | DiOverlay *Overlays[2]; |
1132 | | /// points to associated VOI-LUT-object |
1133 | | DiLookupTable *VoiLutData; |
1134 | | /// points to associated presentation-LUT-object |
1135 | | DiLookupTable *PresLutData; |
1136 | | /// points to intermediate pixel data representation (object) |
1137 | | DiMonoPixel *InterData; |
1138 | | |
1139 | | /// points to grayscale standard display function (only referenced!) |
1140 | | DiDisplayFunction *DisplayFunction; |
1141 | | |
1142 | | |
1143 | | private: |
1144 | | |
1145 | | /// points to current output data (object) |
1146 | | DiMonoOutputPixel *OutputData; |
1147 | | /// points to current overlay plane data (pixel array) |
1148 | | void *OverlayData; |
1149 | | |
1150 | | // --- declarations to avoid compiler warnings |
1151 | | |
1152 | | DiMonoImage(const DiMonoImage &); |
1153 | | DiMonoImage &operator=(const DiMonoImage &); |
1154 | | }; |
1155 | | |
1156 | | |
1157 | | #endif |