private void button1_Click(object sender, EventArgs e) { //Console.WriteLine(bmpAwal.Height); ShowProgressBar(bmpH - 1); var bmp = new Bitmap(bmpAwal); HPF.RunWorkerAsync(argument: bmp); }
public void LoadParams(TextAsset filterParams) { string[] line = filterParams.text.Split ('\n'); int readLine = 0; do { string filterType = ""; if (line[readLine].Contains ("Chorus")) { filterType = "Chorus"; } else if (line[readLine].Contains ("Echo")) { filterType = "Echo"; } else if (line[readLine].Contains ("LPF")) { filterType = "LPF"; } else if (line[readLine].Contains ("HPF")) { filterType = "HPF"; } else { break; } int track = 0; do { readLine++; if (line[readLine].Contains("#")) { ArrayList filter = new ArrayList(4); readLine++; while (readLine < line.Length && line[readLine].Contains(":")) { if (filterType == "HPF" && line[readLine].Split(':')[0].Trim() == "echo") { if (line[readLine].Split(':')[1].Trim() == "1") { float[] temp = new float[4]; readLine++; for (int i = 0; i < 4; i++) { readLine++; temp[i] = float.Parse (line[readLine].Split(':')[1]); } filter.Add (new Echo(temp[0], temp[1], temp[2], temp[3])); } else { filter.Add (null); } } else { filter.Add (float.Parse (line[readLine].Split(':')[1])); } readLine++; } if (filterType == "Chorus" && filter.Count == 7) { chorusEffects[track] = new Chorus((float)filter[0], (float)filter[1], (float)filter[2], (float)filter[3], (float)filter[4], (float)filter[5], (float)filter[6]); } else if (filterType == "Echo" && filter.Count == 4) { echoEffects[track] = new Echo((float)filter[0], (float)filter[1], (float)filter[2], (float)filter[3]); } else if (filterType == "LPF" && filter.Count == 3) { LPFEffects[track] = new LPF((float)filter[0], (float)filter[1], Convert.ToInt32 ((float)filter[2])); } else if (filterType == "HPF" && filter.Count == 4) { HPFEffects[track] = new HPF((float)filter[0], (float)filter[1], Convert.ToInt32 ((float)filter[2]), (Echo)filter[3]); } else { Debug.LogWarning("Error in parsing " + filterType + " filter"); } track++; } } while (!line[readLine].Contains ("*")); } while (readLine < line.Length); }
private void HPF_DoWork(object sender, DoWorkEventArgs e) { if (HPF.IsBusy) { HPF.CancelAsync(); } var bmp = e.Argument as Bitmap; for (int h = 0; h < bmp.Height; h++) { var wX = 0; for (int w = 0; w < bmp.Width; w++) { wX++; int pixel = 0; if (h == 0 && w == 0) //kiri atas { // Console.WriteLine("kiriatas"); pixel = (bmp.GetPixel(w, h).R *4 - bmp.GetPixel(w + 1, h + 1).R) / 9; } else if (h == 0 && w == bmp.Width - 1) // kanan atas { //Console.WriteLine("kananatas"); pixel = (bmp.GetPixel(w, h).R * 4 - bmp.GetPixel(w - 1, h + 1).R) / 9; } else if (h == 0 && w > 0) //tengah atas { // Console.WriteLine("tengahatas"); pixel = (bmp.GetPixel(w, h).R * 4 - bmp.GetPixel(w + 1, h + 1).R - bmp.GetPixel(w - 1, h + 1).R) / 9; } else if (h == bmp.Height - 1 && w == 0) // kiri bawah { // Console.WriteLine("kiribawah"); pixel = (bmp.GetPixel(w, h).R * 4 - bmp.GetPixel(w + 1, h - 1).R) / 9; } else if (h == bmp.Height - 1 && w == bmp.Width - 1) // kanan bawah { // Console.WriteLine("kiribawah"); pixel = (bmp.GetPixel(w, h).R * 4 - bmp.GetPixel(w - 1, h - 1).R) / 9; } else if (h == bmp.Height - 1 && w > 0) //tengah bawah { //Console.WriteLine("tengahbawah"); pixel = (bmp.GetPixel(w, h).R * 4 - bmp.GetPixel(w - 1, h - 1).R - bmp.GetPixel(w + 1, h - 1).R) / 9; } else if (h > 0 && w == 0) // kiri tengah { //Console.WriteLine("kiritengah"); pixel = (bmp.GetPixel(w, h).R * 4 - bmp.GetPixel(w + 1, h + 1).R - bmp.GetPixel(w + 1, h - 1).R) / 9; } else if (h > 0 && w == bmp.Width - 1) // kanan tengah { //Console.WriteLine("kanantengah"); pixel = (bmp.GetPixel(w, h).R * 4 - bmp.GetPixel(w - 1, h + 1).R - bmp.GetPixel(w - 1, h - 1).R) / 9; } else { //Console.WriteLine("biasa"); pixel = (bmp.GetPixel(w, h).R * 4 - bmp.GetPixel(w - 1, h + 1).R - bmp.GetPixel(w - 1, h - 1).R - bmp.GetPixel(w + 1, h - 1).R - bmp.GetPixel(w + 1, h + 1).R) / 9; } if (pixel < 0) { pixel = 0; } // Console.WriteLine(pixel); bmp.SetPixel(w, h, Color.FromArgb(pixel, pixel, pixel)); } HPF.ReportProgress(h); } e.Result = bmp; }