1 /*=========================================================================
4 Module: $RCSfile: gdcmFileHelper.cxx,v $
7 Date: $Date: 2005/07/11 08:30:39 $
8 Version: $Revision: 1.48 $
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 "gdcmBinEntry.h"
27 #include "gdcmValEntry.h"
28 #include "gdcmSeqEntry.h"
29 #include "gdcmSQItem.h"
30 #include "gdcmContentEntry.h"
32 #include "gdcmPixelReadConvert.h"
33 #include "gdcmPixelWriteConvert.h"
34 #include "gdcmDocEntryArchive.h"
35 #include "gdcmDictSet.h"
40 // ----------------------------- WARNING -------------------------
42 These lines will be moved to the document-to-be 'User's Guide'
44 // To read an image, user needs a gdcm::File
45 gdcm::File *f1 = new gdcm::File(fileName);
46 // user can now check some values
47 std::string v = f1->GetEntryValue(groupNb,ElementNb);
48 // to get the pixels, user needs a gdcm::FileHelper
49 gdcm::FileHelper *fh1 = new gdcm::FileHelper(f1);
50 // user may ask not to convert Palette to RGB
51 uint8_t *pixels = fh1->GetImageDataRaw();
52 int imageLength = fh1->GetImageDataRawSize();
53 // He can now use the pixels, create a new image, ...
54 uint8_t *userPixels = ...
56 To re-write the image, user re-uses the gdcm::FileHelper
58 fh1->SetImageData( userPixels, userPixelsLength);
59 fh1->SetTypeToRaw(); // Even if it was possible to convert Palette to RGB
62 fh1->SetWriteTypeToDcmExpl(); // he wants Explicit Value Representation
63 // Little Endian is the default
64 // no other value is allowed
65 (-->SetWriteType(ExplicitVR);)
66 -->WriteType = ExplicitVR;
67 fh1->Write(newFileName); // overwrites the file, if any
70 fh1->WriteDcmExplVR(newFileName);
73 // ----------------------------- WARNING -------------------------
75 These lines will be moved to the document-to-be 'Developer's Guide'
77 WriteMode : WMODE_RAW / WMODE_RGB
78 WriteType : ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO
80 fh1->Write(newFileName);
81 SetWriteFileTypeToImplicitVR() / SetWriteFileTypeToExplicitVR();
82 (modifies TransferSyntax)
83 SetWriteToRaw(); / SetWriteToRGB();
84 (modifies, when necessary : photochromatic interpretation,
85 samples per pixel, Planar configuration,
86 bits allocated, bits stored, high bit -ACR 24 bits-
87 Pixels element VR, pushes out the LUT )
88 CheckWriteIntegrity();
89 (checks user given pixels length)
90 FileInternal->Write(fileName,WriteType)
91 fp = opens file(fileName);
92 ComputeGroup0002Length(writetype);
94 RemoveEntryNoDestroy(palettes, etc)
95 Document::WriteContent(fp, writetype);
97 (moves back to the File all the archived elements)
98 RestoreWriteFileType();
99 (pushes back group 0002, with TransferSyntax)
107 //-------------------------------------------------------------------------
108 // Constructor / Destructor
110 * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
111 * file (gdcm::File only deals with the ... header)
112 * Opens (in read only and when possible) an existing file and checks
113 * for DICOM compliance. Returns NULL on failure.
114 * It will be up to the user to load the pixels into memory
115 * \note the in-memory representation of all available tags found in
116 * the DICOM header is post-poned to first header information access.
117 * This avoid a double parsing of public part of the header when
118 * one sets an a posteriori shadow dictionary (efficiency can be
119 * seen as a side effect).
121 FileHelper::FileHelper( )
123 FileInternal = new File( );
129 * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
130 * file (File only deals with the ... header)
131 * Opens (in read only and when possible) an existing file and checks
132 * for DICOM compliance. Returns NULL on failure.
133 * It will be up to the user to load the pixels into memory
134 * \note the in-memory representation of all available tags found in
135 * the DICOM header is post-poned to first header information access.
136 * This avoid a double parsing of public part of the header when
137 * user sets an a posteriori shadow dictionary (efficiency can be
138 * seen as a side effect).
139 * @param header already built Header
141 FileHelper::FileHelper(File *header)
143 FileInternal = header;
149 * \brief DEPRECATED : use SetFilename() + Load() methods
150 * Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
151 * file (gdcm::File only deals with the ... header)
152 * Opens (in read only and when possible) an existing file and checks
153 * for DICOM compliance. Returns NULL on failure.
154 * It will be up to the user to load the pixels into memory
155 * \note the in-memory representation of all available tags found in
156 * the DICOM header is post-poned to first header information access.
157 * This avoid a double parsing of public part of the header when
158 * one sets an a posteriori shadow dictionary (efficiency can be
159 * seen as a side effect).
160 * @param filename file to be opened for parsing
162 FileHelper::FileHelper(std::string const &filename )
164 FileInternal = new File( filename );
170 * \brief canonical destructor
171 * \note If the header (gdcm::File) was created by the FileHelper constructor,
172 * it is destroyed by the FileHelper
174 FileHelper::~FileHelper()
176 if ( PixelReadConverter )
178 delete PixelReadConverter;
180 if ( PixelWriteConverter )
182 delete PixelWriteConverter;
196 //-----------------------------------------------------------------------------
200 * \brief Sets the LoadMode of the internal gdcm::File as a boolean string.
201 * NO_SEQ, NO_SHADOW, NO_SHADOWSEQ
202 *... (nothing more, right now)
203 * WARNING : before using NO_SHADOW, be sure *all* your files
204 * contain accurate values in the 0x0000 element (if any)
205 * of *each* Shadow Group. The parser will fail if the size is wrong !
206 * @param loadMode Load mode to be used
208 void FileHelper::SetLoadMode(int loadMode)
210 GetFile()->SetLoadMode( loadMode );
213 * \brief Sets the LoadMode of the internal gdcm::File
214 * @param fileName name of the file to be open
216 void FileHelper::SetFileName(std::string const &fileName)
218 FileInternal->SetFileName( fileName );
223 * @return false if file cannot be open or no swap info was found,
224 * or no tag was found.
226 bool FileHelper::Load()
228 return FileInternal->Load();
232 * \brief Accesses an existing DocEntry (i.e. a Dicom Element)
233 * through it's (group, element) and modifies it's content with
235 * @param content new value (string) to substitute with
236 * @param group group number of the Dicom Element to modify
237 * @param elem element number of the Dicom Element to modify
238 * \return false if DocEntry not found
240 bool FileHelper::SetValEntry(std::string const &content,
241 uint16_t group, uint16_t elem)
243 return FileInternal->SetValEntry(content, group, elem);
248 * \brief Accesses an existing DocEntry (i.e. a Dicom Element)
249 * through it's (group, element) and modifies it's content with
251 * @param content new value (void* -> uint8_t*) to substitute with
252 * @param lgth new value length
253 * @param group group number of the Dicom Element to modify
254 * @param elem element number of the Dicom Element to modify
255 * \return false if DocEntry not found
257 bool FileHelper::SetBinEntry(uint8_t *content, int lgth,
258 uint16_t group, uint16_t elem)
260 return FileInternal->SetBinEntry(content, lgth, group, elem);
264 * \brief Modifies the value of a given DocEntry (Dicom entry)
265 * when it exists. Creates it with the given value when unexistant.
266 * @param content (string)value to be set
267 * @param group Group number of the Entry
268 * @param elem Element number of the Entry
269 * \return pointer to the modified/created Dicom entry (NULL when creation
272 ValEntry *FileHelper::InsertValEntry(std::string const &content,
273 uint16_t group, uint16_t elem)
275 return FileInternal->InsertValEntry(content, group, elem);
279 * \brief Modifies the value of a given DocEntry (Dicom entry)
280 * when it exists. Creates it with the given value when unexistant.
281 * A copy of the binArea is made to be kept in the Document.
282 * @param binArea (binary)value to be set
283 * @param lgth new value length
284 * @param group Group number of the Entry
285 * @param elem Element number of the Entry
286 * \return pointer to the modified/created Dicom entry (NULL when creation
289 BinEntry *FileHelper::InsertBinEntry(uint8_t *binArea, int lgth,
290 uint16_t group, uint16_t elem)
292 return FileInternal->InsertBinEntry(binArea, lgth, group, elem);
296 * \brief Modifies the value of a given DocEntry (Dicom entry)
297 * when it exists. Creates it, empty (?!) when unexistant.
298 * @param group Group number of the Entry
299 * @param elem Element number of the Entry
300 * \return pointer to the modified/created Dicom entry (NULL when creation
303 SeqEntry *FileHelper::InsertSeqEntry(uint16_t group, uint16_t elem)
305 return FileInternal->InsertSeqEntry(group, elem);
309 * \brief Get the size of the image data
310 * If the image can be RGB (with a lut or by default), the size
311 * corresponds to the RGB image
312 * (use GetImageDataRawSize if you want to be sure to get *only*
313 * the size of the pixels)
314 * @return The image size
316 size_t FileHelper::GetImageDataSize()
318 if ( PixelWriteConverter->GetUserData() )
320 return PixelWriteConverter->GetUserDataSize();
322 return PixelReadConverter->GetRGBSize();
326 * \brief Get the size of the image data
327 * If the image could be converted to RGB using a LUT,
328 * this transformation is not taken into account by GetImageDataRawSize
329 * (use GetImageDataSize if you wish)
330 * @return The raw image size
332 size_t FileHelper::GetImageDataRawSize()
334 if ( PixelWriteConverter->GetUserData() )
336 return PixelWriteConverter->GetUserDataSize();
338 return PixelReadConverter->GetRawSize();
342 * \brief - Allocates necessary memory,
343 * - Reads the pixels from disk (uncompress if necessary),
344 * - Transforms YBR pixels, if any, into RGB pixels,
345 * - Transforms 3 planes R, G, B, if any, into a single RGB Plane
346 * - Transforms single Grey plane + 3 Palettes into a RGB Plane
347 * - Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
348 * @return Pointer to newly allocated pixel data.
349 * NULL if alloc fails
351 uint8_t *FileHelper::GetImageData()
353 if ( PixelWriteConverter->GetUserData() )
355 return PixelWriteConverter->GetUserData();
360 // If the decompression failed nothing can be done.
364 if ( FileInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
366 return PixelReadConverter->GetRGB();
370 // When no LUT or LUT conversion fails, return the Raw
371 return PixelReadConverter->GetRaw();
376 * \brief Allocates necessary memory,
377 * Transforms YBR pixels (if any) into RGB pixels
378 * Transforms 3 planes R, G, B (if any) into a single RGB Plane
379 * Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
380 * DOES NOT transform Grey plane + 3 Palettes into a RGB Plane
381 * @return Pointer to newly allocated pixel data.
382 * NULL if alloc fails
384 uint8_t *FileHelper::GetImageDataRaw ()
391 * Read the pixels from disk (uncompress if necessary),
392 * Transforms YBR pixels, if any, into RGB pixels
393 * Transforms 3 planes R, G, B, if any, into a single RGB Plane
394 * Transforms single Grey plane + 3 Palettes into a RGB Plane
395 * Copies at most MaxSize bytes of pixel data to caller allocated
397 * \warning This function allows people that want to build a volume
398 * from an image stack *not to* have, first to get the image pixels,
399 * and then move them to the volume area.
400 * It's absolutely useless for any VTK user since vtk chooses
401 * to invert the lines of an image, that is the last line comes first
402 * (for some axis related reasons?). Hence he will have
403 * to load the image line by line, starting from the end.
404 * VTK users have to call GetImageData
406 * @param destination Address (in caller's memory space) at which the
407 * pixel data should be copied
408 * @param maxSize Maximum number of bytes to be copied. When MaxSize
409 * is not sufficient to hold the pixel data the copy is not
410 * executed (i.e. no partial copy).
411 * @return On success, the number of bytes actually copied. Zero on
412 * failure e.g. MaxSize is lower than necessary.
414 size_t FileHelper::GetImageDataIntoVector (void *destination, size_t maxSize)
418 // If the decompression failed nothing can be done.
422 if ( FileInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
424 if ( PixelReadConverter->GetRGBSize() > maxSize )
426 gdcmWarningMacro( "Pixel data bigger than caller's expected MaxSize");
430 (void*)PixelReadConverter->GetRGB(),
431 PixelReadConverter->GetRGBSize() );
432 return PixelReadConverter->GetRGBSize();
435 // Either no LUT conversion necessary or LUT conversion failed
436 if ( PixelReadConverter->GetRawSize() > maxSize )
438 gdcmWarningMacro( "Pixel data bigger than caller's expected MaxSize");
442 (void *)PixelReadConverter->GetRaw(),
443 PixelReadConverter->GetRawSize() );
444 return PixelReadConverter->GetRawSize();
448 * \brief Points the internal pointer to the callers inData
449 * image representation, BUT WITHOUT COPYING THE DATA.
450 * 'image' Pixels are presented as C-like 2D arrays : line per line.
451 * 'volume'Pixels are presented as C-like 3D arrays : plane per plane
452 * \warning Since the pixels are not copied, it is the caller's responsability
453 * not to deallocate its data before gdcm uses them (e.g. with
454 * the Write() method )
455 * @param inData user supplied pixel area (uint8_t* is just for the compiler.
456 * user is allowed to pass any kind of pixelsn since the size is
458 * @param expectedSize total image size, *in Bytes*
460 void FileHelper::SetImageData(uint8_t *inData, size_t expectedSize)
462 SetUserData(inData, expectedSize);
466 * \brief Set the image data defined by the user
467 * \warning When writting the file, this data are get as default data to write
468 * @param inData user supplied pixel area (uint8_t* is just for the compiler.
469 * user is allowed to pass any kind of pixels since the size is
471 * @param expectedSize total image size, *in Bytes*
473 void FileHelper::SetUserData(uint8_t *inData, size_t expectedSize)
475 PixelWriteConverter->SetUserData(inData, expectedSize);
479 * \brief Get the image data defined by the user
480 * \warning When writting the file, this data are get as default data to write
482 uint8_t *FileHelper::GetUserData()
484 return PixelWriteConverter->GetUserData();
488 * \brief Get the image data size defined by the user
489 * \warning When writting the file, this data are get as default data to write
491 size_t FileHelper::GetUserDataSize()
493 return PixelWriteConverter->GetUserDataSize();
497 * \brief Get the image data from the file.
498 * If a LUT is found, the data are expanded to be RGB
500 uint8_t *FileHelper::GetRGBData()
502 return PixelReadConverter->GetRGB();
506 * \brief Get the image data size from the file.
507 * If a LUT is found, the data are expanded to be RGB
509 size_t FileHelper::GetRGBDataSize()
511 return PixelReadConverter->GetRGBSize();
515 * \brief Get the image data from the file.
516 * Even when a LUT is found, the data are not expanded to RGB!
518 uint8_t *FileHelper::GetRawData()
520 return PixelReadConverter->GetRaw();
524 * \brief Get the image data size from the file.
525 * Even when a LUT is found, the data are not expanded to RGB!
527 size_t FileHelper::GetRawDataSize()
529 return PixelReadConverter->GetRawSize();
533 * \brief Access to the underlying \ref PixelReadConverter RGBA LUT
535 uint8_t* FileHelper::GetLutRGBA()
537 if ( PixelReadConverter->GetLutRGBA() ==0 )
538 PixelReadConverter->BuildLUTRGBA();
539 return PixelReadConverter->GetLutRGBA();
543 * \brief Access to the underlying \ref PixelReadConverter RGBA LUT Item Number
545 int FileHelper::GetLutItemNumber()
547 return PixelReadConverter->GetLutItemNumber();
551 * \brief Access to the underlying \ref PixelReadConverter RGBA LUT Item Size
553 int FileHelper::GetLutItemSize()
555 return PixelReadConverter->GetLutItemSize();
559 * \brief Writes on disk A SINGLE Dicom file
560 * NO test is performed on processor "Endiannity".
561 * It's up to the user to call his Reader properly
562 * @param fileName name of the file to be created
563 * (any already existing file is over written)
564 * @return false if write fails
566 bool FileHelper::WriteRawData(std::string const &fileName)
568 std::ofstream fp1(fileName.c_str(), std::ios::out | std::ios::binary );
571 gdcmWarningMacro( "Fail to open (write) file:" << fileName.c_str());
575 if ( PixelWriteConverter->GetUserData() )
577 fp1.write( (char *)PixelWriteConverter->GetUserData(),
578 PixelWriteConverter->GetUserDataSize() );
580 else if ( PixelReadConverter->GetRGB() )
582 fp1.write( (char *)PixelReadConverter->GetRGB(),
583 PixelReadConverter->GetRGBSize());
585 else if ( PixelReadConverter->GetRaw() )
587 fp1.write( (char *)PixelReadConverter->GetRaw(),
588 PixelReadConverter->GetRawSize());
592 gdcmErrorMacro( "Nothing written." );
601 * \brief Writes on disk A SINGLE Dicom file,
602 * using the Implicit Value Representation convention
603 * NO test is performed on processor "Endianity".
604 * @param fileName name of the file to be created
605 * (any already existing file is overwritten)
606 * @return false if write fails
609 bool FileHelper::WriteDcmImplVR (std::string const &fileName)
611 SetWriteTypeToDcmImplVR();
612 return Write(fileName);
616 * \brief Writes on disk A SINGLE Dicom file,
617 * using the Explicit Value Representation convention
618 * NO test is performed on processor "Endiannity".
619 * @param fileName name of the file to be created
620 * (any already existing file is overwritten)
621 * @return false if write fails
624 bool FileHelper::WriteDcmExplVR (std::string const &fileName)
626 SetWriteTypeToDcmExplVR();
627 return Write(fileName);
631 * \brief Writes on disk A SINGLE Dicom file,
632 * using the ACR-NEMA convention
633 * NO test is performed on processor "Endiannity".
634 * (a l'attention des logiciels cliniques
635 * qui ne prennent en entrée QUE des images ACR ...
636 * \warning if a DICOM_V3 header is supplied,
637 * groups < 0x0008 and shadow groups are ignored
638 * \warning NO TEST is performed on processor "Endiannity".
639 * @param fileName name of the file to be created
640 * (any already existing file is overwritten)
641 * @return false if write fails
644 bool FileHelper::WriteAcr (std::string const &fileName)
647 return Write(fileName);
651 * \brief Writes on disk A SINGLE Dicom file,
652 * @param fileName name of the file to be created
653 * (any already existing file is overwritten)
654 * @return false if write fails
656 bool FileHelper::Write(std::string const &fileName)
661 SetWriteFileTypeToImplicitVR();
663 case Unknown: // should never happen; ExplicitVR is the default value
665 SetWriteFileTypeToExplicitVR();
669 // NOTHING is done here just for LibIDO.
670 // Just to avoid further trouble if user creates a file ex-nihilo,
671 // wants to write it as an ACR-NEMA file,
672 // and forgets to create any Entry belonging to group 0008
674 // We add Recognition Code (RET)
675 if ( ! FileInternal->GetValEntry(0x0008, 0x0010) )
676 FileInternal->InsertValEntry("", 0x0008, 0x0010);
677 SetWriteFileTypeToACR();
678 // SetWriteFileTypeToImplicitVR(); // ACR IS implicit VR !
681 CheckMandatoryElements();
683 // --------------------------------------------------------------
684 // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
686 // if recognition code tells us we dealt with a LibIDO image
687 // we reproduce on disk the switch between lineNumber and columnNumber
688 // just before writting ...
689 /// \todo the best trick would be *change* the recognition code
690 /// but pb expected if user deals with, e.g. COMPLEX images
692 if ( WriteType == ACR_LIBIDO )
698 SetWriteToNoLibido();
700 // ----------------- End of Special Patch ----------------
705 SetWriteToRaw(); // modifies and pushes to the archive, when necessary
708 SetWriteToRGB(); // modifies and pushes to the archive, when necessary
712 bool check = CheckWriteIntegrity(); // verifies length
715 check = FileInternal->Write(fileName,WriteType);
719 RestoreWriteFileType();
720 RestoreWriteMandatory();
722 // --------------------------------------------------------------
723 // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
725 // ...and we restore the header to be Dicom Compliant again
726 // just after writting
727 RestoreWriteOfLibido();
728 // ----------------- End of Special Patch ----------------
733 //-----------------------------------------------------------------------------
736 * \brief Checks the write integrity
738 * The tests made are :
739 * - verify the size of the image to write with the possible write
740 * when the user set an image data
741 * @return true if check is successfull
743 bool FileHelper::CheckWriteIntegrity()
745 if ( PixelWriteConverter->GetUserData() )
747 int numberBitsAllocated = FileInternal->GetBitsAllocated();
748 if ( numberBitsAllocated == 0 || numberBitsAllocated == 12 )
750 gdcmWarningMacro( "numberBitsAllocated changed from "
751 << numberBitsAllocated << " to 16 "
752 << " for consistency purpose" );
753 numberBitsAllocated = 16;
756 size_t decSize = FileInternal->GetXSize()
757 * FileInternal->GetYSize()
758 * FileInternal->GetZSize()
759 * FileInternal->GetSamplesPerPixel()
760 * ( numberBitsAllocated / 8 );
761 size_t rgbSize = decSize;
762 if ( FileInternal->HasLUT() )
763 rgbSize = decSize * 3;
768 if ( decSize!=PixelWriteConverter->GetUserDataSize() )
770 gdcmWarningMacro( "Data size (Raw) is incorrect. Should be "
771 << decSize << " / Found :"
772 << PixelWriteConverter->GetUserDataSize() );
777 if ( rgbSize!=PixelWriteConverter->GetUserDataSize() )
779 gdcmWarningMacro( "Data size (RGB) is incorrect. Should be "
780 << decSize << " / Found "
781 << PixelWriteConverter->GetUserDataSize() );
791 * \brief Updates the File to write RAW data (as opposed to RGB data)
792 * (modifies, when necessary, photochromatic interpretation,
793 * bits allocated, Pixels element VR)
795 void FileHelper::SetWriteToRaw()
797 if ( FileInternal->GetNumberOfScalarComponents() == 3
798 && !FileInternal->HasLUT() )
804 ValEntry *photInt = CopyValEntry(0x0028,0x0004);
805 if (FileInternal->HasLUT() )
807 photInt->SetValue("PALETTE COLOR ");
811 photInt->SetValue("MONOCHROME2 ");
814 PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(),
815 PixelReadConverter->GetRawSize());
817 std::string vr = "OB";
818 if ( FileInternal->GetBitsAllocated()>8 )
820 if ( FileInternal->GetBitsAllocated()==24 ) // For RGB ACR files
823 CopyBinEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel(),vr);
824 pixel->SetValue(GDCM_BINLOADED);
825 pixel->SetBinArea(PixelWriteConverter->GetData(),false);
826 pixel->SetLength(PixelWriteConverter->GetDataSize());
828 Archive->Push(photInt);
829 Archive->Push(pixel);
834 * \brief Updates the File to write RGB data (as opposed to RAW data)
835 * (modifies, when necessary, photochromatic interpretation,
836 * samples per pixel, Planar configuration,
837 * bits allocated, bits stored, high bit -ACR 24 bits-
838 * Pixels element VR, pushes out the LUT, )
840 void FileHelper::SetWriteToRGB()
842 if ( FileInternal->GetNumberOfScalarComponents()==3 )
844 PixelReadConverter->BuildRGBImage();
846 ValEntry *spp = CopyValEntry(0x0028,0x0002);
849 ValEntry *planConfig = CopyValEntry(0x0028,0x0006);
850 planConfig->SetValue("0 ");
852 ValEntry *photInt = CopyValEntry(0x0028,0x0004);
853 photInt->SetValue("RGB ");
855 if ( PixelReadConverter->GetRGB() )
857 PixelWriteConverter->SetReadData(PixelReadConverter->GetRGB(),
858 PixelReadConverter->GetRGBSize());
862 PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(),
863 PixelReadConverter->GetRawSize());
866 std::string vr = "OB";
867 if ( FileInternal->GetBitsAllocated()>8 )
869 if ( FileInternal->GetBitsAllocated()==24 ) // For RGB ACR files
872 CopyBinEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel(),vr);
873 pixel->SetValue(GDCM_BINLOADED);
874 pixel->SetBinArea(PixelWriteConverter->GetData(),false);
875 pixel->SetLength(PixelWriteConverter->GetDataSize());
878 Archive->Push(planConfig);
879 Archive->Push(photInt);
880 Archive->Push(pixel);
883 Archive->Push(0x0028,0x1101);
884 Archive->Push(0x0028,0x1102);
885 Archive->Push(0x0028,0x1103);
886 Archive->Push(0x0028,0x1201);
887 Archive->Push(0x0028,0x1202);
888 Archive->Push(0x0028,0x1203);
890 // push out Palette Color Lookup Table UID, if any
891 Archive->Push(0x0028,0x1199);
893 // For old '24 Bits' ACR-NEMA
894 // Thus, we have a RGB image and the bits allocated = 24 and
895 // samples per pixels = 1 (in the read file)
896 if ( FileInternal->GetBitsAllocated()==24 )
898 ValEntry *bitsAlloc = CopyValEntry(0x0028,0x0100);
899 bitsAlloc->SetValue("8 ");
901 ValEntry *bitsStored = CopyValEntry(0x0028,0x0101);
902 bitsStored->SetValue("8 ");
904 ValEntry *highBit = CopyValEntry(0x0028,0x0102);
905 highBit->SetValue("7 ");
907 Archive->Push(bitsAlloc);
908 Archive->Push(bitsStored);
909 Archive->Push(highBit);
919 * \brief Restore the File write mode
921 void FileHelper::RestoreWrite()
923 Archive->Restore(0x0028,0x0002);
924 Archive->Restore(0x0028,0x0004);
925 Archive->Restore(0x0028,0x0006);
926 Archive->Restore(GetFile()->GetGrPixel(),GetFile()->GetNumPixel());
928 // For old ACR-NEMA (24 bits problem)
929 Archive->Restore(0x0028,0x0100);
930 Archive->Restore(0x0028,0x0101);
931 Archive->Restore(0x0028,0x0102);
934 Archive->Restore(0x0028,0x1101);
935 Archive->Restore(0x0028,0x1102);
936 Archive->Restore(0x0028,0x1103);
937 Archive->Restore(0x0028,0x1201);
938 Archive->Restore(0x0028,0x1202);
939 Archive->Restore(0x0028,0x1203);
941 // For the Palette Color Lookup Table UID
942 Archive->Restore(0x0028,0x1203);
945 // group 0002 may be pushed out for ACR-NEMA writting purposes
946 Archive->Restore(0x0002,0x0000);
947 Archive->Restore(0x0002,0x0001);
948 Archive->Restore(0x0002,0x0002);
949 Archive->Restore(0x0002,0x0003);
950 Archive->Restore(0x0002,0x0010);
951 Archive->Restore(0x0002,0x0012);
952 Archive->Restore(0x0002,0x0013);
953 Archive->Restore(0x0002,0x0016);
954 Archive->Restore(0x0002,0x0100);
955 Archive->Restore(0x0002,0x0102);
959 * \brief Pushes out the whole group 0002
960 * FIXME : better, set a flag to tell the writer not to write it ...
961 * FIXME : method should probably have an other name !
962 * SetWriteFileTypeToACR is NOT opposed to
963 * SetWriteFileTypeToExplicitVR and SetWriteFileTypeToImplicitVR
965 void FileHelper::SetWriteFileTypeToACR()
967 Archive->Push(0x0002,0x0000);
968 Archive->Push(0x0002,0x0001);
969 Archive->Push(0x0002,0x0002);
970 Archive->Push(0x0002,0x0003);
971 Archive->Push(0x0002,0x0010);
972 Archive->Push(0x0002,0x0012);
973 Archive->Push(0x0002,0x0013);
974 Archive->Push(0x0002,0x0016);
975 Archive->Push(0x0002,0x0100);
976 Archive->Push(0x0002,0x0102);
980 * \brief Sets in the File the TransferSyntax to 'Explicit VR Little Endian"
982 void FileHelper::SetWriteFileTypeToExplicitVR()
984 std::string ts = Util::DicomString(
985 Global::GetTS()->GetSpecialTransferSyntax(TS::ExplicitVRLittleEndian) );
987 ValEntry *tss = CopyValEntry(0x0002,0x0010);
994 * \brief Sets in the File the TransferSyntax to 'Implicit VR Little Endian"
996 void FileHelper::SetWriteFileTypeToImplicitVR()
998 std::string ts = Util::DicomString(
999 Global::GetTS()->GetSpecialTransferSyntax(TS::ImplicitVRLittleEndian) );
1001 ValEntry *tss = CopyValEntry(0x0002,0x0010);
1009 * \brief Restore in the File the initial group 0002
1011 void FileHelper::RestoreWriteFileType()
1016 * \brief Set the Write not to Libido format
1018 void FileHelper::SetWriteToLibido()
1020 ValEntry *oldRow = dynamic_cast<ValEntry *>
1021 (FileInternal->GetDocEntry(0x0028, 0x0010));
1022 ValEntry *oldCol = dynamic_cast<ValEntry *>
1023 (FileInternal->GetDocEntry(0x0028, 0x0011));
1025 if ( oldRow && oldCol )
1027 std::string rows, columns;
1029 ValEntry *newRow=new ValEntry(oldRow->GetDictEntry());
1030 ValEntry *newCol=new ValEntry(oldCol->GetDictEntry());
1032 newRow->Copy(oldCol);
1033 newCol->Copy(oldRow);
1035 newRow->SetValue(oldCol->GetValue());
1036 newCol->SetValue(oldRow->GetValue());
1038 Archive->Push(newRow);
1039 Archive->Push(newCol);
1042 ValEntry *libidoCode = CopyValEntry(0x0008,0x0010);
1043 libidoCode->SetValue("ACRNEMA_LIBIDO_1.1");
1044 Archive->Push(libidoCode);
1048 * \brief Set the Write not to No Libido format
1050 void FileHelper::SetWriteToNoLibido()
1052 ValEntry *recCode = dynamic_cast<ValEntry *>
1053 (FileInternal->GetDocEntry(0x0008,0x0010));
1056 if ( recCode->GetValue() == "ACRNEMA_LIBIDO_1.1" )
1058 ValEntry *libidoCode = CopyValEntry(0x0008,0x0010);
1059 libidoCode->SetValue("");
1060 Archive->Push(libidoCode);
1066 * \brief Restore the Write format
1068 void FileHelper::RestoreWriteOfLibido()
1070 Archive->Restore(0x0028,0x0010);
1071 Archive->Restore(0x0028,0x0011);
1072 Archive->Restore(0x0008,0x0010);
1074 // Restore 'LibIDO-special' entries, if any
1075 Archive->Restore(0x0028,0x0015);
1076 Archive->Restore(0x0028,0x0016);
1077 Archive->Restore(0x0028,0x0017);
1078 Archive->Restore(0x0028,0x00199);
1082 * \brief Duplicates a ValEntry or creates it.
1083 * @param group Group number of the Entry
1084 * @param elem Element number of the Entry
1085 * \return pointer to the new Val Entry (NULL when creation failed).
1087 ValEntry *FileHelper::CopyValEntry(uint16_t group, uint16_t elem)
1089 DocEntry *oldE = FileInternal->GetDocEntry(group, elem);
1094 newE = new ValEntry(oldE->GetDictEntry());
1099 newE = GetFile()->NewValEntry(group, elem);
1106 * \brief Duplicates a BinEntry or creates it.
1107 * @param group Group number of the Entry
1108 * @param elem Element number of the Entry
1109 * @param vr Value Representation of the Entry
1110 * FIXME : what is it used for?
1111 * \return pointer to the new Bin Entry (NULL when creation failed).
1113 BinEntry *FileHelper::CopyBinEntry(uint16_t group, uint16_t elem,
1114 const std::string &vr)
1116 DocEntry *oldE = FileInternal->GetDocEntry(group, elem);
1120 if ( oldE->GetVR()!=vr )
1125 newE = new BinEntry(oldE->GetDictEntry());
1130 newE = GetFile()->NewBinEntry(group, elem, vr);
1137 * \brief This method is called automatically, just before writting
1138 * in order to produce a 'True Dicom V3' image
1139 * We cannot know *how* the user made the File (reading an old ACR-NEMA
1140 * file or a not very clean DICOM file ...)
1142 * Just before writting :
1143 * - we check the Entries
1144 * - we create the mandatory entries if they are missing
1145 * - we modify the values if necessary
1146 * - we push the sensitive entries to the Archive
1147 * The writing process will restore the entries as they where before
1148 * entering FileHelper::CheckMandatoryElements, so the user will always
1149 * see the entries just as he left them.
1151 * \todo : - warn the user if we had to add some entries :
1152 * even if a mandatory entry is missing, we add it, with a default value
1153 * (we don't want to give up the writting process if user forgot to
1154 * specify Lena's Patient ID, for instance ...)
1155 * - read the whole PS 3.3 Part of DICOM (890 pages)
1156 * and write a *full* checker (probably one method per Modality ...)
1157 * Any contribution is welcome.
1158 * - write a user callable full checker, to allow post reading
1159 * and/or pre writting image consistency check.
1162 void FileHelper::CheckMandatoryElements()
1164 // just to remember : 'official' 0002 group
1165 if ( WriteType != ACR && WriteType != ACR_LIBIDO )
1167 // Group 000002 (Meta Elements) already pushed out
1169 //0002 0000 UL 1 Meta Group Length
1170 //0002 0001 OB 1 File Meta Information Version
1171 //0002 0002 UI 1 Media Stored SOP Class UID
1172 //0002 0003 UI 1 Media Stored SOP Instance UID
1173 //0002 0010 UI 1 Transfer Syntax UID
1174 //0002 0012 UI 1 Implementation Class UID
1175 //0002 0013 SH 1 Implementation Version Name
1176 //0002 0016 AE 1 Source Application Entity Title
1177 //0002 0100 UI 1 Private Information Creator
1178 //0002 0102 OB 1 Private Information
1180 // Create them if not found
1181 // Always modify the value
1182 // Push the entries to the archive.
1183 ValEntry *e_0002_0000 = CopyValEntry(0x0002,0x0000);
1184 e_0002_0000->SetValue("0"); // for the moment
1185 Archive->Push(e_0002_0000);
1187 BinEntry *e_0002_0001 = CopyBinEntry(0x0002,0x0001, "OB");
1188 e_0002_0001->SetBinArea((uint8_t*)Util::GetFileMetaInformationVersion(),
1190 e_0002_0001->SetLength(2);
1191 Archive->Push(e_0002_0001);
1193 // 'Media Stored SOP Class UID'
1194 ValEntry *e_0002_0002 = CopyValEntry(0x0002,0x0002);
1195 // [Secondary Capture Image Storage]
1196 e_0002_0002->SetValue("1.2.840.10008.5.1.4.1.1.7");
1197 Archive->Push(e_0002_0002);
1199 // 'Media Stored SOP Instance UID'
1200 ValEntry *e_0002_0003 = CopyValEntry(0x0002,0x0003);
1201 e_0002_0003->SetValue(Util::CreateUniqueUID());
1202 Archive->Push(e_0002_0003);
1204 // 'Implementation Class UID'
1205 ValEntry *e_0002_0012 = CopyValEntry(0x0002,0x0012);
1206 e_0002_0012->SetValue(Util::CreateUniqueUID());
1207 Archive->Push(e_0002_0012);
1209 // 'Implementation Version Name'
1210 ValEntry *e_0002_0013 = CopyValEntry(0x0002,0x0013);
1211 e_0002_0013->SetValue("GDCM 1.1");
1212 Archive->Push(e_0002_0013);
1214 //'Source Application Entity Title' Not Mandatory
1215 //ValEntry *e_0002_0016 = CopyValEntry(0x0002,0x0016);
1216 // e_0002_0016->SetValue("1.2.840.10008.5.1.4.1.1.7");
1217 // Archive->Push(e_0002_0016);
1220 // Push out 'LibIDO-special' entries, if any
1221 Archive->Push(0x0028,0x0015);
1222 Archive->Push(0x0028,0x0016);
1223 Archive->Push(0x0028,0x0017);
1224 Archive->Push(0x0028,0x00199);
1226 // Deal with the pb of (Bits Stored = 12)
1227 // - we're gonna write the image as Bits Stored = 16
1228 if ( FileInternal->GetEntryValue(0x0028,0x0100) == "12")
1230 ValEntry *e_0028_0100 = CopyValEntry(0x0028,0x0100);
1231 e_0028_0100->SetValue("16");
1232 Archive->Push(e_0028_0100);
1235 // Check if user wasn't drunk ;-)
1237 std::ostringstream s;
1238 // check 'Bits Allocated' vs decent values
1239 int nbBitsAllocated = FileInternal->GetBitsAllocated();
1240 if ( nbBitsAllocated == 0 || nbBitsAllocated > 32)
1242 ValEntry *e_0028_0100 = CopyValEntry(0x0028,0x0100);
1243 e_0028_0100->SetValue("16");
1244 Archive->Push(e_0028_0100);
1245 gdcmWarningMacro("(0028,0100) changed from "
1246 << nbBitsAllocated << " to 16 for consistency purpose");
1247 nbBitsAllocated = 16;
1249 // check 'Bits Stored' vs 'Bits Allocated'
1250 int nbBitsStored = FileInternal->GetBitsStored();
1251 if ( nbBitsStored == 0 || nbBitsStored > nbBitsAllocated )
1253 s << nbBitsAllocated;
1254 ValEntry *e_0028_0101 = CopyValEntry(0x0028,0x0101);
1255 e_0028_0101->SetValue( s.str() );
1256 Archive->Push(e_0028_0101);
1257 gdcmWarningMacro("(0028,0101) changed from "
1258 << nbBitsStored << " to " << nbBitsAllocated
1259 << " for consistency purpose" );
1260 nbBitsStored = nbBitsAllocated;
1262 // check 'Hight Bit Position' vs 'Bits Allocated' and 'Bits Stored'
1263 int highBitPosition = FileInternal->GetHighBitPosition();
1264 if ( highBitPosition == 0 ||
1265 highBitPosition > nbBitsAllocated-1 ||
1266 highBitPosition < nbBitsStored-1 )
1268 ValEntry *e_0028_0102 = CopyValEntry(0x0028,0x0102);
1270 s << nbBitsStored - 1;
1271 e_0028_0102->SetValue( s.str() );
1272 Archive->Push(e_0028_0102);
1273 gdcmWarningMacro("(0028,0102) changed from "
1274 << highBitPosition << " to " << nbBitsAllocated-1
1275 << " for consistency purpose");
1277 // --- Check UID-related Entries ---
1279 // If 'SOP Class UID' exists ('true DICOM' image)
1280 // we create the 'Source Image Sequence' SeqEntry
1281 // to hold informations about the Source Image
1283 ValEntry *e_0008_0016 = FileInternal->GetValEntry(0x0008, 0x0016);
1284 if ( e_0008_0016 != 0 )
1286 // Create 'Source Image Sequence' SeqEntry
1287 SeqEntry *sis = new SeqEntry (
1288 Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x2112) );
1289 SQItem *sqi = new SQItem(1);
1290 // (we assume 'SOP Instance UID' exists too)
1291 // create 'Referenced SOP Class UID'
1292 ValEntry *e_0008_1150 = new ValEntry(
1293 Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x1150) );
1294 e_0008_1150->SetValue( e_0008_0016->GetValue());
1295 sqi->AddEntry(e_0008_1150);
1297 // create 'Referenced SOP Instance UID'
1298 ValEntry *e_0008_0018 = FileInternal->GetValEntry(0x0008, 0x0018);
1299 ValEntry *e_0008_1155 = new ValEntry(
1300 Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x1155) );
1301 e_0008_1155->SetValue( e_0008_0018->GetValue());
1302 sqi->AddEntry(e_0008_1155);
1304 sis->AddSQItem(sqi,1);
1305 // temporarily replaces any previous 'Source Image Sequence'
1308 // 'Image Type' (The written image is no longer an 'ORIGINAL' one)
1309 ValEntry *e_0008_0008 = CopyValEntry(0x0008,0x0008);
1310 e_0008_0008->SetValue("DERIVED\\PRIMARY");
1311 Archive->Push(e_0008_0008);
1315 // There was no 'SOP Class UID'.
1316 // the source image was NOT a true Dicom one.
1317 // We consider the image is a 'Secondary Capture' one
1319 e_0008_0016 = new ValEntry(
1320 Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x0016) );
1321 // [Secondary Capture Image Storage]
1322 e_0008_0016 ->SetValue("1.2.840.10008.5.1.4.1.1.7");
1323 Archive->Push(e_0008_0016);
1326 // ---- The user will never have to take any action on the following ----.
1328 // new value for 'SOP Instance UID'
1329 ValEntry *e_0008_0018 = new ValEntry(
1330 Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x0018) );
1331 e_0008_0018->SetValue( Util::CreateUniqueUID() );
1332 Archive->Push(e_0008_0018);
1334 // Instance Creation Date
1335 ValEntry *e_0008_0012 = CopyValEntry(0x0008,0x0012);
1336 std::string date = Util::GetCurrentDate();
1337 e_0008_0012->SetValue(date.c_str());
1338 Archive->Push(e_0008_0012);
1340 // Instance Creation Time
1341 ValEntry *e_0008_0013 = CopyValEntry(0x0008,0x0013);
1342 std::string time = Util::GetCurrentTime();
1343 e_0008_0013->SetValue(time.c_str());
1344 Archive->Push(e_0008_0013);
1346 // ----- Add Mandatory Entries if missing ---
1348 // Entries whose type is 1 are mandatory, with a mandatory value
1349 // Entries whose type is 1c are mandatory-inside-a-Sequence
1350 // Entries whose type is 2 are mandatory, with a optional value
1351 // Entries whose type is 2c are mandatory-inside-a-Sequence
1352 // Entries whose type is 3 are optional
1354 // 'Serie Instance UID'
1355 // Keep the value if exists
1356 // The user is allowed to create his own Series,
1357 // keeping the same 'Serie Instance UID' for various images
1358 // The user shouldn't add any image to a 'Manufacturer Serie'
1359 // but there is no way no to allowed him to do that
1360 ValEntry *e_0020_000e = FileInternal->GetValEntry(0x0020, 0x000e);
1363 e_0020_000e = new ValEntry(
1364 Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0020, 0x000e) );
1365 e_0020_000e->SetValue(Util::CreateUniqueUID() );
1366 Archive->Push(e_0020_000e);
1369 // 'Study Instance UID'
1370 // Keep the value if exists
1371 // The user is allowed to create his own Study,
1372 // keeping the same 'Study Instance UID' for various images
1373 // The user may add images to a 'Manufacturer Study',
1374 // adding new series to an already existing Study
1375 ValEntry *e_0020_000d = FileInternal->GetValEntry(0x0020, 0x000d);
1378 e_0020_000d = new ValEntry(
1379 Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0020, 0x000d) );
1380 e_0020_000d->SetValue(Util::CreateUniqueUID() );
1381 Archive->Push(e_0020_000d);
1384 // Modality : if missing we set it to 'OTher'
1385 ValEntry *e_0008_0060 = FileInternal->GetValEntry(0x0008, 0x0060);
1388 e_0008_0060 = new ValEntry(
1389 Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x0060) );
1390 e_0008_0060->SetValue("OT");
1391 Archive->Push(e_0008_0060);
1394 // Manufacturer : if missing we set it to 'GDCM Factory'
1395 ValEntry *e_0008_0070 = FileInternal->GetValEntry(0x0008, 0x0070);
1398 e_0008_0070 = new ValEntry(
1399 Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x0070) );
1400 e_0008_0070->SetValue("GDCM Factory");
1401 Archive->Push(e_0008_0070);
1404 // Institution Name : if missing we set it to 'GDCM Hospital'
1405 ValEntry *e_0008_0080 = FileInternal->GetValEntry(0x0008, 0x0080);
1408 e_0008_0080 = new ValEntry(
1409 Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x0080) );
1410 e_0008_0080->SetValue("GDCM Hospital");
1411 Archive->Push(e_0008_0080);
1414 // Patient's Name : if missing, we set it to 'GDCM^Patient'
1415 ValEntry *e_0010_0010 = FileInternal->GetValEntry(0x0010, 0x0010);
1418 e_0010_0010 = new ValEntry(
1419 Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0010, 0x0010) );
1420 e_0010_0010->SetValue("GDCM^Patient");
1421 Archive->Push(e_0010_0010);
1424 // Patient's Birth Date : 'type 2' entry -> must exist, value not mandatory
1425 ValEntry *e_0010_0030 = FileInternal->GetValEntry(0x0010, 0x0030);
1428 e_0010_0030 = new ValEntry(
1429 Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0010, 0x0030) );
1430 e_0010_0030->SetValue("");
1431 Archive->Push(e_0010_0030);
1434 // Patient's Sex :'type 2' entry -> must exist, value not mandatory
1435 ValEntry *e_0010_0040 = FileInternal->GetValEntry(0x0010, 0x0040);
1438 e_0010_0040 = new ValEntry(
1439 Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0010, 0x0040) );
1440 e_0010_0040->SetValue("");
1441 Archive->Push(e_0010_0040);
1444 // Referring Physician's Name :'type 2' entry -> must exist, value not mandatory
1445 ValEntry *e_0008_0090 = FileInternal->GetValEntry(0x0008, 0x0090);
1448 e_0008_0090 = new ValEntry(
1449 Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x0090) );
1450 e_0008_0090->SetValue("");
1451 Archive->Push(e_0008_0090);
1454 // Remove some inconstencies (probably some more will be added)
1456 // if (0028 0008)Number of Frames exists
1457 // Push out (0020 0052),Frame of Reference UID
1458 // (only meaningfull within a Serie)
1459 ValEntry *e_0028_0008 = FileInternal->GetValEntry(0x0028, 0x0008);
1462 Archive->Push(0x0020, 0X0052);
1467 * \brief Restore in the File the initial group 0002
1469 void FileHelper::RestoreWriteMandatory()
1471 // group 0002 may be pushed out for ACR-NEMA writting purposes
1472 Archive->Restore(0x0002,0x0000);
1473 Archive->Restore(0x0002,0x0001);
1474 Archive->Restore(0x0002,0x0002);
1475 Archive->Restore(0x0002,0x0003);
1476 Archive->Restore(0x0002,0x0010);
1477 Archive->Restore(0x0002,0x0012);
1478 Archive->Restore(0x0002,0x0013);
1479 Archive->Restore(0x0002,0x0016);
1480 Archive->Restore(0x0002,0x0100);
1481 Archive->Restore(0x0002,0x0102);
1483 Archive->Restore(0x0008,0x0012);
1484 Archive->Restore(0x0008,0x0013);
1485 Archive->Restore(0x0008,0x0016);
1486 Archive->Restore(0x0008,0x0018);
1487 Archive->Restore(0x0008,0x0060);
1488 Archive->Restore(0x0008,0x0070);
1489 Archive->Restore(0x0008,0x0080);
1490 Archive->Restore(0x0008,0x0090);
1491 Archive->Restore(0x0008,0x2112);
1493 Archive->Restore(0x0010,0x0010);
1494 Archive->Restore(0x0010,0x0030);
1495 Archive->Restore(0x0010,0x0040);
1497 Archive->Restore(0x0020,0x000d);
1498 Archive->Restore(0x0020,0x000e);
1502 //-----------------------------------------------------------------------------
1505 * \brief Factorization for various forms of constructors.
1507 void FileHelper::Initialize()
1509 WriteMode = WMODE_RAW;
1510 WriteType = ExplicitVR;
1512 PixelReadConverter = new PixelReadConvert;
1513 PixelWriteConverter = new PixelWriteConvert;
1514 Archive = new DocEntryArchive( FileInternal );
1516 if ( FileInternal->IsReadable() )
1518 PixelReadConverter->GrabInformationsFromFile( FileInternal );
1523 * \brief Reads/[decompresses] the pixels,
1524 * *without* making RGB from Palette Colors
1525 * @return the pixels area, whatever its type
1526 * (uint8_t is just for prototyping : feel free to Cast it)
1528 uint8_t *FileHelper::GetRaw()
1530 uint8_t *raw = PixelReadConverter->GetRaw();
1533 // The Raw image migth not be loaded yet:
1534 std::ifstream *fp = FileInternal->OpenFile();
1535 PixelReadConverter->ReadAndDecompressPixelData( fp );
1537 FileInternal->CloseFile();
1539 raw = PixelReadConverter->GetRaw();
1542 gdcmWarningMacro( "Read/decompress of pixel data apparently went wrong.");
1549 //-----------------------------------------------------------------------------
1551 * \brief Prints the common part of ValEntry, BinEntry, SeqEntry
1552 * @param os ostream we want to print in
1553 * @param indent (unused)
1555 void FileHelper::Print(std::ostream &os, std::string const &)
1557 FileInternal->SetPrintLevel(PrintLevel);
1558 FileInternal->Print(os);
1560 PixelReadConverter->SetPrintLevel(PrintLevel);
1561 PixelReadConverter->Print(os);
1564 //-----------------------------------------------------------------------------
1565 } // end namespace gdcm