1 /*=========================================================================
4 Module: $RCSfile: gdcmFileHelper.cxx,v $
7 Date: $Date: 2005/10/25 12:42:01 $
8 Version: $Revision: 1.73 $
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"
30 #include "gdcmPixelReadConvert.h"
31 #include "gdcmPixelWriteConvert.h"
32 #include "gdcmDocEntryArchive.h"
33 #include "gdcmDictSet.h"
38 // ----------------------------- WARNING -------------------------
40 These lines will be moved to the document-to-be 'User's Guide'
42 // To read an image, user needs a gdcm::File
43 gdcm::File *f = new gdcm::File(fileName);
45 // user may also decide he doesn't want to load some parts of the header
46 gdcm::File *f = new gdcm::File();
47 f->SetFileName(fileName);
48 f->SetLoadMode(LD_NOSEQ); // or
49 f->SetLoadMode(LD_NOSHADOW); // or
50 f->SetLoadMode(LD_NOSEQ | LD_NOSHADOW); // or
51 f->SetLoadMode(LD_NOSHADOWSEQ);
54 // user can now check some values
55 std::string v = f->GetEntryValue(groupNb,ElementNb);
57 // to get the pixels, user needs a gdcm::FileHelper
58 gdcm::FileHelper *fh = new gdcm::FileHelper(f);
59 // user may ask not to convert Palette to RGB
60 uint8_t *pixels = fh->GetImageDataRaw();
61 int imageLength = fh->GetImageDataRawSize();
62 // He can now use the pixels, create a new image, ...
63 uint8_t *userPixels = ...
65 To re-write the image, user re-uses the gdcm::FileHelper
67 fh->SetImageData( userPixels, userPixelsLength);
68 fh->SetTypeToRaw(); // Even if it was possible to convert Palette to RGB
71 fh->SetWriteTypeToDcmExpl(); // he wants Explicit Value Representation
72 // Little Endian is the default
73 // no other value is allowed
74 (-->SetWriteType(ExplicitVR);)
75 -->WriteType = ExplicitVR;
76 fh->Write(newFileName); // overwrites the file, if any
79 fh->WriteDcmExplVR(newFileName);
82 // ----------------------------- WARNING -------------------------
84 These lines will be moved to the document-to-be 'Developer's Guide'
86 WriteMode : WMODE_RAW / WMODE_RGB
87 WriteType : ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO
89 fh1->Write(newFileName);
90 SetWriteFileTypeToImplicitVR() / SetWriteFileTypeToExplicitVR();
91 (modifies TransferSyntax)
92 SetWriteToRaw(); / SetWriteToRGB();
93 (modifies, when necessary : photochromatic interpretation,
94 samples per pixel, Planar configuration,
95 bits allocated, bits stored, high bit -ACR 24 bits-
96 Pixels element VR, pushes out the LUT )
97 CheckWriteIntegrity();
98 (checks user given pixels length)
99 FileInternal->Write(fileName,WriteType)
100 fp = opens file(fileName);
101 ComputeGroup0002Length( );
103 RemoveEntry(palettes, etc)
104 Document::WriteContent(fp, writetype);
106 (moves back to the File all the archived elements)
107 RestoreWriteFileType();
108 (pushes back group 0002, with TransferSyntax)
116 //-------------------------------------------------------------------------
117 // Constructor / Destructor
119 * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
120 * file (gdcm::File only deals with the ... header)
121 * Opens (in read only and when possible) an existing file and checks
122 * for DICOM compliance. Returns NULL on failure.
123 * It will be up to the user to load the pixels into memory
124 * ( GetImageDataSize() + GetImageData() methods)
125 * \note the in-memory representation of all available tags found in
126 * the DICOM header is post-poned to first header information access.
127 * This avoid a double parsing of public part of the header when
128 * one sets an a posteriori shadow dictionary (efficiency can be
129 * seen as a side effect).
131 FileHelper::FileHelper( )
133 FileInternal = new File( );
139 * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
140 * file (File only deals with the ... header)
141 * Opens (in read only and when possible) an existing file and checks
142 * for DICOM compliance. Returns NULL on failure.
143 * It will be up to the user to load the pixels into memory
144 * ( GetImageDataSize() + GetImageData() methods)
145 * \note the in-memory representation of all available tags found in
146 * the DICOM header is post-poned to first header information access.
147 * This avoid a double parsing of public part of the header when
148 * user sets an a posteriori shadow dictionary (efficiency can be
149 * seen as a side effect).
150 * @param header already built Header
152 FileHelper::FileHelper(File *header)
154 FileInternal = header;
157 if ( FileInternal->IsReadable() )
159 PixelReadConverter->GrabInformationsFromFile( FileInternal );
163 #ifndef GDCM_LEGACY_REMOVE
165 * brief DEPRECATED : use SetFilename() + SetLoadMode() + Load() methods
166 * Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
167 * file (gdcm::File only deals with the ... header)
168 * Opens (in read only and when possible) an existing file and checks
169 * for DICOM compliance. Returns NULL on failure.
170 * It will be up to the user to load the pixels into memory
171 * note the in-memory representation of all available tags found in
172 * the DICOM header is post-poned to first header information access.
173 * This avoid a double parsing of public part of the header when
174 * one sets an a posteriori shadow dictionary (efficiency can be
175 * seen as a side effect).
176 * param filename file to be opened for parsing
177 * deprecated use SetFilename() + Load() methods
179 FileHelper::FileHelper(std::string const &filename )
181 FileInternal = new File( );
182 FileInternal->SetFileName( filename );
183 FileInternal->Load();
186 if ( FileInternal->IsReadable() )
188 PixelReadConverter->GrabInformationsFromFile( FileInternal );
194 * \brief canonical destructor
195 * \note If the header (gdcm::File) was created by the FileHelper constructor,
196 * it is destroyed by the FileHelper
198 FileHelper::~FileHelper()
200 if ( PixelReadConverter )
202 delete PixelReadConverter;
204 if ( PixelWriteConverter )
206 delete PixelWriteConverter;
220 //-----------------------------------------------------------------------------
224 * \brief Sets the LoadMode of the internal gdcm::File as a boolean string.
225 * NO_SEQ, NO_SHADOW, NO_SHADOWSEQ ... (nothing more, right now)
226 * WARNING : before using NO_SHADOW, be sure *all* your files
227 * contain accurate values in the 0x0000 element (if any)
228 * of *each* Shadow Group. The parser will fail if the size is wrong !
229 * @param loadMode Load mode to be used
231 void FileHelper::SetLoadMode(int loadMode)
233 GetFile()->SetLoadMode( loadMode );
236 * \brief Sets the LoadMode of the internal gdcm::File
237 * @param fileName name of the file to be open
239 void FileHelper::SetFileName(std::string const &fileName)
241 FileInternal->SetFileName( fileName );
246 * @return false if file cannot be open or no swap info was found,
247 * or no tag was found.
249 bool FileHelper::Load()
251 if ( !FileInternal->Load() )
254 PixelReadConverter->GrabInformationsFromFile( FileInternal );
259 * \brief Accesses an existing DocEntry (i.e. a Dicom Element)
260 * through it's (group, element) and modifies it's content with
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 DocEntry 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 DocEntry (i.e. a Dicom Element)
276 * through it's (group, element) and modifies it's content with
278 * @param content new value (void* -> uint8_t*) to substitute with
279 * @param lgth new value length
280 * @param group group number of the Dicom Element to modify
281 * @param elem element number of the Dicom Element to modify
282 * \return false if DocEntry not found
284 bool FileHelper::SetEntryBinArea(uint8_t *content, int lgth,
285 uint16_t group, uint16_t elem)
287 return FileInternal->SetEntryBinArea(content, lgth, group, elem);
291 * \brief Modifies the value of a given DocEntry (Dicom entry)
292 * when it exists. Creates it with the given value when unexistant.
293 * @param content (string)value to be set
294 * @param group Group number of the Entry
295 * @param elem Element number of the Entry
296 * \return pointer to the modified/created Dicom entry (NULL when creation
299 DataEntry *FileHelper::InsertEntryString(std::string const &content,
300 uint16_t group, uint16_t elem)
302 return FileInternal->InsertEntryString(content, group, elem);
306 * \brief Modifies the value of a given DocEntry (Dicom entry)
307 * when it exists. Creates it with the given value when unexistant.
308 * A copy of the binArea is made to be kept in the Document.
309 * @param binArea (binary)value to be set
310 * @param lgth new value length
311 * @param group Group number of the Entry
312 * @param elem Element number of the Entry
313 * \return pointer to the modified/created Dicom entry (NULL when creation
316 DataEntry *FileHelper::InsertEntryBinArea(uint8_t *binArea, int lgth,
317 uint16_t group, uint16_t elem)
319 return FileInternal->InsertEntryBinArea(binArea, lgth, group, elem);
323 * \brief Modifies the value of a given DocEntry (Dicom entry)
324 * when it exists. Creates it, empty (?!) when unexistant.
325 * @param group Group number of the Entry
326 * @param elem Element number of the Entry
327 * \return pointer to the modified/created Dicom entry (NULL when creation
330 SeqEntry *FileHelper::InsertSeqEntry(uint16_t group, uint16_t elem)
332 return FileInternal->InsertSeqEntry(group, elem);
336 * \brief Get the size of the image data
337 * If the image can be RGB (with a lut or by default), the size
338 * corresponds to the RGB image
339 * (use GetImageDataRawSize if you want to be sure to get *only*
340 * the size of the pixels)
341 * @return The image size
343 size_t FileHelper::GetImageDataSize()
345 if ( PixelWriteConverter->GetUserData() )
347 return PixelWriteConverter->GetUserDataSize();
349 return PixelReadConverter->GetRGBSize();
353 * \brief Get the size of the image data.
354 * If the image could be converted to RGB using a LUT,
355 * this transformation is not taken into account by GetImageDataRawSize
356 * (use GetImageDataSize if you wish)
357 * @return The raw image size
359 size_t FileHelper::GetImageDataRawSize()
361 if ( PixelWriteConverter->GetUserData() )
363 return PixelWriteConverter->GetUserDataSize();
365 return PixelReadConverter->GetRawSize();
369 * \brief brings pixels into memory :
370 * - Allocates necessary memory,
371 * - Reads the pixels from disk (uncompress if necessary),
372 * - Transforms YBR pixels, if any, into RGB pixels,
373 * - Transforms 3 planes R, G, B, if any, into a single RGB Plane
374 * - Transforms single Grey plane + 3 Palettes into a RGB Plane
375 * - Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
376 * @return Pointer to newly allocated pixel data.
377 * (uint8_t is just for prototyping. feel free to cast)
378 * NULL if alloc fails
380 uint8_t *FileHelper::GetImageData()
382 if ( PixelWriteConverter->GetUserData() )
384 return PixelWriteConverter->GetUserData();
389 // If the decompression failed nothing can be done.
393 if ( FileInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
395 return PixelReadConverter->GetRGB();
399 // When no LUT or LUT conversion fails, return the Raw
400 return PixelReadConverter->GetRaw();
405 * \brief brings pixels into memory :
406 * - Allocates necessary memory,
407 * - Transforms YBR pixels (if any) into RGB pixels
408 * - Transforms 3 planes R, G, B (if any) into a single RGB Plane
409 * - Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
410 * - DOES NOT transform Grey plane + 3 Palettes into a RGB Plane
411 * @return Pointer to newly allocated pixel data.
412 * (uint8_t is just for prototyping. feel free to cast)
413 * NULL if alloc fails
415 uint8_t *FileHelper::GetImageDataRaw ()
420 #ifndef GDCM_LEGACY_REMOVE
422 * \ brief Useless function, since PixelReadConverter forces us
423 * copy the Pixels anyway.
424 * Reads the pixels from disk (uncompress if necessary),
425 * Transforms YBR pixels, if any, into RGB pixels
426 * Transforms 3 planes R, G, B, if any, into a single RGB Plane
427 * Transforms single Grey plane + 3 Palettes into a RGB Plane
428 * Copies at most MaxSize bytes of pixel data to caller allocated
430 * \ warning This function allows people that want to build a volume
431 * from an image stack *not to* have, first to get the image pixels,
432 * and then move them to the volume area.
433 * It's absolutely useless for any VTK user since vtk chooses
434 * to invert the lines of an image, that is the last line comes first
435 * (for some axis related reasons?). Hence he will have
436 * to load the image line by line, starting from the end.
437 * VTK users have to call GetImageData
439 * @ param destination Address (in caller's memory space) at which the
440 * pixel data should be copied
441 * @ param maxSize Maximum number of bytes to be copied. When MaxSize
442 * is not sufficient to hold the pixel data the copy is not
443 * executed (i.e. no partial copy).
444 * @ return On success, the number of bytes actually copied. Zero on
445 * failure e.g. MaxSize is lower than necessary.
447 size_t FileHelper::GetImageDataIntoVector (void *destination, size_t maxSize)
451 // If the decompression failed nothing can be done.
455 if ( FileInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
457 if ( PixelReadConverter->GetRGBSize() > maxSize )
459 gdcmWarningMacro( "Pixel data bigger than caller's expected MaxSize");
463 (void*)PixelReadConverter->GetRGB(),
464 PixelReadConverter->GetRGBSize() );
465 return PixelReadConverter->GetRGBSize();
468 // Either no LUT conversion necessary or LUT conversion failed
469 if ( PixelReadConverter->GetRawSize() > maxSize )
471 gdcmWarningMacro( "Pixel data bigger than caller's expected MaxSize");
475 (void *)PixelReadConverter->GetRaw(),
476 PixelReadConverter->GetRawSize() );
477 return PixelReadConverter->GetRawSize();
482 * \brief Points the internal pointer to the callers inData
483 * image representation, BUT WITHOUT COPYING THE DATA.
484 * 'image' Pixels are presented as C-like 2D arrays : line per line.
485 * 'volume'Pixels are presented as C-like 3D arrays : plane per plane
486 * \warning Since the pixels are not copied, it is the caller's responsability
487 * not to deallocate its data before gdcm uses them (e.g. with
488 * the Write() method )
489 * @param inData user supplied pixel area (uint8_t* is just for the compiler.
490 * user is allowed to pass any kind of pixelsn since the size is
492 * @param expectedSize total image size, *in Bytes*
494 void FileHelper::SetImageData(uint8_t *inData, size_t expectedSize)
496 SetUserData(inData, expectedSize);
500 * \brief Set the image data defined by the user
501 * \warning When writting the file, this data are get as default data to write
502 * @param inData user supplied pixel area (uint8_t* is just for the compiler.
503 * user is allowed to pass any kind of pixels since the size is
505 * @param expectedSize total image size, *in Bytes*
507 void FileHelper::SetUserData(uint8_t *inData, size_t expectedSize)
509 PixelWriteConverter->SetUserData(inData, expectedSize);
513 * \brief Get the image data defined by the user
514 * \warning When writting the file, this data are get as default data to write
516 uint8_t *FileHelper::GetUserData()
518 return PixelWriteConverter->GetUserData();
522 * \brief Get the image data size defined by the user
523 * \warning When writting the file, this data are get as default data to write
525 size_t FileHelper::GetUserDataSize()
527 return PixelWriteConverter->GetUserDataSize();
531 * \brief Get the image data from the file.
532 * If a LUT is found, the data are expanded to be RGB
534 uint8_t *FileHelper::GetRGBData()
536 return PixelReadConverter->GetRGB();
540 * \brief Get the image data size from the file.
541 * If a LUT is found, the data are expanded to be RGB
543 size_t FileHelper::GetRGBDataSize()
545 return PixelReadConverter->GetRGBSize();
549 * \brief Get the image data from the file.
550 * Even when a LUT is found, the data are not expanded to RGB!
552 uint8_t *FileHelper::GetRawData()
554 return PixelReadConverter->GetRaw();
558 * \brief Get the image data size from the file.
559 * Even when a LUT is found, the data are not expanded to RGB!
561 size_t FileHelper::GetRawDataSize()
563 return PixelReadConverter->GetRawSize();
567 * \brief Access to the underlying \ref PixelReadConverter RGBA LUT
569 uint8_t* FileHelper::GetLutRGBA()
571 if ( PixelReadConverter->GetLutRGBA() ==0 )
572 PixelReadConverter->BuildLUTRGBA();
573 return PixelReadConverter->GetLutRGBA();
577 * \brief Access to the underlying \ref PixelReadConverter RGBA LUT Item Number
579 int FileHelper::GetLutItemNumber()
581 return PixelReadConverter->GetLutItemNumber();
585 * \brief Access to the underlying \ref PixelReadConverter RGBA LUT Item Size
587 int FileHelper::GetLutItemSize()
589 return PixelReadConverter->GetLutItemSize();
593 * \brief Writes on disk A SINGLE Dicom file
594 * NO test is performed on processor "Endiannity".
595 * It's up to the user to call his Reader properly
596 * @param fileName name of the file to be created
597 * (any already existing file is over written)
598 * @return false if write fails
600 bool FileHelper::WriteRawData(std::string const &fileName)
602 std::ofstream fp1(fileName.c_str(), std::ios::out | std::ios::binary );
605 gdcmWarningMacro( "Fail to open (write) file:" << fileName.c_str());
609 if ( PixelWriteConverter->GetUserData() )
611 fp1.write( (char *)PixelWriteConverter->GetUserData(),
612 PixelWriteConverter->GetUserDataSize() );
614 else if ( PixelReadConverter->GetRGB() )
616 fp1.write( (char *)PixelReadConverter->GetRGB(),
617 PixelReadConverter->GetRGBSize());
619 else if ( PixelReadConverter->GetRaw() )
621 fp1.write( (char *)PixelReadConverter->GetRaw(),
622 PixelReadConverter->GetRawSize());
626 gdcmErrorMacro( "Nothing written." );
635 * \brief Writes on disk A SINGLE Dicom file,
636 * using the Implicit Value Representation convention
637 * NO test is performed on processor "Endianity".
638 * @param fileName name of the file to be created
639 * (any already existing file is overwritten)
640 * @return false if write fails
643 bool FileHelper::WriteDcmImplVR (std::string const &fileName)
645 SetWriteTypeToDcmImplVR();
646 return Write(fileName);
650 * \brief Writes on disk A SINGLE Dicom file,
651 * using the Explicit Value Representation convention
652 * NO test is performed on processor "Endiannity".
653 * @param fileName name of the file to be created
654 * (any already existing file is overwritten)
655 * @return false if write fails
658 bool FileHelper::WriteDcmExplVR (std::string const &fileName)
660 SetWriteTypeToDcmExplVR();
661 return Write(fileName);
665 * \brief Writes on disk A SINGLE Dicom file,
666 * using the ACR-NEMA convention
667 * NO test is performed on processor "Endiannity".
668 * (a l'attention des logiciels cliniques
669 * qui ne prennent en entrée QUE des images ACR ...
670 * \warning if a DICOM_V3 header is supplied,
671 * groups < 0x0008 and shadow groups are ignored
672 * \warning NO TEST is performed on processor "Endiannity".
673 * @param fileName name of the file to be created
674 * (any already existing file is overwritten)
675 * @return false if write fails
678 bool FileHelper::WriteAcr (std::string const &fileName)
681 return Write(fileName);
685 * \brief Writes on disk A SINGLE Dicom file,
686 * @param fileName name of the file to be created
687 * (any already existing file is overwritten)
688 * @return false if write fails
690 bool FileHelper::Write(std::string const &fileName)
695 SetWriteFileTypeToImplicitVR();
697 case Unknown: // should never happen; ExplicitVR is the default value
699 SetWriteFileTypeToExplicitVR();
703 // NOTHING is done here just for LibIDO.
704 // Just to avoid further trouble if user creates a file ex-nihilo,
705 // wants to write it as an ACR-NEMA file,
706 // and forgets to create any Entry belonging to group 0008
708 // We add Recognition Code (RET)
709 if ( ! FileInternal->GetDataEntry(0x0008, 0x0010) )
710 FileInternal->InsertEntryString("ACR-NEMA V1.0 ", 0x0008, 0x0010);
711 SetWriteFileTypeToACR();
712 // SetWriteFileTypeToImplicitVR(); // ACR IS implicit VR !
715 SetWriteFileTypeToJPEG();
716 std::cerr << "Writting as JPEG" << std::endl;
719 CheckMandatoryElements();
721 // --------------------------------------------------------------
722 // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
724 // if recognition code tells us we dealt with a LibIDO image
725 // we reproduce on disk the switch between lineNumber and columnNumber
726 // just before writting ...
727 /// \todo the best trick would be *change* the recognition code
728 /// but pb expected if user deals with, e.g. COMPLEX images
730 if ( WriteType == ACR_LIBIDO )
736 SetWriteToNoLibido();
738 // ----------------- End of Special Patch ----------------
743 SetWriteToRaw(); // modifies and pushes to the archive, when necessary
746 SetWriteToRGB(); // modifies and pushes to the archive, when necessary
750 bool check = CheckWriteIntegrity(); // verifies length
751 if (WriteType == JPEG ) check = true;
754 check = FileInternal->Write(fileName,WriteType);
758 RestoreWriteFileType();
759 RestoreWriteMandatory();
761 // --------------------------------------------------------------
762 // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
764 // ...and we restore the header to be Dicom Compliant again
765 // just after writting
766 RestoreWriteOfLibido();
767 // ----------------- End of Special Patch ----------------
772 //-----------------------------------------------------------------------------
775 * \brief Checks the write integrity
777 * The tests made are :
778 * - verify the size of the image to write with the possible write
779 * when the user set an image data
780 * @return true if check is successfull
782 bool FileHelper::CheckWriteIntegrity()
784 if ( PixelWriteConverter->GetUserData() )
786 int numberBitsAllocated = FileInternal->GetBitsAllocated();
787 if ( numberBitsAllocated == 0 || numberBitsAllocated == 12 )
789 gdcmWarningMacro( "numberBitsAllocated changed from "
790 << numberBitsAllocated << " to 16 "
791 << " for consistency purpose" );
792 numberBitsAllocated = 16;
795 size_t decSize = FileInternal->GetXSize()
796 * FileInternal->GetYSize()
797 * FileInternal->GetZSize()
798 * FileInternal->GetSamplesPerPixel()
799 * ( numberBitsAllocated / 8 );
800 size_t rgbSize = decSize;
801 if ( FileInternal->HasLUT() )
802 rgbSize = decSize * 3;
807 if ( decSize!=PixelWriteConverter->GetUserDataSize() )
809 gdcmWarningMacro( "Data size (Raw) is incorrect. Should be "
810 << decSize << " / Found :"
811 << PixelWriteConverter->GetUserDataSize() );
816 if ( rgbSize!=PixelWriteConverter->GetUserDataSize() )
818 gdcmWarningMacro( "Data size (RGB) is incorrect. Should be "
819 << decSize << " / Found "
820 << PixelWriteConverter->GetUserDataSize() );
831 * \brief Updates the File to write RAW data (as opposed to RGB data)
832 * (modifies, when necessary, photochromatic interpretation,
833 * bits allocated, Pixels element VR)
835 void FileHelper::SetWriteToRaw()
837 if ( FileInternal->GetNumberOfScalarComponents() == 3
838 && !FileInternal->HasLUT() )
844 DataEntry *photInt = CopyDataEntry(0x0028,0x0004);
845 if (FileInternal->HasLUT() )
847 photInt->SetString("PALETTE COLOR ");
851 photInt->SetString("MONOCHROME2 ");
854 PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(),
855 PixelReadConverter->GetRawSize());
857 std::string vr = "OB";
858 if ( FileInternal->GetBitsAllocated()>8 )
860 if ( FileInternal->GetBitsAllocated()==24 ) // For RGB ACR files
863 CopyDataEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel(),vr);
864 pixel->SetFlag(DataEntry::FLAG_PIXELDATA);
865 pixel->SetBinArea(PixelWriteConverter->GetData(),false);
866 pixel->SetLength(PixelWriteConverter->GetDataSize());
868 Archive->Push(photInt);
869 Archive->Push(pixel);
877 * \brief Updates the File to write RGB data (as opposed to RAW data)
878 * (modifies, when necessary, photochromatic interpretation,
879 * samples per pixel, Planar configuration,
880 * bits allocated, bits stored, high bit -ACR 24 bits-
881 * Pixels element VR, pushes out the LUT, )
883 void FileHelper::SetWriteToRGB()
885 if ( FileInternal->GetNumberOfScalarComponents()==3 )
887 PixelReadConverter->BuildRGBImage();
889 DataEntry *spp = CopyDataEntry(0x0028,0x0002);
890 spp->SetString("3 ");
892 DataEntry *planConfig = CopyDataEntry(0x0028,0x0006);
893 planConfig->SetString("0 ");
895 DataEntry *photInt = CopyDataEntry(0x0028,0x0004);
896 photInt->SetString("RGB ");
898 if ( PixelReadConverter->GetRGB() )
900 PixelWriteConverter->SetReadData(PixelReadConverter->GetRGB(),
901 PixelReadConverter->GetRGBSize());
905 PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(),
906 PixelReadConverter->GetRawSize());
909 std::string vr = "OB";
910 if ( FileInternal->GetBitsAllocated()>8 )
912 if ( FileInternal->GetBitsAllocated()==24 ) // For RGB ACR files
915 CopyDataEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel(),vr);
916 pixel->SetFlag(DataEntry::FLAG_PIXELDATA);
917 pixel->SetBinArea(PixelWriteConverter->GetData(),false);
918 pixel->SetLength(PixelWriteConverter->GetDataSize());
921 Archive->Push(planConfig);
922 Archive->Push(photInt);
923 Archive->Push(pixel);
926 planConfig->Delete();
931 Archive->Push(0x0028,0x1101);
932 Archive->Push(0x0028,0x1102);
933 Archive->Push(0x0028,0x1103);
934 Archive->Push(0x0028,0x1201);
935 Archive->Push(0x0028,0x1202);
936 Archive->Push(0x0028,0x1203);
938 // push out Palette Color Lookup Table UID, if any
939 Archive->Push(0x0028,0x1199);
941 // For old '24 Bits' ACR-NEMA
942 // Thus, we have a RGB image and the bits allocated = 24 and
943 // samples per pixels = 1 (in the read file)
944 if ( FileInternal->GetBitsAllocated()==24 )
946 DataEntry *bitsAlloc = CopyDataEntry(0x0028,0x0100);
947 bitsAlloc->SetString("8 ");
949 DataEntry *bitsStored = CopyDataEntry(0x0028,0x0101);
950 bitsStored->SetString("8 ");
952 DataEntry *highBit = CopyDataEntry(0x0028,0x0102);
953 highBit->SetString("7 ");
955 Archive->Push(bitsAlloc);
956 Archive->Push(bitsStored);
957 Archive->Push(highBit);
960 bitsStored->Delete();
971 * \brief Restore the File write mode
973 void FileHelper::RestoreWrite()
975 Archive->Restore(0x0028,0x0002);
976 Archive->Restore(0x0028,0x0004);
977 Archive->Restore(0x0028,0x0006);
978 Archive->Restore(GetFile()->GetGrPixel(),GetFile()->GetNumPixel());
980 // For old ACR-NEMA (24 bits problem)
981 Archive->Restore(0x0028,0x0100);
982 Archive->Restore(0x0028,0x0101);
983 Archive->Restore(0x0028,0x0102);
986 Archive->Restore(0x0028,0x1101);
987 Archive->Restore(0x0028,0x1102);
988 Archive->Restore(0x0028,0x1103);
989 Archive->Restore(0x0028,0x1201);
990 Archive->Restore(0x0028,0x1202);
991 Archive->Restore(0x0028,0x1203);
993 // For the Palette Color Lookup Table UID
994 Archive->Restore(0x0028,0x1203);
997 // group 0002 may be pushed out for ACR-NEMA writting purposes
998 Archive->Restore(0x0002,0x0000);
999 Archive->Restore(0x0002,0x0001);
1000 Archive->Restore(0x0002,0x0002);
1001 Archive->Restore(0x0002,0x0003);
1002 Archive->Restore(0x0002,0x0010);
1003 Archive->Restore(0x0002,0x0012);
1004 Archive->Restore(0x0002,0x0013);
1005 Archive->Restore(0x0002,0x0016);
1006 Archive->Restore(0x0002,0x0100);
1007 Archive->Restore(0x0002,0x0102);
1011 * \brief Pushes out the whole group 0002
1012 * FIXME : better, set a flag to tell the writer not to write it ...
1013 * FIXME : method should probably have an other name !
1014 * SetWriteFileTypeToACR is NOT opposed to
1015 * SetWriteFileTypeToExplicitVR and SetWriteFileTypeToImplicitVR
1017 void FileHelper::SetWriteFileTypeToACR()
1019 Archive->Push(0x0002,0x0000);
1020 Archive->Push(0x0002,0x0001);
1021 Archive->Push(0x0002,0x0002);
1022 Archive->Push(0x0002,0x0003);
1023 Archive->Push(0x0002,0x0010);
1024 Archive->Push(0x0002,0x0012);
1025 Archive->Push(0x0002,0x0013);
1026 Archive->Push(0x0002,0x0016);
1027 Archive->Push(0x0002,0x0100);
1028 Archive->Push(0x0002,0x0102);
1032 * \brief Sets in the File the TransferSyntax to 'Explicit VR Little Endian"
1034 void FileHelper::SetWriteFileTypeToJPEG()
1036 std::string ts = Util::DicomString(
1037 Global::GetTS()->GetSpecialTransferSyntax(TS::JPEGBaselineProcess1) );
1039 DataEntry *tss = CopyDataEntry(0x0002,0x0010);
1046 void FileHelper::SetWriteFileTypeToExplicitVR()
1048 std::string ts = Util::DicomString(
1049 Global::GetTS()->GetSpecialTransferSyntax(TS::ExplicitVRLittleEndian) );
1051 DataEntry *tss = CopyDataEntry(0x0002,0x0010);
1059 * \brief Sets in the File the TransferSyntax to 'Implicit VR Little Endian"
1061 void FileHelper::SetWriteFileTypeToImplicitVR()
1063 std::string ts = Util::DicomString(
1064 Global::GetTS()->GetSpecialTransferSyntax(TS::ImplicitVRLittleEndian) );
1066 DataEntry *tss = CopyDataEntry(0x0002,0x0010);
1075 * \brief Restore in the File the initial group 0002
1077 void FileHelper::RestoreWriteFileType()
1082 * \brief Set the Write not to Libido format
1084 void FileHelper::SetWriteToLibido()
1086 DataEntry *oldRow = FileInternal->GetDataEntry(0x0028, 0x0010);
1087 DataEntry *oldCol = FileInternal->GetDataEntry(0x0028, 0x0011);
1089 if ( oldRow && oldCol )
1091 std::string rows, columns;
1093 DataEntry *newRow=DataEntry::New(oldRow->GetDictEntry());
1094 DataEntry *newCol=DataEntry::New(oldCol->GetDictEntry());
1096 newRow->Copy(oldCol);
1097 newCol->Copy(oldRow);
1099 newRow->SetString(oldCol->GetString());
1100 newCol->SetString(oldRow->GetString());
1102 Archive->Push(newRow);
1103 Archive->Push(newCol);
1109 DataEntry *libidoCode = CopyDataEntry(0x0008,0x0010);
1110 libidoCode->SetString("ACRNEMA_LIBIDO_1.1");
1111 Archive->Push(libidoCode);
1112 libidoCode->Delete();
1116 * \brief Set the Write not to No Libido format
1118 void FileHelper::SetWriteToNoLibido()
1120 DataEntry *recCode = FileInternal->GetDataEntry(0x0008,0x0010);
1123 if ( recCode->GetString() == "ACRNEMA_LIBIDO_1.1" )
1125 DataEntry *libidoCode = CopyDataEntry(0x0008,0x0010);
1126 libidoCode->SetString("");
1127 Archive->Push(libidoCode);
1128 libidoCode->Delete();
1134 * \brief Restore the Write format
1136 void FileHelper::RestoreWriteOfLibido()
1138 Archive->Restore(0x0028,0x0010);
1139 Archive->Restore(0x0028,0x0011);
1140 Archive->Restore(0x0008,0x0010);
1142 // Restore 'LibIDO-special' entries, if any
1143 Archive->Restore(0x0028,0x0015);
1144 Archive->Restore(0x0028,0x0016);
1145 Archive->Restore(0x0028,0x0017);
1146 Archive->Restore(0x0028,0x00199);
1150 * \brief Duplicates a DataEntry or creates it.
1151 * @param group Group number of the Entry
1152 * @param elem Element number of the Entry
1153 * @param vr Value Representation of the Entry
1154 * FIXME : what is it used for?
1155 * \return pointer to the new Bin Entry (NULL when creation failed).
1157 DataEntry *FileHelper::CopyDataEntry(uint16_t group, uint16_t elem,
1160 DocEntry *oldE = FileInternal->GetDocEntry(group, elem);
1163 if ( oldE && vr != GDCM_VRUNKNOWN )
1164 if ( oldE->GetVR() != vr )
1169 newE = DataEntry::New(oldE->GetDictEntry());
1174 newE = GetFile()->NewDataEntry(group, elem, vr);
1181 * \brief This method is called automatically, just before writting
1182 * in order to produce a 'True Dicom V3' image
1183 * We cannot know *how* the user made the File (reading an old ACR-NEMA
1184 * file or a not very clean DICOM file ...)
1186 * Just before writting :
1187 * - we check the Entries
1188 * - we create the mandatory entries if they are missing
1189 * - we modify the values if necessary
1190 * - we push the sensitive entries to the Archive
1191 * The writing process will restore the entries as they where before
1192 * entering FileHelper::CheckMandatoryElements, so the user will always
1193 * see the entries just as he left them.
1195 * - Entries whose type is 1 are mandatory, with a mandatory value
1196 * - Entries whose type is 1c are mandatory-inside-a-Sequence,
1197 * with a mandatory value
1198 * - Entries whose type is 2 are mandatory, with an optional value
1199 * - Entries whose type is 2c are mandatory-inside-a-Sequence,
1200 * with an optional value
1201 * - Entries whose type is 3 are optional
1203 * \todo : - warn the user if we had to add some entries :
1204 * even if a mandatory entry is missing, we add it, with a default value
1205 * (we don't want to give up the writting process if user forgot to
1206 * specify Lena's Patient ID, for instance ...)
1207 * - read the whole PS 3.3 Part of DICOM (890 pages)
1208 * and write a *full* checker (probably one method per Modality ...)
1209 * Any contribution is welcome.
1210 * - write a user callable full checker, to allow post reading
1211 * and/or pre writting image consistency check.
1214 /* -------------------------------------------------------------------------------------
1215 To be moved to User's guide / WIKI ?
1218 -->'Media Storage SOP Class UID' (0x0002,0x0002)
1219 -->'SOP Class UID' (0x0008,0x0016) are set to
1220 [Secondary Capture Image Storage]
1221 (Potentialy, the image was modified by user, and post-processed;
1222 it's no longer a 'native' image)
1224 --> 'Image Type' (0x0008,0x0008)
1225 is forced to "DERIVED\PRIMARY"
1226 (The written image is no longer an 'ORIGINAL' one)
1228 --> 'Modality' (0x0008,0x0060)
1229 is defaulted to "OT" (other) if missing.
1230 (a fully user created image belongs to *no* modality)
1232 --> 'Media Storage SOP Instance UID' (0x0002,0x0003)
1233 --> 'Implementation Class UID' (0x0002,0x0012)
1234 are automatically generated; no user intervention possible
1236 --> 'Serie Instance UID'(0x0020,0x000e)
1237 --> 'Study Instance UID'(0x0020,0x000d) are kept as is if already exist
1238 created if it doesn't.
1239 The user is allowed to create his own Series/Studies,
1240 keeping the same 'Serie Instance UID' / 'Study Instance UID'
1243 The user shouldn't add any image to a 'Manufacturer Serie'
1244 but there is no way no to allowed him to do that
1247 --> If 'SOP Class UID' exists in the native image ('true DICOM' image)
1248 we create the 'Source Image Sequence' SeqEntry (0x0008, 0x2112)
1250 --> 'Referenced SOP Class UID' (0x0008, 0x1150)
1251 whose value is the original 'SOP Class UID'
1252 ---> 'Referenced SOP Instance UID' (0x0008, 0x1155)
1253 whose value is the original 'SOP Class UID'
1255 --> Bits Stored, Bits Allocated, Hight Bit Position are checked for consistency
1256 --> Pixel Spacing (0x0028,0x0030) is defaulted to "1.0\1.0"
1257 --> Samples Per Pixel (0x0028,0x0002) is defaulted to 1 (grayscale)
1259 --> Instance Creation Date, Instance Creation Time, Study Date, Study Time
1260 are force to current Date and Time
1262 --> Conversion Type (0x0008,0x0064)
1265 --> Study ID, Series Number, Instance Number, Patient Orientation (Type 2)
1266 are created, with empty value if there are missing.
1268 --> Manufacturer, Institution Name, Patient's Name, (Type 2)
1269 are defaulted with a 'gdcm' value.
1271 --> Patient ID, Patient's Birth Date, Patient's Sex, (Type 2)
1272 --> Referring Physician's Name (Type 2)
1273 are created, with empty value if there are missing.
1275 -------------------------------------------------------------------------------------*/
1277 void FileHelper::CheckMandatoryElements()
1279 std::string sop = Util::CreateUniqueUID();
1281 // just to remember : 'official' 0002 group
1282 if ( WriteType != ACR && WriteType != ACR_LIBIDO )
1284 // Group 000002 (Meta Elements) already pushed out
1286 //0002 0000 UL 1 Meta Group Length
1287 //0002 0001 OB 1 File Meta Information Version
1288 //0002 0002 UI 1 Media Stored SOP Class UID
1289 //0002 0003 UI 1 Media Stored SOP Instance UID
1290 //0002 0010 UI 1 Transfer Syntax UID
1291 //0002 0012 UI 1 Implementation Class UID
1292 //0002 0013 SH 1 Implementation Version Name
1293 //0002 0016 AE 1 Source Application Entity Title
1294 //0002 0100 UI 1 Private Information Creator
1295 //0002 0102 OB 1 Private Information
1297 // Create them if not found
1298 // Always modify the value
1299 // Push the entries to the archive.
1300 CopyMandatoryEntry(0x0002,0x0000,"0");
1302 DataEntry *e_0002_0001 = CopyDataEntry(0x0002,0x0001, "OB");
1303 e_0002_0001->SetBinArea((uint8_t*)Util::GetFileMetaInformationVersion(),
1305 e_0002_0001->SetLength(2);
1306 Archive->Push(e_0002_0001);
1307 e_0002_0001->Delete();
1309 // Potentialy post-processed image --> [Secondary Capture Image Storage]
1310 // 'Media Storage SOP Class UID'
1311 CopyMandatoryEntry(0x0002,0x0002,"1.2.840.10008.5.1.4.1.1.7");
1313 // 'Media Storage SOP Instance UID'
1314 CopyMandatoryEntry(0x0002,0x0003,sop);
1316 // 'Implementation Class UID'
1317 CopyMandatoryEntry(0x0002,0x0012,Util::CreateUniqueUID());
1319 // 'Implementation Version Name'
1320 std::string version = "GDCM ";
1321 version += Util::GetVersion();
1322 CopyMandatoryEntry(0x0002,0x0013,version);
1325 // Push out 'LibIDO-special' entries, if any
1326 Archive->Push(0x0028,0x0015);
1327 Archive->Push(0x0028,0x0016);
1328 Archive->Push(0x0028,0x0017);
1329 Archive->Push(0x0028,0x00199);
1331 // Deal with the pb of (Bits Stored = 12)
1332 // - we're gonna write the image as Bits Stored = 16
1333 if ( FileInternal->GetEntryString(0x0028,0x0100) == "12")
1335 CopyMandatoryEntry(0x0028,0x0100,"16");
1338 // Check if user wasn't drunk ;-)
1340 std::ostringstream s;
1341 // check 'Bits Allocated' vs decent values
1342 int nbBitsAllocated = FileInternal->GetBitsAllocated();
1343 if ( nbBitsAllocated == 0 || nbBitsAllocated > 32)
1345 CopyMandatoryEntry(0x0028,0x0100,"16");
1346 gdcmWarningMacro("(0028,0100) changed from "
1347 << nbBitsAllocated << " to 16 for consistency purpose");
1348 nbBitsAllocated = 16;
1350 // check 'Bits Stored' vs 'Bits Allocated'
1351 int nbBitsStored = FileInternal->GetBitsStored();
1352 if ( nbBitsStored == 0 || nbBitsStored > nbBitsAllocated )
1355 s << nbBitsAllocated;
1356 CopyMandatoryEntry(0x0028,0x0101,s.str());
1357 gdcmWarningMacro("(0028,0101) changed from "
1358 << nbBitsStored << " to " << nbBitsAllocated
1359 << " for consistency purpose" );
1360 nbBitsStored = nbBitsAllocated;
1362 // check 'Hight Bit Position' vs 'Bits Allocated' and 'Bits Stored'
1363 int highBitPosition = FileInternal->GetHighBitPosition();
1364 if ( highBitPosition == 0 ||
1365 highBitPosition > nbBitsAllocated-1 ||
1366 highBitPosition < nbBitsStored-1 )
1369 s << nbBitsStored - 1;
1370 CopyMandatoryEntry(0x0028,0x0102,s.str());
1371 gdcmWarningMacro("(0028,0102) changed from "
1372 << highBitPosition << " to " << nbBitsAllocated-1
1373 << " for consistency purpose");
1376 // Pixel Spacing : defaulted to 1.0\1.0
1377 CheckMandatoryEntry(0x0028,0x0030,"1.0\\1.0");
1379 // Samples Per Pixel (type 1) : default to grayscale
1380 CheckMandatoryEntry(0x0028,0x0002,"1");
1383 // --- Check UID-related Entries ---
1385 // If 'SOP Class UID' exists ('true DICOM' image)
1386 // we create the 'Source Image Sequence' SeqEntry
1387 // to hold informations about the Source Image
1389 DataEntry *e_0008_0016 = FileInternal->GetDataEntry(0x0008, 0x0016);
1392 // Create 'Source Image Sequence' SeqEntry
1393 SeqEntry *sis = SeqEntry::New (
1394 Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x2112) );
1395 SQItem *sqi = new SQItem(1);
1396 // (we assume 'SOP Instance UID' exists too)
1397 // create 'Referenced SOP Class UID'
1398 DataEntry *e_0008_1150 = DataEntry::New(
1399 Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x1150) );
1400 e_0008_1150->SetString( e_0008_0016->GetString());
1401 sqi->AddEntry(e_0008_1150);
1403 // create 'Referenced SOP Instance UID'
1404 DataEntry *e_0008_0018 = FileInternal->GetDataEntry(0x0008, 0x0018);
1405 DataEntry *e_0008_1155 = DataEntry::New(
1406 Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x1155) );
1407 e_0008_1155->SetString( e_0008_0018->GetString());
1408 sqi->AddEntry(e_0008_1155);
1410 sis->AddSQItem(sqi,1);
1411 // temporarily replaces any previous 'Source Image Sequence'
1415 // FIXME : is 'Image Type' *really* depending on the presence of'SOP Class UID'?
1417 // 'Image Type' (The written image is no longer an 'ORIGINAL' one)
1418 CopyMandatoryEntry(0x0008,0x0008,"DERIVED\\PRIMARY");
1421 // At the end, not to overwrite the original ones,
1422 // needed by 'Referenced SOP Instance UID', 'Referenced SOP Class UID'
1423 // 'SOP Instance UID'
1424 CopyMandatoryEntry(0x0008,0x0018,sop);
1426 // whether a 'SOP Class UID' already exists or not in the original image
1427 // the gdcm written image *is* a [Secondary Capture Image Storage] !
1428 // 'SOP Class UID' : [Secondary Capture Image Storage]
1429 CopyMandatoryEntry(0x0008,0x0016,"1.2.840.10008.5.1.4.1.1.7");
1431 // ---- The user will never have to take any action on the following ----.
1432 // new value for 'SOP Instance UID'
1433 //SetMandatoryEntry(0x0008,0x0018,Util::CreateUniqueUID());
1435 // Instance Creation Date
1436 const std::string &date = Util::GetCurrentDate();
1437 CopyMandatoryEntry(0x0008,0x0012,date);
1439 // Instance Creation Time
1440 const std::string &time = Util::GetCurrentTime();
1441 CopyMandatoryEntry(0x0008,0x0013,time);
1444 CopyMandatoryEntry(0x0008,0x0020,date);
1446 CopyMandatoryEntry(0x0008,0x0030,time);
1449 CopyMandatoryEntry(0x0008,0x0050,"");
1451 // Conversion Type ... FIXME (type 1)
1452 // See PS 3.3, Page 408
1453 CopyMandatoryEntry(0x0008,0x0064,"SYN");
1455 // ----- Add Mandatory Entries if missing ---
1456 // Entries whose type is 1 are mandatory, with a mandatory value
1457 // Entries whose type is 1c are mandatory-inside-a-Sequence,
1458 // with a mandatory value
1459 // Entries whose type is 2 are mandatory, with an optional value
1460 // Entries whose type is 2c are mandatory-inside-a-Sequence,
1461 // with an optional value
1462 // Entries whose type is 3 are optional
1464 // 'Study Instance UID'
1465 // Keep the value if exists
1466 // The user is allowed to create his own Study,
1467 // keeping the same 'Study Instance UID' for various images
1468 // The user may add images to a 'Manufacturer Study',
1469 // adding new series to an already existing Study
1470 CheckMandatoryEntry(0x0020,0x000d,Util::CreateUniqueUID());
1472 // 'Serie Instance UID'
1473 // Keep the value if exists
1474 // The user is allowed to create his own Series,
1475 // keeping the same 'Serie Instance UID' for various images
1476 // The user shouldn't add any image to a 'Manufacturer Serie'
1477 // but there is no way no to allowed him to do that
1478 CheckMandatoryEntry(0x0020,0x000e,Util::CreateUniqueUID());
1481 CheckMandatoryEntry(0x0020,0x0010,"");
1484 CheckMandatoryEntry(0x0020,0x0011,"");
1487 CheckMandatoryEntry(0x0020,0x0013,"");
1489 // Patient Orientation FIXME 1\0\0\0\1\0 or empty ?
1490 CheckMandatoryEntry(0x0020,0x0020,"");
1492 // Modality : if missing we set it to 'OTher'
1493 CheckMandatoryEntry(0x0008,0x0060,"OT");
1495 // Manufacturer : if missing we set it to 'GDCM Factory'
1496 CheckMandatoryEntry(0x0008,0x0070,"GDCM Factory");
1498 // Institution Name : if missing we set it to 'GDCM Hospital'
1499 CheckMandatoryEntry(0x0008,0x0080,"GDCM Hospital");
1501 // Patient's Name : if missing, we set it to 'GDCM^Patient'
1502 CheckMandatoryEntry(0x0010,0x0010,"GDCM^Patient");
1505 CheckMandatoryEntry(0x0010,0x0020,"");
1507 // Patient's Birth Date : 'type 2' entry -> must exist, value not mandatory
1508 CheckMandatoryEntry(0x0010,0x0030,"");
1510 // Patient's Sex :'type 2' entry -> must exist, value not mandatory
1511 CheckMandatoryEntry(0x0010,0x0040,"");
1513 // Referring Physician's Name :'type 2' entry -> must exist, value not mandatory
1514 CheckMandatoryEntry(0x0008,0x0090,"");
1516 // Remove some inconstencies (probably some more will be added)
1518 // if (0028 0008)Number of Frames exists
1519 // Push out (0020 0052),Frame of Reference UID
1520 // (only meaningfull within a Serie)
1521 DataEntry *e_0028_0008 = FileInternal->GetDataEntry(0x0028, 0x0008);
1524 Archive->Push(0x0020, 0x0052);
1528 void FileHelper::CheckMandatoryEntry(uint16_t group,uint16_t elem,std::string value)
1530 DataEntry *entry = FileInternal->GetDataEntry(group,elem);
1533 entry = DataEntry::New(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem));
1534 entry->SetString(value);
1535 Archive->Push(entry);
1540 void FileHelper::SetMandatoryEntry(uint16_t group,uint16_t elem,std::string value)
1542 DataEntry *entry = DataEntry::New(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem));
1543 entry->SetString(value);
1544 Archive->Push(entry);
1548 void FileHelper::CopyMandatoryEntry(uint16_t group,uint16_t elem,std::string value)
1550 DataEntry *entry = CopyDataEntry(group,elem);
1551 entry->SetString(value);
1552 Archive->Push(entry);
1557 * \brief Restore in the File the initial group 0002
1559 void FileHelper::RestoreWriteMandatory()
1561 // group 0002 may be pushed out for ACR-NEMA writting purposes
1562 Archive->Restore(0x0002,0x0000);
1563 Archive->Restore(0x0002,0x0001);
1564 Archive->Restore(0x0002,0x0002);
1565 Archive->Restore(0x0002,0x0003);
1566 Archive->Restore(0x0002,0x0010);
1567 Archive->Restore(0x0002,0x0012);
1568 Archive->Restore(0x0002,0x0013);
1569 Archive->Restore(0x0002,0x0016);
1570 Archive->Restore(0x0002,0x0100);
1571 Archive->Restore(0x0002,0x0102);
1573 Archive->Restore(0x0008,0x0012);
1574 Archive->Restore(0x0008,0x0013);
1575 Archive->Restore(0x0008,0x0016);
1576 Archive->Restore(0x0008,0x0018);
1577 Archive->Restore(0x0008,0x0060);
1578 Archive->Restore(0x0008,0x0070);
1579 Archive->Restore(0x0008,0x0080);
1580 Archive->Restore(0x0008,0x0090);
1581 Archive->Restore(0x0008,0x2112);
1583 Archive->Restore(0x0010,0x0010);
1584 Archive->Restore(0x0010,0x0030);
1585 Archive->Restore(0x0010,0x0040);
1587 Archive->Restore(0x0020,0x000d);
1588 Archive->Restore(0x0020,0x000e);
1591 //-----------------------------------------------------------------------------
1594 * \brief Factorization for various forms of constructors.
1596 void FileHelper::Initialize()
1600 WriteMode = WMODE_RAW;
1601 WriteType = ExplicitVR;
1603 PixelReadConverter = new PixelReadConvert;
1604 PixelWriteConverter = new PixelWriteConvert;
1605 Archive = new DocEntryArchive( FileInternal );
1609 * \brief Reads/[decompresses] the pixels,
1610 * *without* making RGB from Palette Colors
1611 * @return the pixels area, whatever its type
1612 * (uint8_t is just for prototyping : feel free to Cast it)
1614 uint8_t *FileHelper::GetRaw()
1616 PixelReadConverter->SetUserFunction( UserFunction );
1618 uint8_t *raw = PixelReadConverter->GetRaw();
1621 // The Raw image migth not be loaded yet:
1622 std::ifstream *fp = FileInternal->OpenFile();
1623 PixelReadConverter->ReadAndDecompressPixelData( fp );
1625 FileInternal->CloseFile();
1627 raw = PixelReadConverter->GetRaw();
1630 gdcmWarningMacro( "Read/decompress of pixel data apparently went wrong.");
1637 //-----------------------------------------------------------------------------
1639 * \brief Prints the common part of DataEntry, SeqEntry
1640 * @param os ostream we want to print in
1641 * @param indent (unused)
1643 void FileHelper::Print(std::ostream &os, std::string const &)
1645 FileInternal->SetPrintLevel(PrintLevel);
1646 FileInternal->Print(os);
1648 if ( FileInternal->IsReadable() )
1650 PixelReadConverter->SetPrintLevel(PrintLevel);
1651 PixelReadConverter->Print(os);
1655 //-----------------------------------------------------------------------------
1656 } // end namespace gdcm