1 /*=========================================================================
4 Module: $RCSfile: gdcmFileHelper.cxx,v $
7 Date: $Date: 2007/07/05 10:53:48 $
8 Version: $Revision: 1.116 $
10 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
11 l'Image). All rights reserved. See Doc/License.txt or
12 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
14 This software is distributed WITHOUT ANY WARRANTY; without even
15 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 PURPOSE. See the above copyright notices for more information.
18 =========================================================================*/
20 #include "gdcmFileHelper.h"
21 #include "gdcmGlobal.h"
23 #include "gdcmDocument.h"
24 #include "gdcmDebug.h"
26 #include "gdcmSeqEntry.h"
27 #include "gdcmSQItem.h"
28 #include "gdcmDataEntry.h"
29 #include "gdcmDocEntry.h"
31 #include "gdcmPixelReadConvert.h"
32 #include "gdcmPixelWriteConvert.h"
33 #include "gdcmDocEntryArchive.h"
34 #include "gdcmDictSet.h"
35 #include "gdcmOrientation.h"
37 #if defined(__BORLANDC__)
38 #include <mem.h> // for memset
44 // ----------------------------- WARNING -------------------------
46 These lines will be moved to the document-to-be 'User's Guide'
48 // To read an image, user needs a gdcm::File
49 gdcm::File *f = new gdcm::File(fileName);
51 // user may also decide he doesn't want to load some parts of the header
52 gdcm::File *f = new gdcm::File();
53 f->SetFileName(fileName);
54 f->SetLoadMode(LD_NOSEQ); // or
55 f->SetLoadMode(LD_NOSHADOW); // or
56 f->SetLoadMode(LD_NOSEQ | LD_NOSHADOW); // or
57 f->SetLoadMode(LD_NOSHADOWSEQ);
60 // To decide whether it's an 'image of interest for him, or not,
61 // user can now check some values
62 std::string v = f->GetEntryValue(groupNb,ElementNb);
64 // to get the pixels, user needs a gdcm::FileHelper
65 gdcm::FileHelper *fh = new gdcm::FileHelper(f);
66 // user may ask not to convert Palette (if any) to RGB
67 uint8_t *pixels = fh->GetImageDataRaw();
68 int imageLength = fh->GetImageDataRawSize();
69 // He can now use the pixels, create a new image, ...
70 uint8_t *userPixels = ...
72 To re-write the image, user re-uses the gdcm::FileHelper
74 fh->SetImageData( userPixels, userPixelsLength);
75 fh->SetTypeToRaw(); // Even if it was possible to convert Palette to RGB
78 fh->SetWriteTypeToDcmExpl(); // he wants Explicit Value Representation
79 // Little Endian is the default
80 // no other value is allowed
81 (-->SetWriteType(ExplicitVR);)
82 -->WriteType = ExplicitVR;
83 fh->Write(newFileName); // overwrites the file, if any
86 fh->WriteDcmExplVR(newFileName);
89 // ----------------------------- WARNING -------------------------
92 These lines will be moved to the document-to-be 'Developer's Guide'
94 WriteMode : WMODE_RAW / WMODE_RGB
95 WriteType : ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO
96 PhotometricInterpretation : MONOCHROME2 (0=black), MONOCHROME2 (0=white)
99 fh->SetWriteMode(WMODE_RAW / WMODE_RGB)
101 fh->SetWriteType( ImplicitVR/ExplicitVR/ACR/ACR_LIBIDO/JPEG/JPEG2000)
103 fh->Write(newFileName);
104 CheckMandatoryElements(); // Checks existing ones / Add missing ones
105 Fix VR if unknown elements
106 SetWriteFileTypeToImplicitVR() / SetWriteFileTypeToExplicitVR(); /
107 SetWriteFileTypeToACR() / SetWriteFileTypeToJPEG() / SetWriteFileTypeToJ2K()
108 (Modifies TransferSyntax if any; Pushes to the Archives old one)
109 SetWriteToRaw(); / SetWriteToRGB();
110 (Modifies and pushes to the Archive, when necessary : photochr. interp.,
111 samples per pixel, Planar configuration,
112 bits allocated, bits stored, high bit -ACR 24 bits-
113 Pixels element VR, pushes out the LUT )
115 Sets Photometric Interpretation
116 DataEntry *pixel =CopyDataEntry(7fe0,0010,VR)
117 Sets VR, BinArea, Length for PixelData
120 Archive->Push(photInt);
121 Archive->Push(pixel);
125 if NumberOfScalarComponents==1
126 SetWriteToRaw(); return;
127 PixelReadConverter->BuildRGBImage()
128 DataEntry *pixel =CopyDataEntry(7fe0,0010,VR)
129 Archives spp, planConfig,photInt, pixel
131 CheckWriteIntegrity();
132 (checks user given pixels length)
133 FileInternal->Write(fileName,WriteType)
134 fp = opens file(fileName); // out|binary
135 ComputeGroup0002Length( );
136 Document::WriteContent(fp, writetype);
137 writes Dicom File Preamble not ACR-NEMA
138 ElementSet::WriteContent(fp, writetype);
139 writes recursively all DataElements
141 (moves back to the gdcm::File all the archived elements)
147 namespace GDCM_NAME_SPACE
149 typedef std::map<uint16_t, int> GroupHT; // Hash Table
150 //-------------------------------------------------------------------------
151 // Constructor / Destructor
153 * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
154 * file (gdcm::File only deals with the ... header)
155 * Opens (in read only and when possible) an existing file and checks
156 * for DICOM compliance. Returns NULL on failure.
157 * It will be up to the user to load the pixels into memory
158 * ( GetImageDataSize() + GetImageData() methods)
159 * \note the in-memory representation of all available tags found in
160 * the DICOM header is post-poned to first header information access.
161 * This avoid a double parsing of public part of the header when
162 * one sets an a posteriori shadow dictionary (efficiency can be
163 * seen as a side effect).
165 FileHelper::FileHelper( )
167 FileInternal = File::New( );
172 * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
173 * file (File only deals with the ... header)
174 * Opens (in read only and when possible) an existing file and checks
175 * for DICOM compliance. Returns NULL on failure.
176 * It will be up to the user to load the pixels into memory
177 * ( GetImageDataSize() + GetImageData() methods)
178 * \note the in-memory representation of all available tags found in
179 * the DICOM header is post-poned to first header information access.
180 * This avoid a double parsing of public part of the header when
181 * user sets an a posteriori shadow dictionary (efficiency can be
182 * seen as a side effect).
183 * @param header already built Header
185 FileHelper::FileHelper(File *header)
187 gdcmAssertMacro(header);
189 FileInternal = header;
190 FileInternal->Register();
192 if ( FileInternal->IsReadable() )
194 PixelReadConverter->GrabInformationsFromFile( FileInternal, this );
199 * \brief canonical destructor
200 * \note If the header (gdcm::File) was created by the FileHelper constructor,
201 * it is destroyed by the FileHelper
203 FileHelper::~FileHelper()
205 if ( PixelReadConverter )
207 delete PixelReadConverter;
209 if ( PixelWriteConverter )
211 delete PixelWriteConverter;
218 FileInternal->Unregister();
221 //-----------------------------------------------------------------------------
225 * \brief Sets the LoadMode of the internal gdcm::File as a boolean string.
226 * NO_SEQ, NO_SHADOW, NO_SHADOWSEQ ... (nothing more, right now)
227 * WARNING : before using NO_SHADOW, be sure *all* your files
228 * contain accurate values in the 0x0000 element (if any)
229 * of *each* Shadow Group. The parser will fail if the size is wrong !
230 * @param loadMode Load mode to be used
232 void FileHelper::SetLoadMode(int loadMode)
234 GetFile()->SetLoadMode( loadMode );
237 * \brief Sets the LoadMode of the internal gdcm::File
238 * @param fileName name of the file to be open
240 void FileHelper::SetFileName(std::string const &fileName)
242 FileInternal->SetFileName( fileName );
247 * @return false if file cannot be open or no swap info was found,
248 * or no tag was found.
250 bool FileHelper::Load()
252 if ( !FileInternal->Load() )
255 PixelReadConverter->GrabInformationsFromFile( FileInternal, this );
260 * \brief Accesses an existing DataEntry through its (group, element)
261 * and modifies its content with the given value.
262 * @param content new value (string) to substitute with
263 * @param group group number of the Dicom Element to modify
264 * @param elem element number of the Dicom Element to modify
265 * \return false if DataEntry not found
267 bool FileHelper::SetEntryString(std::string const &content,
268 uint16_t group, uint16_t elem)
270 return FileInternal->SetEntryString(content, group, elem);
275 * \brief Accesses an existing DataEntry through its (group, element)
276 * and modifies its content with the given value.
277 * @param content new value (void* -> uint8_t*) to substitute with
278 * @param lgth new value length
279 * @param group group number of the Dicom Element to modify
280 * @param elem element number of the Dicom Element to modify
281 * \return false if DataEntry not found
283 bool FileHelper::SetEntryBinArea(uint8_t *content, int lgth,
284 uint16_t group, uint16_t elem)
286 return FileInternal->SetEntryBinArea(content, lgth, group, elem);
290 * \brief Modifies the value of a given DataEntry when it exists.
291 * Creates it with the given value when unexistant.
292 * @param content (string) value to be set
293 * @param group Group number of the Entry
294 * @param elem Element number of the Entry
295 * @param vr Value Representation of the DataElement to be inserted
296 * \return pointer to the modified/created DataEntry (NULL when creation
299 DataEntry *FileHelper::InsertEntryString(std::string const &content,
300 uint16_t group, uint16_t elem,
303 return FileInternal->InsertEntryString(content, group, elem, vr);
307 * \brief Modifies the value of a given DataEntry when it exists.
308 * Creates it with the given value when unexistant.
309 * A copy of the binArea is made to be kept in the Document.
310 * @param binArea (binary) value to be set
311 * @param lgth new value length
312 * @param group Group number of the Entry
313 * @param elem Element number of the Entry
314 * @param vr Value Representation of the DataElement to be inserted
315 * \return pointer to the modified/created DataEntry (NULL when creation
318 DataEntry *FileHelper::InsertEntryBinArea(uint8_t *binArea, int lgth,
319 uint16_t group, uint16_t elem,
322 return FileInternal->InsertEntryBinArea(binArea, lgth, group, elem, vr);
326 * \brief Adds an empty SeqEntry
327 * (remove any existing entry with same group,elem)
328 * @param group Group number of the Entry
329 * @param elem Element number of the Entry
330 * \return pointer to the created SeqEntry (NULL when creation
333 SeqEntry *FileHelper::InsertSeqEntry(uint16_t group, uint16_t elem)
335 return FileInternal->InsertSeqEntry(group, elem);
339 * \brief Get the size of the image data
340 * If the image can be RGB (with a lut or by default), the size
341 * corresponds to the RGB image
342 * (use GetImageDataRawSize if you want to be sure to get *only*
343 * the size of the pixels)
344 * @return The image size
346 size_t FileHelper::GetImageDataSize()
348 if ( PixelWriteConverter->GetUserData() )
350 return PixelWriteConverter->GetUserDataSize();
352 return PixelReadConverter->GetRGBSize();
356 * \brief Get the size of the image data.
357 * If the image could be converted to RGB using a LUT,
358 * this transformation is not taken into account by GetImageDataRawSize
359 * (use GetImageDataSize if you wish)
360 * @return The raw image size
362 size_t FileHelper::GetImageDataRawSize()
364 if ( PixelWriteConverter->GetUserData() )
366 return PixelWriteConverter->GetUserDataSize();
368 return PixelReadConverter->GetRawSize();
372 * \brief brings pixels into memory :
373 * - Allocates necessary memory,
374 * - Reads the pixels from disk (uncompress if necessary),
375 * - Transforms YBR pixels, if any, into RGB pixels,
376 * - Transforms 3 planes R, G, B, if any, into a single RGB Plane
377 * - Transforms single Grey plane + 3 Palettes into a RGB Plane
378 * - Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
379 * @return Pointer to newly allocated pixel data.
380 * (uint8_t is just for prototyping. feel free to cast)
381 * NULL if alloc fails
383 uint8_t *FileHelper::GetImageData()
385 if ( PixelWriteConverter->GetUserData() )
387 return PixelWriteConverter->GetUserData();
392 // If the decompression failed nothing can be done.
396 if ( FileInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
398 return PixelReadConverter->GetRGB();
402 // When no LUT or LUT conversion fails, return the Raw
403 return PixelReadConverter->GetRaw();
408 * \brief brings pixels into memory :
409 * - Allocates necessary memory,
410 * - Transforms YBR pixels (if any) into RGB pixels
411 * - Transforms 3 planes R, G, B (if any) into a single RGB Plane
412 * - Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
413 * - DOES NOT transform Grey plane + 3 Palettes into a RGB Plane
414 * @return Pointer to newly allocated pixel data.
415 * (uint8_t is just for prototyping. feel free to cast)
416 * NULL if alloc fails
418 uint8_t *FileHelper::GetImageDataRaw ()
423 //#ifndef GDCM_LEGACY_REMOVE
425 * \brief Useless function, since PixelReadConverter forces us
426 * copy the Pixels anyway.
427 * Reads the pixels from disk (uncompress if necessary),
428 * Transforms YBR pixels, if any, into RGB pixels
429 * Transforms 3 planes R, G, B, if any, into a single RGB Plane
430 * Transforms single Grey plane + 3 Palettes into a RGB Plane
431 * Copies at most MaxSize bytes of pixel data to caller allocated
433 * \warning This function allows people that want to build a volume
434 * from an image stack *not to* have, first to get the image pixels,
435 * and then move them to the volume area.
436 * It's absolutely useless for any VTK user since vtk chooses
437 * to invert the lines of an image, that is the last line comes first
438 * (for some axis related reasons?). Hence he will have
439 * to load the image line by line, starting from the end.
440 * VTK users have to call GetImageData
442 * @param destination Address (in caller's memory space) at which the
443 * pixel data should be copied
444 * @param maxSize Maximum number of bytes to be copied. When MaxSize
445 * is not sufficient to hold the pixel data the copy is not
446 * executed (i.e. no partial copy).
447 * @return On success, the number of bytes actually copied. Zero on
448 * failure e.g. MaxSize is lower than necessary.
451 size_t FileHelper::GetImageDataIntoVector (void *destination, size_t maxSize)
455 // If the decompression failed nothing can be done.
459 if ( FileInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
461 if ( PixelReadConverter->GetRGBSize() > maxSize )
463 gdcmWarningMacro( "Pixel data bigger than caller's expected MaxSize");
467 (void*)PixelReadConverter->GetRGB(),
468 PixelReadConverter->GetRGBSize() );
469 return PixelReadConverter->GetRGBSize();
472 // Either no LUT conversion necessary or LUT conversion failed
473 if ( PixelReadConverter->GetRawSize() > maxSize )
475 gdcmWarningMacro( "Pixel data bigger than caller's expected MaxSize");
479 (void *)PixelReadConverter->GetRaw(),
480 PixelReadConverter->GetRawSize() );
481 return PixelReadConverter->GetRawSize();
487 * \brief Points the internal pointer to the callers inData
488 * image representation, BUT WITHOUT COPYING THE DATA.
489 * 'image' Pixels are presented as C-like 2D arrays : line per line.
490 * 'volume'Pixels are presented as C-like 3D arrays : plane per plane
491 * \warning Since the pixels are not copied, it is the caller's responsability
492 * not to deallocate its data before gdcm uses them (e.g. with
493 * the Write() method )
494 * @param inData user supplied pixel area (uint8_t* is just for the compiler.
495 * user is allowed to pass any kind of pixelsn since the size is
497 * @param expectedSize total image size, *in Bytes*
499 void FileHelper::SetImageData(uint8_t *inData, size_t expectedSize)
501 PixelWriteConverter->SetUserData(inData, expectedSize);
505 * \brief Set the image data defined by the user
506 * \warning When writting the file, this data are get as default data to write
507 * @param inData user supplied pixel area (uint8_t* is just for the compiler.
508 * user is allowed to pass any kind of pixels since the size is
510 * @param expectedSize total image size, *in Bytes*
512 void FileHelper::SetUserData(uint8_t *inData, size_t expectedSize)
514 PixelWriteConverter->SetUserData(inData, expectedSize);
518 * \brief Get the image data defined by the user
519 * \warning When writting the file, this data are get as default data to write
521 uint8_t *FileHelper::GetUserData()
523 return PixelWriteConverter->GetUserData();
527 * \brief Get the image data size defined by the user
528 * \warning When writting the file, this data are get as default data to write
530 size_t FileHelper::GetUserDataSize()
532 return PixelWriteConverter->GetUserDataSize();
536 * \brief Get the image data from the file.
537 * If a LUT is found, the data are expanded to be RGB
539 uint8_t *FileHelper::GetRGBData()
541 return PixelReadConverter->GetRGB();
545 * \brief Get the image data size from the file.
546 * If a LUT is found, the data are expanded to be RGB
548 size_t FileHelper::GetRGBDataSize()
550 return PixelReadConverter->GetRGBSize();
554 * \brief Get the image data from the file.
555 * Even when a LUT is found, the data are not expanded to RGB!
557 uint8_t *FileHelper::GetRawData()
559 return PixelReadConverter->GetRaw();
563 * \brief Get the image data size from the file.
564 * Even when a LUT is found, the data are not expanded to RGB!
566 size_t FileHelper::GetRawDataSize()
568 return PixelReadConverter->GetRawSize();
572 * \brief Access to the underlying \ref PixelReadConverter RGBA LUT
574 uint8_t* FileHelper::GetLutRGBA()
576 if ( PixelReadConverter->GetLutRGBA() ==0 )
577 PixelReadConverter->BuildLUTRGBA();
578 return PixelReadConverter->GetLutRGBA();
582 * \brief Access to the underlying \ref PixelReadConverter RGBA LUT Item Number
584 int FileHelper::GetLutItemNumber()
586 return PixelReadConverter->GetLutItemNumber();
590 * \brief Access to the underlying \ref PixelReadConverter RGBA LUT Item Size
592 int FileHelper::GetLutItemSize()
594 return PixelReadConverter->GetLutItemSize();
598 * \brief Writes on disk A SINGLE Dicom file
599 * NO test is performed on processor "Endiannity".
600 * It's up to the user to call his Reader properly
601 * @param fileName name of the file to be created
602 * (any already existing file is over written)
603 * @return false if write fails
605 bool FileHelper::WriteRawData(std::string const &fileName)
607 std::ofstream fp1(fileName.c_str(), std::ios::out | std::ios::binary );
610 gdcmWarningMacro( "Fail to open (write) file:" << fileName.c_str());
614 if ( PixelWriteConverter->GetUserData() )
616 fp1.write( (char *)PixelWriteConverter->GetUserData(),
617 PixelWriteConverter->GetUserDataSize() );
619 else if ( PixelReadConverter->GetRGB() )
621 fp1.write( (char *)PixelReadConverter->GetRGB(),
622 PixelReadConverter->GetRGBSize());
624 else if ( PixelReadConverter->GetRaw() )
626 fp1.write( (char *)PixelReadConverter->GetRaw(),
627 PixelReadConverter->GetRawSize());
631 gdcmErrorMacro( "Nothing written." );
640 * \brief Writes on disk A SINGLE Dicom file,
641 * using the Implicit Value Representation convention
642 * NO test is performed on processor "Endianity".
643 * @param fileName name of the file to be created
644 * (any already existing file is overwritten)
645 * @return false if write fails
648 bool FileHelper::WriteDcmImplVR (std::string const &fileName)
650 SetWriteTypeToDcmImplVR();
651 return Write(fileName);
655 * \brief Writes on disk A SINGLE Dicom file,
656 * using the Explicit Value Representation convention
657 * NO test is performed on processor "Endiannity".
658 * @param fileName name of the file to be created
659 * (any already existing file is overwritten)
660 * @return false if write fails
663 bool FileHelper::WriteDcmExplVR (std::string const &fileName)
665 SetWriteTypeToDcmExplVR();
666 return Write(fileName);
670 * \brief Writes on disk A SINGLE Dicom file,
671 * using the ACR-NEMA convention
672 * NO test is performed on processor "Endiannity".
673 * (a l'attention des logiciels cliniques
674 * qui ne prennent en entrée QUE des images ACR ...
675 * \warning if a DICOM_V3 header is supplied,
676 * groups < 0x0008 and shadow groups are ignored
677 * \warning NO TEST is performed on processor "Endiannity".
678 * @param fileName name of the file to be created
679 * (any already existing file is overwritten)
680 * @return false if write fails
683 bool FileHelper::WriteAcr (std::string const &fileName)
686 return Write(fileName);
690 * \brief Writes on disk A SINGLE Dicom file,
691 * @param fileName name of the file to be created
692 * (any already existing file is overwritten)
693 * @return false if write fails
695 bool FileHelper::Write(std::string const &fileName)
698 CheckMandatoryElements(); //called once, here !
705 SetWriteFileTypeToImplicitVR();
708 case Unknown: // should never happen; ExplicitVR is the default value
711 // User should ask gdcm to write an image in Explicit VR mode
712 // only when he is sure *all* the VR of *all* the DataElements is known.
713 // i.e : when there are *only* Public Groups
714 // or *all* the Shadow Groups are fully described in the relevant Shadow
716 // Let's just *dream* about it; *never* trust a user !
717 // We turn to Implicit VR if at least the VR of one element is unknown.
720 e = FileInternal->GetFirstEntry();
723 if (e->GetVR() == " ")
725 SetWriteTypeToDcmImplVR();
726 SetWriteFileTypeToImplicitVR();
730 e = FileInternal->GetNextEntry();
735 SetWriteFileTypeToExplicitVR();
739 SetWriteFileTypeToExplicitVR(); // to see JPRx
743 // NOTHING is done here just for LibIDO.
744 // Just to avoid further trouble if user creates a file ex-nihilo,
745 // wants to write it as an ACR-NEMA file,
746 // and forgets to create any Entry belonging to group 0008
748 // We add Recognition Code (RET)
749 if ( ! FileInternal->GetDataEntry(0x0008, 0x0010) )
750 FileInternal->InsertEntryString("ACR-NEMA V1.0 ",
751 0x0008, 0x0010, "LO");
752 SetWriteFileTypeToACR();
753 // SetWriteFileTypeToImplicitVR(); // ACR IS implicit VR !
756 /// \todo FIXME : JPEG may be either ExplicitVR or ImplicitVR
758 SetWriteFileTypeToJPEG();
762 SetWriteFileTypeToJPEG2000();
766 // --------------------------------------------------------------
767 // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
769 // if recognition code tells us we dealt with a LibIDO image
770 // we reproduce on disk the switch between lineNumber and columnNumber
771 // just before writting ...
772 /// \todo the best trick would be *change* the recognition code
773 /// but pb expected if user deals with, e.g. COMPLEX images
775 if ( WriteType == ACR_LIBIDO )
781 SetWriteToNoLibido();
783 // ----------------- End of Special Patch ----------------
788 SetWriteToRaw(); // modifies and pushes to the archive, when necessary
791 SetWriteToRGB(); // modifies and pushes to the archive, when necessary
795 bool check = CheckWriteIntegrity(); // verifies length
796 if (WriteType == JPEG || WriteType == JPEG2000) check = true;
799 check = FileInternal->Write(fileName,WriteType);
803 // RestoreWriteFileType();
804 // RestoreWriteMandatory();
807 // --------------------------------------------------------------
808 // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
810 // ...and we restore the header to be Dicom Compliant again
811 // just after writting
812 RestoreWriteOfLibido();
813 // ----------------- End of Special Patch ----------------
818 //-----------------------------------------------------------------------------
821 * \brief * \brief Verifies the size of the user given PixelData
822 * @return true if check is successfull
824 bool FileHelper::CheckWriteIntegrity()
826 if ( PixelWriteConverter->GetUserData() )
828 int numberBitsAllocated = FileInternal->GetBitsAllocated();
829 if ( numberBitsAllocated == 0 || numberBitsAllocated == 12 )
831 gdcmWarningMacro( "numberBitsAllocated changed from "
832 << numberBitsAllocated << " to 16 "
833 << " for consistency purpose" );
834 numberBitsAllocated = 16;
837 size_t decSize = FileInternal->GetXSize()
838 * FileInternal->GetYSize()
839 * FileInternal->GetZSize()
840 * FileInternal->GetTSize()
841 * FileInternal->GetSamplesPerPixel()
842 * ( numberBitsAllocated / 8 );
843 size_t rgbSize = decSize;
844 if ( FileInternal->HasLUT() )
845 rgbSize = decSize * 3;
850 if ( decSize!=PixelWriteConverter->GetUserDataSize() )
852 gdcmWarningMacro( "Data size (Raw) is incorrect. Should be "
853 << decSize << " / Found :"
854 << PixelWriteConverter->GetUserDataSize() );
859 if ( rgbSize!=PixelWriteConverter->GetUserDataSize() )
861 gdcmWarningMacro( "Data size (RGB) is incorrect. Should be "
862 << decSize << " / Found "
863 << PixelWriteConverter->GetUserDataSize() );
874 * \brief Updates the File to write RAW data (as opposed to RGB data)
875 * (modifies, when necessary, photochromatic interpretation,
876 * bits allocated, Pixels element VR)
877 * WARNING : if SetPhotometricInterpretationToMonochrome1() was called
878 * before Pixel Elements if modified :-(
880 void FileHelper::SetWriteToRaw()
882 if ( FileInternal->GetNumberOfScalarComponents() == 3
883 && !FileInternal->HasLUT() )
889 // 0x0028,0x0004 : Photometric Interpretation
890 DataEntry *photInt = CopyDataEntry(0x0028,0x0004,"CS");
891 if (FileInternal->HasLUT() )
893 photInt->SetString("PALETTE COLOR ");
897 if (GetPhotometricInterpretation() == 2)
898 photInt->SetString("MONOCHROME2 "); // 0 = Black
900 photInt->SetString("MONOCHROME1 "); // 0 = White !
903 PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(),
904 PixelReadConverter->GetRawSize());
906 std::string vr = "OB";
907 if ( FileInternal->GetBitsAllocated()>8 )
909 if ( FileInternal->GetBitsAllocated()==24 ) // For RGB ACR files
911 // For non RAW data. Mainly JPEG
912 if( WriteType == JPEG || WriteType == JPEG2000)
918 CopyDataEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel(),vr);
919 pixel->SetFlag(DataEntry::FLAG_PIXELDATA);
920 pixel->SetBinArea(PixelWriteConverter->GetData(),false);
921 pixel->SetLength(PixelWriteConverter->GetDataSize());
923 if (!FileInternal->HasLUT() && GetPhotometricInterpretation() == 1)
925 ConvertFixGreyLevels( pixel->GetBinArea(), pixel->GetLength() );
928 Archive->Push(photInt);
929 Archive->Push(pixel);
937 * \brief Updates the File to write RGB data (as opposed to RAW data)
938 * (modifies, when necessary, photochromatic interpretation,
939 * samples per pixel, Planar configuration,
940 * bits allocated, bits stored, high bit -ACR 24 bits-
941 * Pixels element VR, pushes out the LUT, )
943 void FileHelper::SetWriteToRGB()
945 if ( FileInternal->GetNumberOfScalarComponents()==3 )
947 PixelReadConverter->BuildRGBImage();
949 DataEntry *spp = CopyDataEntry(0x0028,0x0002,"US");
950 spp->SetString("3 ");
952 DataEntry *planConfig = CopyDataEntry(0x0028,0x0006,"US");
953 planConfig->SetString("0 ");
955 DataEntry *photInt = CopyDataEntry(0x0028,0x0004,"CS");
956 photInt->SetString("RGB ");
958 if ( PixelReadConverter->GetRGB() )
960 PixelWriteConverter->SetReadData(PixelReadConverter->GetRGB(),
961 PixelReadConverter->GetRGBSize());
965 PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(),
966 PixelReadConverter->GetRawSize());
969 std::string vr = "OB";
970 if ( FileInternal->GetBitsAllocated()>8 )
972 if ( FileInternal->GetBitsAllocated()==24 ) // For RGB ACR files
975 CopyDataEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel(),vr);
976 pixel->SetFlag(DataEntry::FLAG_PIXELDATA);
977 pixel->SetBinArea(PixelWriteConverter->GetData(),false);
978 pixel->SetLength(PixelWriteConverter->GetDataSize());
981 Archive->Push(planConfig);
982 Archive->Push(photInt);
983 Archive->Push(pixel);
986 planConfig->Delete();
991 Archive->Push(0x0028,0x1101);
992 Archive->Push(0x0028,0x1102);
993 Archive->Push(0x0028,0x1103);
994 Archive->Push(0x0028,0x1201);
995 Archive->Push(0x0028,0x1202);
996 Archive->Push(0x0028,0x1203);
998 // push out Palette Color Lookup Table UID, if any
999 Archive->Push(0x0028,0x1199);
1001 // For old '24 Bits' ACR-NEMA
1002 // Thus, we have a RGB image and the bits allocated = 24 and
1003 // samples per pixels = 1 (in the read file)
1004 if ( FileInternal->GetBitsAllocated()==24 )
1006 DataEntry *bitsAlloc = CopyDataEntry(0x0028,0x0100,"US");
1007 bitsAlloc->SetString("8 ");
1009 DataEntry *bitsStored = CopyDataEntry(0x0028,0x0101,"US");
1010 bitsStored->SetString("8 ");
1012 DataEntry *highBit = CopyDataEntry(0x0028,0x0102,"US");
1013 highBit->SetString("7 ");
1015 Archive->Push(bitsAlloc);
1016 Archive->Push(bitsStored);
1017 Archive->Push(highBit);
1019 bitsAlloc->Delete();
1020 bitsStored->Delete();
1031 * \brief Restore the File write mode
1033 void FileHelper::RestoreWrite()
1036 Archive->Restore(0x0028,0x0002);
1037 Archive->Restore(0x0028,0x0004);
1039 Archive->Restore(0x0028,0x0006);
1040 Archive->Restore(GetFile()->GetGrPixel(),GetFile()->GetNumPixel());
1042 // For old ACR-NEMA (24 bits problem)
1043 Archive->Restore(0x0028,0x0100);
1044 Archive->Restore(0x0028,0x0101);
1045 Archive->Restore(0x0028,0x0102);
1048 Archive->Restore(0x0028,0x1101);
1049 Archive->Restore(0x0028,0x1102);
1050 Archive->Restore(0x0028,0x1103);
1051 Archive->Restore(0x0028,0x1201);
1052 Archive->Restore(0x0028,0x1202);
1053 Archive->Restore(0x0028,0x1203);
1055 // For the Palette Color Lookup Table UID
1056 Archive->Restore(0x0028,0x1203);
1058 // group 0002 may be pushed out for ACR-NEMA writting purposes
1059 Archive->Restore(0x0002,0x0000);
1060 Archive->Restore(0x0002,0x0001);
1061 Archive->Restore(0x0002,0x0002);
1062 Archive->Restore(0x0002,0x0003);
1063 Archive->Restore(0x0002,0x0010);
1064 Archive->Restore(0x0002,0x0012);
1065 Archive->Restore(0x0002,0x0013);
1066 Archive->Restore(0x0002,0x0016);
1067 Archive->Restore(0x0002,0x0100);
1068 Archive->Restore(0x0002,0x0102);
1073 * \brief Pushes out the whole group 0002
1074 * FIXME : better, set a flag to tell the writer not to write it ...
1075 * FIXME : method should probably have an other name !
1076 * SetWriteFileTypeToACR is NOT opposed to
1077 * SetWriteFileTypeToExplicitVR and SetWriteFileTypeToImplicitVR
1079 void FileHelper::SetWriteFileTypeToACR()
1081 Archive->Push(0x0002,0x0000);
1082 Archive->Push(0x0002,0x0001);
1083 Archive->Push(0x0002,0x0002);
1084 Archive->Push(0x0002,0x0003);
1085 Archive->Push(0x0002,0x0010);
1086 Archive->Push(0x0002,0x0012);
1087 Archive->Push(0x0002,0x0013);
1088 Archive->Push(0x0002,0x0016);
1089 Archive->Push(0x0002,0x0100);
1090 Archive->Push(0x0002,0x0102);
1094 * \brief Sets in the File the TransferSyntax to 'JPEG2000'
1096 void FileHelper::SetWriteFileTypeToJPEG2000()
1098 std::string ts = Util::DicomString(
1099 Global::GetTS()->GetSpecialTransferSyntax(TS::JPEG2000Lossless) );
1101 DataEntry *tss = CopyDataEntry(0x0002,0x0010,"UI");
1109 * \brief Sets in the File the TransferSyntax to 'JPEG'
1111 void FileHelper::SetWriteFileTypeToJPEG()
1113 std::string ts = Util::DicomString(
1114 Global::GetTS()->GetSpecialTransferSyntax(TS::JPEGBaselineProcess1) );
1116 DataEntry *tss = CopyDataEntry(0x0002,0x0010,"UI");
1124 * \brief Sets in the File the TransferSyntax to 'Explicit VR Little Endian"
1126 void FileHelper::SetWriteFileTypeToExplicitVR()
1128 std::string ts = Util::DicomString(
1129 Global::GetTS()->GetSpecialTransferSyntax(TS::ExplicitVRLittleEndian) );
1131 DataEntry *tss = CopyDataEntry(0x0002,0x0010,"UI");
1138 * \brief Sets in the File the TransferSyntax to 'Implicit VR Little Endian"
1140 void FileHelper::SetWriteFileTypeToImplicitVR()
1142 std::string ts = Util::DicomString(
1143 Global::GetTS()->GetSpecialTransferSyntax(TS::ImplicitVRLittleEndian) );
1145 DataEntry *tss = CopyDataEntry(0x0002,0x0010,"UI");
1152 * \brief Set the Write not to Libido format
1154 void FileHelper::SetWriteToLibido()
1156 DataEntry *oldRow = FileInternal->GetDataEntry(0x0028, 0x0010);
1157 DataEntry *oldCol = FileInternal->GetDataEntry(0x0028, 0x0011);
1159 if ( oldRow && oldCol )
1161 std::string rows, columns;
1163 //DataEntry *newRow=DataEntry::New(oldRow->GetDictEntry());
1164 //DataEntry *newCol=DataEntry::New(oldCol->GetDictEntry());
1166 DataEntry *newRow=DataEntry::New(0x0028, 0x0010, "US");
1167 DataEntry *newCol=DataEntry::New(0x0028, 0x0011, "US");
1169 newRow->Copy(oldCol);
1170 newCol->Copy(oldRow);
1172 newRow->SetString(oldCol->GetString());
1173 newCol->SetString(oldRow->GetString());
1175 Archive->Push(newRow);
1176 Archive->Push(newCol);
1182 DataEntry *libidoCode = CopyDataEntry(0x0008,0x0010,"LO");
1183 libidoCode->SetString("ACRNEMA_LIBIDO_1.1");
1184 Archive->Push(libidoCode);
1185 libidoCode->Delete();
1189 * \brief Set the Write not to No Libido format
1191 void FileHelper::SetWriteToNoLibido()
1193 DataEntry *recCode = FileInternal->GetDataEntry(0x0008,0x0010);
1196 if ( recCode->GetString() == "ACRNEMA_LIBIDO_1.1" )
1198 DataEntry *libidoCode = CopyDataEntry(0x0008,0x0010,"LO");
1199 libidoCode->SetString("");
1200 Archive->Push(libidoCode);
1201 libidoCode->Delete();
1207 * \brief Restore the Write format
1209 void FileHelper::RestoreWriteOfLibido()
1211 Archive->Restore(0x0028,0x0010);
1212 Archive->Restore(0x0028,0x0011);
1213 Archive->Restore(0x0008,0x0010);
1215 // Restore 'LibIDO-special' entries, if any
1216 Archive->Restore(0x0028,0x0015);
1217 Archive->Restore(0x0028,0x0016);
1218 Archive->Restore(0x0028,0x0017);
1219 Archive->Restore(0x0028,0x00199);
1223 * \brief Duplicates a DataEntry or creates it.
1224 * @param group Group number of the Entry
1225 * @param elem Element number of the Entry
1226 * @param vr Value Representation of the Entry
1227 * \return pointer to the new Bin Entry (NULL when creation failed).
1229 DataEntry *FileHelper::CopyDataEntry(uint16_t group, uint16_t elem,
1232 DocEntry *oldE = FileInternal->GetDocEntry(group, elem);
1235 if ( oldE && vr != GDCM_VRUNKNOWN )
1236 if ( oldE->GetVR() != vr )
1241 //newE = DataEntry::New(oldE->GetDictEntry());
1242 newE = DataEntry::New(group, elem, vr);
1247 newE = GetFile()->NewDataEntry(group, elem, vr);
1254 * \brief This method is called automatically, just before writting
1255 * in order to produce a 'True Dicom V3' image.
1257 * We cannot know *how* the user made the File :
1258 * (reading an old ACR-NEMA file or a not very clean DICOM file ...)
1259 * Just before writting :
1260 * - we check the Entries
1261 * - we create the mandatory entries if they are missing
1262 * - we modify the values if necessary
1263 * - we push the sensitive entries to the Archive
1264 * The writing process will restore the entries as they where before
1265 * entering FileHelper::CheckMandatoryElements, so the user will always
1266 * see the entries just as they were before he decided to write.
1269 * - Entries whose type is 1 are mandatory, with a mandatory value
1270 * - Entries whose type is 1c are mandatory-inside-a-Sequence,
1271 * with a mandatory value
1272 * - Entries whose type is 2 are mandatory, with an optional value
1273 * - Entries whose type is 2c are mandatory-inside-a-Sequence,
1274 * with an optional value
1275 * - Entries whose type is 3 are optional
1278 * - warn the user if we had to add some entries :
1279 * even if a mandatory entry is missing, we add it, with a default value
1280 * (we don't want to give up the writting process if user forgot to
1281 * specify Lena's Patient ID, for instance ...)
1282 * - read the whole PS 3.3 Part of DICOM (890 pages)
1283 * and write a *full* checker (probably one method per Modality ...)
1284 * Any contribution is welcome.
1285 * - write a user callable full checker, to allow post reading
1286 * and/or pre writting image consistency check.
1289 /* -------------------------------------------------------------------------------------
1290 To be moved to User's guide / WIKI ?
1292 We have to deal with 4 *very* different cases :
1293 -1) user created ex nihilo his own image and wants to write it as a Dicom image.
1295 -2) user modified the pixels of an existing image.
1297 -3) user created a new image, using a set of existing images (eg MIP, MPR, cartography image)
1299 -4) user modified/added some tags *without processing* the pixels (anonymization..
1300 UNMODIFIED_PIXELS_IMAGE
1301 -Probabely some more to be added
1303 gdcm::FileHelper::CheckMandatoryElements() deals automatically with these cases.
1306 0008 0012 Instance Creation Date
1307 0008 0013 Instance Creation Time
1308 0008 0018 SOP Instance UID
1309 are *always* created with the current values; user has *no* possible intervention on
1312 'Serie Instance UID'(0x0020,0x000e)
1313 'Study Instance UID'(0x0020,0x000d) are kept as is if already exist,
1314 created if it doesn't.
1315 The user is allowed to create his own Series/Studies,
1316 keeping the same 'Serie Instance UID' / 'Study Instance UID' for various images
1318 The user shouldn't add any image to a 'Manufacturer Serie'
1319 but there is no way no to allow him to do that
1321 None of the 'shadow elements' are droped out.
1325 'Conversion Type (0x0008,0x0064) is forced to 'SYN' (Synthetic Image).
1328 'Media Storage SOP Class UID' (0x0002,0x0002)
1329 'SOP Class UID' (0x0008,0x0016) are set to
1330 [Secondary Capture Image Storage]
1331 'Image Type' (0x0008,0x0008) is forced to "DERIVED\PRIMARY"
1332 Conversion Type (0x0008,0x0064) is forced to 'SYN' (Synthetic Image)
1335 If 'SOP Class UID' exists in the native image ('true DICOM' image)
1336 we create the 'Source Image Sequence' SeqEntry (0x0008, 0x2112)
1337 --> 'Referenced SOP Class UID' (0x0008, 0x1150)
1338 whose value is the original 'SOP Class UID'
1339 --> 'Referenced SOP Instance UID' (0x0008, 0x1155)
1340 whose value is the original 'SOP Class UID'
1342 3) TODO : find a trick to allow user to pass to the writter the list of the Dicom images
1343 or the Series, (or the Study ?) he used to created his image
1344 (MIP, MPR, cartography image, ...)
1345 These info should be stored (?)
1346 0008 1110 SQ 1 Referenced Study Sequence
1347 0008 1115 SQ 1 Referenced Series Sequence
1348 0008 1140 SQ 1 Referenced Image Sequence
1350 4) When user *knows* he didn't modified the pixels, we keep some informations unchanged :
1351 'Media Storage SOP Class UID' (0x0002,0x0002)
1352 'SOP Class UID' (0x0008,0x0016)
1353 'Image Type' (0x0008,0x0008)
1354 'Conversion Type' (0x0008,0x0064)
1357 Bellow follows the full description (hope so !) of the consistency checks performed
1358 by gdcm::FileHelper::CheckMandatoryElements()
1361 -->'Media Storage SOP Class UID' (0x0002,0x0002)
1362 -->'SOP Class UID' (0x0008,0x0016) are defaulted to
1363 [Secondary Capture Image Storage]
1364 --> 'Image Type' (0x0008,0x0008)
1365 is forced to "DERIVED\PRIMARY"
1366 (The written image is no longer an 'ORIGINAL' one)
1367 Except if user knows he didn't modify the image (e.g. : he just anonymized the file)
1369 --> Conversion Type (0x0008,0x0064)
1370 is defaulted to 'SYN' (Synthetic Image)
1371 when *he* knows he created his own image ex nihilo
1373 --> 'Modality' (0x0008,0x0060)
1374 is defaulted to "OT" (other) if missing.
1375 (a fully user created image belongs to *no* modality)
1377 --> 'Media Storage SOP Instance UID' (0x0002,0x0003)
1378 --> 'Implementation Class UID' (0x0002,0x0012)
1379 are automatically generated; no user intervention possible
1381 --> 'Serie Instance UID'(0x0020,0x000e)
1382 --> 'Study Instance UID'(0x0020,0x000d) are kept as is if already exist
1383 created if it doesn't.
1384 The user is allowed to create his own Series/Studies,
1385 keeping the same 'Serie Instance UID' / 'Study Instance UID'
1388 The user shouldn't add any image to a 'Manufacturer Serie'
1389 but there is no way no to allowed him to do that
1391 --> If 'SOP Class UID' exists in the native image ('true DICOM' image)
1392 we create the 'Source Image Sequence' SeqEntry (0x0008, 0x2112)
1394 --> 'Referenced SOP Class UID' (0x0008, 0x1150)
1395 whose value is the original 'SOP Class UID'
1396 --> 'Referenced SOP Instance UID' (0x0008, 0x1155)
1397 whose value is the original 'SOP Class UID'
1399 --> Bits Stored, Bits Allocated, Hight Bit Position are checked for consistency
1400 --> Pixel Spacing (0x0028,0x0030) is defaulted to "1.0\1.0"
1401 --> Samples Per Pixel (0x0028,0x0002) is defaulted to 1 (grayscale)
1403 --> Imager Pixel Spacing (0x0018,0x1164) : defaulted to Pixel Spacing value
1405 --> Instance Creation Date, Instance Creation Time are forced to current Date and Time
1407 --> Study Date, Study Time are defaulted to current Date and Time
1408 (they remain unchanged if they exist)
1410 --> Patient Orientation : (0x0020,0x0020), if not present, is deduced from
1411 Image Orientation (Patient) : (0020|0037) or from
1412 Image Orientation (RET) : (0020 0035)
1414 --> Study ID, Series Number, Instance Number, Patient Orientation (Type 2)
1415 are created, with empty value if there are missing.
1417 --> Manufacturer, Institution Name, Patient's Name, (Type 2)
1418 are defaulted with a 'gdcm' value.
1420 --> Patient ID, Patient's Birth Date, Patient's Sex, (Type 2)
1421 --> Referring Physician's Name (Type 2)
1422 are created, with empty value if there are missing.
1424 -------------------------------------------------------------------------------------*/
1426 void FileHelper::CheckMandatoryElements()
1428 std::string sop = Util::CreateUniqueUID();
1430 // --------------------- For Meta Elements ---------------------
1431 // just to remember : 'official' 0002 group
1432 if ( WriteType != ACR && WriteType != ACR_LIBIDO )
1434 // Group 000002 (Meta Elements) already pushed out
1436 //0002 0000 UL 1 Meta Group Length
1437 //0002 0001 OB 1 File Meta Information Version
1438 //0002 0002 UI 1 Media Stored SOP Class UID
1439 //0002 0003 UI 1 Media Stored SOP Instance UID
1440 //0002 0010 UI 1 Transfer Syntax UID
1441 //0002 0012 UI 1 Implementation Class UID
1442 //0002 0013 SH 1 Implementation Version Name
1443 //0002 0016 AE 1 Source Application Entity Title
1444 //0002 0100 UI 1 Private Information Creator
1445 //0002 0102 OB 1 Private Information
1447 // Push out 'ACR-NEMA-special' entries, if any
1448 Archive->Push(0x0008,0x0001); // Length to End
1449 Archive->Push(0x0008,0x0010); // Recognition Code
1450 Archive->Push(0x0028,0x0005); // Image Dimension
1452 // Create them if not found
1453 // Always modify the value
1454 // Push the entries to the archive.
1455 CopyMandatoryEntry(0x0002,0x0000,"0","UL");
1457 DataEntry *e_0002_0001 = CopyDataEntry(0x0002,0x0001, "OB");
1458 e_0002_0001->SetBinArea((uint8_t*)Util::GetFileMetaInformationVersion(),
1460 e_0002_0001->SetLength(2);
1461 Archive->Push(e_0002_0001);
1462 e_0002_0001->Delete();
1464 if ( ContentType == FILTERED_IMAGE || ContentType == UNMODIFIED_PIXELS_IMAGE)
1466 // we keep the original 'Media Storage SOP Class UID', we default it if missing
1467 CheckMandatoryEntry(0x0002,0x0002,"1.2.840.10008.5.1.4.1.1.7","UI");
1471 // It's *not* an image comming straight from a source. We force
1472 // 'Media Storage SOP Class UID' --> [Secondary Capture Image Storage]
1473 CopyMandatoryEntry(0x0002,0x0002,"1.2.840.10008.5.1.4.1.1.7","UI");
1476 // 'Media Storage SOP Instance UID'
1477 CopyMandatoryEntry(0x0002,0x0003,sop,"UI");
1479 // 'Implementation Class UID'
1480 // FIXME : in all examples we have, 0x0002,0x0012 is not so long :
1481 // seems to be Root UID + 4 digits (?)
1482 CopyMandatoryEntry(0x0002,0x0012,Util::CreateUniqueUID(),"UI");
1484 // 'Implementation Version Name'
1485 std::string version = "GDCM ";
1486 version += Util::GetVersion();
1487 CopyMandatoryEntry(0x0002,0x0013,version,"SH");
1490 // --------------------- For DataSet ---------------------
1492 if ( ContentType != USER_OWN_IMAGE) // when it's not a user made image
1495 gdcmDebugMacro( "USER_OWN_IMAGE (1)");
1496 // If 'SOP Class UID' exists ('true DICOM' image)
1497 // we create the 'Source Image Sequence' SeqEntry
1498 // to hold informations about the Source Image
1500 DataEntry *e_0008_0016 = FileInternal->GetDataEntry(0x0008, 0x0016);
1503 // Create 'Source Image Sequence' SeqEntry
1504 // SeqEntry *sis = SeqEntry::New (
1505 // Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x2112) );
1506 SeqEntry *sis = SeqEntry::New (0x0008, 0x2112);
1507 SQItem *sqi = SQItem::New(1);
1508 // (we assume 'SOP Instance UID' exists too)
1509 // create 'Referenced SOP Class UID'
1510 // DataEntry *e_0008_1150 = DataEntry::New(
1511 // Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x1150) );
1512 DataEntry *e_0008_1150 = DataEntry::New(0x0008, 0x1150, "UI");
1513 e_0008_1150->SetString( e_0008_0016->GetString());
1514 sqi->AddEntry(e_0008_1150);
1515 e_0008_1150->Delete();
1517 // create 'Referenced SOP Instance UID'
1518 DataEntry *e_0008_0018 = FileInternal->GetDataEntry(0x0008, 0x0018);
1519 // DataEntry *e_0008_1155 = DataEntry::New(
1520 // Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x1155) );
1521 DataEntry *e_0008_1155 = DataEntry::New(0x0008, 0x1155, "UI");
1522 e_0008_1155->SetString( e_0008_0018->GetString());
1523 sqi->AddEntry(e_0008_1155);
1524 e_0008_1155->Delete();
1526 sis->AddSQItem(sqi,1);
1529 // temporarily replaces any previous 'Source Image Sequence'
1533 // FIXME : is 'Image Type' *really* depending on the presence of 'SOP Class UID'?
1534 if ( ContentType == FILTERED_IMAGE)
1535 // the user *knows* he just modified the pixels
1536 // the image is no longer an 'Original' one
1537 CopyMandatoryEntry(0x0008,0x0008,"DERIVED\\PRIMARY","CS");
1541 if ( ContentType == FILTERED_IMAGE || ContentType == UNMODIFIED_PIXELS_IMAGE)
1543 // we keep the original 'Media Storage SOP Class UID', we default it if missing (it should be present !)
1544 CheckMandatoryEntry(0x0008,0x0016,"1.2.840.10008.5.1.4.1.1.7","UI");
1548 // It's *not* an image comming straight from a source. We force
1549 // 'Media Storage SOP Class UID' --> [Secondary Capture Image Storage]
1550 CopyMandatoryEntry(0x0008,0x0016,"1.2.840.10008.5.1.4.1.1.7", "UI");
1553 Archive->Push(0x0028,0x005); // [Image Dimensions (RET)
1554 // Push out 'LibIDO-special' entries, if any
1555 Archive->Push(0x0028,0x0015);
1556 Archive->Push(0x0028,0x0016);
1557 Archive->Push(0x0028,0x0017);
1558 Archive->Push(0x0028,0x0198); // very old versions
1559 Archive->Push(0x0028,0x0199);
1561 // Replace deprecated 0028 0012 US Planes
1562 // by new 0028 0008 IS Number of Frames
1564 ///\todo : find if there is a rule!
1565 DataEntry *e_0028_0012 = FileInternal->GetDataEntry(0x0028, 0x0012);
1568 CopyMandatoryEntry(0x0028, 0x0008,e_0028_0012->GetString(),"IS");
1569 Archive->Push(0x0028,0x0012);
1572 // Deal with the pb of (Bits Stored = 12)
1573 // - we're gonna write the image as Bits Stored = 16
1574 if ( FileInternal->GetEntryString(0x0028,0x0100) == "12")
1576 CopyMandatoryEntry(0x0028,0x0100,"16","US");
1579 // Check if user wasn't drunk ;-)
1581 std::ostringstream s;
1582 // check 'Bits Allocated' vs decent values
1583 int nbBitsAllocated = FileInternal->GetBitsAllocated();
1584 if ( nbBitsAllocated == 0 || nbBitsAllocated > 32
1585 || ( nbBitsAllocated > 8 && nbBitsAllocated <16) )
1587 CopyMandatoryEntry(0x0028,0x0100,"16","US");
1588 gdcmWarningMacro("(0028,0100) changed from "
1589 << nbBitsAllocated << " to 16 for consistency purpose");
1590 nbBitsAllocated = 16;
1592 // check 'Bits Stored' vs 'Bits Allocated'
1593 int nbBitsStored = FileInternal->GetBitsStored();
1594 if ( nbBitsStored == 0 || nbBitsStored > nbBitsAllocated )
1597 s << nbBitsAllocated;
1598 CopyMandatoryEntry(0x0028,0x0101,s.str(),"US");
1599 gdcmWarningMacro("(0028,0101) changed from "
1600 << nbBitsStored << " to " << nbBitsAllocated
1601 << " for consistency purpose" );
1602 nbBitsStored = nbBitsAllocated;
1604 // check 'Hight Bit Position' vs 'Bits Allocated' and 'Bits Stored'
1605 int highBitPosition = FileInternal->GetHighBitPosition();
1606 if ( highBitPosition == 0 ||
1607 highBitPosition > nbBitsAllocated-1 ||
1608 highBitPosition < nbBitsStored-1 )
1611 s << nbBitsStored - 1;
1612 CopyMandatoryEntry(0x0028,0x0102,s.str(),"US");
1613 gdcmWarningMacro("(0028,0102) changed from "
1614 << highBitPosition << " to " << nbBitsAllocated-1
1615 << " for consistency purpose");
1618 // check Pixel Representation (default it as 0 -unsigned-)
1620 DataEntry *e_0028_0103 = FileInternal->GetDataEntry(0x0028, 0x0103);
1623 gdcmWarningMacro("PixelRepresentation (0028,0103) is supposed to be mandatory");
1624 CopyMandatoryEntry(0x0028, 0x0103,"0","US");
1628 int sign = (int)e_0028_0103->GetValue(0);
1629 if (sign !=1 && sign !=0)
1631 gdcmWarningMacro("PixelRepresentation (0028,0103) is supposed to be =1 or =0");
1632 CopyMandatoryEntry(0x0028, 0x0103,"0","US");
1636 std::string pixelSpacing = FileInternal->GetEntryString(0x0028,0x0030);
1637 if ( pixelSpacing == GDCM_UNFOUND )
1639 pixelSpacing = "1.0\\1.0";
1640 // if missing, Pixel Spacing forced to "1.0\1.0"
1641 CopyMandatoryEntry(0x0028,0x0030,pixelSpacing,"DS");
1644 // 'Imager Pixel Spacing' : defaulted to 'Pixel Spacing'
1645 // --> This one is the *legal* one !
1646 if ( ContentType != USER_OWN_IMAGE)
1647 // we write it only when we are *sure* the image comes from
1648 // an imager (see also 0008,0x0064)
1649 CheckMandatoryEntry(0x0018,0x1164,pixelSpacing,"DS");
1652 ///Exact meaning of RETired fields
1654 // See page 73 of ACR-NEMA_300-1988.pdf !
1656 // 0020,0020 : Patient Orientation :
1657 Patient direction of the first row and
1658 column of the images. The first entry id the direction of the raws, given by the
1659 direction of the last pixel in the first row from the first pixel in tha row.
1660 the second entry is the direction of the columns, given by the direction of the
1661 last pixel in the first column from the first pixel in that column.
1662 L : Left, F : Feet, A : Anterior, P : Posterior.
1663 Up to 3 letters can be used in combination to indicate oblique planes.
1665 //0020,0030 Image Position (RET)
1666 x,y,z coordinates im mm of the first pixel in the image
1668 // 0020,0035 Image Orientation (RET)
1669 Direction cosines of the R axis of the image system with respect to the
1670 equipment coordinate axes x,y,z, followed by direction cosines of the C axis of
1671 the image system with respect to the same axes
1673 //0020,0050 Location
1674 An image location reference, standard for the modality (such as CT bed
1675 position), used to indicate position. Calculation of position for other purposes
1676 is only from (0020,0030) and (0020,0035)
1680 // if imagePositionPatient not found, default it with imagePositionRet, if any
1681 // if imageOrientationPatient not found, default it with imageOrientationRet, if any
1683 std::string imagePositionRet = FileInternal->GetEntryString(0x0020,0x0030);
1684 std::string imageOrientationRet = FileInternal->GetEntryString(0x0020,0x0035);
1685 std::string imagePositionPatient = FileInternal->GetEntryString(0x0020,0x0032);
1686 std::string imageOrientationPatient = FileInternal->GetEntryString(0x0020,0x0037);
1688 if( imagePositionPatient == GDCM_UNFOUND && imageOrientationPatient == GDCM_UNFOUND
1689 && imagePositionRet != GDCM_UNFOUND && imageOrientationRet != GDCM_UNFOUND)
1691 CopyMandatoryEntry(0x0020, 0x0032,imagePositionRet,"DS");
1692 Archive->Push(0x0020,0x0030);
1693 CopyMandatoryEntry(0x0020, 0x0037,imageOrientationRet,"DS");
1694 Archive->Push(0x0020,0x0035);
1698 // Samples Per Pixel (type 1) : default to grayscale
1699 CheckMandatoryEntry(0x0028,0x0002,"1","US");
1701 // --- Check UID-related Entries ---
1703 // At the end, not to overwrite the original ones,
1704 // needed by 'Referenced SOP Instance UID', 'Referenced SOP Class UID'
1705 // 'SOP Instance UID'
1706 CopyMandatoryEntry(0x0008,0x0018,sop,"UI");
1708 if ( ContentType == USER_OWN_IMAGE)
1710 gdcmDebugMacro( "USER_OWN_IMAGE (2)");
1712 // Other possible values are :
1713 // See PS 3.3, Page 408
1715 // DV = Digitized Video
1716 // DI = Digital Interface
1717 // DF = Digitized Film
1718 // WSD = Workstation
1719 // SD = Scanned Document
1720 // SI = Scanned Image
1722 // SYN = Synthetic Image
1724 CheckMandatoryEntry(0x0008,0x0064,"SYN","CS"); // Why not?
1727 if ( ContentType == CREATED_IMAGE)
1729 /// \todo : find a trick to pass the Media Storage SOP Instance UID of the images used to create the current image
1734 // ---- The user will never have to take any action on the following ----
1736 // new value for 'SOP Instance UID'
1737 //SetMandatoryEntry(0x0008,0x0018,Util::CreateUniqueUID());
1739 // Instance Creation Date
1740 const std::string &date = Util::GetCurrentDate();
1741 CopyMandatoryEntry(0x0008,0x0012,date,"DA");
1743 // Instance Creation Time
1744 const std::string &time = Util::GetCurrentTime();
1745 CopyMandatoryEntry(0x0008,0x0013,time,"TM");
1748 CheckMandatoryEntry(0x0008,0x0020,date,"DA");
1750 CheckMandatoryEntry(0x0008,0x0030,time,"TM");
1753 //CopyMandatoryEntry(0x0008,0x0050,"");
1754 CheckMandatoryEntry(0x0008,0x0050,"","SH");
1757 // ----- Add Mandatory Entries if missing ---
1758 // Entries whose type is 1 are mandatory, with a mandatory value
1759 // Entries whose type is 1c are mandatory-inside-a-Sequence,
1760 // with a mandatory value
1761 // Entries whose type is 2 are mandatory, with an optional value
1762 // Entries whose type is 2c are mandatory-inside-a-Sequence,
1763 // with an optional value
1764 // Entries whose type is 3 are optional
1766 // 'Study Instance UID'
1767 // Keep the value if exists
1768 // The user is allowed to create his own Study,
1769 // keeping the same 'Study Instance UID' for various images
1770 // The user may add images to a 'Manufacturer Study',
1771 // adding new Series to an already existing Study
1772 CheckMandatoryEntry(0x0020,0x000d,Util::CreateUniqueUID(),"UI");
1774 // 'Serie Instance UID'
1775 // Keep the value if exists
1776 // The user is allowed to create his own Series,
1777 // keeping the same 'Serie Instance UID' for various images
1778 // The user shouldn't add any image to a 'Manufacturer Serie'
1779 // but there is no way no to prevent him for doing that
1780 CheckMandatoryEntry(0x0020,0x000e,Util::CreateUniqueUID(),"UI");
1783 CheckMandatoryEntry(0x0020,0x0010,"","SH");
1786 CheckMandatoryEntry(0x0020,0x0011,"","IS");
1789 CheckMandatoryEntry(0x0020,0x0013,"","IS");
1791 // Patient Orientation
1792 // Can be computed from (0020|0037) : Image Orientation (Patient)
1793 GDCM_NAME_SPACE::Orientation *o = GDCM_NAME_SPACE::Orientation::New();
1794 std::string ori = o->GetOrientation ( FileInternal );
1796 if (ori != "\\" && ori != GDCM_UNFOUND)
1797 CheckMandatoryEntry(0x0020,0x0020,ori,"CS");
1799 CheckMandatoryEntry(0x0020,0x0020,"","CS");
1801 // Default Patient Position to HFS
1802 CheckMandatoryEntry(0x0018,0x5100,"HFS","CS");
1804 // Modality : if missing we set it to 'OTher'
1805 CheckMandatoryEntry(0x0008,0x0060,"OT","CS");
1807 // Manufacturer : if missing we set it to 'GDCM Factory'
1808 CheckMandatoryEntry(0x0008,0x0070,"GDCM Factory","LO");
1810 // Institution Name : if missing we set it to 'GDCM Hospital'
1811 CheckMandatoryEntry(0x0008,0x0080,"GDCM Hospital","LO");
1813 // Patient's Name : if missing, we set it to 'GDCM^Patient'
1814 CheckMandatoryEntry(0x0010,0x0010,"GDCM^Patient","PN");
1816 // Patient ID : some clinical softwares *demand* it although it's a 'type 2' entry.
1817 CheckMandatoryEntry(0x0010,0x0020,"gdcm ID","LO");
1819 // Patient's Birth Date : 'type 2' entry -> must exist, value not mandatory
1820 CheckMandatoryEntry(0x0010,0x0030,"","DA");
1822 // Patient's Sex :'type 2' entry -> must exist, value not mandatory
1823 CheckMandatoryEntry(0x0010,0x0040,"","CS");
1825 // Referring Physician's Name :'type 2' entry -> must exist, value not mandatory
1826 CheckMandatoryEntry(0x0008,0x0090,"","PN");
1829 // Deal with element 0x0000 (group length) of each group.
1830 // First stage : get all the different Groups
1833 DocEntry *d = FileInternal->GetFirstEntry();
1836 grHT[d->GetGroup()] = 0;
1837 d=FileInternal->GetNextEntry();
1839 // Second stage : add the missing ones (if any)
1840 for (GroupHT::iterator it = grHT.begin(); it != grHT.end(); ++it)
1842 CheckMandatoryEntry(it->first, 0x0000, "0");
1844 // Third stage : update all 'zero level' groups length
1848 if (PhotometricInterpretation == 1)
1853 void FileHelper::CheckMandatoryEntry(uint16_t group,uint16_t elem,std::string value,const VRKey &vr )
1855 DataEntry *entry = FileInternal->GetDataEntry(group,elem);
1858 //entry = DataEntry::New(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem));
1859 entry = DataEntry::New(group,elem,vr);
1860 entry->SetString(value);
1861 Archive->Push(entry);
1866 /// \todo : what is it used for ? (FileHelper::SetMandatoryEntry)
1867 void FileHelper::SetMandatoryEntry(uint16_t group,uint16_t elem,std::string value,const VRKey &vr)
1869 //DataEntry *entry = DataEntry::New(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem));
1870 DataEntry *entry = DataEntry::New(group,elem,vr);
1871 entry->SetString(value);
1872 Archive->Push(entry);
1876 void FileHelper::CopyMandatoryEntry(uint16_t group,uint16_t elem,std::string value,const VRKey &vr)
1878 DataEntry *entry = CopyDataEntry(group,elem,vr);
1879 entry->SetString(value);
1880 Archive->Push(entry);
1885 * \brief Restore in the File the initial group 0002
1887 void FileHelper::RestoreWriteMandatory()
1889 // group 0002 may be pushed out for ACR-NEMA writting purposes
1890 Archive->Restore(0x0002,0x0000);
1891 Archive->Restore(0x0002,0x0001);
1892 Archive->Restore(0x0002,0x0002);
1893 Archive->Restore(0x0002,0x0003);
1894 Archive->Restore(0x0002,0x0010);
1895 Archive->Restore(0x0002,0x0012);
1896 Archive->Restore(0x0002,0x0013);
1897 Archive->Restore(0x0002,0x0016);
1898 Archive->Restore(0x0002,0x0100);
1899 Archive->Restore(0x0002,0x0102);
1901 // FIXME : Check if none is missing !
1903 Archive->Restore(0x0008,0x0012);
1904 Archive->Restore(0x0008,0x0013);
1905 Archive->Restore(0x0008,0x0016);
1906 Archive->Restore(0x0008,0x0018);
1907 Archive->Restore(0x0008,0x0060);
1908 Archive->Restore(0x0008,0x0070);
1909 Archive->Restore(0x0008,0x0080);
1910 Archive->Restore(0x0008,0x0090);
1911 Archive->Restore(0x0008,0x2112);
1913 Archive->Restore(0x0010,0x0010);
1914 Archive->Restore(0x0010,0x0030);
1915 Archive->Restore(0x0010,0x0040);
1917 Archive->Restore(0x0020,0x000d);
1918 Archive->Restore(0x0020,0x000e);
1923 * \brief CallStartMethod
1925 void FileHelper::CallStartMethod()
1929 CommandManager::ExecuteCommand(this,CMD_STARTPROGRESS);
1933 * \brief CallProgressMethod
1935 void FileHelper::CallProgressMethod()
1937 CommandManager::ExecuteCommand(this,CMD_PROGRESS);
1941 * \brief CallEndMethod
1943 void FileHelper::CallEndMethod()
1946 CommandManager::ExecuteCommand(this,CMD_ENDPROGRESS);
1949 //-----------------------------------------------------------------------------
1952 * \brief Factorization for various forms of constructors.
1954 void FileHelper::Initialize()
1957 ContentType = USER_OWN_IMAGE;
1959 WriteMode = WMODE_RAW;
1960 WriteType = ExplicitVR;
1962 PhotometricInterpretation = 2; // Black = 0
1964 PixelReadConverter = new PixelReadConvert;
1965 PixelWriteConverter = new PixelWriteConvert;
1966 Archive = new DocEntryArchive( FileInternal );
1970 * \brief Reads/[decompresses] the pixels,
1971 * *without* making RGB from Palette Colors
1972 * @return the pixels area, whatever its type
1973 * (uint8_t is just for prototyping : feel free to Cast it)
1975 uint8_t *FileHelper::GetRaw()
1977 PixelReadConverter->SetUserFunction( UserFunction );
1979 uint8_t *raw = PixelReadConverter->GetRaw();
1982 // The Raw image migth not be loaded yet:
1983 std::ifstream *fp = FileInternal->OpenFile();
1984 PixelReadConverter->ReadAndDecompressPixelData( fp );
1986 FileInternal->CloseFile();
1988 raw = PixelReadConverter->GetRaw();
1991 gdcmWarningMacro( "Read/decompress of pixel data apparently went wrong.");
2000 * \brief Deal with Grey levels i.e. re-arange them
2001 * to have low values = dark, high values = bright
2003 void FileHelper::ConvertFixGreyLevels(uint8_t *raw, size_t rawSize)
2005 uint32_t i; // to please M$VC6
2008 // Number of Bits Allocated for storing a Pixel is defaulted to 16
2009 // when absent from the file.
2010 int bitsAllocated = FileInternal->GetBitsAllocated();
2011 if ( bitsAllocated == 0 )
2016 else if (bitsAllocated > 8 && bitsAllocated < 16 && bitsAllocated != 12)
2020 // Number of "Bits Stored", defaulted to number of "Bits Allocated"
2021 // when absent from the file.
2022 int bitsStored = FileInternal->GetBitsStored();
2023 if ( bitsStored == 0 )
2025 bitsStored = bitsAllocated;
2028 if (!FileInternal->IsSignedPixelData())
2030 if ( bitsAllocated == 8 )
2032 uint8_t *deb = (uint8_t *)raw;
2033 for (i=0; i<rawSize; i++)
2041 if ( bitsAllocated == 16 )
2044 for (j=0; j<bitsStored-1; j++)
2046 mask = (mask << 1) +1; // will be fff when BitsStored=12
2049 uint16_t *deb = (uint16_t *)raw;
2050 for (i=0; i<rawSize/2; i++)
2060 if ( bitsAllocated == 8 )
2062 uint8_t smask8 = 255;
2063 uint8_t *deb = (uint8_t *)raw;
2064 for (i=0; i<rawSize; i++)
2066 *deb = smask8 - *deb;
2071 if ( bitsAllocated == 16 )
2073 uint16_t smask16 = 65535;
2074 uint16_t *deb = (uint16_t *)raw;
2075 for (i=0; i<rawSize/2; i++)
2077 *deb = smask16 - *deb;
2085 //-----------------------------------------------------------------------------
2087 * \brief Prints the common part of DataEntry, SeqEntry
2088 * @param os ostream we want to print in
2089 * @param indent (unused)
2091 void FileHelper::Print(std::ostream &os, std::string const &)
2093 FileInternal->SetPrintLevel(PrintLevel);
2094 FileInternal->Print(os);
2096 if ( FileInternal->IsReadable() )
2098 PixelReadConverter->SetPrintLevel(PrintLevel);
2099 PixelReadConverter->Print(os);
2103 //-----------------------------------------------------------------------------
2104 } // end namespace gdcm
2107 /* Probabely something to be added to use Rescale Slope/Intercept
2108 Have a look ,at ITK code !
2110 // Internal function to rescale pixel according to Rescale Slope/Intercept
2111 template<class TBuffer, class TSource>
2112 void RescaleFunction(TBuffer* buffer, TSource *source,
2113 double slope, double intercept, size_t size)
2115 size /= sizeof(TSource);
2117 if (slope != 1.0 && intercept != 0.0)
2119 // Duff's device. Instead of this code:
2121 // for(unsigned int i=0; i<size; i++)
2123 // buffer[i] = (TBuffer)(source[i]*slope + intercept);
2126 // use Duff's device which exploits "fall through"
2127 register size_t n = (size + 7) / 8;
2130 case 0: do { *buffer++ = (TBuffer)((*source++)*slope + intercept);
2131 case 7: *buffer++ = (TBuffer)((*source++)*slope + intercept);
2132 case 6: *buffer++ = (TBuffer)((*source++)*slope + intercept);
2133 case 5: *buffer++ = (TBuffer)((*source++)*slope + intercept);
2134 case 4: *buffer++ = (TBuffer)((*source++)*slope + intercept);
2135 case 3: *buffer++ = (TBuffer)((*source++)*slope + intercept);
2136 case 2: *buffer++ = (TBuffer)((*source++)*slope + intercept);
2137 case 1: *buffer++ = (TBuffer)((*source++)*slope + intercept);
2141 else if (slope == 1.0 && intercept != 0.0)
2143 // Duff's device. Instead of this code:
2145 // for(unsigned int i=0; i<size; i++)
2147 // buffer[i] = (TBuffer)(source[i] + intercept);
2150 // use Duff's device which exploits "fall through"
2151 register size_t n = (size + 7) / 8;
2154 case 0: do { *buffer++ = (TBuffer)(*source++ + intercept);
2155 case 7: *buffer++ = (TBuffer)(*source++ + intercept);
2156 case 6: *buffer++ = (TBuffer)(*source++ + intercept);
2157 case 5: *buffer++ = (TBuffer)(*source++ + intercept);
2158 case 4: *buffer++ = (TBuffer)(*source++ + intercept);
2159 case 3: *buffer++ = (TBuffer)(*source++ + intercept);
2160 case 2: *buffer++ = (TBuffer)(*source++ + intercept);
2161 case 1: *buffer++ = (TBuffer)(*source++ + intercept);
2165 else if (slope != 1.0 && intercept == 0.0)
2167 // Duff's device. Instead of this code:
2169 // for(unsigned int i=0; i<size; i++)
2171 // buffer[i] = (TBuffer)(source[i]*slope);
2174 // use Duff's device which exploits "fall through"
2175 register size_t n = (size + 7) / 8;
2178 case 0: do { *buffer++ = (TBuffer)((*source++)*slope);
2179 case 7: *buffer++ = (TBuffer)((*source++)*slope);
2180 case 6: *buffer++ = (TBuffer)((*source++)*slope);
2181 case 5: *buffer++ = (TBuffer)((*source++)*slope);
2182 case 4: *buffer++ = (TBuffer)((*source++)*slope);
2183 case 3: *buffer++ = (TBuffer)((*source++)*slope);
2184 case 2: *buffer++ = (TBuffer)((*source++)*slope);
2185 case 1: *buffer++ = (TBuffer)((*source++)*slope);
2191 // Duff's device. Instead of this code:
2193 // for(unsigned int i=0; i<size; i++)
2195 // buffer[i] = (TBuffer)(source[i]);
2198 // use Duff's device which exploits "fall through"
2199 register size_t n = (size + 7) / 8;
2202 case 0: do { *buffer++ = (TBuffer)(*source++);
2203 case 7: *buffer++ = (TBuffer)(*source++);
2204 case 6: *buffer++ = (TBuffer)(*source++);
2205 case 5: *buffer++ = (TBuffer)(*source++);
2206 case 4: *buffer++ = (TBuffer)(*source++);
2207 case 3: *buffer++ = (TBuffer)(*source++);
2208 case 2: *buffer++ = (TBuffer)(*source++);
2209 case 1: *buffer++ = (TBuffer)(*source++);
2218 template<class TSource>
2219 void RescaleFunction(ImageIOBase::IOComponentType bufferType,
2220 void* buffer, TSource *source,
2221 double slope, double intercept, size_t size)
2225 case ImageIOBase::UCHAR:
2226 RescaleFunction( (unsigned char *)buffer, source, slope, intercept, size);
2228 case ImageIOBase::CHAR:
2229 RescaleFunction( (char *)buffer, source, slope, intercept, size);
2231 case ImageIOBase::USHORT:
2232 RescaleFunction( (unsigned short *)buffer, source, slope, intercept,size);
2234 case ImageIOBase::SHORT:
2235 RescaleFunction( (short *)buffer, source, slope, intercept, size);
2237 case ImageIOBase::UINT:
2238 RescaleFunction( (unsigned int *)buffer, source, slope, intercept, size);
2240 case ImageIOBase::INT:
2241 RescaleFunction( (int *)buffer, source, slope, intercept, size);
2243 case ImageIOBase::FLOAT:
2244 RescaleFunction( (float *)buffer, source, slope, intercept, size);
2246 case ImageIOBase::DOUBLE:
2247 RescaleFunction( (double *)buffer, source, slope, intercept, size);
2250 ::itk::OStringStream message;
2251 message << "itk::ERROR: GDCMImageIO: Unknown component type : " << bufferType;
2252 ::itk::ExceptionObject e(__FILE__, __LINE__, message.str().c_str(),ITK_LOCATION);