+ case 'V' :
+ case 'v' :
+ if ( fh->GetFile()->GetBitsAllocated() == 8)
+ {
+ std::cout << "videoinv for 8 bits" << std::endl;
+ for (int i=0; i<dataSize; i++)
+ {
+ ((uint8_t*)imageData)[i] = 255 - ((uint8_t*)imageData)[i];
+ }
+ }
+ else
+ {
+ std::cout << "videoinv for 16 bits" << std::endl;
+ for (int i=0; i<dataSize/2; i++)
+ {
+ ((uint16_t*)imageData)[i] = 65535 - ((uint16_t*)imageData)[i];
+ }
+ }
+ std::cout << "WriteDCM Explicit VR + VideoInv" << std::endl;
+ fh->SetWriteTypeToDcmExplVR();
+ break;
+ }
+
+
+//
+// user wants to keep only a part of the image (ROI, and/or some frames)
+// ---------------------------------------------------------------------
+// (==> this is no longer really 'ReWrite' !)
+
+ int subImDimX = nX;
+ int subImDimY = nY;
+
+ if (roi)
+ {
+ if (roiBoundVal[0]<0 || roiBoundVal[0]>=nX)
+ {
+ std::cout << "xBegin out of bounds; 'roi' ignored" << std::endl;
+ fail = true;
+ }
+ if (roiBoundVal[1]<0 || roiBoundVal[1]>=nX)
+ {
+ std::cout << "xEnd out of bounds; 'roi' ignored" << std::endl;
+ fail = true;
+ }
+ if (roiBoundVal[0] > roiBoundVal[1])
+ {
+ std::cout << "xBegin greater than xEnd; 'roi' ignored" << std::endl;
+ fail = true;
+ }
+
+ if (roiBoundVal[2]<0 || roiBoundVal[2]>=nY)
+ {
+ std::cout << "yBegin out of bounds; 'roi' ignored" << std::endl;
+ fail = true;
+ }
+ if (roiBoundVal[3]<0 || roiBoundVal[3]>=nY)
+ {
+ std::cout << "yEnd out of bounds; 'roi' ignored" << std::endl;
+ fail = true;
+ }
+ if (roiBoundVal[2] > roiBoundVal[3])
+ {
+ std::cout << "yBegin greater than yEnd; 'roi' ignored" << std::endl;
+ fail = true;
+ }
+ }
+ else
+ {
+ roiBoundVal = new int[4];
+ roiBoundVal[0] = 0;
+ roiBoundVal[1] = nX-1;
+ roiBoundVal[2] = 0;
+ roiBoundVal[3] = nY-1;
+ }
+
+ subImDimX = roiBoundVal[1]-roiBoundVal[0]+1;
+ subImDimY = roiBoundVal[3]-roiBoundVal[2]+1;
+
+ if (roi || beg != -1 || end != -1)
+ {
+ if (beg == -1)
+ beg = 0;
+ if (end == -1)
+ end = nZ-1;
+
+ std::ostringstream str;
+
+ // Set the data that will be *actually* written.
+
+ int pixelSize = fh->GetFile()->GetPixelSize();
+ size_t lgrSubLine = subImDimX* pixelSize * numberOfScalarComponents;
+ size_t lgrSubFrame = subImDimY*lgrSubLine;
+ ;
+ int lgrSubImage = (end-beg+1) * lgrSubFrame;
+
+ uint8_t * subImage = new uint8_t[lgrSubImage];
+
+ uint8_t * srcCopy = (uint8_t *) imageData;
+ uint8_t * destCopy = subImage;
+ int lineSize = nX*pixelSize*numberOfScalarComponents;
+ int frameSize = nY*lineSize;
+
+ int lineOffset = roiBoundVal[0]*pixelSize * numberOfScalarComponents;
+
+ for (int frameNb=beg, frameCount=0; frameNb<=end; frameNb++, frameCount++)
+ {
+ for (int lineNb=roiBoundVal[2], lineCount=0; lineNb<=roiBoundVal[3]; lineNb++, lineCount++)
+ {
+ /// \todo : increment data pointer, don't multiply so much!
+ memcpy( (void *)(destCopy + frameCount*lgrSubFrame + lineCount*lgrSubLine),
+ (void *)(srcCopy + frameNb*frameSize + lineNb*lineSize + lineOffset ),
+ lgrSubLine);
+ }