示例#1
0
文件: EntryPoint.cs 项目: hexlify/tdd
        private static void Main(string[] args)
        {
            var randomLayouter = LayouterWithRandomSizeRectangles();

            Console.WriteLine("Random generated");
            var simpleLayouter = SimpleLayouter();

            Console.WriteLine("Simple generated");

            var imageWriter = new ImageWriter();
            var imageDrawer = new ImageDrawer();

            imageWriter.Write(imageDrawer.Draw(randomLayouter), "random.png");
            imageWriter.Write(imageDrawer.Draw(simpleLayouter), "simple.png");
        }
示例#2
0
        internal void SaveAsImage(Stream stream, int width, int height, ImageWriterFormat format)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream", "'stream' cannot be null (Nothing in Visual Basic)");
            }
            if (width <= 0)
            {
                throw new ArgumentOutOfRangeException("width", width, "'width' cannot be less than or equal to zero");
            }
            if (height <= 0)
            {
                throw new ArgumentOutOfRangeException("height", height, "'height' cannot be less than or equal to zero");
            }
            byte[] data = null;
            try
            {
                data = new byte[width * height * 4];
                GetData(data);

                var writer = new ImageWriter();
                writer.Write(data, width, height, 4, format, stream);
            }
            finally
            {
                if (data != null)
                {
                    data = null;
                }
            }
        }
示例#3
0
        public void Patch(string outFile)
        {
            if (_merged.Entries.Count == 0)
            {
                return;
            }

            _logger.Info("Patching Win32 resources");

            var ms = new MemoryStream();

            using (var f = File.Open(outFile, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                f.CopyTo(ms);
            }
            ms.Position = 0;


            var reader = new ImageReader(ms);

            using (var file = File.Open(outFile, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
            {
                var writer = new ImageWriter(reader, file);
                writer.Prepare(_merged);
                writer.Write();
            }
        }
示例#4
0
文件: X.cs 项目: key-moon/X
    public static int Solve(Case testCase)
    {
        Image image = testCase.Image;

        ImageWriter.Add(image);
        image.Clean();
        ImageWriter.Add(image);
        var separated = image.Separate().ToArray();

        ImageWriter.Add(separated);

        var    parser = new CharactorParser();
        string parsed = "";

        foreach (var charImg in separated)
        {
            parsed += parser.Parse(charImg);
        }

        Console.WriteLine(parsed);

        ImageWriter.Add(parsed.Select(x => FontData.Data[x]).ToArray());
        ImageWriter.Write(testCase.Num.ToString());

        int evalRes = FormulaEvaluator.Eval(parsed);

        return(evalRes);
    }
示例#5
0
    public static int Main(string[] args)
    {
        string      file1  = args[0];
        string      file2  = args[1];
        ImageReader reader = new ImageReader();

        reader.SetFileName(file1);
        bool ret = reader.Read();

        if (!ret)
        {
            return(1);
        }

        Image image = new Image();
        Image ir    = reader.GetImage();

        image.SetNumberOfDimensions(ir.GetNumberOfDimensions());

        //Just for fun:
        //int dircos =  ir.GetDirectionCosines();
        //t = gdcm.Orientation.GetType(dircos);
        //int l = gdcm.Orientation.GetLabel(t);
        //System.Console.WriteLine( "Orientation label:" + l );

        // Set the dimensions,
        // 1. either one at a time
        //image.SetDimension(0, ir.GetDimension(0) );
        //image.SetDimension(1, ir.GetDimension(1) );

        // 2. the array at once
        uint[] dims = { 0, 0 };
        // Just for fun let's invert the dimensions:
        dims[0] = ir.GetDimension(1);
        dims[1] = ir.GetDimension(0);
        ir.SetDimensions(dims);

        PixelFormat pixeltype = ir.GetPixelFormat();

        image.SetPixelFormat(pixeltype);

        PhotometricInterpretation pi = ir.GetPhotometricInterpretation();

        image.SetPhotometricInterpretation(pi);

        DataElement pixeldata = new DataElement(new Tag(0x7fe0, 0x0010));

        byte[] str1 = new byte[ir.GetBufferLength()];
        ir.GetBuffer(str1);
        //System.Console.WriteLine( ir.GetBufferLength() );
        pixeldata.SetByteValue(str1, new VL((uint)str1.Length));
        //image.SetDataElement( pixeldata );
        ir.SetDataElement(pixeldata);


        ImageWriter writer = new ImageWriter();

        writer.SetFileName(file2);
        writer.SetFile(reader.GetFile());
        writer.SetImage(ir);
        ret = writer.Write();
        if (!ret)
        {
            return(1);
        }

        return(0);
    }
示例#6
0
    public static int Main(string[] args)
    {
        if (args.Length < 2)
        {
            System.Console.WriteLine(" input.dcm output.dcm");
            return(1);
        }
        string filename    = args[0];
        string outfilename = args[1];

        ImageReader reader = new ImageReader();

        reader.SetFileName(filename);
        if (!reader.Read())
        {
            System.Console.WriteLine("Could not read: " + filename);
            return(1);
        }

        // The output of gdcm::Reader is a gdcm::File
        File file = reader.GetFile();

        // the dataset is the the set of element we are interested in:
        DataSet ds = file.GetDataSet();

        Image image = reader.GetImage();
        //image.Print( cout );

        ImageChangeTransferSyntax change   = new ImageChangeTransferSyntax();
        TransferSyntax            targetts = new TransferSyntax(TransferSyntax.TSType.JPEGBaselineProcess1);

        change.SetTransferSyntax(targetts);

        // Setup our JPEGCodec, warning it should be compatible with JPEGBaselineProcess1
        JPEGCodec jpegcodec = new JPEGCodec();

        if (!jpegcodec.CanCode(targetts))
        {
            System.Console.WriteLine("Something went really wrong, JPEGCodec cannot handle JPEGBaselineProcess1");
            return(1);
        }
        jpegcodec.SetLossless(false);
        jpegcodec.SetQuality(50);       // poor quality !
        change.SetUserCodec(jpegcodec); // specify the codec to use to the ImageChangeTransferSyntax

        change.SetInput(image);
        bool b = change.Change();

        if (!b)
        {
            System.Console.WriteLine("Could not change the Transfer Syntax");
            return(1);
        }

        ImageWriter writer = new ImageWriter();

        writer.SetImage((gdcm.Image)change.GetOutput());
        writer.SetFile(reader.GetFile());
        writer.SetFileName(outfilename);
        if (!writer.Write())
        {
            System.Console.WriteLine("Could not write: " + outfilename);
            return(1);
        }

        return(0);
    }
示例#7
0
    public static int Main(string[] args)
    {
        string file1 = args[0];
        string file2 = args[1];
        ImageReader reader = new ImageReader();
        reader.SetFileName( file1 );
        bool ret = reader.Read();
        if( !ret )
          {
          return 1;
          }

        Image image = new Image();
        Image ir = reader.GetImage();

        image.SetNumberOfDimensions( ir.GetNumberOfDimensions() );

        //Just for fun:
        //int dircos =  ir.GetDirectionCosines();
        //t = gdcm.Orientation.GetType(dircos);
        //int l = gdcm.Orientation.GetLabel(t);
        //System.Console.WriteLine( "Orientation label:" + l );

        // Set the dimensions,
        // 1. either one at a time
        //image.SetDimension(0, ir.GetDimension(0) );
        //image.SetDimension(1, ir.GetDimension(1) );

        // 2. the array at once
        uint[] dims = {0, 0};
        // Just for fun let's invert the dimensions:
        dims[0] = ir.GetDimension(1);
        dims[1] = ir.GetDimension(0);
        ir.SetDimensions( dims );

        PixelFormat pixeltype = ir.GetPixelFormat();
        image.SetPixelFormat( pixeltype );

        PhotometricInterpretation pi = ir.GetPhotometricInterpretation();
        image.SetPhotometricInterpretation( pi );

        DataElement pixeldata = new DataElement( new Tag(0x7fe0,0x0010) );
        byte[] str1 = new byte[ ir.GetBufferLength()];
        ir.GetBuffer( str1 );
        //System.Console.WriteLine( ir.GetBufferLength() );
        pixeldata.SetByteValue( str1, new VL( (uint)str1.Length ) );
        //image.SetDataElement( pixeldata );
        ir.SetDataElement( pixeldata );

        ImageWriter writer = new ImageWriter();
        writer.SetFileName( file2 );
        writer.SetFile( reader.GetFile() );
        writer.SetImage( ir );
        ret = writer.Write();
        if( !ret )
          {
          return 1;
          }

        return 0;
    }
  public static int Main(string[] args)
    {
    string filename = args[0];

    // instanciate the reader:
    gdcm.ImageReader reader = new gdcm.ImageReader();
    reader.SetFileName( filename );

    if (!reader.Read()) return 1;

    Image ir = reader.GetImage();

    uint[] dims = {0, 0, 0};
    dims[0] = ir.GetDimension(0);
    dims[1] = ir.GetDimension(1);
    dims[2] = ir.GetDimension(2);
    System.Console.WriteLine( "Dim:" + dims[0] );
    System.Console.WriteLine( "Dim:" + dims[1] );
    System.Console.WriteLine( "Dim:" + dims[2] );

    // buffer to get the pixels
    byte[] buffer = new byte[ ir.GetBufferLength()];
    System.Console.WriteLine( "Dim:" + ir.GetBufferLength() );
    ir.GetBuffer( buffer );

    for (uint z = 0; z < dims[2]; z++)
      {
      for (uint y = 0; y < dims[1] / 2; y++) // only half Y
        {
        for (uint x = 0; x < dims[0] / 2; x++) // only half X
          {
          buffer[ (z * dims[1] + y) * dims[0] + x ] = 0; // works when pixel type == UINT8
          }
        }
      }

    DataElement pixeldata = new DataElement( new Tag(0x7fe0,0x0010) );
    pixeldata.SetByteValue( buffer, new VL( (uint)buffer.Length ) );
    ir.SetDataElement( pixeldata );
    ir.SetTransferSyntax( new TransferSyntax( TransferSyntax.TSType.ExplicitVRLittleEndian ) );

    ImageChangeTransferSyntax change = new ImageChangeTransferSyntax();
    change.SetTransferSyntax( new TransferSyntax( TransferSyntax.TSType.JPEGLSLossless ) );
    change.SetInput( ir );
    if( !change.Change() )
      {
      System.Console.WriteLine( "Could not change: " + filename );
      return 1;
      }

    ImageWriter writer = new ImageWriter();
    writer.SetFileName( "out.dcm" );
    writer.SetFile( reader.GetFile() );
    writer.SetImage( change.GetOutput() );
    bool ret = writer.Write();
    if( !ret )
      {
      return 1;
      }


    return 0;
    }
示例#9
0
    public static int Main(string[] args)
    {
        if( args.Length < 2 )
          {
          System.Console.WriteLine( " input.dcm output.dcm" );
          return 1;
          }
        string filename = args[0];
        string outfilename = args[1];

        ImageReader reader = new ImageReader();
        reader.SetFileName( filename );
        if( !reader.Read() )
          {
          System.Console.WriteLine( "Could not read: " + filename );
          return 1;
          }

        // The output of gdcm::Reader is a gdcm::File
        File file = reader.GetFile();

        // the dataset is the the set of element we are interested in:
        DataSet ds = file.GetDataSet();

        Image image = reader.GetImage();
        //image.Print( cout );

        ImageChangeTransferSyntax change = new ImageChangeTransferSyntax();
        TransferSyntax targetts =  new TransferSyntax( TransferSyntax.TSType.JPEGBaselineProcess1 );
        change.SetTransferSyntax( targetts );

        // Setup our JPEGCodec, warning it should be compatible with JPEGBaselineProcess1
        JPEGCodec jpegcodec = new JPEGCodec();
        if( !jpegcodec.CanCode( targetts ) )
          {
          System.Console.WriteLine( "Something went really wrong, JPEGCodec cannot handle JPEGBaselineProcess1" );
          return 1;
          }
        jpegcodec.SetLossless( false );
        jpegcodec.SetQuality( 50 ); // poor quality !
        change.SetUserCodec( jpegcodec ); // specify the codec to use to the ImageChangeTransferSyntax

        change.SetInput( image );
        bool b = change.Change();
        if( !b )
          {
          System.Console.WriteLine( "Could not change the Transfer Syntax" );
          return 1;
          }

        ImageWriter writer = new ImageWriter();
        writer.SetImage( change.GetOutput() );
        writer.SetFile( reader.GetFile() );
        writer.SetFileName( outfilename );
        if( !writer.Write() )
          {
          System.Console.WriteLine( "Could not write: " + outfilename );
          return 1;
          }

        return 0;
    }
示例#10
0
  public static int Main(string[] args)
    {
    string file1 = args[0];
    Mpeg2VideoInfo info = new Mpeg2VideoInfo(file1);
    System.Console.WriteLine( info.StartTime );
    System.Console.WriteLine( info.EndTime );
    System.Console.WriteLine( info.Duration );
    System.Console.WriteLine( info.AspectRatio );
    System.Console.WriteLine( info.FrameRate );
    System.Console.WriteLine( info.PictureWidth );
    System.Console.WriteLine( info.PictureHeight );

    ImageReader r = new ImageReader();
    //Image image = new Image();
    Image image = r.GetImage();
    image.SetNumberOfDimensions( 3 );
    DataElement pixeldata = new DataElement( new gdcm.Tag(0x7fe0,0x0010) );

    System.IO.FileStream infile =
      new System.IO.FileStream(file1, System.IO.FileMode.Open, System.IO.FileAccess.Read);
    uint fsize = gdcm.PosixEmulation.FileSize(file1);

    byte[] jstream  = new byte[fsize];
    infile.Read(jstream, 0 , jstream.Length);

    SmartPtrFrag sq = SequenceOfFragments.New();
    Fragment frag = new Fragment();
    frag.SetByteValue( jstream, new gdcm.VL( (uint)jstream.Length) );
    sq.AddFragment( frag );
    pixeldata.SetValue( sq.__ref__() );

    // insert:
    image.SetDataElement( pixeldata );

    PhotometricInterpretation pi = new PhotometricInterpretation( PhotometricInterpretation.PIType.YBR_PARTIAL_420 );
    image.SetPhotometricInterpretation( pi );
    // FIXME hardcoded:
    PixelFormat pixeltype = new PixelFormat(3,8,8,7);
    image.SetPixelFormat( pixeltype );

    // FIXME hardcoded:
    TransferSyntax ts = new TransferSyntax( TransferSyntax.TSType.MPEG2MainProfile);
    image.SetTransferSyntax( ts );

    image.SetDimension(0, (uint)info.PictureWidth);
    image.SetDimension(1, (uint)info.PictureHeight);
    image.SetDimension(2, 721);

    ImageWriter writer = new ImageWriter();
    gdcm.File file = writer.GetFile();
    file.GetHeader().SetDataSetTransferSyntax( ts );
    Anonymizer anon = new Anonymizer();
    anon.SetFile( file );

    MediaStorage ms = new MediaStorage( MediaStorage.MSType.VideoEndoscopicImageStorage);

    UIDGenerator gen = new UIDGenerator();
    anon.Replace( new Tag(0x0008,0x16), ms.GetString() );
    anon.Replace( new Tag(0x0018,0x40), "25" );
    anon.Replace( new Tag(0x0018,0x1063), "40.000000" );
    anon.Replace( new Tag(0x0028,0x34), "4\\3" );
    anon.Replace( new Tag(0x0028,0x2110), "01" );

    writer.SetImage( image );
    writer.SetFileName( "dummy.dcm" );
    if( !writer.Write() )
      {
      System.Console.WriteLine( "Could not write" );
      return 1;
      }

    return 0;
    }
示例#11
0
    public static int Main(string[] args)
    {
        string         file1 = args[0];
        Mpeg2VideoInfo info  = new Mpeg2VideoInfo(file1);

        System.Console.WriteLine(info.StartTime);
        System.Console.WriteLine(info.EndTime);
        System.Console.WriteLine(info.Duration);
        System.Console.WriteLine(info.AspectRatio);
        System.Console.WriteLine(info.FrameRate);
        System.Console.WriteLine(info.PictureWidth);
        System.Console.WriteLine(info.PictureHeight);

        ImageReader r = new ImageReader();
        //Image image = new Image();
        Image image = r.GetImage();

        image.SetNumberOfDimensions(3);
        DataElement pixeldata = new DataElement(new gdcm.Tag(0x7fe0, 0x0010));

        System.IO.FileStream infile =
            new System.IO.FileStream(file1, System.IO.FileMode.Open, System.IO.FileAccess.Read);
        uint fsize = gdcm.PosixEmulation.FileSize(file1);

        byte[] jstream = new byte[fsize];
        infile.Read(jstream, 0, jstream.Length);

        SmartPtrFrag sq   = SequenceOfFragments.New();
        Fragment     frag = new Fragment();

        frag.SetByteValue(jstream, new gdcm.VL((uint)jstream.Length));
        sq.AddFragment(frag);
        pixeldata.SetValue(sq.__ref__());

        // insert:
        image.SetDataElement(pixeldata);

        PhotometricInterpretation pi = new PhotometricInterpretation(PhotometricInterpretation.PIType.YBR_PARTIAL_420);

        image.SetPhotometricInterpretation(pi);
        // FIXME hardcoded:
        PixelFormat pixeltype = new PixelFormat(3, 8, 8, 7);

        image.SetPixelFormat(pixeltype);

        // FIXME hardcoded:
        TransferSyntax ts = new TransferSyntax(TransferSyntax.TSType.MPEG2MainProfile);

        image.SetTransferSyntax(ts);

        image.SetDimension(0, (uint)info.PictureWidth);
        image.SetDimension(1, (uint)info.PictureHeight);
        image.SetDimension(2, 721);

        ImageWriter writer = new ImageWriter();

        gdcm.File file = writer.GetFile();
        file.GetHeader().SetDataSetTransferSyntax(ts);
        Anonymizer anon = new Anonymizer();

        anon.SetFile(file);

        MediaStorage ms = new MediaStorage(MediaStorage.MSType.VideoEndoscopicImageStorage);

        UIDGenerator gen = new UIDGenerator();

        anon.Replace(new Tag(0x0008, 0x16), ms.GetString());
        anon.Replace(new Tag(0x0018, 0x40), "25");
        anon.Replace(new Tag(0x0018, 0x1063), "40.000000");
        anon.Replace(new Tag(0x0028, 0x34), "4\\3");
        anon.Replace(new Tag(0x0028, 0x2110), "01");

        writer.SetImage(image);
        writer.SetFileName("dummy.dcm");
        if (!writer.Write())
        {
            System.Console.WriteLine("Could not write");
            return(1);
        }

        return(0);
    }
示例#12
0
    public static int Main(string[] args)
    {
        string filename = args[0];

        // instanciate the reader:
        gdcm.ImageReader reader = new gdcm.ImageReader();
        reader.SetFileName(filename);

        if (!reader.Read())
        {
            return(1);
        }

        Image ir = reader.GetImage();

        uint[] dims = { 0, 0, 0 };
        dims[0] = ir.GetDimension(0);
        dims[1] = ir.GetDimension(1);
        dims[2] = ir.GetDimension(2);
        System.Console.WriteLine("Dim:" + dims[0]);
        System.Console.WriteLine("Dim:" + dims[1]);
        System.Console.WriteLine("Dim:" + dims[2]);

        // buffer to get the pixels
        byte[] buffer = new byte[ir.GetBufferLength()];
        System.Console.WriteLine("Dim:" + ir.GetBufferLength());
        ir.GetBuffer(buffer);

        for (uint z = 0; z < dims[2]; z++)
        {
            for (uint y = 0; y < dims[1] / 2; y++)               // only half Y
            {
                for (uint x = 0; x < dims[0] / 2; x++)           // only half X
                {
                    buffer[(z * dims[1] + y) * dims[0] + x] = 0; // works when pixel type == UINT8
                }
            }
        }

        DataElement pixeldata = new DataElement(new Tag(0x7fe0, 0x0010));

        pixeldata.SetByteValue(buffer, new VL((uint)buffer.Length));
        ir.SetDataElement(pixeldata);
        ir.SetTransferSyntax(new TransferSyntax(TransferSyntax.TSType.ExplicitVRLittleEndian));

        ImageChangeTransferSyntax change = new ImageChangeTransferSyntax();

        change.SetTransferSyntax(new TransferSyntax(TransferSyntax.TSType.JPEGLSLossless));
        change.SetInput(ir);
        if (!change.Change())
        {
            System.Console.WriteLine("Could not change: " + filename);
            return(1);
        }

        ImageWriter writer = new ImageWriter();

        writer.SetFileName("out.dcm");
        writer.SetFile(reader.GetFile());
        writer.SetImage(change.GetOutput());
        bool ret = writer.Write();

        if (!ret)
        {
            return(1);
        }


        return(0);
    }