1 /*=========================================================================
4 Module: $RCSfile: gdcmFileHelper.cxx,v $
6 Date: $Date: 2005/02/02 16:18:48 $
7 Version: $Revision: 1.11 $
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 group Group number of the Entry
178 * @param elem Element number of the Entry
179 * \return pointer to the modified/created Dicom entry (NULL when creation
182 BinEntry *FileHelper::InsertBinEntry(uint8_t *binArea, int lgth,
183 uint16_t group, uint16_t elem)
185 return FileInternal->InsertBinEntry(binArea,lgth,group,elem);
189 * \brief Modifies the value of a given DocEntry (Dicom entry)
190 * when it exists. Create it with the given value when unexistant.
191 * A copy of the binArea is made to be kept in the Document.
192 * @param group Group number of the Entry
193 * @param elem Element number of the Entry
194 * \return pointer to the modified/created Dicom entry (NULL when creation
197 SeqEntry *FileHelper::InsertSeqEntry(uint16_t group, uint16_t elem)
199 return FileInternal->InsertSeqEntry(group,elem);
203 * \brief Get the size of the image data
204 * If the image can be RGB (with a lut or by default), the size
205 * corresponds to the RGB image
206 * (use GetImageDataRawSize if you want to be sure to get *only*
207 * the size of the pixels)
208 * @return The image size
210 size_t FileHelper::GetImageDataSize()
212 if ( PixelWriteConverter->GetUserData() )
214 return PixelWriteConverter->GetUserDataSize();
217 return PixelReadConverter->GetRGBSize();
221 * \brief Get the size of the image data
222 * If the image could be converted to RGB using a LUT,
223 * this transformation is not taken into account by GetImageDataRawSize
224 * (use GetImageDataSize if you wish)
225 * @return The raw image size
227 size_t FileHelper::GetImageDataRawSize()
229 if ( PixelWriteConverter->GetUserData() )
231 return PixelWriteConverter->GetUserDataSize();
234 return PixelReadConverter->GetRawSize();
238 * \brief - Allocates necessary memory,
239 * - Reads the pixels from disk (uncompress if necessary),
240 * - Transforms YBR pixels, if any, into RGB pixels
241 * - Transforms 3 planes R, G, B, if any, into a single RGB Plane
242 * - Transforms single Grey plane + 3 Palettes into a RGB Plane
243 * - Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
244 * @return Pointer to newly allocated pixel data.
245 * NULL if alloc fails
247 uint8_t *FileHelper::GetImageData()
249 if ( PixelWriteConverter->GetUserData() )
251 return PixelWriteConverter->GetUserData();
256 // If the decompression failed nothing can be done.
260 if ( FileInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
262 return PixelReadConverter->GetRGB();
266 // When no LUT or LUT conversion fails, return the Raw
267 return PixelReadConverter->GetRaw();
272 * \brief Allocates necessary memory,
273 * Transforms YBR pixels (if any) into RGB pixels
274 * Transforms 3 planes R, G, B (if any) into a single RGB Plane
275 * Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
276 * DOES NOT transform Grey plane + 3 Palettes into a RGB Plane
277 * @return Pointer to newly allocated pixel data.
278 * \ NULL if alloc fails
280 uint8_t *FileHelper::GetImageDataRaw ()
287 * Read the pixels from disk (uncompress if necessary),
288 * Transforms YBR pixels, if any, into RGB pixels
289 * Transforms 3 planes R, G, B, if any, into a single RGB Plane
290 * Transforms single Grey plane + 3 Palettes into a RGB Plane
291 * Copies at most MaxSize bytes of pixel data to caller allocated
293 * \warning This function allows people that want to build a volume
294 * from an image stack *not to* have, first to get the image pixels,
295 * and then move them to the volume area.
296 * It's absolutely useless for any VTK user since vtk chooses
297 * to invert the lines of an image, that is the last line comes first
298 * (for some axis related reasons?). Hence he will have
299 * to load the image line by line, starting from the end.
300 * VTK users have to call GetImageData
302 * @param destination Address (in caller's memory space) at which the
303 * pixel data should be copied
304 * @param maxSize Maximum number of bytes to be copied. When MaxSize
305 * is not sufficient to hold the pixel data the copy is not
306 * executed (i.e. no partial copy).
307 * @return On success, the number of bytes actually copied. Zero on
308 * failure e.g. MaxSize is lower than necessary.
310 size_t FileHelper::GetImageDataIntoVector (void *destination, size_t maxSize)
314 // If the decompression failed nothing can be done.
318 if ( FileInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
320 if ( PixelReadConverter->GetRGBSize() > maxSize )
322 gdcmVerboseMacro( "Pixel data bigger than caller's expected MaxSize");
326 (void*)PixelReadConverter->GetRGB(),
327 PixelReadConverter->GetRGBSize() );
328 return PixelReadConverter->GetRGBSize();
331 // Either no LUT conversion necessary or LUT conversion failed
332 if ( PixelReadConverter->GetRawSize() > maxSize )
334 gdcmVerboseMacro( "Pixel data bigger than caller's expected MaxSize");
338 (void*)PixelReadConverter->GetRaw(),
339 PixelReadConverter->GetRawSize() );
340 return PixelReadConverter->GetRawSize();
344 * \brief Points the internal pointer to the callers inData
345 * image representation, BUT WITHOUT COPYING THE DATA.
346 * 'image' Pixels are presented as C-like 2D arrays : line per line.
347 * 'volume'Pixels are presented as C-like 3D arrays : plane per plane
348 * \warning Since the pixels are not copied, it is the caller's responsability
349 * not to deallocate its data before gdcm uses them (e.g. with
350 * the Write() method.
351 * @param inData user supplied pixel area
352 * @param expectedSize total image size, in Bytes
356 void FileHelper::SetImageData(uint8_t *inData, size_t expectedSize)
358 SetUserData(inData,expectedSize);
362 * \brief Set the image data defined by the user
363 * \warning When writting the file, this data are get as default data to write
365 void FileHelper::SetUserData(uint8_t *data, size_t expectedSize)
367 PixelWriteConverter->SetUserData(data,expectedSize);
371 * \brief Get the image data defined by the user
372 * \warning When writting the file, this data are get as default data to write
374 uint8_t *FileHelper::GetUserData()
376 return PixelWriteConverter->GetUserData();
380 * \brief Get the image data size defined by the user
381 * \warning When writting the file, this data are get as default data to write
383 size_t FileHelper::GetUserDataSize()
385 return PixelWriteConverter->GetUserDataSize();
389 * \brief Get the image data from the file.
390 * If a LUT is found, the data are expanded to be RGB
392 uint8_t *FileHelper::GetRGBData()
394 return PixelReadConverter->GetRGB();
398 * \brief Get the image data size from the file.
399 * If a LUT is found, the data are expanded to be RGB
401 size_t FileHelper::GetRGBDataSize()
403 return PixelReadConverter->GetRGBSize();
407 * \brief Get the image data from the file.
408 * If a LUT is found, the data are not expanded !
410 uint8_t *FileHelper::GetRawData()
412 return PixelReadConverter->GetRaw();
416 * \brief Get the image data size from the file.
417 * If a LUT is found, the data are not expanded !
419 size_t FileHelper::GetRawDataSize()
421 return PixelReadConverter->GetRawSize();
425 * \brief Access to the underlying \ref PixelReadConverter RGBA LUT
427 uint8_t* FileHelper::GetLutRGBA()
429 return PixelReadConverter->GetLutRGBA();
433 * \brief Writes on disk A SINGLE Dicom file
434 * NO test is performed on processor "Endiannity".
435 * It's up to the user to call his Reader properly
436 * @param fileName name of the file to be created
437 * (any already existing file is over written)
438 * @return false if write fails
440 bool FileHelper::WriteRawData(std::string const &fileName)
442 std::ofstream fp1(fileName.c_str(), std::ios::out | std::ios::binary );
445 gdcmVerboseMacro( "Fail to open (write) file:" << fileName.c_str());
449 if( PixelWriteConverter->GetUserData() )
451 fp1.write( (char*)PixelWriteConverter->GetUserData(),
452 PixelWriteConverter->GetUserDataSize() );
454 else if ( PixelReadConverter->GetRGB() )
456 fp1.write( (char*)PixelReadConverter->GetRGB(),
457 PixelReadConverter->GetRGBSize());
459 else if ( PixelReadConverter->GetRaw() )
461 fp1.write( (char*)PixelReadConverter->GetRaw(),
462 PixelReadConverter->GetRawSize());
466 gdcmErrorMacro( "Nothing written." );
475 * \brief Writes on disk A SINGLE Dicom file,
476 * using the Implicit Value Representation convention
477 * NO test is performed on processor "Endiannity".
478 * @param fileName name of the file to be created
479 * (any already existing file is overwritten)
480 * @return false if write fails
483 bool FileHelper::WriteDcmImplVR (std::string const &fileName)
485 SetWriteTypeToDcmImplVR();
486 return Write(fileName);
490 * \brief Writes on disk A SINGLE Dicom file,
491 * using the Explicit Value Representation convention
492 * NO test is performed on processor "Endiannity".
493 * @param fileName name of the file to be created
494 * (any already existing file is overwritten)
495 * @return false if write fails
498 bool FileHelper::WriteDcmExplVR (std::string const &fileName)
500 SetWriteTypeToDcmExplVR();
501 return Write(fileName);
505 * \brief Writes on disk A SINGLE Dicom file,
506 * using the ACR-NEMA convention
507 * NO test is performed on processor "Endiannity".
508 * (a l'attention des logiciels cliniques
509 * qui ne prennent en entrée QUE des images ACR ...
510 * \warning if a DICOM_V3 header is supplied,
511 * groups < 0x0008 and shadow groups are ignored
512 * \warning NO TEST is performed on processor "Endiannity".
513 * @param fileName name of the file to be created
514 * (any already existing file is overwritten)
515 * @return false if write fails
518 bool FileHelper::WriteAcr (std::string const &fileName)
521 return Write(fileName);
525 * \brief Writes on disk A SINGLE Dicom file,
526 * @param fileName name of the file to be created
527 * (any already existing file is overwritten)
528 * @return false if write fails
530 bool FileHelper::Write(std::string const &fileName)
535 SetWriteFileTypeToImplicitVR();
538 SetWriteFileTypeToExplicitVR();
542 SetWriteFileTypeToACR();
545 SetWriteFileTypeToExplicitVR();
548 // --------------------------------------------------------------
549 // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
551 // if recognition code tells us we dealt with a LibIDO image
552 // we reproduce on disk the switch between lineNumber and columnNumber
553 // just before writting ...
554 /// \todo the best trick would be *change* the recognition code
555 /// but pb expected if user deals with, e.g. COMPLEX images
556 if( WriteType == ACR_LIBIDO )
562 SetWriteToNoLibido();
564 // ----------------- End of Special Patch ----------------
576 bool check = CheckWriteIntegrity();
579 check = FileInternal->Write(fileName,WriteType);
583 RestoreWriteFileType();
585 // --------------------------------------------------------------
586 // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
588 // ...and we restore the header to be Dicom Compliant again
589 // just after writting
590 RestoreWriteOfLibido();
591 // ----------------- End of Special Patch ----------------
596 //-----------------------------------------------------------------------------
599 * \brief Check the write integrity
601 * The tests made are :
602 * - verify the size of the image to write with the possible write
603 * when the user set an image data
604 * @return true if check is successfull
606 bool FileHelper::CheckWriteIntegrity()
608 if(PixelWriteConverter->GetUserData())
610 int numberBitsAllocated = FileInternal->GetBitsAllocated();
611 if ( numberBitsAllocated == 0 || numberBitsAllocated == 12 )
613 numberBitsAllocated = 16;
616 size_t decSize = FileInternal->GetXSize()
617 * FileInternal->GetYSize()
618 * FileInternal->GetZSize()
619 * ( numberBitsAllocated / 8 )
620 * FileInternal->GetSamplesPerPixel();
621 size_t rgbSize = decSize;
622 if( FileInternal->HasLUT() )
623 rgbSize = decSize * 3;
628 if( decSize!=PixelWriteConverter->GetUserDataSize() )
630 gdcmVerboseMacro( "Data size (Raw) is incorrect. Should be "
631 << decSize << " / Found :"
632 << PixelWriteConverter->GetUserDataSize() );
637 if( rgbSize!=PixelWriteConverter->GetUserDataSize() )
639 gdcmVerboseMacro( "Data size (RGB) is incorrect. Should be "
640 << decSize << " / Found "
641 << PixelWriteConverter->GetUserDataSize() );
652 * \brief Update the File to write RAW datas
654 void FileHelper::SetWriteToRaw()
656 if( FileInternal->GetNumberOfScalarComponents() == 3
657 && !FileInternal->HasLUT())
663 ValEntry *photInt = CopyValEntry(0x0028,0x0004);
664 if(FileInternal->HasLUT())
666 photInt->SetValue("PALETTE COLOR ");
670 photInt->SetValue("MONOCHROME1 ");
673 PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(),
674 PixelReadConverter->GetRawSize());
677 CopyBinEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel());
678 pixel->SetValue(GDCM_BINLOADED);
679 pixel->SetBinArea(PixelWriteConverter->GetData(),false);
680 pixel->SetLength(PixelWriteConverter->GetDataSize());
682 Archive->Push(photInt);
683 Archive->Push(pixel);
688 * \brief Update the File to write RGB datas
690 void FileHelper::SetWriteToRGB()
692 if(FileInternal->GetNumberOfScalarComponents()==3)
694 PixelReadConverter->BuildRGBImage();
696 ValEntry *spp = CopyValEntry(0x0028,0x0002);
699 ValEntry *planConfig = CopyValEntry(0x0028,0x0006);
700 planConfig->SetValue("0 ");
702 ValEntry *photInt = CopyValEntry(0x0028,0x0004);
703 photInt->SetValue("RGB ");
705 if(PixelReadConverter->GetRGB())
707 PixelWriteConverter->SetReadData(PixelReadConverter->GetRGB(),
708 PixelReadConverter->GetRGBSize());
712 PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(),
713 PixelReadConverter->GetRawSize());
717 CopyBinEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel());
718 pixel->SetValue(GDCM_BINLOADED);
719 pixel->SetBinArea(PixelWriteConverter->GetData(),false);
720 pixel->SetLength(PixelWriteConverter->GetDataSize());
723 Archive->Push(planConfig);
724 Archive->Push(photInt);
725 Archive->Push(pixel);
728 Archive->Push(0x0028,0x1101);
729 Archive->Push(0x0028,0x1102);
730 Archive->Push(0x0028,0x1103);
731 Archive->Push(0x0028,0x1201);
732 Archive->Push(0x0028,0x1202);
733 Archive->Push(0x0028,0x1203);
736 // Thus, we have a RGB image and the bits allocated = 24 and
737 // samples per pixels = 1 (in the read file)
738 if(FileInternal->GetBitsAllocated()==24)
740 ValEntry *bitsAlloc = CopyValEntry(0x0028,0x0100);
741 bitsAlloc->SetValue("8 ");
743 ValEntry *bitsStored = CopyValEntry(0x0028,0x0101);
744 bitsStored->SetValue("8 ");
746 ValEntry *highBit = CopyValEntry(0x0028,0x0102);
747 highBit->SetValue("7 ");
749 Archive->Push(bitsAlloc);
750 Archive->Push(bitsStored);
751 Archive->Push(highBit);
761 * \brief Restore the File write mode
763 void FileHelper::RestoreWrite()
765 Archive->Restore(0x0028,0x0002);
766 Archive->Restore(0x0028,0x0004);
767 Archive->Restore(0x0028,0x0006);
768 Archive->Restore(GetFile()->GetGrPixel(),GetFile()->GetNumPixel());
770 // For old ACR-NEMA (24 bits problem)
771 Archive->Restore(0x0028,0x0100);
772 Archive->Restore(0x0028,0x0101);
773 Archive->Restore(0x0028,0x0102);
776 Archive->Restore(0x0028,0x1101);
777 Archive->Restore(0x0028,0x1102);
778 Archive->Restore(0x0028,0x1103);
779 Archive->Restore(0x0028,0x1201);
780 Archive->Restore(0x0028,0x1202);
781 Archive->Restore(0x0028,0x1203);
785 * \brief Set in the File the write type to ACR
787 void FileHelper::SetWriteFileTypeToACR()
789 Archive->Push(0x0002,0x0010);
793 * \brief Set in the File the write type to Explicit VR
795 void FileHelper::SetWriteFileTypeToExplicitVR()
797 std::string ts = Util::DicomString(
798 Global::GetTS()->GetSpecialTransferSyntax(TS::ExplicitVRLittleEndian) );
800 ValEntry *tss = CopyValEntry(0x0002,0x0010);
807 * \brief Set in the File the write type to Implicit VR
809 void FileHelper::SetWriteFileTypeToImplicitVR()
811 std::string ts = Util::DicomString(
812 Global::GetTS()->GetSpecialTransferSyntax(TS::ImplicitVRLittleEndian) );
814 ValEntry *tss = CopyValEntry(0x0002,0x0010);
822 * \brief Restore in the File the write type
824 void FileHelper::RestoreWriteFileType()
826 Archive->Restore(0x0002,0x0010);
830 * \brief Set the Write not to Libido format
832 void FileHelper::SetWriteToLibido()
834 ValEntry *oldRow = dynamic_cast<ValEntry *>
835 (FileInternal->GetDocEntry(0x0028, 0x0010));
836 ValEntry *oldCol = dynamic_cast<ValEntry *>
837 (FileInternal->GetDocEntry(0x0028, 0x0011));
839 if( oldRow && oldCol )
841 std::string rows, columns;
843 ValEntry *newRow=new ValEntry(oldRow->GetDictEntry());
844 ValEntry *newCol=new ValEntry(oldCol->GetDictEntry());
846 newRow->Copy(oldCol);
847 newCol->Copy(oldRow);
849 newRow->SetValue(oldCol->GetValue());
850 newCol->SetValue(oldRow->GetValue());
852 Archive->Push(newRow);
853 Archive->Push(newCol);
856 ValEntry *libidoCode = CopyValEntry(0x0008,0x0010);
857 libidoCode->SetValue("ACRNEMA_LIBIDO_1.1");
858 Archive->Push(libidoCode);
862 * \brief Set the Write not to No Libido format
864 void FileHelper::SetWriteToNoLibido()
866 ValEntry *recCode = dynamic_cast<ValEntry *>
867 (FileInternal->GetDocEntry(0x0008,0x0010));
870 if( recCode->GetValue() == "ACRNEMA_LIBIDO_1.1" )
872 ValEntry *libidoCode = CopyValEntry(0x0008,0x0010);
873 libidoCode->SetValue("");
874 Archive->Push(libidoCode);
880 * \brief Restore the Write format
882 void FileHelper::RestoreWriteOfLibido()
884 Archive->Restore(0x0028,0x0010);
885 Archive->Restore(0x0028,0x0011);
886 Archive->Restore(0x0008,0x0010);
890 * \brief Copy a ValEntry content
891 * @param group Group number of the Entry
892 * @param elem Element number of the Entry
893 * \return pointer to the modified/created Val Entry (NULL when creation
896 ValEntry *FileHelper::CopyValEntry(uint16_t group,uint16_t elem)
898 DocEntry *oldE = FileInternal->GetDocEntry(group, elem);
903 newE = new ValEntry(oldE->GetDictEntry());
908 newE = GetFile()->NewValEntry(group,elem);
915 * \brief Modifies the value of a given Bin Entry (Dicom Element)
916 * when it exists. Create it with the given value when unexistant.
917 * @param group Group number of the Entry
918 * @param elem Element number of the Entry
919 * \return pointer to the modified/created Bin Entry (NULL when creation
922 BinEntry *FileHelper::CopyBinEntry(uint16_t group,uint16_t elem)
924 DocEntry *oldE = FileInternal->GetDocEntry(group, elem);
929 newE = new BinEntry(oldE->GetDictEntry());
934 newE = GetFile()->NewBinEntry(group,elem);
940 //-----------------------------------------------------------------------------
943 * \brief Factorization for various forms of constructors.
945 void FileHelper::Initialize()
947 WriteMode = WMODE_RAW;
948 WriteType = ExplicitVR;
950 PixelReadConverter = new PixelReadConvert;
951 PixelWriteConverter = new PixelWriteConvert;
952 Archive = new DocEntryArchive( FileInternal );
954 if ( FileInternal->IsReadable() )
956 PixelReadConverter->GrabInformationsFromFile( FileInternal );
963 uint8_t *FileHelper::GetRaw()
965 uint8_t *raw = PixelReadConverter->GetRaw();
968 // The Raw image migth not be loaded yet:
969 std::ifstream *fp = FileInternal->OpenFile();
970 PixelReadConverter->ReadAndDecompressPixelData( fp );
972 FileInternal->CloseFile();
974 raw = PixelReadConverter->GetRaw();
977 gdcmVerboseMacro( "Read/decompress of pixel data apparently went wrong.");
985 //-----------------------------------------------------------------------------
987 void FileHelper::Print(std::ostream &os, std::string const &)
989 FileInternal->SetPrintLevel(PrintLevel);
990 FileInternal->Print(os);
992 PixelReadConverter->SetPrintLevel(PrintLevel);
993 PixelReadConverter->Print(os);
996 //-----------------------------------------------------------------------------
997 } // end namespace gdcm