First blog entry in CSDN :)

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[88];
            
double[,] myTransValue = new double[88];
            
//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. :)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值