using System;
using gdcm;
public class StandardizeFiles
{
public static bool ProcessOneFile( string filename, string outfilename )
{
PixmapReader reader = new PixmapReader();
reader.SetFileName( filename );
if( !reader.Read() )
{
System.Console.WriteLine( "Could not read: " + filename );
return false;
}
ImageChangeTransferSyntax change = new ImageChangeTransferSyntax();
change.SetForce( false );
change.SetCompressIconImage( false );
change.SetTransferSyntax( new TransferSyntax( TransferSyntax.TSType.JPEG2000Lossless ) );
change.SetInput( reader.GetPixmap() );
if( !change.Change() )
{
System.Console.WriteLine( "Could not change: " + filename );
return false;
}
gdcm.FileMetaInformation fmi = reader.GetFile().GetHeader();
fmi.Remove( new gdcm.Tag(0x0002,0x0012) );
fmi.Remove( new gdcm.Tag(0x0002,0x0013) );
fmi.Remove( new gdcm.Tag(0x0002,0x0016) );
PixmapWriter writer = new PixmapWriter();
writer.SetFileName( outfilename );
writer.SetFile( reader.GetFile() );
gdcm.Bitmap bitout = change.GetOutput();
gdcm.Pixmap pixout = (gdcm.Pixmap)bitout;
writer.SetPixmap( pixout );
if( !writer.Write() )
{
System.Console.WriteLine( "Could not write: " + outfilename );
return false;
}
return true;
}
public static int Main(string[] args)
{
gdcm.FileMetaInformation.SetSourceApplicationEntityTitle( "My Standardize App" );
string THERALYS_ORG_ROOT = "1.3.6.1.4.17434";
gdcm.UIDGenerator.SetRoot( THERALYS_ORG_ROOT );
System.Console.WriteLine( "Root dir is now: " + gdcm.UIDGenerator.GetRoot() );
string dir1 = args[0];
string dir2 = args[1];
if( !gdcm.PosixEmulation.FileIsDirectory(dir1) )
{
System.Console.WriteLine( "Input directory: " + dir1 + " does not exist. Sorry" );
return 1;
}
if( !gdcm.PosixEmulation.FileIsDirectory(dir2) )
{
System.Console.WriteLine( "Output directory: " + dir2 + " does not exist. Sorry" );
return 1;
}
Directory d = new Directory();
uint nfiles = d.Load( dir1, true );
if(nfiles == 0) return 1;
FilenamesType filenames = d.GetFilenames();
for( uint i = 0; i < nfiles; ++i )
{
string filename = filenames[ (int)i ];
string outfilename = filename.Replace( dir1, dir2 );
System.Console.WriteLine( "Filename: " + filename );
System.Console.WriteLine( "Out Filename: " + outfilename );
if( !ProcessOneFile( filename, outfilename ) )
{
System.Console.WriteLine( "Could not process filename: " + filename );
}
}
return 0;
}
}