As a programmer, I wanted to find a place to record down some useful stuffs as my references, which are including frequently used codes for my current work and study. Finally, I found here, where I can put the source codes formally, It's really cool!
Moreover, I will use english to write my blog, for improving my poor English writing skills hopefully :)
Well, let's me put some source codes here:
using
System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
namespace DCTProcess
... {
public partial class Form1 : Form
...{
public Form1()
...{
InitializeComponent();
}
private void btnTransform_Click(object sender, EventArgs e)
...{
CultureInfo ci = new CultureInfo("en-us");
double[,] myOriValue = new double[8, 8];
double[,] myTransValue = new double[8, 8];
//int x, y = 0;
char[] delimiterChars = ...{ ',' };
string myOritext = richtxt1.Text;
string[] myOriValueS = myOritext.Split(delimiterChars);
richTextBox2.Text = "";
//make the 1d array to be 2d array
for (int i = 0; i < 64; i++)
...{
int myX, myY = 0;
myY = (int) Math.Truncate((double)i/8);
myX = i % 8;
myOriValue[myX, myY] = double.Parse(myOriValueS[i]);
}
//4 levels loop for the formula
for (int xa = 0; xa <= 7; xa++)
...{
for (int ya = 0; ya <= 7; ya++)
...{
myTransValue[xa, ya] = GetK(xa) * GetK(ya) * InnerLoop(xa,ya,myOriValue);
}
}
//Display the result F matrix
for (int yc = 0; yc <= 7; yc++)
...{
for (int xc = 0; xc <= 7; xc++)
...{
int spacer = 12;
spacer -= myTransValue[xc, yc].ToString("F02", ci).Length;
richTextBox2.Text += myTransValue[xc, yc].ToString("F02",ci);
for (int sp = 0; sp < spacer; sp++)
richTextBox2.Text += " ";
}
richTextBox2.Text += " ";
}
}
private double GetK(int value)
...{
if (value == 0)
return 1 / (2 * Math.Sqrt(2));
else
return 0.5;
}
private double InnerLoop(int myM, int myN, double[,] myArray)
...{
double result = 0;
double pi = Math.PI;
for (int xb = 0; xb <= 7; xb++)
...{
for (int yb = 0; yb <= 7; yb++)
...{
result += myArray[xb, yb] * Math.Cos(((2 * xb + 1) * myM * pi) / 16) * Math.Cos(((2 * yb + 1) * myN * pi) / 16);
}
}
return result;
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
namespace DCTProcess
... {
public partial class Form1 : Form
...{
public Form1()
...{
InitializeComponent();
}
private void btnTransform_Click(object sender, EventArgs e)
...{
CultureInfo ci = new CultureInfo("en-us");
double[,] myOriValue = new double[8, 8];
double[,] myTransValue = new double[8, 8];
//int x, y = 0;
char[] delimiterChars = ...{ ',' };
string myOritext = richtxt1.Text;
string[] myOriValueS = myOritext.Split(delimiterChars);
richTextBox2.Text = "";
//make the 1d array to be 2d array
for (int i = 0; i < 64; i++)
...{
int myX, myY = 0;
myY = (int) Math.Truncate((double)i/8);
myX = i % 8;
myOriValue[myX, myY] = double.Parse(myOriValueS[i]);
}
//4 levels loop for the formula
for (int xa = 0; xa <= 7; xa++)
...{
for (int ya = 0; ya <= 7; ya++)
...{
myTransValue[xa, ya] = GetK(xa) * GetK(ya) * InnerLoop(xa,ya,myOriValue);
}
}
//Display the result F matrix
for (int yc = 0; yc <= 7; yc++)
...{
for (int xc = 0; xc <= 7; xc++)
...{
int spacer = 12;
spacer -= myTransValue[xc, yc].ToString("F02", ci).Length;
richTextBox2.Text += myTransValue[xc, yc].ToString("F02",ci);
for (int sp = 0; sp < spacer; sp++)
richTextBox2.Text += " ";
}
richTextBox2.Text += " ";
}
}
private double GetK(int value)
...{
if (value == 0)
return 1 / (2 * Math.Sqrt(2));
else
return 0.5;
}
private double InnerLoop(int myM, int myN, double[,] myArray)
...{
double result = 0;
double pi = Math.PI;
for (int xb = 0; xb <= 7; xb++)
...{
for (int yb = 0; yb <= 7; yb++)
...{
result += myArray[xb, yb] * Math.Cos(((2 * xb + 1) * myM * pi) / 16) * Math.Cos(((2 * yb + 1) * myN * pi) / 16);
}
}
return result;
}
}
}
Above coding (written in C#) is a part of my school assignment, which is DCT process for getting the F matrix during JPEG encoding. :)