コード例 #1
0
ファイル: ExportCtl.cs プロジェクト: xxxxst/gifEdit
        void collectProc(object data)
        {
            ThreadCollectModel md = data as ThreadCollectModel;

            APNG apngBase = new APNG();

            do
            {
                if (md.needStop)
                {
                    return;
                }

                const int waitTime = 10;

                //Dictionary<int, PNG> mapData = new Dictionary<int, PNG>();

                List <PNG> lstData = new List <PNG>();
                lock (md.mapData) {
                    for (int i = 0; i < md.frameCount; ++i)
                    {
                        int idx = md.nowFrameIdx + i;
                        if (!md.mapData.ContainsKey(idx))
                        {
                            break;
                        }

                        lstData.Add(md.mapData[idx]);
                        md.mapData.Remove(idx);
                    }
                }

                if (lstData.Count <= 0)
                {
                    Thread.Sleep(waitTime);
                    continue;
                }

                for (int i = 0; i < lstData.Count; ++i)
                {
                    apngBase.Add(lstData[i], md.fps);
                    updateProgress();
                }

                md.nowFrameIdx += lstData.Count;
                if (md.nowFrameIdx >= md.frameCount)
                {
                    apngBase.Save(md.savePath);
                    updateProgressToEnd();
                    clearThread();
                }
            } while(!md.needStop);
        }
コード例 #2
0
ファイル: ExportCtl.cs プロジェクト: xxxxst/gifEdit
        void workProc(object data)
        {
            ThreadWorkModel    md        = data as ThreadWorkModel;
            ThreadCollectModel thCollect = mdThreadCollect;

            do
            {
                if (md.needStop)
                {
                    return;
                }

                const int waitTime = 10;

                Dictionary <int, ImageModel> mapData = new Dictionary <int, ImageModel>();
                lock (md.lockCom) {
                    foreach (int key in md.mapData.Keys)
                    {
                        mapData[key] = md.mapData[key];
                    }

                    md.mapData = new Dictionary <int, ImageModel>();
                }

                if (mapData.Count <= 0)
                {
                    Thread.Sleep(waitTime);
                    continue;
                }

                foreach (int key in mapData.Keys)
                {
                    PNG png = formatPng(mapData[key]);

                    lock (thCollect.lockCom) {
                        thCollect.mapData[key] = png;
                    }
                }
            } while(!md.needStop);
        }
コード例 #3
0
ファイル: ExportCtl.cs プロジェクト: xxxxst/gifEdit
        //Thread thManage = null;
        //Thread thCollect = null;
        //bool isThreadStop = false;
        void initThread(string savePath, int startFrameIdx, int frameCount, int fps)
        {
            clearThread();

            nowProgress   = 0;
            totalProgress = frameCount + 1;

            mdThreadManage = new ThreadManageModel();
            mdThreadManage.startFrameIdx  = startFrameIdx;
            mdThreadManage.frameCount     = frameCount;
            mdThreadManage.fps            = fps;
            mdThreadManage.isTransparency = true;
            mdThreadManage.th             = new Thread(manageProc);
            mdThreadManage.th.Priority    = ThreadPriority.BelowNormal;
            mdThreadManage.th.Start(mdThreadManage);

            mdThreadCollect             = new ThreadCollectModel();
            mdThreadCollect.th          = new Thread(collectProc);
            mdThreadCollect.frameCount  = frameCount;
            mdThreadCollect.fps         = fps;
            mdThreadCollect.savePath    = savePath;
            mdThreadCollect.th.Priority = ThreadPriority.BelowNormal;
            mdThreadCollect.th.Start(mdThreadCollect);

            int count = Environment.ProcessorCount - 1;

            count = Math.Max(1, count);
            for (int i = 0; i < count; ++i)
            {
                ThreadWorkModel md = new ThreadWorkModel();
                md.idx         = i;
                md.th          = new Thread(workProc);
                md.th.Priority = ThreadPriority.BelowNormal;
                lstThreadWork.Add(md);
                md.th.Start(md);
            }
        }