]> Creatis software - gdcm.git/blob - src/gdcmFile.cxx
* Example/WriteDicomSimple.cxx : example to write a dicom file from nothing.
[gdcm.git] / src / gdcmFile.cxx
1   /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmFile.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/12/07 17:28:50 $
7   Version:   $Revision: 1.174 $
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18
19 #include "gdcmFile.h"
20 #include "gdcmDocument.h"
21 #include "gdcmDebug.h"
22 #include "gdcmUtil.h"
23 #include "gdcmBinEntry.h"
24 #include "gdcmHeader.h"
25 #include "gdcmPixelReadConvert.h"
26 #include "gdcmPixelWriteConvert.h"
27 #include "gdcmDocEntryArchive.h"
28
29 #include <fstream>
30
31 namespace gdcm 
32 {
33 typedef std::pair<TagDocEntryHT::iterator,TagDocEntryHT::iterator> IterHT;
34
35 //-------------------------------------------------------------------------
36 // Constructor / Destructor
37 /**
38  * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
39  *        file (Header only deals with the ... header)
40  *        Opens (in read only and when possible) an existing file and checks
41  *        for DICOM compliance. Returns NULL on failure.
42  *        It will be up to the user to load the pixels into memory
43  *        (see GetImageData, GetImageDataRaw)
44  * \note  the in-memory representation of all available tags found in
45  *        the DICOM header is post-poned to first header information access.
46  *        This avoid a double parsing of public part of the header when
47  *        one sets an a posteriori shadow dictionary (efficiency can be
48  *        seen as a side effect).   
49  */
50 File::File( )
51 {
52    HeaderInternal = new Header( );
53    SelfHeader = true;
54    Initialise();
55 }
56
57 /**
58  * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
59  *        file (Header only deals with the ... header)
60  *        Opens (in read only and when possible) an existing file and checks
61  *        for DICOM compliance. Returns NULL on failure.
62  *        It will be up to the user to load the pixels into memory
63  *        (see GetImageData, GetImageDataRaw)
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
70  */
71 File::File(Header *header)
72 {
73    HeaderInternal = header;
74    SelfHeader = false;
75    Initialise();
76 }
77
78 /**
79  * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
80  *        file (Header 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  *        (see GetImageData, GetImageDataRaw)
85  * \note  the in-memory representation of all available tags found in
86  *        the DICOM header is post-poned to first header information access.
87  *        This avoid a double parsing of public part of the header when
88  *        one sets an a posteriori shadow dictionary (efficiency can be
89  *        seen as a side effect).   
90  * @param filename file to be opened for parsing
91  */
92 File::File(std::string const & filename )
93 {
94    HeaderInternal = new Header( filename );
95    SelfHeader = true;
96    Initialise();
97 }
98
99 /**
100  * \brief Factorization for various forms of constructors.
101  */
102 void File::Initialise()
103 {
104    WriteMode = WMODE_DECOMPRESSED;
105    WriteType = ExplicitVR;
106
107    PixelReadConverter = new PixelReadConvert;
108    PixelWriteConverter = new PixelWriteConvert;
109    Archive = new DocEntryArchive( HeaderInternal );
110
111    if ( HeaderInternal->IsReadable() )
112    {
113       PixelReadConverter->GrabInformationsFromHeader( HeaderInternal );
114    }
115 }
116
117 /**
118  * \brief canonical destructor
119  * \note  If the Header was created by the File constructor,
120  *        it is destroyed by the File
121  */
122 File::~File()
123
124    if( PixelReadConverter )
125    {
126       delete PixelReadConverter;
127    }
128    if( PixelWriteConverter )
129    {
130       delete PixelWriteConverter;
131    }
132    if( Archive )
133    {
134       delete Archive;
135    }
136
137    if( SelfHeader )
138    {
139       delete HeaderInternal;
140    }
141    HeaderInternal = 0;
142 }
143
144 //-----------------------------------------------------------------------------
145 // Print
146
147 //-----------------------------------------------------------------------------
148 // Public
149 /**
150  * \brief   Get the size of the image data
151  * 
152  *          If the image can be RGB (with a lut or by default), the size 
153  *          corresponds to the RGB image
154  * @return  The image size
155  */
156 size_t File::GetImageDataSize()
157 {
158    return PixelReadConverter->GetRGBSize();
159 }
160
161 /**
162  * \brief   Get the size of the image data
163  * 
164  *          If the image can be RGB by transformation in a LUT, this
165  *          transformation isn't considered
166  * @return  The raw image size
167  */
168 size_t File::GetImageDataRawSize()
169 {
170    return PixelReadConverter->GetDecompressedSize();
171 }
172
173 /**
174  * \brief   - Allocates necessary memory, 
175  *          - Reads the pixels from disk (uncompress if necessary),
176  *          - Transforms YBR pixels, if any, into RGB pixels
177  *          - Transforms 3 planes R, G, B, if any, into a single RGB Plane
178  *          - Transforms single Grey plane + 3 Palettes into a RGB Plane
179  *          - Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
180  * @return  Pointer to newly allocated pixel data.
181  *          NULL if alloc fails 
182  */
183 uint8_t* File::GetImageData()
184 {
185    if ( ! GetDecompressed() )
186    {
187       // If the decompression failed nothing can be done.
188       return 0;
189    }
190
191    if ( HeaderInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
192    {
193       return PixelReadConverter->GetRGB();
194    }
195    else
196    {
197       // When no LUT or LUT conversion fails, return the decompressed
198       return PixelReadConverter->GetDecompressed();
199    }
200 }
201
202 /**
203  * \brief
204  *          Read the pixels from disk (uncompress if necessary),
205  *          Transforms YBR pixels, if any, into RGB pixels
206  *          Transforms 3 planes R, G, B, if any, into a single RGB Plane
207  *          Transforms single Grey plane + 3 Palettes into a RGB Plane   
208  *          Copies at most MaxSize bytes of pixel data to caller allocated
209  *          memory space.
210  * \warning This function allows people that want to build a volume
211  *          from an image stack *not to* have, first to get the image pixels, 
212  *          and then move them to the volume area.
213  *          It's absolutely useless for any VTK user since vtk chooses 
214  *          to invert the lines of an image, that is the last line comes first
215  *          (for some axis related reasons?). Hence he will have 
216  *          to load the image line by line, starting from the end.
217  *          VTK users have to call GetImageData
218  *     
219  * @param   destination Address (in caller's memory space) at which the
220  *          pixel data should be copied
221  * @param   maxSize Maximum number of bytes to be copied. When MaxSize
222  *          is not sufficient to hold the pixel data the copy is not
223  *          executed (i.e. no partial copy).
224  * @return  On success, the number of bytes actually copied. Zero on
225  *          failure e.g. MaxSize is lower than necessary.
226  */
227 size_t File::GetImageDataIntoVector (void* destination, size_t maxSize)
228 {
229    if ( ! GetDecompressed() )
230    {
231       // If the decompression failed nothing can be done.
232       return 0;
233    }
234
235    if ( HeaderInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
236    {
237       if ( PixelReadConverter->GetRGBSize() > maxSize )
238       {
239          dbg.Verbose(0, "File::GetImageDataIntoVector: pixel data bigger"
240                         "than caller's expected MaxSize");
241          return 0;
242       }
243       memcpy( destination,
244               (void*)PixelReadConverter->GetRGB(),
245               PixelReadConverter->GetRGBSize() );
246       return PixelReadConverter->GetRGBSize();
247    }
248
249    // Either no LUT conversion necessary or LUT conversion failed
250    if ( PixelReadConverter->GetDecompressedSize() > maxSize )
251    {
252       dbg.Verbose(0, "File::GetImageDataIntoVector: pixel data bigger"
253                      "than caller's expected MaxSize");
254       return 0;
255    }
256    memcpy( destination,
257            (void*)PixelReadConverter->GetDecompressed(),
258            PixelReadConverter->GetDecompressedSize() );
259    return PixelReadConverter->GetDecompressedSize();
260 }
261
262 /**
263  * \brief   Allocates necessary memory, 
264  *          Transforms YBR pixels (if any) into RGB pixels
265  *          Transforms 3 planes R, G, B  (if any) into a single RGB Plane
266  *          Copies the pixel data (image[s]/volume[s]) to newly allocated zone. 
267  *          DOES NOT transform Grey plane + 3 Palettes into a RGB Plane
268  * @return  Pointer to newly allocated pixel data.
269  * \        NULL if alloc fails 
270  */
271 uint8_t* File::GetImageDataRaw ()
272 {
273    return GetDecompressed();
274 }
275
276 uint8_t* File::GetDecompressed()
277 {
278    uint8_t* decompressed = PixelReadConverter->GetDecompressed();
279    if ( ! decompressed )
280    {
281       // The decompressed image migth not be loaded yet:
282       std::ifstream* fp = HeaderInternal->OpenFile();
283       PixelReadConverter->ReadAndDecompressPixelData( fp );
284       if(fp) 
285          HeaderInternal->CloseFile();
286
287       decompressed = PixelReadConverter->GetDecompressed();
288       if ( ! decompressed )
289       {
290          dbg.Verbose(0, "File::GetDecompressed: read/decompress of "
291                         "pixel data apparently went wrong.");
292          return 0;
293       }
294    }
295
296    return decompressed;
297 }
298
299 /**
300  * \brief   Points the internal pointer to the callers inData
301  *          image representation, BUT WITHOUT COPYING THE DATA.
302  *          'image' Pixels are presented as C-like 2D arrays : line per line.
303  *          'volume'Pixels are presented as C-like 3D arrays : plane per plane 
304  * \warning Since the pixels are not copied, it is the caller's responsability
305  *          not to deallocate it's data before gdcm uses them (e.g. with
306  *          the Write() method.
307  * @param inData user supplied pixel area
308  * @param expectedSize total image size, in Bytes
309  *
310  * @return boolean
311  */
312 bool File::SetImageData(uint8_t* inData, size_t expectedSize)
313 {
314    PixelWriteConverter->SetUserData(inData,expectedSize);
315
316    return true;
317 }
318
319 /**
320  * \brief Writes on disk A SINGLE Dicom file
321  *        NO test is performed on  processor "Endiannity".
322  *        It's up to the user to call his Reader properly
323  * @param fileName name of the file to be created
324  *                 (any already existing file is over written)
325  * @return false if write fails
326  */
327
328 bool File::WriteRawData(std::string const & fileName)
329 {
330   std::ofstream fp1(fileName.c_str(), std::ios::out | std::ios::binary );
331    if (!fp1)
332    {
333       dbg.Verbose(2, "Fail to open (write) file:", fileName.c_str());
334       return false;
335    }
336
337    if(PixelWriteConverter->GetUserData())
338       fp1.write((char*)PixelWriteConverter->GetUserData(), PixelWriteConverter->GetUserDataSize());
339    else if(PixelReadConverter->GetRGB())
340       fp1.write((char*)PixelReadConverter->GetRGB(), PixelReadConverter->GetRGBSize());
341    else if(PixelReadConverter->GetDecompressed())
342       fp1.write((char*)PixelReadConverter->GetDecompressed(), PixelReadConverter->GetDecompressedSize());
343
344    fp1.close();
345
346    return true;
347 }
348
349 /**
350  * \brief Writes on disk A SINGLE Dicom file, 
351  *        using the Implicit Value Representation convention
352  *        NO test is performed on  processor "Endiannity".
353  * @param fileName name of the file to be created
354  *                 (any already existing file is overwritten)
355  * @return false if write fails
356  */
357
358 bool File::WriteDcmImplVR (std::string const & fileName)
359 {
360    SetWriteTypeToDcmImplVR();
361    return Write(fileName);
362 }
363
364 /**
365 * \brief Writes on disk A SINGLE Dicom file, 
366  *        using the Explicit Value Representation convention
367  *        NO test is performed on  processor "Endiannity". * @param fileName name of the file to be created
368  *                 (any already existing file is overwritten)
369  * @return false if write fails
370  */
371
372 bool File::WriteDcmExplVR (std::string const & fileName)
373 {
374    SetWriteTypeToDcmExplVR();
375    return Write(fileName);
376 }
377
378 /**
379  * \brief Writes on disk A SINGLE Dicom file, 
380  *        using the ACR-NEMA convention
381  *        NO test is performed on  processor "Endiannity".
382  *        (a l'attention des logiciels cliniques 
383  *        qui ne prennent en entrée QUE des images ACR ...
384  * \warning if a DICOM_V3 header is supplied,
385  *         groups < 0x0008 and shadow groups are ignored
386  * \warning NO TEST is performed on processor "Endiannity".
387  * @param fileName name of the file to be created
388  *                 (any already existing file is overwritten)
389  * @return false if write fails
390  */
391
392 bool File::WriteAcr (std::string const & fileName)
393 {
394    SetWriteTypeToAcr();
395    return Write(fileName);
396 }
397
398 bool File::Write(std::string const& fileName)
399 {
400    return WriteBase(fileName);
401 }
402
403 bool File::SetEntryByNumber(std::string const& content,
404                             uint16_t group, uint16_t element)
405
406    return HeaderInternal->SetEntryByNumber(content,group,element);
407 }
408
409 bool File::SetEntryByNumber(uint8_t* content, int lgth,
410                             uint16_t group, uint16_t element)
411 {
412    return HeaderInternal->SetEntryByNumber(content,lgth,group,element);
413 }
414
415 bool File::ReplaceOrCreateByNumber(std::string const& content,
416                                    uint16_t group, uint16_t element)
417 {
418    return HeaderInternal->ReplaceOrCreateByNumber(content,group,element) != NULL;
419 }
420
421 /**
422  * \brief Access to the underlying \ref PixelReadConverter RGBA LUT
423  */
424 uint8_t* File::GetLutRGBA()
425 {
426    return PixelReadConverter->GetLutRGBA();
427 }
428
429 //-----------------------------------------------------------------------------
430 // Protected
431 /**
432  * \brief NOT a end user inteded function
433  *        (used by WriteDcmExplVR, WriteDcmImplVR, WriteAcr, etc)
434  * @param fileName name of the file to be created
435  *                 (any already existing file is overwritten)
436  * @param  type file type (ExplicitVR, ImplicitVR, ...)
437  * @return false if write fails
438  */
439 bool File::WriteBase (std::string const & fileName)
440 {
441    switch(WriteType)
442    {
443       case ImplicitVR:
444          SetWriteFileTypeToImplicitVR();
445          break;
446       case ExplicitVR:
447          SetWriteFileTypeToExplicitVR();
448          break;
449       case ACR:
450       case ACR_LIBIDO:
451          SetWriteFileTypeToACR();
452          break;
453       default:
454          SetWriteFileTypeToExplicitVR();
455    }
456
457    // --------------------------------------------------------------
458    // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
459    //
460    // if recognition code tells us we dealt with a LibIDO image
461    // we reproduce on disk the switch between lineNumber and columnNumber
462    // just before writting ...
463    /// \todo the best trick would be *change* the recognition code
464    ///       but pb expected if user deals with, e.g. COMPLEX images
465    if( WriteType == ACR_LIBIDO )
466    {
467       SetWriteToLibido();
468    }
469    else
470    {
471       SetWriteToNoLibido();
472    }
473    // ----------------- End of Special Patch ----------------
474   
475    switch(WriteMode)
476    {
477       case WMODE_DECOMPRESSED :
478          SetWriteToDecompressed();
479          break;
480       case WMODE_RGB :
481          SetWriteToRGB();
482          break;
483    }
484
485    bool check = CheckWriteIntegrity();
486    if(check)
487    {
488       check = HeaderInternal->Write(fileName,WriteType);
489    }
490
491    RestoreWrite();
492    RestoreWriteFileType();
493
494    // --------------------------------------------------------------
495    // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
496    // 
497    // ...and we restore the Header to be Dicom Compliant again 
498    // just after writting
499    RestoreWriteOfLibido();
500    // ----------------- End of Special Patch ----------------
501
502    return check;
503 }
504
505 /**
506  * \brief Check the write integrity
507  *
508  * The tests made are :
509  *  - verify the size of the image to write with the possible write
510  *    when the user set an image data
511  * @return true if the check successfulls
512  */
513 bool File::CheckWriteIntegrity()
514 {
515    if(PixelWriteConverter->GetUserData())
516    {
517       int numberBitsAllocated = HeaderInternal->GetBitsAllocated();
518       if ( numberBitsAllocated == 0 || numberBitsAllocated == 12 )
519       {
520          numberBitsAllocated = 16;
521       }
522
523       size_t decSize = HeaderInternal->GetXSize()
524                     * HeaderInternal->GetYSize() 
525                     * HeaderInternal->GetZSize()
526                     * ( numberBitsAllocated / 8 )
527                     * HeaderInternal->GetSamplesPerPixel();
528       size_t rgbSize = decSize;
529       if( HeaderInternal->HasLUT() )
530          rgbSize = decSize * 3;
531
532       switch(WriteMode)
533       {
534          case WMODE_DECOMPRESSED :
535             if( decSize!=PixelWriteConverter->GetUserDataSize() )
536             {
537                dbg.Verbose(0, "File::CheckWriteIntegrity: Data size is incorrect");
538                return false;
539             }
540             break;
541          case WMODE_RGB :
542             if( rgbSize!=PixelWriteConverter->GetUserDataSize() )
543             {
544                dbg.Verbose(0, "File::CheckWriteIntegrity: Data size is incorrect");
545                return false;
546             }
547             break;
548       }
549    }
550    
551    return true;
552 }
553
554 void File::SetWriteToDecompressed()
555 {
556    if(HeaderInternal->GetNumberOfScalarComponents()==3 && !HeaderInternal->HasLUT())
557    {
558       SetWriteToRGB();
559    } 
560    else
561    {
562       ValEntry* photInt = CopyValEntry(0x0028,0x0004);
563       if(HeaderInternal->HasLUT())
564       {
565          photInt->SetValue("PALETTE COLOR ");
566       }
567       else
568       {
569          photInt->SetValue("MONOCHROME1 ");
570       }
571
572       PixelWriteConverter->SetReadData(PixelReadConverter->GetDecompressed(),
573                                        PixelReadConverter->GetDecompressedSize());
574
575       BinEntry* pixel = CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel());
576       pixel->SetValue(GDCM_BINLOADED);
577       pixel->SetBinArea(PixelWriteConverter->GetData(),false);
578       pixel->SetLength(PixelWriteConverter->GetDataSize());
579
580       Archive->Push(photInt);
581       Archive->Push(pixel);
582    }
583 }
584
585 void File::SetWriteToRGB()
586 {
587    if(HeaderInternal->GetNumberOfScalarComponents()==3)
588    {
589       PixelReadConverter->BuildRGBImage();
590       
591       ValEntry* spp = CopyValEntry(0x0028,0x0002);
592       spp->SetValue("3 ");
593
594       ValEntry* planConfig = CopyValEntry(0x0028,0x0006);
595       planConfig->SetValue("0 ");
596
597       ValEntry* photInt = CopyValEntry(0x0028,0x0004);
598       photInt->SetValue("RGB ");
599
600       if(PixelReadConverter->GetRGB())
601       {
602          PixelWriteConverter->SetReadData(PixelReadConverter->GetRGB(),
603                                           PixelReadConverter->GetRGBSize());
604       }
605       else // Decompressed data
606       {
607          PixelWriteConverter->SetReadData(PixelReadConverter->GetDecompressed(),
608                                           PixelReadConverter->GetDecompressedSize());
609       }
610
611       BinEntry* pixel = CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel());
612       pixel->SetValue(GDCM_BINLOADED);
613       pixel->SetBinArea(PixelWriteConverter->GetData(),false);
614       pixel->SetLength(PixelWriteConverter->GetDataSize());
615
616       Archive->Push(spp);
617       Archive->Push(planConfig);
618       Archive->Push(photInt);
619       Archive->Push(pixel);
620
621       // Remove any LUT
622       Archive->Push(0x0028,0x1101);
623       Archive->Push(0x0028,0x1102);
624       Archive->Push(0x0028,0x1103);
625       Archive->Push(0x0028,0x1201);
626       Archive->Push(0x0028,0x1202);
627       Archive->Push(0x0028,0x1203);
628
629       // For old ACR-NEMA
630       // Thus, we have a RGB image and the bits allocated = 24 and 
631       // samples per pixels = 1 (in the read file)
632       if(HeaderInternal->GetBitsAllocated()==24) 
633       {
634          ValEntry* bitsAlloc = CopyValEntry(0x0028,0x0100);
635          bitsAlloc->SetValue("8 ");
636
637          ValEntry* bitsStored = CopyValEntry(0x0028,0x0101);
638          bitsStored->SetValue("8 ");
639
640          ValEntry* highBit = CopyValEntry(0x0028,0x0102);
641          highBit->SetValue("7 ");
642
643          Archive->Push(bitsAlloc);
644          Archive->Push(bitsStored);
645          Archive->Push(highBit);
646       }
647    }
648    else
649    {
650       SetWriteToDecompressed();
651    }
652 }
653
654 void File::RestoreWrite()
655 {
656    Archive->Restore(0x0028,0x0002);
657    Archive->Restore(0x0028,0x0004);
658    Archive->Restore(0x0028,0x0006);
659    Archive->Restore(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel());
660
661    // For old ACR-NEMA (24 bits problem)
662    Archive->Restore(0x0028,0x0100);
663    Archive->Restore(0x0028,0x0101);
664    Archive->Restore(0x0028,0x0102);
665
666    // For the LUT
667    Archive->Restore(0x0028,0x1101);
668    Archive->Restore(0x0028,0x1102);
669    Archive->Restore(0x0028,0x1103);
670    Archive->Restore(0x0028,0x1201);
671    Archive->Restore(0x0028,0x1202);
672    Archive->Restore(0x0028,0x1203);
673 }
674
675 void File::SetWriteFileTypeToACR()
676 {
677    Archive->Push(0x0002,0x0010);
678 }
679
680 void File::SetWriteFileTypeToExplicitVR()
681 {
682    std::string ts = Util::DicomString( 
683       Document::GetTransferSyntaxValue(ExplicitVRLittleEndian).c_str() );
684
685    ValEntry* tss = CopyValEntry(0x0002,0x0010);
686    tss->SetValue(ts);
687
688    Archive->Push(tss);
689 }
690
691 void File::SetWriteFileTypeToImplicitVR()
692 {
693    std::string ts = Util::DicomString(
694       Document::GetTransferSyntaxValue(ImplicitVRLittleEndian).c_str() );
695
696    ValEntry* tss = CopyValEntry(0x0002,0x0010);
697    tss->SetValue(ts);
698 }
699
700 void File::RestoreWriteFileType()
701 {
702    Archive->Restore(0x0002,0x0010);
703 }
704
705 void File::SetWriteToLibido()
706 {
707    ValEntry *oldRow = dynamic_cast<ValEntry *>(HeaderInternal->GetDocEntryByNumber(0x0028, 0x0010));
708    ValEntry *oldCol = dynamic_cast<ValEntry *>(HeaderInternal->GetDocEntryByNumber(0x0028, 0x0011));
709    
710    if( oldRow && oldCol )
711    {
712       std::string rows, columns; 
713
714       ValEntry *newRow=new ValEntry(oldRow->GetDictEntry());
715       ValEntry *newCol=new ValEntry(oldCol->GetDictEntry());
716
717       newRow->Copy(oldCol);
718       newCol->Copy(oldRow);
719
720       newRow->SetValue(oldCol->GetValue());
721       newCol->SetValue(oldRow->GetValue());
722
723       Archive->Push(newRow);
724       Archive->Push(newCol);
725    }
726
727    ValEntry *libidoCode = CopyValEntry(0x0008,0x0010);
728    libidoCode->SetValue("ACRNEMA_LIBIDO_1.1");
729    Archive->Push(libidoCode);
730 }
731
732 void File::SetWriteToNoLibido()
733 {
734    ValEntry *recCode = dynamic_cast<ValEntry *>(HeaderInternal->GetDocEntryByNumber(0x0008,0x0010));
735    if( recCode )
736    {
737       if( recCode->GetValue() == "ACRNEMA_LIBIDO_1.1" )
738       {
739          ValEntry *libidoCode = CopyValEntry(0x0008,0x0010);
740          libidoCode->SetValue("");
741          Archive->Push(libidoCode);
742       }
743    }
744 }
745
746 void File::RestoreWriteOfLibido()
747 {
748    Archive->Restore(0x0028,0x0010);
749    Archive->Restore(0x0028,0x0011);
750    Archive->Restore(0x0008,0x0010);
751 }
752
753 ValEntry* File::CopyValEntry(uint16_t group,uint16_t element)
754 {
755    DocEntry* oldE = HeaderInternal->GetDocEntryByNumber(group, element);
756    ValEntry* newE;
757
758    if(oldE)
759    {
760       newE = new ValEntry(oldE->GetDictEntry());
761       newE->Copy(oldE);
762    }
763    else
764    {
765       newE = GetHeader()->NewValEntryByNumber(group,element);
766    }
767
768    return(newE);
769 }
770
771 BinEntry* File::CopyBinEntry(uint16_t group,uint16_t element)
772 {
773    DocEntry* oldE = HeaderInternal->GetDocEntryByNumber(group, element);
774    BinEntry* newE;
775
776    if(oldE)
777    {
778       newE = new BinEntry(oldE->GetDictEntry());
779       newE->Copy(oldE);
780    }
781    else
782    {
783       newE = GetHeader()->NewBinEntryByNumber(group,element);
784    }
785
786    return(newE);
787 }
788
789 //-----------------------------------------------------------------------------
790 // Private
791
792 //-----------------------------------------------------------------------------
793 } // end namespace gdcm
794