Exemplo n.º 1
0
        private int isTimeSelection() // ret: 0-2 == 選択していない, 選択中, 選択範囲内
        {
            int ret = 0;              // 選択していない

            if (Gnd.i.md == null)
            {
                // noop
            }
            else
            {
                if (Gnd.i.md.ed.a.selectEnd != -1)                 // ? 時間選択_済み
                {
                    int index = this.seekBar.Value;

                    if (IntTools.isRange(index, Gnd.i.md.ed.a.selectBegin, Gnd.i.md.ed.a.selectEnd)) // ? 時間選択_範囲内
                    {
                        ret = 2;                                                                     // 選択範囲内
                    }
                }
                else if (Gnd.i.md.ed.a.selectBegin != -1) // ? 時間選択_中
                {
                    ret = 1;                              // 選択中
                }
            }
            return(ret);
        }
Exemplo n.º 2
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    if (IntTools.isRange(int.Parse(this.txtRelayPortNo.Text), 1, 65535) == false)
                    {
                        throw null;
                    }
                }
                catch
                {
                    throw new FailedOperation(
                              "中継用ポート番号に問題があります。\n" +
                              "・指定できる値は 1 以上 65535 以下の整数です。"
                              );
                }

                // save
                {
                    Ground.i.relayPortNo            = int.Parse(this.txtRelayPortNo.Text);
                    Ground.i.mouseActiveOutOfScreen = this.cbActivateOutOfScreen.Checked;
                }
                this.Close();
            }
            catch (Exception ex)
            {
                FailedOperation.caught(ex);
            }
        }
Exemplo n.º 3
0
        public static int wavFileToCsvFile(string rFile, string wFile, string stdoutFile)
        {
            int hz;

            if (File.Exists(rFile) == false)
            {
                throw new FileNotFoundException(rFile);
            }

            using (WorkingDir wd = new WorkingDir())
            {
                string wHzFile = wd.makePath();

                runCTools("/W2C " + rFile + " " + wFile + " " + wHzFile + " > " + stdoutFile);

                if (File.Exists(wFile) == false)
                {
                    throw new FileNotFoundException(wFile);
                }

                hz = int.Parse(File.ReadAllText(wHzFile, Encoding.ASCII));
            }
            if (IntTools.isRange(hz, 1, IntTools.IMAX) == false)
            {
                throw new Exception(".wav ファイルのサンプリングレートを認識出来ません。" + hz);
            }

            return(hz);
        }
Exemplo n.º 4
0
            private void add(int x, int y, long scale)
            {
                if (
                    IntTools.isRange(x, 0, _img.Width - 1) &&
                    IntTools.isRange(y, 0, _img.Height - 1)
                    )
                {
                    Color color = _img.GetPixel(x, y);

                    _r     += (long)color.R * scale;
                    _g     += (long)color.G * scale;
                    _b     += (long)color.B * scale;
                    _count += scale;
                }
            }
Exemplo n.º 5
0
        private Color getBokashiDotColor(Bitmap img, int trgX, int trgY)
        {
            int r     = 0;
            int g     = 0;
            int b     = 0;
            int count = 0;

            for (int sx = -_bokashi_rad; sx <= _bokashi_rad; sx++)
            {
                for (int sy = -_bokashi_rad; sy <= _bokashi_rad; sy++)
                {
                    if (sx * sx + sy * sy <= _bokashi_rad * _bokashi_rad)
                    {
                        int x = trgX + sx;
                        int y = trgY + sy;

                        if (
                            IntTools.isRange(x, 0, img.Width - 1) &&
                            IntTools.isRange(y, 0, img.Height - 1)
                            )
                        {
                            Color color = img.GetPixel(x, y);

                            r += color.R;
                            g += color.G;
                            b += color.B;
                            count++;
                        }
                    }
                }
            }
            r = IntTools.toInt((double)r / count);
            g = IntTools.toInt((double)g / count);
            b = IntTools.toInt((double)b / count);

            return(Color.FromArgb(r, g, b));
        }
Exemplo n.º 6
0
        public void perform()
        {
            if (Gnd.i.md == null)
            {
                return;
            }

            if (Gnd.i.md.ed.a.selectEnd == -1)             // ? ! 時間選択完了
            {
                throw new FailedOperation("時間を選択して下さい。");
            }

            Gnd.i.progressMessage.post("動画をカットしています...");

            vCount = Gnd.i.md.ed.v.getCount();
            aCount = Gnd.i.md.ed.a.getCount();

            if (vCount < 1)
            {
                throw null;
            }

            if (aCount < 1)
            {
                throw null;
            }

            int vStartIndex = Gnd.i.md.ed.a.selectBegin;             // ここから
            int vEndIndex   = Gnd.i.md.ed.a.selectEnd + 1;           // この直前まで

            if (IntTools.isRange(vStartIndex, 0, vCount - 1) == false)
            {
                throw null;
            }

            if (IntTools.isRange(vEndIndex, 0, vCount) == false)
            {
                throw null;
            }

            if (vEndIndex <= vStartIndex)
            {
                throw null;
            }

            int aStartIndex = Utils.videoFrameIndexToAudioWavCsvRowIndex(vStartIndex); // ここから
            int aEndIndex   = Utils.videoFrameIndexToAudioWavCsvRowIndex(vEndIndex);   // この直前まで

            if (vEndIndex == vCount)                                                   // 映像の終端までなら、音声も終端までにする。
            {
                aEndIndex = aCount;
            }

            if (vStartIndex == 0 && vEndIndex == vCount)
            {
                throw new FailedOperation("映像を空にすることは出来ません。");
            }

            if (aStartIndex == 0 && aEndIndex == aCount)
            {
                throw new FailedOperation("音声を空にすることは出来ません。");
            }

            cutVideo(vStartIndex, vEndIndex);
            cutAudio(aStartIndex, aEndIndex);

            Gnd.i.progressMessage.post("");             // 完了
        }
Exemplo n.º 7
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    if (IntTools.isRange(int.Parse(this.txtPortNo.Text), 1, 65535) == false)
                    {
                        throw null;
                    }
                }
                catch
                {
                    throw new FailedOperation(
                              "ポート番号に問題があります。\n" +
                              "・指定できる値は 1 以上 65535 以下の整数です。"
                              );
                }

                switch (this.cmbCipherMode.SelectedIndex)
                {
                case (int)Consts.CipherMode_e.NOT_ENCRYPT:
                    break;

                case (int)Consts.CipherMode_e.ENCRYPT_BY_KEY:
                {
                    if (_key == null)
                    {
                        throw new FailedOperation("鍵が指定されていません。");
                    }
                }
                break;

                case (int)Consts.CipherMode_e.ENCRYPT_BY_PASSPHRASE:
                {
                    if (this.txtPassphrase.Text == "")
                    {
                        throw new FailedOperation("パスフレーズが指定されていません。");
                    }

                    if (this.txtPassphrase.Text != JString.toJString(this.txtPassphrase.Text, true, false, false, false))
                    {
                        throw new FailedOperation(
                                  "パスフレーズに問題があります。\n" +
                                  "・Shift_JISに変換できない文字は使用できません。\n" +
                                  "・空白は使用できません。"
                                  );
                    }
                }
                break;

                default:
                    throw null;
                }

                if (this.cmbCipherMode.SelectedIndex != (int)Consts.CipherMode_e.NOT_ENCRYPT)
                {
                    try
                    {
                        if (IntTools.isRange(int.Parse(this.txtForwardPortNo.Text), 1, 65535) == false)
                        {
                            throw null;
                        }
                    }
                    catch
                    {
                        throw new FailedOperation(
                                  "中継用ポート番号に問題があります。\n" +
                                  "・指定できる値は 1 以上 65535 以下の整数です。"
                                  );
                    }
                }

                // <-- check

                // save
                {
                    Ground.i.portNo     = int.Parse(this.txtPortNo.Text);
                    Ground.i.key        = null;
                    Ground.i.passphrase = "";

                    switch (this.cmbCipherMode.SelectedIndex)
                    {
                    case (int)Consts.CipherMode_e.NOT_ENCRYPT:
                        break;

                    case (int)Consts.CipherMode_e.ENCRYPT_BY_KEY:
                        Ground.i.key = _key;
                        break;

                    case (int)Consts.CipherMode_e.ENCRYPT_BY_PASSPHRASE:
                        Ground.i.passphrase = this.txtPassphrase.Text;
                        break;

                    default:
                        throw null;
                    }

                    Ground.i.forwardPortNo = IntTools.toInt(this.txtForwardPortNo.Text, 1, 65535, 55901);
                }
                this.Close();
            }
            catch (Exception ex)
            {
                FailedOperation.caught(ex);
            }
        }
Exemplo n.º 8
0
        private void loadFile()
        {
            string redirFile = _wd.makePath();

            Gnd.i.progressMessage.post("入力ファイルをコピーしています...");

            File.Copy(_origFile, _duplFile);

            Gnd.i.progressMessage.post("入力ファイルのフォーマットを調べています...");

            ProcessTools.runOnBatch(
                "ffprobe.exe " + _duplFile + " 2> " + redirFile,
                FFmpegBin.i.getBinDir()
                );

            foreach (string fLine in FileTools.readAllLines(redirFile, Encoding.ASCII))
            {
                string line = fLine.Trim();

                if (line.StartsWith("Stream"))
                {
                    List <string> sInts    = StringTools.tokenize(line, StringTools.DIGIT, true, true);
                    int           mapIndex = int.Parse(sInts[1]);

                    List <string> tokens = StringTools.tokenize(line, " ,", false, true);

                    if (line.Contains("Audio:"))
                    {
                        AudioStream stream = new AudioStream();

                        stream.mapIndex = mapIndex;

                        _audioStreams.Add(stream);
                    }
                    else if (line.Contains("Video:"))
                    {
                        VideoStream stream = new VideoStream();

                        stream.mapIndex = mapIndex;

                        {
                            int index = ArrayTools.indexOf <string>(tokens.ToArray(), "fps", StringTools.comp);

                            if (index == -1)
                            {
                                throw new Exception("映像ストリームの秒間フレーム数を取得出来ませんでした。");
                            }

                            stream.fps = IntTools.toInt(double.Parse(tokens[index - 1]));
                        }

                        {
                            string token = Utils.getTokenDigitFormat(tokens.ToArray(), "9x9");

                            if (token == null)
                            {
                                throw new Exception("映像ストリームの画面サイズを取得出来ませんでした。");
                            }

                            List <string> s_wh = StringTools.tokenize(token, StringTools.DIGIT, true, true);

                            stream.w = int.Parse(s_wh[0]);
                            stream.h = int.Parse(s_wh[1]);
                        }

                        if (IntTools.isRange(stream.fps, 1, IntTools.IMAX) == false)
                        {
                            throw new FailedOperation("映像ストリームの秒間フレーム数を認識出来ません。" + stream.fps);
                        }

                        if (IntTools.isRange(stream.w, 1, IntTools.IMAX) == false)
                        {
                            throw new FailedOperation("映像ストリームの画面の幅を認識出来ません。" + stream.w);
                        }

                        if (IntTools.isRange(stream.h, 1, IntTools.IMAX) == false)
                        {
                            throw new FailedOperation("映像ストリームの画面の高さを認識出来ません。" + stream.h);
                        }

                        _videoStreams.Add(stream);
                    }
                    else
                    {
                        // "Data:" とか
                    }
                }
            }

            if (_audioStreams.Count == 0)
            {
                throw new FailedOperation("音声ストリームがありません。");
            }

            if (_videoStreams.Count == 0)
            {
                throw new FailedOperation("映像ストリームがありません。");
            }

            _targetAudioStream = _audioStreams[0];
            _targetVideoStream = _videoStreams[0];

            // ---- Audio Stream ----

            Gnd.i.progressMessage.post("音声ストリームを取り出しています...");

            ProcessTools.runOnBatch(
                "ffmpeg.exe -i " + _duplFile + " -map 0:" + _targetAudioStream.mapIndex + " -ac 2 " + _wavFile + " 2> " + _wd.makePath("mk_wav_stderr.txt"),
                FFmpegBin.i.getBinDir()
                );

            Gnd.i.progressMessage.post("音声ストリームを展開しています...");

            _wavHz = CTools.wavFileToCsvFile(_wavFile, _wavCsvFile, _wd.makePath("mk_wav-csv_stdout.txt"));

            // 1 <= 音声の長さ < IMAX

            {
                long size = new FileInfo(_wavCsvFile).Length;

                if (size % 12L != 0)
                {
                    throw new Exception("wav-csv data size error");
                }

                long count = size / 12L;

                if (count == 0L)
                {
                    throw new FailedOperation("音声ストリームに最初のサンプリング値がありません。");
                }

                if (IntTools.IMAX <= count)
                {
                    throw new FailedOperation("音声ストリームが長過ぎます。");
                }
            }

            // ---- Video Stream ----

            Gnd.i.progressMessage.post("映像ストリームを展開しています...");

            ProcessTools.runOnBatch(
                "ffmpeg.exe -i " + _duplFile + " -map 0:" + _targetVideoStream.mapIndex + " -r " + _targetVideoStream.fps + " -f image2 -vcodec " + Consts.V_IMG_VCODEC + " " + _imgDir + "\\%%010d" + Consts.V_IMG_EXT + " 2> " + _wd.makePath("mk_img_stderr.txt"),
                FFmpegBin.i.getBinDir()
                );

            // 1 <= 映像の長さ < IMAX

            if (File.Exists(_imgDir + "\\0000000001" + Consts.V_IMG_EXT) == false)
            {
                throw new FailedOperation("映像ストリームに最初のフレームがありません。");
            }

            if (File.Exists(_imgDir + "\\1000000001" + Consts.V_IMG_EXT))
            {
                throw new FailedOperation("映像ストリームが長過ぎます。");
            }

            // ----

            Gnd.i.progressMessage.post("");             // 完了

            ed = new EditData(this);

            // VIDEO_W/H_MIN/MAX
            {
                Image img = ed.v.getImage(0);

                if (img.Width < Consts.VIDEO_W_MIN)
                {
                    throw new FailedOperation("映像の幅が小さ過ぎます。" + img.Width);
                }

                if (Consts.VIDEO_W_MAX < img.Width)
                {
                    throw new FailedOperation("映像の幅が大き過ぎます。" + img.Width);
                }

                if (img.Height < Consts.VIDEO_H_MIN)
                {
                    throw new FailedOperation("映像の高さが小さ過ぎます。" + img.Height);
                }

                if (Consts.VIDEO_H_MAX < img.Height)
                {
                    throw new FailedOperation("映像の高さが大き過ぎます。" + img.Height);
                }
            }

            // AUDIO_HZ_MIN/MAX
            {
                int hz = this._wavHz;

                if (hz < Consts.AUDIO_HZ_MIN)
                {
                    throw new FailedOperation("音声ストリームのサンプリング周波数が小さ過ぎます。" + hz);
                }

                if (Consts.AUDIO_HZ_MAX < hz)
                {
                    throw new FailedOperation("音声ストリームのサンプリング周波数が大き過ぎます。" + hz);
                }
            }
        }
Exemplo n.º 9
0
        private void doBokashiBitmap(Bitmap img, int img_w, int img_h, Bitmap destImg, bool mainThStaff)
        {
            for (int x = 0; x < img_w; x++)
            {
                for (int y = 0; y < img_h; y++)
                {
                    destImg.SetPixel(x, y, img.GetPixel(x, y));
                }
            }

            // pbn == per bonnou

            int pbnSpan = Math.Max(1, ((_bokashi_r - _bokashi_l + 1) * (_bokashi_b - _bokashi_t + 1)) / 108);
            int pbn     = 0;
            int count   = 0;

            if (_strongMode)
            {
                BokashiDotColor bdcX = new BokashiDotColor(img, _bokashi_l, _bokashi_t, _bokashi_rad);

                for (int x = _bokashi_l; x <= _bokashi_r; x++)
                {
                    if (_bokashi_l < x)
                    {
                        bdcX._右へ();
                    }

                    BokashiDotColor bdcY = bdcX.getClone();

                    for (int y = _bokashi_t; y <= _bokashi_b; y++)
                    {
                        if (_bokashi_t < y)
                        {
                            bdcY._下へ();
                        }

                        if (
                            IntTools.isRange(x, 0, img_w - 1) &&
                            IntTools.isRange(y, 0, img_h - 1)
                            )
                        {
                            destImg.SetPixel(x, y, bdcY.getColor());
                        }

                        if (mainThStaff)
                        {
                            if (count % pbnSpan == 0)
                            {
                                Gnd.i.progressOptionalMessage.post(pbn + " pbn");
                                pbn++;
                            }
                            count++;
                        }
                    }
                }
            }
            else
            {
                for (int x = _bokashi_l; x <= _bokashi_r; x++)
                {
                    for (int y = _bokashi_t; y <= _bokashi_b; y++)
                    {
                        if (
                            IntTools.isRange(x, 0, img_w - 1) &&
                            IntTools.isRange(y, 0, img_h - 1)
                            )
                        {
                            destImg.SetPixel(x, y, getBokashiDotColor(img, x, y));
                        }

                        if (mainThStaff)
                        {
                            if (count % pbnSpan == 0)
                            {
                                Gnd.i.progressOptionalMessage.post(pbn + " pbn");
                                pbn++;
                            }
                            count++;
                        }
                    }
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 画面の入力値から ServerInfo を生成する。
        /// 入力に問題があれば、例外を投げる。
        /// </summary>
        /// <returns></returns>
        private Ground.ServerInfo getServerInfo(bool anonimousMode = false)
        {
            if (!anonimousMode)
            {
                if (this.txtTitle.Text == "")
                {
                    throw new FailedOperation("名前が指定されていません。");
                }

                if (this.txtTitle.Text != this.txtTitle.Text.Trim())
                {
                    throw new FailedOperation(
                              "名前に問題があります。\n" +
                              "・前後に空白は使用できません。"
                              );
                }
            }
            if (this.txtHost.Text == "")
            {
                throw new FailedOperation("ホスト名が指定されていません。");
            }

            if (this.txtHost.Text != JString.toJString(this.txtHost.Text, false, false, false, false))
            {
                throw new FailedOperation(
                          "ホスト名に問題があります。\n" +
                          "・ASCIIに変換できない文字は使用できません。\n" +
                          "・空白は使用できません。"
                          );
            }

            if (this.txtPortNo.Text == "")
            {
                throw new FailedOperation("ポート番号が指定されていません。");
            }

            try
            {
                if (IntTools.isRange(int.Parse(this.txtPortNo.Text), 1, 65535) == false)
                {
                    throw null;
                }
            }
            catch
            {
                throw new FailedOperation(
                          "ポート番号に問題があります。\n" +
                          "・指定できる値は 1 以上 65535 以下の整数です。"
                          );
            }

            switch (this.cmbCipherMode.SelectedIndex)
            {
            case (int)Consts.CipherMode_e.NOT_ENCRYPT:
                break;

            case (int)Consts.CipherMode_e.ENCRYPT_BY_KEY:
            {
                if (_keyData == null)
                {
                    throw new FailedOperation("鍵が指定されていません。");
                }
            }
            break;

            case (int)Consts.CipherMode_e.ENCRYPT_BY_PASSPHRASE:
            {
                if (this.txtPassphrase.Text == "")
                {
                    throw new FailedOperation("パスフレーズが指定されていません。");
                }

                if (this.txtPassphrase.Text != JString.toJString(this.txtPassphrase.Text, true, false, false, false))
                {
                    throw new FailedOperation(
                              "パスフレーズに問題があります。\n" +
                              "・Shift_JISに変換できない文字は使用できません。\n" +
                              "・空白は使用できません。"
                              );
                }
            }
            break;

            default:
                throw null;
            }

            try
            {
                if (IntTools.isRange(int.Parse(this.txtRelayPortNo.Text), 1, 65535) == false)
                {
                    throw null;
                }
            }
            catch
            {
                throw new FailedOperation(
                          "中継用ポート番号に問題があります。\n" +
                          "・指定できる値は 1 以上 65535 以下の整数です。"
                          );
            }

            // <-- check

            Ground.ServerInfo si = new Ground.ServerInfo();

            si.title      = this.txtTitle.Text;
            si.host       = this.txtHost.Text;
            si.portNo     = int.Parse(this.txtPortNo.Text);
            si.key        = null;
            si.passphrase = "";

            switch (this.cmbCipherMode.SelectedIndex)
            {
            case (int)Consts.CipherMode_e.ENCRYPT_BY_KEY:
                si.key = _keyData;
                break;

            case (int)Consts.CipherMode_e.ENCRYPT_BY_PASSPHRASE:
                si.passphrase = this.txtPassphrase.Text;
                break;

            default:
                break;
            }

            Ground.i.relayPortNo = int.Parse(this.txtRelayPortNo.Text);             // ここでいいのか?

            return(si);
        }