1 /*=========================================================================
4 Module: $RCSfile: gdcmFileHelper.cxx,v $
6 Date: $Date: 2005/02/05 01:37:08 $
7 Version: $Revision: 1.13 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmFileHelper.h"
20 #include "gdcmGlobal.h"
22 #include "gdcmDocument.h"
23 #include "gdcmDebug.h"
25 #include "gdcmBinEntry.h"
26 #include "gdcmValEntry.h"
27 #include "gdcmContentEntry.h"
29 #include "gdcmPixelReadConvert.h"
30 #include "gdcmPixelWriteConvert.h"
31 #include "gdcmDocEntryArchive.h"
37 //-------------------------------------------------------------------------
38 // Constructor / Destructor
40 * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
41 * file (gdcm::File only deals with the ... header)
42 * Opens (in read only and when possible) an existing file and checks
43 * for DICOM compliance. Returns NULL on failure.
44 * It will be up to the user to load the pixels into memory
45 * \note the in-memory representation of all available tags found in
46 * the DICOM header is post-poned to first header information access.
47 * This avoid a double parsing of public part of the header when
48 * one sets an a posteriori shadow dictionary (efficiency can be
49 * seen as a side effect).
51 FileHelper::FileHelper( )
53 FileInternal = new File( );
59 * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
60 * file (File only deals with the ... header)
61 * Opens (in read only and when possible) an existing file and checks
62 * for DICOM compliance. Returns NULL on failure.
63 * It will be up to the user to load the pixels into memory
64 * \note the in-memory representation of all available tags found in
65 * the DICOM header is post-poned to first header information access.
66 * This avoid a double parsing of public part of the header when
67 * user sets an a posteriori shadow dictionary (efficiency can be
68 * seen as a side effect).
69 * @param header already built Header
71 FileHelper::FileHelper(File *header)
73 FileInternal = header;
79 * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
80 * file (gdcm::File only deals with the ... header)
81 * Opens (in read only and when possible) an existing file and checks
82 * for DICOM compliance. Returns NULL on failure.
83 * It will be up to the user to load the pixels into memory
84 * \note the in-memory representation of all available tags found in
85 * the DICOM header is post-poned to first header information access.
86 * This avoid a double parsing of public part of the header when
87 * one sets an a posteriori shadow dictionary (efficiency can be
88 * seen as a side effect).
89 * @param filename file to be opened for parsing
91 FileHelper::FileHelper(std::string const &filename )
93 FileInternal = new File( filename );
99 * \brief canonical destructor
100 * \note If the header (gdcm::File) was created by the FileHelper constructor,
101 * it is destroyed by the FileHelper
103 FileHelper::~FileHelper()
105 if( PixelReadConverter )
107 delete PixelReadConverter;
109 if( PixelWriteConverter )
111 delete PixelWriteConverter;
125 //-----------------------------------------------------------------------------
128 * \brief Accesses an existing DocEntry (i.e. a Dicom Element)
129 * through it's (group, element) and modifies it's content with
131 * @param content new value (string) to substitute with
132 * @param group group number of the Dicom Element to modify
133 * @param elem element number of the Dicom Element to modify
135 bool FileHelper::SetValEntry(std::string const &content,
136 uint16_t group, uint16_t elem)
138 return FileInternal->SetValEntry(content,group,elem);
143 * \brief Accesses an existing DocEntry (i.e. a Dicom Element)
144 * through it's (group, element) and modifies it's content with
146 * @param content new value (void* -> uint8_t*) to substitute with
147 * @param lgth new value length
148 * @param group group number of the Dicom Element to modify
149 * @param elem element number of the Dicom Element to modify
151 bool FileHelper::SetBinEntry(uint8_t *content, int lgth,
152 uint16_t group, uint16_t elem)
154 return FileInternal->SetBinEntry(content,lgth,group,elem);
158 * \brief Modifies the value of a given DocEntry (Dicom entry)
159 * when it exists. Create it with the given value when unexistant.
160 * @param content (string) Value to be set
161 * @param group Group number of the Entry
162 * @param elem Element number of the Entry
163 * \return pointer to the modified/created Dicom entry (NULL when creation
166 ValEntry *FileHelper::InsertValEntry(std::string const &content,
167 uint16_t group, uint16_t elem)
169 return FileInternal->InsertValEntry(content,group,elem);
173 * \brief Modifies the value of a given DocEntry (Dicom entry)
174 * when it exists. Create it with the given value when unexistant.
175 * A copy of the binArea is made to be kept in the Document.
176 * @param binArea (binary) value to be set
177 * @param lgth new value length
178 * @param group Group number of the Entry
179 * @param elem Element number of the Entry
180 * \return pointer to the modified/created Dicom entry (NULL when creation
183 BinEntry *FileHelper::InsertBinEntry(uint8_t *binArea, int lgth,
184 uint16_t group, uint16_t elem)
186 return FileInternal->InsertBinEntry(binArea,lgth,group,elem);
190 * \brief Modifies the value of a given DocEntry (Dicom entry)
191 * when it exists. Create it with the given value when unexistant.
192 * A copy of the binArea is made to be kept in the Document.
193 * @param group Group number of the Entry
194 * @param elem Element number of the Entry
195 * \return pointer to the modified/created Dicom entry (NULL when creation
198 SeqEntry *FileHelper::InsertSeqEntry(uint16_t group, uint16_t elem)
200 return FileInternal->InsertSeqEntry(group,elem);
204 * \brief Get the size of the image data
205 * If the image can be RGB (with a lut or by default), the size
206 * corresponds to the RGB image
207 * (use GetImageDataRawSize if you want to be sure to get *only*
208 * the size of the pixels)
209 * @return The image size
211 size_t FileHelper::GetImageDataSize()
213 if ( PixelWriteConverter->GetUserData() )
215 return PixelWriteConverter->GetUserDataSize();
218 return PixelReadConverter->GetRGBSize();
222 * \brief Get the size of the image data
223 * If the image could be converted to RGB using a LUT,
224 * this transformation is not taken into account by GetImageDataRawSize
225 * (use GetImageDataSize if you wish)
226 * @return The raw image size
228 size_t FileHelper::GetImageDataRawSize()
230 if ( PixelWriteConverter->GetUserData() )
232 return PixelWriteConverter->GetUserDataSize();
235 return PixelReadConverter->GetRawSize();
239 * \brief - Allocates necessary memory,
240 * - Reads the pixels from disk (uncompress if necessary),
241 * - Transforms YBR pixels, if any, into RGB pixels,
242 * - Transforms 3 planes R, G, B, if any, into a single RGB Plane
243 * - Transforms single Grey plane + 3 Palettes into a RGB Plane
244 * - Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
245 * @return Pointer to newly allocated pixel data.
246 * NULL if alloc fails
248 uint8_t *FileHelper::GetImageData()
250 if ( PixelWriteConverter->GetUserData() )
252 return PixelWriteConverter->GetUserData();
257 // If the decompression failed nothing can be done.
261 if ( FileInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
263 return PixelReadConverter->GetRGB();
267 // When no LUT or LUT conversion fails, return the Raw
268 return PixelReadConverter->GetRaw();
273 * \brief Allocates necessary memory,
274 * Transforms YBR pixels (if any) into RGB pixels
275 * Transforms 3 planes R, G, B (if any) into a single RGB Plane
276 * Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
277 * DOES NOT transform Grey plane + 3 Palettes into a RGB Plane
278 * @return Pointer to newly allocated pixel data.
279 * \ NULL if alloc fails
281 uint8_t *FileHelper::GetImageDataRaw ()
288 * Read the pixels from disk (uncompress if necessary),
289 * Transforms YBR pixels, if any, into RGB pixels
290 * Transforms 3 planes R, G, B, if any, into a single RGB Plane
291 * Transforms single Grey plane + 3 Palettes into a RGB Plane
292 * Copies at most MaxSize bytes of pixel data to caller allocated
294 * \warning This function allows people that want to build a volume
295 * from an image stack *not to* have, first to get the image pixels,
296 * and then move them to the volume area.
297 * It's absolutely useless for any VTK user since vtk chooses
298 * to invert the lines of an image, that is the last line comes first
299 * (for some axis related reasons?). Hence he will have
300 * to load the image line by line, starting from the end.
301 * VTK users have to call GetImageData
303 * @param destination Address (in caller's memory space) at which the
304 * pixel data should be copied
305 * @param maxSize Maximum number of bytes to be copied. When MaxSize
306 * is not sufficient to hold the pixel data the copy is not
307 * executed (i.e. no partial copy).
308 * @return On success, the number of bytes actually copied. Zero on
309 * failure e.g. MaxSize is lower than necessary.
311 size_t FileHelper::GetImageDataIntoVector (void *destination, size_t maxSize)
315 // If the decompression failed nothing can be done.
319 if ( FileInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
321 if ( PixelReadConverter->GetRGBSize() > maxSize )
323 gdcmWarningMacro( "Pixel data bigger than caller's expected MaxSize");
327 (void*)PixelReadConverter->GetRGB(),
328 PixelReadConverter->GetRGBSize() );
329 return PixelReadConverter->GetRGBSize();
332 // Either no LUT conversion necessary or LUT conversion failed
333 if ( PixelReadConverter->GetRawSize() > maxSize )
335 gdcmWarningMacro( "Pixel data bigger than caller's expected MaxSize");
339 (void*)PixelReadConverter->GetRaw(),
340 PixelReadConverter->GetRawSize() );
341 return PixelReadConverter->GetRawSize();
345 * \brief Points the internal pointer to the callers inData
346 * image representation, BUT WITHOUT COPYING THE DATA.
347 * 'image' Pixels are presented as C-like 2D arrays : line per line.
348 * 'volume'Pixels are presented as C-like 3D arrays : plane per plane
349 * \warning Since the pixels are not copied, it is the caller's responsability
350 * not to deallocate its data before gdcm uses them (e.g. with
351 * the Write() method )
352 * @param inData user supplied pixel area (uint8_t* is just for the compiler.
353 * user is allowed to pass any kind of pixelsn since the size is
355 * @param expectedSize total image size, *in Bytes*
359 void FileHelper::SetImageData(uint8_t *inData, size_t expectedSize)
361 SetUserData(inData,expectedSize);
365 * \brief Set the image data defined by the user
366 * \warning When writting the file, this data are get as default data to write
367 * @param inData user supplied pixel area (uint8_t* is just for the compiler.
368 * user is allowed to pass any kind of pixelsn since the size is
370 * @param expectedSize total image size, *in Bytes*
373 void FileHelper::SetUserData(uint8_t *inData, size_t expectedSize)
375 PixelWriteConverter->SetUserData(inData,expectedSize);
379 * \brief Get the image data defined by the user
380 * \warning When writting the file, this data are get as default data to write
382 uint8_t *FileHelper::GetUserData()
384 return PixelWriteConverter->GetUserData();
388 * \brief Get the image data size defined by the user
389 * \warning When writting the file, this data are get as default data to write
391 size_t FileHelper::GetUserDataSize()
393 return PixelWriteConverter->GetUserDataSize();
397 * \brief Get the image data from the file.
398 * If a LUT is found, the data are expanded to be RGB
400 uint8_t *FileHelper::GetRGBData()
402 return PixelReadConverter->GetRGB();
406 * \brief Get the image data size from the file.
407 * If a LUT is found, the data are expanded to be RGB
409 size_t FileHelper::GetRGBDataSize()
411 return PixelReadConverter->GetRGBSize();
415 * \brief Get the image data from the file.
416 * If a LUT is found, the data are not expanded !
418 uint8_t *FileHelper::GetRawData()
420 return PixelReadConverter->GetRaw();
424 * \brief Get the image data size from the file.
425 * If a LUT is found, the data are not expanded !
427 size_t FileHelper::GetRawDataSize()
429 return PixelReadConverter->GetRawSize();
433 * \brief Access to the underlying \ref PixelReadConverter RGBA LUT
435 uint8_t* FileHelper::GetLutRGBA()
437 return PixelReadConverter->GetLutRGBA();
441 * \brief Writes on disk A SINGLE Dicom file
442 * NO test is performed on processor "Endiannity".
443 * It's up to the user to call his Reader properly
444 * @param fileName name of the file to be created
445 * (any already existing file is over written)
446 * @return false if write fails
448 bool FileHelper::WriteRawData(std::string const &fileName)
450 std::ofstream fp1(fileName.c_str(), std::ios::out | std::ios::binary );
453 gdcmWarningMacro( "Fail to open (write) file:" << fileName.c_str());
457 if( PixelWriteConverter->GetUserData() )
459 fp1.write( (char*)PixelWriteConverter->GetUserData(),
460 PixelWriteConverter->GetUserDataSize() );
462 else if ( PixelReadConverter->GetRGB() )
464 fp1.write( (char*)PixelReadConverter->GetRGB(),
465 PixelReadConverter->GetRGBSize());
467 else if ( PixelReadConverter->GetRaw() )
469 fp1.write( (char*)PixelReadConverter->GetRaw(),
470 PixelReadConverter->GetRawSize());
474 gdcmErrorMacro( "Nothing written." );
483 * \brief Writes on disk A SINGLE Dicom file,
484 * using the Implicit Value Representation convention
485 * NO test is performed on processor "Endiannity".
486 * @param fileName name of the file to be created
487 * (any already existing file is overwritten)
488 * @return false if write fails
491 bool FileHelper::WriteDcmImplVR (std::string const &fileName)
493 SetWriteTypeToDcmImplVR();
494 return Write(fileName);
498 * \brief Writes on disk A SINGLE Dicom file,
499 * using the Explicit Value Representation convention
500 * NO test is performed on processor "Endiannity".
501 * @param fileName name of the file to be created
502 * (any already existing file is overwritten)
503 * @return false if write fails
506 bool FileHelper::WriteDcmExplVR (std::string const &fileName)
508 SetWriteTypeToDcmExplVR();
509 return Write(fileName);
513 * \brief Writes on disk A SINGLE Dicom file,
514 * using the ACR-NEMA convention
515 * NO test is performed on processor "Endiannity".
516 * (a l'attention des logiciels cliniques
517 * qui ne prennent en entrée QUE des images ACR ...
518 * \warning if a DICOM_V3 header is supplied,
519 * groups < 0x0008 and shadow groups are ignored
520 * \warning NO TEST is performed on processor "Endiannity".
521 * @param fileName name of the file to be created
522 * (any already existing file is overwritten)
523 * @return false if write fails
526 bool FileHelper::WriteAcr (std::string const &fileName)
529 return Write(fileName);
533 * \brief Writes on disk A SINGLE Dicom file,
534 * @param fileName name of the file to be created
535 * (any already existing file is overwritten)
536 * @return false if write fails
538 bool FileHelper::Write(std::string const &fileName)
543 SetWriteFileTypeToImplicitVR();
546 SetWriteFileTypeToExplicitVR();
550 SetWriteFileTypeToACR();
553 SetWriteFileTypeToExplicitVR();
556 // --------------------------------------------------------------
557 // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
559 // if recognition code tells us we dealt with a LibIDO image
560 // we reproduce on disk the switch between lineNumber and columnNumber
561 // just before writting ...
562 /// \todo the best trick would be *change* the recognition code
563 /// but pb expected if user deals with, e.g. COMPLEX images
564 if( WriteType == ACR_LIBIDO )
570 SetWriteToNoLibido();
572 // ----------------- End of Special Patch ----------------
584 bool check = CheckWriteIntegrity();
587 check = FileInternal->Write(fileName,WriteType);
591 RestoreWriteFileType();
593 // --------------------------------------------------------------
594 // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
596 // ...and we restore the header to be Dicom Compliant again
597 // just after writting
598 RestoreWriteOfLibido();
599 // ----------------- End of Special Patch ----------------
604 //-----------------------------------------------------------------------------
607 * \brief Check the write integrity
609 * The tests made are :
610 * - verify the size of the image to write with the possible write
611 * when the user set an image data
612 * @return true if check is successfull
614 bool FileHelper::CheckWriteIntegrity()
616 if(PixelWriteConverter->GetUserData())
618 int numberBitsAllocated = FileInternal->GetBitsAllocated();
619 if ( numberBitsAllocated == 0 || numberBitsAllocated == 12 )
621 numberBitsAllocated = 16;
624 size_t decSize = FileInternal->GetXSize()
625 * FileInternal->GetYSize()
626 * FileInternal->GetZSize()
627 * ( numberBitsAllocated / 8 )
628 * FileInternal->GetSamplesPerPixel();
629 size_t rgbSize = decSize;
630 if( FileInternal->HasLUT() )
631 rgbSize = decSize * 3;
636 if( decSize!=PixelWriteConverter->GetUserDataSize() )
638 gdcmWarningMacro( "Data size (Raw) is incorrect. Should be "
639 << decSize << " / Found :"
640 << PixelWriteConverter->GetUserDataSize() );
645 if( rgbSize!=PixelWriteConverter->GetUserDataSize() )
647 gdcmWarningMacro( "Data size (RGB) is incorrect. Should be "
648 << decSize << " / Found "
649 << PixelWriteConverter->GetUserDataSize() );
660 * \brief Update the File to write RAW datas
662 void FileHelper::SetWriteToRaw()
664 if( FileInternal->GetNumberOfScalarComponents() == 3
665 && !FileInternal->HasLUT())
671 ValEntry *photInt = CopyValEntry(0x0028,0x0004);
672 if(FileInternal->HasLUT())
674 photInt->SetValue("PALETTE COLOR ");
678 photInt->SetValue("MONOCHROME1 ");
681 PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(),
682 PixelReadConverter->GetRawSize());
685 CopyBinEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel());
686 pixel->SetValue(GDCM_BINLOADED);
687 pixel->SetBinArea(PixelWriteConverter->GetData(),false);
688 pixel->SetLength(PixelWriteConverter->GetDataSize());
690 Archive->Push(photInt);
691 Archive->Push(pixel);
696 * \brief Update the File to write RGB datas
698 void FileHelper::SetWriteToRGB()
700 if(FileInternal->GetNumberOfScalarComponents()==3)
702 PixelReadConverter->BuildRGBImage();
704 ValEntry *spp = CopyValEntry(0x0028,0x0002);
707 ValEntry *planConfig = CopyValEntry(0x0028,0x0006);
708 planConfig->SetValue("0 ");
710 ValEntry *photInt = CopyValEntry(0x0028,0x0004);
711 photInt->SetValue("RGB ");
713 if(PixelReadConverter->GetRGB())
715 PixelWriteConverter->SetReadData(PixelReadConverter->GetRGB(),
716 PixelReadConverter->GetRGBSize());
720 PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(),
721 PixelReadConverter->GetRawSize());
725 CopyBinEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel());
726 pixel->SetValue(GDCM_BINLOADED);
727 pixel->SetBinArea(PixelWriteConverter->GetData(),false);
728 pixel->SetLength(PixelWriteConverter->GetDataSize());
731 Archive->Push(planConfig);
732 Archive->Push(photInt);
733 Archive->Push(pixel);
736 Archive->Push(0x0028,0x1101);
737 Archive->Push(0x0028,0x1102);
738 Archive->Push(0x0028,0x1103);
739 Archive->Push(0x0028,0x1201);
740 Archive->Push(0x0028,0x1202);
741 Archive->Push(0x0028,0x1203);
744 // Thus, we have a RGB image and the bits allocated = 24 and
745 // samples per pixels = 1 (in the read file)
746 if(FileInternal->GetBitsAllocated()==24)
748 ValEntry *bitsAlloc = CopyValEntry(0x0028,0x0100);
749 bitsAlloc->SetValue("8 ");
751 ValEntry *bitsStored = CopyValEntry(0x0028,0x0101);
752 bitsStored->SetValue("8 ");
754 ValEntry *highBit = CopyValEntry(0x0028,0x0102);
755 highBit->SetValue("7 ");
757 Archive->Push(bitsAlloc);
758 Archive->Push(bitsStored);
759 Archive->Push(highBit);
769 * \brief Restore the File write mode
771 void FileHelper::RestoreWrite()
773 Archive->Restore(0x0028,0x0002);
774 Archive->Restore(0x0028,0x0004);
775 Archive->Restore(0x0028,0x0006);
776 Archive->Restore(GetFile()->GetGrPixel(),GetFile()->GetNumPixel());
778 // For old ACR-NEMA (24 bits problem)
779 Archive->Restore(0x0028,0x0100);
780 Archive->Restore(0x0028,0x0101);
781 Archive->Restore(0x0028,0x0102);
784 Archive->Restore(0x0028,0x1101);
785 Archive->Restore(0x0028,0x1102);
786 Archive->Restore(0x0028,0x1103);
787 Archive->Restore(0x0028,0x1201);
788 Archive->Restore(0x0028,0x1202);
789 Archive->Restore(0x0028,0x1203);
793 * \brief Set in the File the write type to ACR
795 void FileHelper::SetWriteFileTypeToACR()
797 Archive->Push(0x0002,0x0010);
801 * \brief Set in the File the write type to Explicit VR
803 void FileHelper::SetWriteFileTypeToExplicitVR()
805 std::string ts = Util::DicomString(
806 Global::GetTS()->GetSpecialTransferSyntax(TS::ExplicitVRLittleEndian) );
808 ValEntry *tss = CopyValEntry(0x0002,0x0010);
815 * \brief Set in the File the write type to Implicit VR
817 void FileHelper::SetWriteFileTypeToImplicitVR()
819 std::string ts = Util::DicomString(
820 Global::GetTS()->GetSpecialTransferSyntax(TS::ImplicitVRLittleEndian) );
822 ValEntry *tss = CopyValEntry(0x0002,0x0010);
830 * \brief Restore in the File the write type
832 void FileHelper::RestoreWriteFileType()
834 Archive->Restore(0x0002,0x0010);
838 * \brief Set the Write not to Libido format
840 void FileHelper::SetWriteToLibido()
842 ValEntry *oldRow = dynamic_cast<ValEntry *>
843 (FileInternal->GetDocEntry(0x0028, 0x0010));
844 ValEntry *oldCol = dynamic_cast<ValEntry *>
845 (FileInternal->GetDocEntry(0x0028, 0x0011));
847 if( oldRow && oldCol )
849 std::string rows, columns;
851 ValEntry *newRow=new ValEntry(oldRow->GetDictEntry());
852 ValEntry *newCol=new ValEntry(oldCol->GetDictEntry());
854 newRow->Copy(oldCol);
855 newCol->Copy(oldRow);
857 newRow->SetValue(oldCol->GetValue());
858 newCol->SetValue(oldRow->GetValue());
860 Archive->Push(newRow);
861 Archive->Push(newCol);
864 ValEntry *libidoCode = CopyValEntry(0x0008,0x0010);
865 libidoCode->SetValue("ACRNEMA_LIBIDO_1.1");
866 Archive->Push(libidoCode);
870 * \brief Set the Write not to No Libido format
872 void FileHelper::SetWriteToNoLibido()
874 ValEntry *recCode = dynamic_cast<ValEntry *>
875 (FileInternal->GetDocEntry(0x0008,0x0010));
878 if( recCode->GetValue() == "ACRNEMA_LIBIDO_1.1" )
880 ValEntry *libidoCode = CopyValEntry(0x0008,0x0010);
881 libidoCode->SetValue("");
882 Archive->Push(libidoCode);
888 * \brief Restore the Write format
890 void FileHelper::RestoreWriteOfLibido()
892 Archive->Restore(0x0028,0x0010);
893 Archive->Restore(0x0028,0x0011);
894 Archive->Restore(0x0008,0x0010);
898 * \brief Copy a ValEntry content
899 * @param group Group number of the Entry
900 * @param elem Element number of the Entry
901 * \return pointer to the modified/created Val Entry (NULL when creation
904 ValEntry *FileHelper::CopyValEntry(uint16_t group,uint16_t elem)
906 DocEntry *oldE = FileInternal->GetDocEntry(group, elem);
911 newE = new ValEntry(oldE->GetDictEntry());
916 newE = GetFile()->NewValEntry(group,elem);
923 * \brief Modifies the value of a given Bin Entry (Dicom Element)
924 * when it exists. Create it with the given value when unexistant.
925 * @param group Group number of the Entry
926 * @param elem Element number of the Entry
927 * \return pointer to the modified/created Bin Entry (NULL when creation
930 BinEntry *FileHelper::CopyBinEntry(uint16_t group,uint16_t elem)
932 DocEntry *oldE = FileInternal->GetDocEntry(group, elem);
937 newE = new BinEntry(oldE->GetDictEntry());
942 newE = GetFile()->NewBinEntry(group,elem);
948 //-----------------------------------------------------------------------------
951 * \brief Factorization for various forms of constructors.
953 void FileHelper::Initialize()
955 WriteMode = WMODE_RAW;
956 WriteType = ExplicitVR;
958 PixelReadConverter = new PixelReadConvert;
959 PixelWriteConverter = new PixelWriteConvert;
960 Archive = new DocEntryArchive( FileInternal );
962 if ( FileInternal->IsReadable() )
964 PixelReadConverter->GrabInformationsFromFile( FileInternal );
971 uint8_t *FileHelper::GetRaw()
973 uint8_t *raw = PixelReadConverter->GetRaw();
976 // The Raw image migth not be loaded yet:
977 std::ifstream *fp = FileInternal->OpenFile();
978 PixelReadConverter->ReadAndDecompressPixelData( fp );
980 FileInternal->CloseFile();
982 raw = PixelReadConverter->GetRaw();
985 gdcmWarningMacro( "Read/decompress of pixel data apparently went wrong.");
993 //-----------------------------------------------------------------------------
995 void FileHelper::Print(std::ostream &os, std::string const &)
997 FileInternal->SetPrintLevel(PrintLevel);
998 FileInternal->Print(os);
1000 PixelReadConverter->SetPrintLevel(PrintLevel);
1001 PixelReadConverter->Print(os);
1004 //-----------------------------------------------------------------------------
1005 } // end namespace gdcm