1 /*=========================================================================
4 Module: $RCSfile: gdcmFileHelper.cxx,v $
6 Date: $Date: 2005/01/26 16:28:58 $
7 Version: $Revision: 1.8 $
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 typedef std::pair<TagDocEntryHT::iterator,TagDocEntryHT::iterator> IterHT;
39 //-------------------------------------------------------------------------
40 // Constructor / Destructor
42 * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
43 * file (gdcm::File only deals with the ... header)
44 * Opens (in read only and when possible) an existing file and checks
45 * for DICOM compliance. Returns NULL on failure.
46 * It will be up to the user to load the pixels into memory
47 * \note the in-memory representation of all available tags found in
48 * the DICOM header is post-poned to first header information access.
49 * This avoid a double parsing of public part of the header when
50 * one sets an a posteriori shadow dictionary (efficiency can be
51 * seen as a side effect).
53 FileHelper::FileHelper( )
55 FileInternal = new File( );
61 * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
62 * file (File only deals with the ... header)
63 * Opens (in read only and when possible) an existing file and checks
64 * for DICOM compliance. Returns NULL on failure.
65 * It will be up to the user to load the pixels into memory
66 * \note the in-memory representation of all available tags found in
67 * the DICOM header is post-poned to first header information access.
68 * This avoid a double parsing of public part of the header when
69 * user sets an a posteriori shadow dictionary (efficiency can be
70 * seen as a side effect).
71 * @param header already built Header
73 FileHelper::FileHelper(File *header)
75 FileInternal = header;
81 * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
82 * file (gdcm::File only deals with the ... header)
83 * Opens (in read only and when possible) an existing file and checks
84 * for DICOM compliance. Returns NULL on failure.
85 * It will be up to the user to load the pixels into memory
86 * \note the in-memory representation of all available tags found in
87 * the DICOM header is post-poned to first header information access.
88 * This avoid a double parsing of public part of the header when
89 * one sets an a posteriori shadow dictionary (efficiency can be
90 * seen as a side effect).
91 * @param filename file to be opened for parsing
93 FileHelper::FileHelper(std::string const & filename )
95 FileInternal = new File( filename );
101 * \brief canonical destructor
102 * \note If the header (gdcm::File) was created by the FileHelper constructor,
103 * it is destroyed by the FileHelper
105 FileHelper::~FileHelper()
107 if( PixelReadConverter )
109 delete PixelReadConverter;
111 if( PixelWriteConverter )
113 delete PixelWriteConverter;
127 //-----------------------------------------------------------------------------
129 void FileHelper::Print(std::ostream &os, std::string const &)
131 FileInternal->SetPrintLevel(PrintLevel);
132 FileInternal->Print(os);
134 PixelReadConverter->SetPrintLevel(PrintLevel);
135 PixelReadConverter->Print(os);
138 //-----------------------------------------------------------------------------
141 * \brief Get the size of the image data
142 * If the image can be RGB (with a lut or by default), the size
143 * corresponds to the RGB image
144 * (use GetImageDataRawSize if you want to be sure to get *only*
145 * the size of the pixels)
146 * @return The image size
148 size_t FileHelper::GetImageDataSize()
150 if ( PixelWriteConverter->GetUserData() )
152 return PixelWriteConverter->GetUserDataSize();
155 return PixelReadConverter->GetRGBSize();
159 * \brief Get the size of the image data
160 * If the image could be converted to RGB using a LUT,
161 * this transformation is not taken into account by GetImageDataRawSize
162 * (use GetImageDataSize if you wish)
163 * @return The raw image size
165 size_t FileHelper::GetImageDataRawSize()
167 if ( PixelWriteConverter->GetUserData() )
169 return PixelWriteConverter->GetUserDataSize();
172 return PixelReadConverter->GetRawSize();
176 * \brief - Allocates necessary memory,
177 * - Reads the pixels from disk (uncompress if necessary),
178 * - Transforms YBR pixels, if any, into RGB pixels
179 * - Transforms 3 planes R, G, B, if any, into a single RGB Plane
180 * - Transforms single Grey plane + 3 Palettes into a RGB Plane
181 * - Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
182 * @return Pointer to newly allocated pixel data.
183 * NULL if alloc fails
185 uint8_t *FileHelper::GetImageData()
187 if ( PixelWriteConverter->GetUserData() )
189 return PixelWriteConverter->GetUserData();
194 // If the decompression failed nothing can be done.
198 if ( FileInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
200 return PixelReadConverter->GetRGB();
204 // When no LUT or LUT conversion fails, return the Raw
205 return PixelReadConverter->GetRaw();
210 * \brief Allocates necessary memory,
211 * Transforms YBR pixels (if any) into RGB pixels
212 * Transforms 3 planes R, G, B (if any) into a single RGB Plane
213 * Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
214 * DOES NOT transform Grey plane + 3 Palettes into a RGB Plane
215 * @return Pointer to newly allocated pixel data.
216 * \ NULL if alloc fails
218 uint8_t *FileHelper::GetImageDataRaw ()
225 * Read the pixels from disk (uncompress if necessary),
226 * Transforms YBR pixels, if any, into RGB pixels
227 * Transforms 3 planes R, G, B, if any, into a single RGB Plane
228 * Transforms single Grey plane + 3 Palettes into a RGB Plane
229 * Copies at most MaxSize bytes of pixel data to caller allocated
231 * \warning This function allows people that want to build a volume
232 * from an image stack *not to* have, first to get the image pixels,
233 * and then move them to the volume area.
234 * It's absolutely useless for any VTK user since vtk chooses
235 * to invert the lines of an image, that is the last line comes first
236 * (for some axis related reasons?). Hence he will have
237 * to load the image line by line, starting from the end.
238 * VTK users have to call GetImageData
240 * @param destination Address (in caller's memory space) at which the
241 * pixel data should be copied
242 * @param maxSize Maximum number of bytes to be copied. When MaxSize
243 * is not sufficient to hold the pixel data the copy is not
244 * executed (i.e. no partial copy).
245 * @return On success, the number of bytes actually copied. Zero on
246 * failure e.g. MaxSize is lower than necessary.
248 size_t FileHelper::GetImageDataIntoVector (void *destination, size_t maxSize)
252 // If the decompression failed nothing can be done.
256 if ( FileInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
258 if ( PixelReadConverter->GetRGBSize() > maxSize )
260 gdcmVerboseMacro( "Pixel data bigger than caller's expected MaxSize");
264 (void*)PixelReadConverter->GetRGB(),
265 PixelReadConverter->GetRGBSize() );
266 return PixelReadConverter->GetRGBSize();
269 // Either no LUT conversion necessary or LUT conversion failed
270 if ( PixelReadConverter->GetRawSize() > maxSize )
272 gdcmVerboseMacro( "Pixel data bigger than caller's expected MaxSize");
276 (void*)PixelReadConverter->GetRaw(),
277 PixelReadConverter->GetRawSize() );
278 return PixelReadConverter->GetRawSize();
282 * \brief Points the internal pointer to the callers inData
283 * image representation, BUT WITHOUT COPYING THE DATA.
284 * 'image' Pixels are presented as C-like 2D arrays : line per line.
285 * 'volume'Pixels are presented as C-like 3D arrays : plane per plane
286 * \warning Since the pixels are not copied, it is the caller's responsability
287 * not to deallocate its data before gdcm uses them (e.g. with
288 * the Write() method.
289 * @param inData user supplied pixel area
290 * @param expectedSize total image size, in Bytes
294 void FileHelper::SetImageData(uint8_t *inData, size_t expectedSize)
296 SetUserData(inData,expectedSize);
300 * \brief Set the image data defined by the user
301 * \warning When writting the file, this data are get as default data to write
303 void FileHelper::SetUserData(uint8_t *data, size_t expectedSize)
305 PixelWriteConverter->SetUserData(data,expectedSize);
309 * \brief Get the image data defined by the user
310 * \warning When writting the file, this data are get as default data to write
312 uint8_t *FileHelper::GetUserData()
314 return PixelWriteConverter->GetUserData();
318 * \brief Get the image data size defined by the user
319 * \warning When writting the file, this data are get as default data to write
321 size_t FileHelper::GetUserDataSize()
323 return PixelWriteConverter->GetUserDataSize();
327 * \brief Get the image data from the file.
328 * If a LUT is found, the data are expanded to be RGB
330 uint8_t *FileHelper::GetRGBData()
332 return PixelReadConverter->GetRGB();
336 * \brief Get the image data size from the file.
337 * If a LUT is found, the data are expanded to be RGB
339 size_t FileHelper::GetRGBDataSize()
341 return PixelReadConverter->GetRGBSize();
345 * \brief Get the image data from the file.
346 * If a LUT is found, the data are not expanded !
348 uint8_t *FileHelper::GetRawData()
350 return PixelReadConverter->GetRaw();
354 * \brief Get the image data size from the file.
355 * If a LUT is found, the data are not expanded !
357 size_t FileHelper::GetRawDataSize()
359 return PixelReadConverter->GetRawSize();
363 * \brief Writes on disk A SINGLE Dicom file
364 * NO test is performed on processor "Endiannity".
365 * It's up to the user to call his Reader properly
366 * @param fileName name of the file to be created
367 * (any already existing file is over written)
368 * @return false if write fails
371 bool FileHelper::WriteRawData(std::string const &fileName)
373 std::ofstream fp1(fileName.c_str(), std::ios::out | std::ios::binary );
376 gdcmVerboseMacro( "Fail to open (write) file:" << fileName.c_str());
380 if( PixelWriteConverter->GetUserData() )
382 fp1.write( (char*)PixelWriteConverter->GetUserData(),
383 PixelWriteConverter->GetUserDataSize() );
385 else if ( PixelReadConverter->GetRGB() )
387 fp1.write( (char*)PixelReadConverter->GetRGB(),
388 PixelReadConverter->GetRGBSize());
390 else if ( PixelReadConverter->GetRaw() )
392 fp1.write( (char*)PixelReadConverter->GetRaw(),
393 PixelReadConverter->GetRawSize());
397 gdcmErrorMacro( "Nothing written." );
406 * \brief Writes on disk A SINGLE Dicom file,
407 * using the Implicit Value Representation convention
408 * NO test is performed on processor "Endiannity".
409 * @param fileName name of the file to be created
410 * (any already existing file is overwritten)
411 * @return false if write fails
414 bool FileHelper::WriteDcmImplVR (std::string const &fileName)
416 SetWriteTypeToDcmImplVR();
417 return Write(fileName);
421 * \brief Writes on disk A SINGLE Dicom file,
422 * using the Explicit Value Representation convention
423 * NO test is performed on processor "Endiannity".
424 * @param fileName name of the file to be created
425 * (any already existing file is overwritten)
426 * @return false if write fails
429 bool FileHelper::WriteDcmExplVR (std::string const &fileName)
431 SetWriteTypeToDcmExplVR();
432 return Write(fileName);
436 * \brief Writes on disk A SINGLE Dicom file,
437 * using the ACR-NEMA convention
438 * NO test is performed on processor "Endiannity".
439 * (a l'attention des logiciels cliniques
440 * qui ne prennent en entrée QUE des images ACR ...
441 * \warning if a DICOM_V3 header is supplied,
442 * groups < 0x0008 and shadow groups are ignored
443 * \warning NO TEST is performed on processor "Endiannity".
444 * @param fileName name of the file to be created
445 * (any already existing file is overwritten)
446 * @return false if write fails
449 bool FileHelper::WriteAcr (std::string const &fileName)
452 return Write(fileName);
456 * \brief Writes on disk A SINGLE Dicom file,
457 * @param fileName name of the file to be created
458 * (any already existing file is overwritten)
459 * @return false if write fails
461 bool FileHelper::Write(std::string const &fileName)
466 SetWriteFileTypeToImplicitVR();
469 SetWriteFileTypeToExplicitVR();
473 SetWriteFileTypeToACR();
476 SetWriteFileTypeToExplicitVR();
479 // --------------------------------------------------------------
480 // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
482 // if recognition code tells us we dealt with a LibIDO image
483 // we reproduce on disk the switch between lineNumber and columnNumber
484 // just before writting ...
485 /// \todo the best trick would be *change* the recognition code
486 /// but pb expected if user deals with, e.g. COMPLEX images
487 if( WriteType == ACR_LIBIDO )
493 SetWriteToNoLibido();
495 // ----------------- End of Special Patch ----------------
507 bool check = CheckWriteIntegrity();
510 check = FileInternal->Write(fileName,WriteType);
514 RestoreWriteFileType();
516 // --------------------------------------------------------------
517 // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
519 // ...and we restore the header to be Dicom Compliant again
520 // just after writting
521 RestoreWriteOfLibido();
522 // ----------------- End of Special Patch ----------------
528 * \brief Accesses an existing DocEntry (i.e. a Dicom Element)
529 * through it's (group, element) and modifies it's content with
531 * @param content new value (string) to substitute with
532 * @param group group number of the Dicom Element to modify
533 * @param elem element number of the Dicom Element to modify
535 bool FileHelper::SetValEntry(std::string const &content,
536 uint16_t group, uint16_t elem)
538 return FileInternal->SetValEntry(content,group,elem);
543 * \brief Accesses an existing DocEntry (i.e. a Dicom Element)
544 * through it's (group, element) and modifies it's content with
546 * @param content new value (void* -> uint8_t*) to substitute with
547 * @param lgth new value length
548 * @param group group number of the Dicom Element to modify
549 * @param elem element number of the Dicom Element to modify
551 bool FileHelper::SetBinEntry(uint8_t *content, int lgth,
552 uint16_t group, uint16_t elem)
554 return FileInternal->SetBinEntry(content,lgth,group,elem);
558 * \brief Modifies the value of a given DocEntry (Dicom entry)
559 * when it exists. Create it with the given value when unexistant.
560 * @param content (string) Value to be set
561 * @param group Group number of the Entry
562 * @param elem Element number of the Entry
563 * \return pointer to the modified/created Dicom entry (NULL when creation
566 ValEntry *FileHelper::InsertValEntry(std::string const &content,
567 uint16_t group, uint16_t elem)
569 return FileInternal->InsertValEntry(content,group,elem);
573 * \brief Modifies the value of a given DocEntry (Dicom entry)
574 * when it exists. Create it with the given value when unexistant.
575 * A copy of the binArea is made to be kept in the Document.
576 * @param binArea (binary) value to be set
577 * @param group Group number of the Entry
578 * @param elem Element number of the Entry
579 * \return pointer to the modified/created Dicom entry (NULL when creation
582 BinEntry *FileHelper::InsertBinEntry(uint8_t *binArea, int lgth,
583 uint16_t group, uint16_t elem)
585 return FileInternal->InsertBinEntry(binArea,lgth,group,elem);
589 * \brief Modifies the value of a given DocEntry (Dicom entry)
590 * when it exists. Create it with the given value when unexistant.
591 * A copy of the binArea is made to be kept in the Document.
592 * @param group Group number of the Entry
593 * @param elem Element number of the Entry
594 * \return pointer to the modified/created Dicom entry (NULL when creation
597 SeqEntry *FileHelper::InsertSeqEntry(uint16_t group, uint16_t elem)
599 return FileInternal->InsertSeqEntry(group,elem);
603 * \brief Access to the underlying \ref PixelReadConverter RGBA LUT
605 uint8_t* FileHelper::GetLutRGBA()
607 return PixelReadConverter->GetLutRGBA();
610 //-----------------------------------------------------------------------------
614 * \brief Check the write integrity
616 * The tests made are :
617 * - verify the size of the image to write with the possible write
618 * when the user set an image data
619 * @return true if check is successfull
621 bool FileHelper::CheckWriteIntegrity()
623 if(PixelWriteConverter->GetUserData())
625 int numberBitsAllocated = FileInternal->GetBitsAllocated();
626 if ( numberBitsAllocated == 0 || numberBitsAllocated == 12 )
628 numberBitsAllocated = 16;
631 size_t decSize = FileInternal->GetXSize()
632 * FileInternal->GetYSize()
633 * FileInternal->GetZSize()
634 * ( numberBitsAllocated / 8 )
635 * FileInternal->GetSamplesPerPixel();
636 size_t rgbSize = decSize;
637 if( FileInternal->HasLUT() )
638 rgbSize = decSize * 3;
643 if( decSize!=PixelWriteConverter->GetUserDataSize() )
645 gdcmVerboseMacro( "Data size (Raw) is incorrect. Should be "
646 << decSize << " / Found :"
647 << PixelWriteConverter->GetUserDataSize() );
652 if( rgbSize!=PixelWriteConverter->GetUserDataSize() )
654 gdcmVerboseMacro( "Data size (RGB) is incorrect. Should be "
655 << decSize << " / Found "
656 << PixelWriteConverter->GetUserDataSize() );
669 void FileHelper::SetWriteToRaw()
671 if( FileInternal->GetNumberOfScalarComponents() == 3
672 && !FileInternal->HasLUT())
678 ValEntry *photInt = CopyValEntry(0x0028,0x0004);
679 if(FileInternal->HasLUT())
681 photInt->SetValue("PALETTE COLOR ");
685 photInt->SetValue("MONOCHROME1 ");
688 PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(),
689 PixelReadConverter->GetRawSize());
692 CopyBinEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel());
693 pixel->SetValue(GDCM_BINLOADED);
694 pixel->SetBinArea(PixelWriteConverter->GetData(),false);
695 pixel->SetLength(PixelWriteConverter->GetDataSize());
697 Archive->Push(photInt);
698 Archive->Push(pixel);
705 void FileHelper::SetWriteToRGB()
707 if(FileInternal->GetNumberOfScalarComponents()==3)
709 PixelReadConverter->BuildRGBImage();
711 ValEntry *spp = CopyValEntry(0x0028,0x0002);
714 ValEntry *planConfig = CopyValEntry(0x0028,0x0006);
715 planConfig->SetValue("0 ");
717 ValEntry *photInt = CopyValEntry(0x0028,0x0004);
718 photInt->SetValue("RGB ");
720 if(PixelReadConverter->GetRGB())
722 PixelWriteConverter->SetReadData(PixelReadConverter->GetRGB(),
723 PixelReadConverter->GetRGBSize());
727 PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(),
728 PixelReadConverter->GetRawSize());
732 CopyBinEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel());
733 pixel->SetValue(GDCM_BINLOADED);
734 pixel->SetBinArea(PixelWriteConverter->GetData(),false);
735 pixel->SetLength(PixelWriteConverter->GetDataSize());
738 Archive->Push(planConfig);
739 Archive->Push(photInt);
740 Archive->Push(pixel);
743 Archive->Push(0x0028,0x1101);
744 Archive->Push(0x0028,0x1102);
745 Archive->Push(0x0028,0x1103);
746 Archive->Push(0x0028,0x1201);
747 Archive->Push(0x0028,0x1202);
748 Archive->Push(0x0028,0x1203);
751 // Thus, we have a RGB image and the bits allocated = 24 and
752 // samples per pixels = 1 (in the read file)
753 if(FileInternal->GetBitsAllocated()==24)
755 ValEntry *bitsAlloc = CopyValEntry(0x0028,0x0100);
756 bitsAlloc->SetValue("8 ");
758 ValEntry *bitsStored = CopyValEntry(0x0028,0x0101);
759 bitsStored->SetValue("8 ");
761 ValEntry *highBit = CopyValEntry(0x0028,0x0102);
762 highBit->SetValue("7 ");
764 Archive->Push(bitsAlloc);
765 Archive->Push(bitsStored);
766 Archive->Push(highBit);
778 void FileHelper::RestoreWrite()
780 Archive->Restore(0x0028,0x0002);
781 Archive->Restore(0x0028,0x0004);
782 Archive->Restore(0x0028,0x0006);
783 Archive->Restore(GetFile()->GetGrPixel(),GetFile()->GetNumPixel());
785 // For old ACR-NEMA (24 bits problem)
786 Archive->Restore(0x0028,0x0100);
787 Archive->Restore(0x0028,0x0101);
788 Archive->Restore(0x0028,0x0102);
791 Archive->Restore(0x0028,0x1101);
792 Archive->Restore(0x0028,0x1102);
793 Archive->Restore(0x0028,0x1103);
794 Archive->Restore(0x0028,0x1201);
795 Archive->Restore(0x0028,0x1202);
796 Archive->Restore(0x0028,0x1203);
802 void FileHelper::SetWriteFileTypeToACR()
804 Archive->Push(0x0002,0x0010);
810 void FileHelper::SetWriteFileTypeToExplicitVR()
812 std::string ts = Util::DicomString(
813 Global::GetTS()->GetSpecialTransferSyntax(TS::ExplicitVRLittleEndian) );
815 ValEntry *tss = CopyValEntry(0x0002,0x0010);
824 void FileHelper::SetWriteFileTypeToImplicitVR()
826 std::string ts = Util::DicomString(
827 Global::GetTS()->GetSpecialTransferSyntax(TS::ImplicitVRLittleEndian) );
829 ValEntry *tss = CopyValEntry(0x0002,0x0010);
839 void FileHelper::RestoreWriteFileType()
841 Archive->Restore(0x0002,0x0010);
844 void FileHelper::SetWriteToLibido()
846 ValEntry *oldRow = dynamic_cast<ValEntry *>
847 (FileInternal->GetDocEntry(0x0028, 0x0010));
848 ValEntry *oldCol = dynamic_cast<ValEntry *>
849 (FileInternal->GetDocEntry(0x0028, 0x0011));
851 if( oldRow && oldCol )
853 std::string rows, columns;
855 ValEntry *newRow=new ValEntry(oldRow->GetDictEntry());
856 ValEntry *newCol=new ValEntry(oldCol->GetDictEntry());
858 newRow->Copy(oldCol);
859 newCol->Copy(oldRow);
861 newRow->SetValue(oldCol->GetValue());
862 newCol->SetValue(oldRow->GetValue());
864 Archive->Push(newRow);
865 Archive->Push(newCol);
868 ValEntry *libidoCode = CopyValEntry(0x0008,0x0010);
869 libidoCode->SetValue("ACRNEMA_LIBIDO_1.1");
870 Archive->Push(libidoCode);
876 void FileHelper::SetWriteToNoLibido()
878 ValEntry *recCode = dynamic_cast<ValEntry *>
879 (FileInternal->GetDocEntry(0x0008,0x0010));
882 if( recCode->GetValue() == "ACRNEMA_LIBIDO_1.1" )
884 ValEntry *libidoCode = CopyValEntry(0x0008,0x0010);
885 libidoCode->SetValue("");
886 Archive->Push(libidoCode);
894 void FileHelper::RestoreWriteOfLibido()
896 Archive->Restore(0x0028,0x0010);
897 Archive->Restore(0x0028,0x0011);
898 Archive->Restore(0x0008,0x0010);
901 ValEntry *FileHelper::CopyValEntry(uint16_t group,uint16_t elem)
903 DocEntry *oldE = FileInternal->GetDocEntry(group, elem);
908 newE = new ValEntry(oldE->GetDictEntry());
913 newE = GetFile()->NewValEntry(group,elem);
920 * \brief Modifies the value of a given Bin Entry (Dicom Element)
921 * when it exists. Create it with the given value when unexistant.
922 * @param group Group number of the Entry
923 * @param elem Element number of the Entry
924 * \return pointer to the modified/created Bin Entry (NULL when creation
927 BinEntry *FileHelper::CopyBinEntry(uint16_t group,uint16_t elem)
929 DocEntry *oldE = FileInternal->GetDocEntry(group, elem);
934 newE = new BinEntry(oldE->GetDictEntry());
939 newE = GetFile()->NewBinEntry(group,elem);
945 //-----------------------------------------------------------------------------
948 * \brief Factorization for various forms of constructors.
950 void FileHelper::Initialize()
952 WriteMode = WMODE_RAW;
953 WriteType = ExplicitVR;
955 PixelReadConverter = new PixelReadConvert;
956 PixelWriteConverter = new PixelWriteConvert;
957 Archive = new DocEntryArchive( FileInternal );
959 if ( FileInternal->IsReadable() )
961 PixelReadConverter->GrabInformationsFromFile( FileInternal );
968 uint8_t *FileHelper::GetRaw()
970 uint8_t *raw = PixelReadConverter->GetRaw();
973 // The Raw image migth not be loaded yet:
974 std::ifstream *fp = FileInternal->OpenFile();
975 PixelReadConverter->ReadAndDecompressPixelData( fp );
977 FileInternal->CloseFile();
979 raw = PixelReadConverter->GetRaw();
982 gdcmVerboseMacro( "Read/decompress of pixel data apparently went wrong.");
990 //-----------------------------------------------------------------------------
993 //-----------------------------------------------------------------------------
994 } // end namespace gdcm