+ CopyMandatoryEntry(0x0028,0x0100,"16","US");
+ }
+
+ // Check if user wasn't drunk ;-)
+
+ std::ostringstream s;
+ // check 'Bits Allocated' vs decent values
+ int nbBitsAllocated = FileInternal->GetBitsAllocated();
+ if ( (nbBitsAllocated == 0 || nbBitsAllocated > 32)
+ || ( nbBitsAllocated > 8 && nbBitsAllocated <16) )
+ {
+ CopyMandatoryEntry(0x0028,0x0100,"16","US");
+ gdcmWarningMacro("(0028,0100) changed from "
+ << nbBitsAllocated << " to 16 for consistency purpose");
+ nbBitsAllocated = 16;
+ }
+ // check 'Bits Stored' vs 'Bits Allocated'
+ int nbBitsStored = FileInternal->GetBitsStored();
+ if ( nbBitsStored == 0 || nbBitsStored > nbBitsAllocated )
+ {
+ s.str("");
+ s << nbBitsAllocated;
+ CopyMandatoryEntry(0x0028,0x0101,s.str(),"US");
+ gdcmWarningMacro("(0028,0101) changed from "
+ << nbBitsStored << " to " << nbBitsAllocated
+ << " for consistency purpose" );
+ nbBitsStored = nbBitsAllocated;
+ }
+ // check 'Hight Bit Position' vs 'Bits Allocated' and 'Bits Stored'
+ int highBitPosition = FileInternal->GetHighBitPosition();
+ if ( highBitPosition == 0 ||
+ highBitPosition > nbBitsAllocated-1 ||
+ highBitPosition < nbBitsStored-1 )
+ {
+ s.str("");
+ s << nbBitsStored - 1;
+ CopyMandatoryEntry(0x0028,0x0102,s.str(),"US");
+ gdcmWarningMacro("(0028,0102) changed from "
+ << highBitPosition << " to " << nbBitsAllocated-1
+ << " for consistency purpose");
+ }
+
+ // check Pixel Representation (default it as 0 -unsigned-)
+
+ DataEntry *e_0028_0103 = FileInternal->GetDataEntry(0x0028, 0x0103);
+ if ( !e_0028_0103 )
+ {
+ gdcmWarningMacro("PixelRepresentation (0028,0103) is supposed to be mandatory");
+ CopyMandatoryEntry(0x0028, 0x0103,"0","US");
+ }
+ else
+ {
+ int sign = (int)e_0028_0103->GetValue(0);
+ if (sign !=1 && sign !=0)
+ {
+ gdcmWarningMacro("PixelRepresentation (0028,0103) is supposed to be =1 or =0");
+ CopyMandatoryEntry(0x0028, 0x0103,"0","US");
+ }
+ }
+
+ std::string pixelAspectRatio = FileInternal->GetEntryString(0x0028,0x0034);
+ if ( pixelAspectRatio == GDCM_UNFOUND ) // avoid conflict with pixelSpacing !
+ {
+ std::string pixelSpacing = FileInternal->GetEntryString(0x0028,0x0030);
+ if ( pixelSpacing == GDCM_UNFOUND )
+ {
+ pixelSpacing = "1.0\\1.0";
+ // if missing, Pixel Spacing forced to "1.0\1.0"
+ CopyMandatoryEntry(0x0028,0x0030,pixelSpacing,"DS");
+ }
+
+ // 'Imager Pixel Spacing' : defaulted to 'Pixel Spacing'
+ // --> This one is the *legal* one !
+ if ( ContentType != USER_OWN_IMAGE)
+ // we write it only when we are *sure* the image comes from
+ // an imager (see also 0008,0x0064)
+ CheckMandatoryEntry(0x0018,0x1164,pixelSpacing,"DS");
+ }
+/*
+///Exact meaning of RETired fields
+
+// See page 73 of ACR-NEMA_300-1988.pdf !
+
+// 0020,0020 : Patient Orientation :
+Patient direction of the first row and
+column of the images. The first entry id the direction of the raws, given by the
+direction of the last pixel in the first row from the first pixel in tha row.
+the second entry is the direction of the columns, given by the direction of the
+last pixel in the first column from the first pixel in that column.
+L : Left, F : Feet, A : Anterior, P : Posterior.
+Up to 3 letters can be used in combination to indicate oblique planes.
+
+//0020,0030 Image Position (RET)
+x,y,z coordinates im mm of the first pixel in the image
+
+// 0020,0035 Image Orientation (RET)
+Direction cosines of the R axis of the image system with respect to the
+equipment coordinate axes x,y,z, followed by direction cosines of the C axis of
+the image system with respect to the same axes
+
+//0020,0050 Location
+An image location reference, standard for the modality (such as CT bed position),
+used to indicate position. Calculation of position for other purposes
+is only from (0020,0030) and (0020,0035)
+*/
+
+/*
+// if imagePositionPatient not found, default it with imagePositionRet, if any
+// if imageOrientationPatient not found, default it with imageOrientationRet, if any
+
+ std::string imagePositionRet = FileInternal->GetEntryString(0x0020,0x0030);
+ std::string imageOrientationRet = FileInternal->GetEntryString(0x0020,0x0035);
+ std::string imagePositionPatient = FileInternal->GetEntryString(0x0020,0x0032);
+ std::string imageOrientationPatient = FileInternal->GetEntryString(0x0020,0x0037);
+
+ if( imagePositionPatient == GDCM_UNFOUND && imageOrientationPatient == GDCM_UNFOUND
+ && imagePositionRet != GDCM_UNFOUND && imageOrientationRet != GDCM_UNFOUND)
+ {
+ CopyMandatoryEntry(0x0020, 0x0032,imagePositionRet,"DS");
+ Archive->Push(0x0020,0x0030);
+ CopyMandatoryEntry(0x0020, 0x0037,imageOrientationRet,"DS");
+ Archive->Push(0x0020,0x0035);
+ }
+*/
+
+ // Samples Per Pixel (type 1) : default to grayscale
+ CheckMandatoryEntry(0x0028,0x0002,"1","US");
+
+ // --- Check UID-related Entries ---