Exemple #1
0
        public void ThreadSplit(object o)
        {
            ThreadParameter tp = (ThreadParameter)o;

            this.SetEnableInvoke(false);
            namedProgressBar1.Text = "Split";
            namedProgressBar2.Text = "Merge";
            namedProgressBar1.ResetMaximum();


            GifSplitter g = new GifSplitter();

            g.ProgressChange += (GifSplitter Self, int Now, int Total) =>
            {
                ProgressChangeGeneral(Self, Now, Total, namedProgressBar1);
            };
            g.StateChange += (GifSplitter This, State state) =>
            {
                StateChangeGeneral(This, state, namedProgressBar1);
            };



            if (tp.tipoOut == TipoOut.File_Separati)
            {
                String path     = Directory.GetParent(tp.Sorgente).FullName;
                String FileName = Path.GetFileNameWithoutExtension(tp.Sorgente);
                String PathOut  = Path.Combine(path, FileName);
                String Ext      = tp.formatoOut.ToString();
                int    i        = 0;

                if (!Directory.Exists(PathOut))
                {
                    Directory.CreateDirectory(PathOut);
                }


                g.ElementFinish += (Image This) => {
                    ImageCollectionManager.ExportSingle(This, tp.formatoOut, Path.Combine(PathOut, FileName + "_" + i + "." + Ext));
                    i++;
                };
                g.SplitOneByOne(tp.Sorgente);
            }
            else
            {
                ImageCollection        ic  = g.Split(tp.Sorgente);
                ImageCollectionManager icm = new ImageCollectionManager(ic);
                icm.ProgressChange += (ImageCollectionManager Self, int Now, int Total) =>
                {
                    ProgressChangeGeneral(Self, Now, Total, namedProgressBar2);
                };
                icm.StateChange += (ImageCollectionManager This, State state) =>
                {
                    StateChangeGeneral(This, state, namedProgressBar2);
                };


                String path     = Directory.GetParent(tp.Sorgente).FullName;
                String FileName = Path.GetFileNameWithoutExtension(tp.Sorgente);

                String OutFile = Path.Combine(path, FileName + "." + tp.formatoOut);
                icm.Export(OutFile, tp.formatoOut);
                ic.Dispose();
            }
            g = null;


            this.SetEnableInvoke(true);
        }
Exemple #2
0
        public void ThreadSplitOneByOne(object o)
        {
            ThreadParameter tp = (ThreadParameter)o;

            this.SetEnableInvoke(false);
            namedProgressBar1.ResetMaximum();
            namedProgressBar2.ResetMaximum();
            namedProgressBar1.Text = "Lettura Frame";
            namedProgressBar2.Text = "Salvataggio Frame";


            GifSplitter g = new GifSplitter();

            g.ProgressChange += (GifSplitter Self, int Now, int Total) =>
            {
                ProgressChangeGeneral(Self, Now, Total, namedProgressBar1);
            };
            g.StateChange += (GifSplitter This, State state) =>
            {
                StateChangeGeneral(This, state, namedProgressBar1);
            };



            String path     = Directory.GetParent(tp.Sorgente).FullName;
            String FileName = Path.GetFileNameWithoutExtension(tp.Sorgente);
            String PathOut  = Path.Combine(path, FileName);

            if (!Directory.Exists(PathOut))
            {
                Directory.CreateDirectory(PathOut);
            }



            int i          = 0;
            int MaxElement = tp.Righe * tp.Colonne;

            ImageCollection ic = new ImageCollection();



            ImageCollectionManager icm = new ImageCollectionManager(ic);

            icm.Colonne = tp.Colonne;

            icm.ProgressChange += (ImageCollectionManager Self, int Now, int Total) =>
            {
                ProgressChangeGeneral(Self, Now, Total, namedProgressBar2);
            };
            icm.StateChange += (ImageCollectionManager This2, State state) =>
            {
                if (state == State.Finish)
                {
                    namedProgressBar2.Value = 0;
                }
            };



            g.ElementFinish += (Image This) => {
                /*
                 * TODO: se si vuole implementare un ottimizzazione di frame ( controllo se il frame precedente è uguale al successivo
                 * if (ic.Count != 0)
                 * {
                 *  if( !This.EqualImage(ic.Collection.Last()))
                 *      ic.Collection.Add(This.CloneFast());
                 * }
                 * else
                 *  ic.Collection.Add(This.CloneFast());*/

                ic.Collection.Add(This.CloneFast());


                if (ic.Count >= MaxElement)
                {
                    namedProgressBar2.ResetMaximum();
                    icm.SetCollection(ic);
                    icm.Export(Path.Combine(PathOut, FileName + "_" + i + "." + tp.formatoOut), tp.formatoOut);
                    ic.Dispose();
                    ic = new ImageCollection();
                    i++;
                }
            };
            g.StateChange += (GifSplitter This, State state) => {
                if (state == State.Finish)
                {
                    icm.SetCollection(ic);


                    /*icm.StateChange += (ImageCollectionManager This2, State state2) =>
                     * {
                     *  StateChangeGeneral(This2, state2, namedProgressBar2);
                     * };*/
                    icm.Export(Path.Combine(PathOut, FileName + "_" + i + "." + tp.formatoOut), tp.formatoOut);
                    ic.Dispose();
                    this.SetEnableInvoke(true);
                }
            };

            g.SplitOneByOne(tp.Sorgente);
        }