contoh kompresi video menggunakan bahasa java

Upload: kang-sakir

Post on 06-Mar-2016

231 views

Category:

Documents


1 download

DESCRIPTION

Contoh Kompresi Video Menggunakan Bahasa Java

TRANSCRIPT

  • LAMPIRAN 1

    1. Kode Program Tampilan Antarmuka (Interface)

    Sedangkan untuk program javanya adalah sebagai berikut: public static final class drawable { public static final int icon=0x7f020000; } public static final class id { public static final int AbsoluteLayout01=0x7f050001; public static final int Button01=0x7f050003; public static final int EditText01=0x7f050000; public static final int EditText02=0x7f050004; public static final int TextView01=0x7f050002; public static final int listView1=0x7f050005; } public static final class layout { public static final int compress=0x7f030000; public static final int download=0x7f030001; public static final int main=0x7f030002; public static final int upload=0x7f030003; } public static final class string { public static final int app_name=0x7f040001; public static final int hello=0x7f040000; } }

    Universitas Sumatera Utara

  • 2. Kelas Utama DCTforCompress.java

    package febri_aulia_nugroho.tugasakhir.com; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import android.widget.AdapterView.OnItemClickListener; public class DCTforCompress extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);

    ListView menu1 =(ListView) findViewById(R.id.listView1);

    String [] menu = {"Compres", "Decompres","Upload", "Download", "Perihal","Keluar"}; menu1.setAdapter(new ArrayAdapter(this,

    android.R.layout.simple_list_item_1, menu)); menu1.setOnItemClickListener(menuClickListener); }

    private OnItemClickListener menuClickListener = new OnItemClickListener() { public void onItemClick(AdapterView av, View v, int position, long id) {

    Universitas Sumatera Utara

  • String option = ((TextView) v).getText().toString(); show(option); } }; protected void show(String pilihan) {

    //Intent digunakan untuk sebagai pengenal suatu activity Intent i = null;

    if (pilihan.equals("Compres")) { i = new Intent(this, Compres.class);

    //Toast.makeText(getApplicationContext(), "Compress", 10).show(); }

    else if (pilihan.equals("Decompres")) { i = new Intent(this, Decompress.class);

    //Toast.makeText(getApplicationContext(), "Decompress", 10).show(); }

    else if (pilihan.equals("Upload")) { i = new Intent(this, Upload.class); } else if (pilihan.equals("Download")) { i = new Intent(this, DownloadFile.class); }

    else if (pilihan.equals("Perihal")) { //i = new Intent(this, Perihal.class);

    Toast.makeText(getApplicationContext(), "Perihal", 10).show(); } else if (pilihan.equals("Keluar")) {

    Universitas Sumatera Utara

  • int pid = android.os.Process.myPid(); android.os.Process.killProcess(pid); } if (i != null) startActivity(i); } }

    3. Kelas Compress.java

    package febri_aulia_nugroho.tugasakhir.com; import java.io.BufferedInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; import org.apache.http.util.ByteArrayBuffer; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.EditText; public class Compres extends Activity { double[][] result = new double[8][8]; double[] zigzag = new double[64]; int levelQ = 50; private EditText text; private final String PATH = "/sdcard/"; private int i1 = 0;

    Universitas Sumatera Utara

  • private int counter = 54; private double[] input = new double[100000]; double[][] matrix = new double[8][8]; private double[] zigZag = new double[64]; private int index = 1; double data = 0; private double[] huff = new double[100000]; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.compress); text = (EditText) findViewById(R.id.EditText01); text.setText("No Results"); input = DownloadFromUrl("http://10.0.2.2/DCT/videopendek.avi", "videopendek.avi"); for (int i = 0; i < i1 / 64; i++) { matrix = formMatrix(input); DiscreteCosineTransform dct = new DiscreteCosineTransform(); result = dct.compress(matrix, levelQ); zigZag = initZigZag(result); huffman(zigZag); } tulis(huff); //show2(huff); show(result); } void tulis(double[] param) { try { File file2 = new File("hasil.avi");

    Universitas Sumatera Utara

  • FileOutputStream fos2 = new FileOutputStream(PATH + file2); ByteArrayBuffer baf2 = new ByteArrayBuffer(50); for (int i = 0; i < index; i++) { baf2.append((byte) param[i]); } fos2.write(baf2.toByteArray()); fos2.close(); } catch (IOException e) {

    Log.d("ImageManager", "Error tulis : " + e); } } private void huffman(double[] zigZag) { data = zigZag[0]; int count = 1; for (int i = 1; i < 64; i++) { if (zigZag[i] == data) count++; else { huff[index] = data; huff[index + 1] = (double) count; index = index + 2; data = zigZag[i]; count = 1; } } huff[index] = data; huff[index + 1] = (double) count; index = index + 2; } private double[] initZigZag(double[][] result) {

    Universitas Sumatera Utara

  • zigZag[0] = result[0][0]; // 0,0 zigZag[1] = result[0][1]; // 0,1 zigZag[2] = result[1][0]; // 1,0 zigZag[3] = result[2][0]; // 2,0 zigZag[4] = result[1][1]; // 1,1 zigZag[5] = result[0][2]; // 0,2 zigZag[6] = result[0][3]; // 0,3 zigZag[7] = result[1][2]; // 1,2 zigZag[8] = result[2][1]; // 2,1 zigZag[9] = result[3][0]; // 3,0 zigZag[10] = result[4][0]; // 4,0 zigZag[11] = result[3][1]; // 3,1 zigZag[12] = result[2][2]; // 2,2 zigZag[13] = result[1][3]; // 1,3 zigZag[14] = result[0][4]; // 0,4 zigZag[15] = result[0][5]; // 0,5 zigZag[16] = result[1][4]; // 1,4 zigZag[17] = result[2][3]; // 2,3 zigZag[18] = result[3][2]; // 3,2 zigZag[19] = result[4][1]; // 4,1 zigZag[20] = result[5][0]; // 5,0 zigZag[21] = result[6][0]; // 6,0 zigZag[22] = result[5][1]; // 5,1 zigZag[23] = result[4][2]; // 4,2 zigZag[24] = result[3][3]; // 3,3 zigZag[25] = result[2][4]; // 2,4 zigZag[26] = result[1][5]; // 1,5 zigZag[27] = result[0][6]; // 0,6 zigZag[28] = result[0][7]; // 0,7 zigZag[29] = result[1][6]; // 1,6 zigZag[30] = result[2][5]; // 2,5

    Universitas Sumatera Utara

  • zigZag[31] = result[3][4]; // 3,4 zigZag[32] = result[4][3]; // 4,3 zigZag[33] = result[5][2]; // 5,2 zigZag[34] = result[6][1]; // 6,1 zigZag[35] = result[7][0]; // 7,0 zigZag[36] = result[7][1]; // 7,1 zigZag[37] = result[6][2]; // 6,2 zigZag[38] = result[5][3]; // 5,3 zigZag[39] = result[4][4]; // 4,4 zigZag[40] = result[3][5]; // 3,5 zigZag[41] = result[2][6]; // 2,6 zigZag[42] = result[1][7]; // 1,7 zigZag[43] = result[2][7]; // 2,7 zigZag[44] = result[3][6]; // 3,6 zigZag[45] = result[4][5]; // 4,5 zigZag[46] = result[5][4]; // 5,4 zigZag[47] = result[6][3]; // 6,3 zigZag[48] = result[7][2]; // 7,2 zigZag[49] = result[7][3]; // 7,3 zigZag[50] = result[6][4]; // 6,4 zigZag[51] = result[5][5]; // 5,5 zigZag[52] = result[4][6]; // 4,6 zigZag[53] = result[3][7]; // 3,7 zigZag[54] = result[4][7]; // 4,7 zigZag[55] = result[5][6]; // 5,6 zigZag[56] = result[6][5]; // 6,5 zigZag[57] = result[7][4]; // 7,4 zigZag[58] = result[7][5]; // 7,5 zigZag[59] = result[6][6]; // 6,6 zigZag[60] = result[5][7]; // 5,7 zigZag[61] = result[6][7]; // 6,7

    Universitas Sumatera Utara

  • zigZag[62] = result[7][6]; // 7,6 zigZag[63] = result[7][7]; // 7,7 return zigZag; }

    public double[] DownloadFromUrl(String imageURL, String fileName) { ByteArrayBuffer baf = new ByteArrayBuffer(50); try { URL url = new URL(imageURL); File file = new File(fileName); URLConnection ucon = url.openConnection(); InputStream is = ucon.getInputStream();

    BufferedInputStream bis = new BufferedInputStream(is); int current = 0; try {

    while ((current = bis.read()) != -1) { baf.append((byte) current); input[i1] = current; //Log.d("ImageManager DownloadFromUrl LoG", i1 + " " + input[i1]); i1++; } } catch(Exception e) {

    FileOutputStream fos = new FileOutputStream(PATH + file); fos.write(baf.toByteArray()); fos.close(); }

    Universitas Sumatera Utara

  • } catch (IOException e) {

    Log.d("ImageManager", "Error DownloadFromUrl : " + e); } return input; } double[][] formMatrix(double[] input) { for (int i = 0; i

  • public void show2(double[] param) { //String R = ""; for (int i = 0; i < index; i++) {

    Log.d("ImageManager Show Huff", i + " " + param[i]);

    //R += "ImageManager : " + i + " " + param[i] + "\n"; } //text.setText(R); }

    }

    4. Kelas Decompress.java

    package febri_aulia_nugroho.tugasakhir.com; import java.io.BufferedInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; import org.apache.http.util.ByteArrayBuffer; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.EditText; public class Decompress extends Activity { double[][] result = new double[8][8]; double[][] result2 = new double[8][8]; double[][] toMatrix2 = new double[8][8]; double[] zigzag = new double[64]; int levelQ = 50; private EditText text; private final String PATH = "/sdcard/"; private int i2 = 0; private int counter = 54; private double[] input2 = new double[100000]; double[] unrle1 = new double[100000]; double[][] matrix = new double[8][8];

    Universitas Sumatera Utara

  • private double[] zigZag = new double[64]; private int index = 0; private int index2 = 0; private int index3 = 0; double data = 0; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.compress); text = (EditText) findViewById(R.id.EditText01); text.setText("No Results"); input2 = DownloadFromUrl2("http://10.0.2.2/DCT/upload/compresvideopendek.avi"); //Log.d("DownloadFromUrl2", i2 + " "); unrle(input2); tulis2(unrle1, "decompresvideopendek.avi"); // tulis ke file external show(result2); } void tulis2(double[] param, String filename) { try { File file2 = new File(filename); FileOutputStream fos2 = new FileOutputStream(PATH + file2); ByteArrayBuffer baf2 = new ByteArrayBuffer(50); for (int i = 0; i < index3; i++) { baf2.append((byte) param[i]); Log.d("tulis2", i + " " + param[i]); } fos2.write(baf2.toByteArray()); fos2.close(); } catch (IOException e) { Log.d("tulis2", "Error: " + e); } } public void unrle(double[] zigZag1) { //hasil baca file kompresan double[] result = new double[64]; double data1 = 0; int data2 = 0; for (int i = 0; i = 64) { show3(result); toMatrix2 = toMatrix1(result);

    Universitas Sumatera Utara

  • DiscreteCosineTransform dctCom = new DiscreteCosineTransform(); result2 = dctCom.decompress(toMatrix2, levelQ); for (int l = 0; l < 8; l++) { for (int m = 0; m < 8; m++) { Log.d("decompress", l + " " + result2[l][m]); } } zigZag = initZigZag(result2); for (int j = 0; j < 64; j++) { unrle1[index3 + j] = zigZag[j]; Log.d("decompress", j + " " + zigZag[j]); } index3 = index3 + 64; index2 = 0; } } } public double[] DownloadFromUrl2(String imageURL) { try { URL url = new URL(imageURL); URLConnection ucon = url.openConnection(); InputStream is = ucon.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); int current = 0; while ((current = bis.read()) != -1) { input2[i2] = (byte) current; Log.d("DownloadFromUrl2", i2 + " " + input2[i2]); i2++; } } catch (IOException e) { Log.d("DownloadFromUrl2", "Error: " + e); } return input2; } private double[][] toMatrix1(double[] result) { double[][] toMatrix = new double[8][8]; toMatrix[0][0] = result[0]; // 0,0 toMatrix[0][1] = result[1]; // 0,1 toMatrix[1][0] = result[2]; // 1,0 toMatrix[2][0] = result[3]; // 2,0 toMatrix[1][1] = result[4]; // 1,1 toMatrix[0][2] = result[5]; // 0,2 toMatrix[0][3] = result[6]; // 0,3 toMatrix[1][2] = result[7]; // 1,2 toMatrix[2][1] = result[8]; // 2,1 toMatrix[3][0] = result[9]; // 3,0 toMatrix[4][0] = result[10]; // 4,0 toMatrix[3][1] = result[11]; // 3,1 toMatrix[2][2] = result[12]; // 2,2 toMatrix[1][3] = result[13]; // 1,3 toMatrix[0][4] = result[14]; // 0,4

    Universitas Sumatera Utara

  • toMatrix[0][5] = result[15]; // 0,5 toMatrix[1][4] = result[16]; // 1,4 toMatrix[2][3] = result[17]; // 2,3 toMatrix[3][2] = result[18]; // 3,2 toMatrix[4][1] = result[19]; // 4,1 toMatrix[5][0] = result[20]; // 5,0 toMatrix[6][0] = result[21]; // 6,0 toMatrix[5][1] = result[22]; // 5,1 toMatrix[4][2] = result[23]; // 4,2 toMatrix[3][3] = result[24]; // 3,3 toMatrix[2][4] = result[25]; // 2,4 toMatrix[1][5] = result[26]; // 1,5 toMatrix[0][6] = result[27]; // 0,6 toMatrix[0][7] = result[28]; // 0,7 toMatrix[1][6] = result[29]; // 1,6 toMatrix[2][5] = result[30]; // 2,5 toMatrix[3][4] = result[31]; // 3,4 toMatrix[4][3] = result[32]; // 4,3 toMatrix[5][2] = result[33]; // 5,2 toMatrix[6][1] = result[34]; // 6,1 toMatrix[7][0] = result[35]; // 7,0 toMatrix[7][1] = result[36]; // 7,1 toMatrix[6][2] = result[37]; // 6,2 toMatrix[5][3] = result[38]; // 5,3 toMatrix[4][4] = result[39]; // 4,4 toMatrix[3][5] = result[40]; // 3,5 toMatrix[2][6] = result[41]; // 2,6 toMatrix[1][7] = result[42]; // 1,7 toMatrix[2][7] = result[43]; // 2,7 toMatrix[3][6] = result[44]; // 3,6 toMatrix[4][5] = result[45]; // 4,5 toMatrix[5][4] = result[46]; // 5,4 toMatrix[6][3] = result[47]; // 6,3 toMatrix[7][2] = result[48]; // 7,2 toMatrix[7][3] = result[49]; // 7,3 toMatrix[6][4] = result[50]; // 6,4 toMatrix[5][5] = result[51]; // 5,5 toMatrix[4][6] = result[52]; // 4,6 toMatrix[3][7] = result[53]; // 3,7 toMatrix[4][7] = result[54]; // 4,7 toMatrix[5][6] = result[55]; // 5,6 toMatrix[6][5] = result[56]; // 6,5 toMatrix[7][4] = result[57]; // 7,4 toMatrix[7][5] = result[58]; // 7,5 toMatrix[6][6] = result[59]; // 6,6 toMatrix[5][7] = result[60]; // 5,7 toMatrix[6][7] = result[61]; // 6,7 toMatrix[7][6] = result[62]; // 7,6 toMatrix[7][7] = result[63]; // 7,7 return toMatrix; } void tulis(double[] param) { try { File file2 = new File("compresvideopendek.avi"); FileOutputStream fos2 = new FileOutputStream(PATH + file2); ByteArrayBuffer baf2 = new ByteArrayBuffer(50); for (int i = 0; i < index; i++) {

    Universitas Sumatera Utara

  • baf2.append((byte) param[i]); } fos2.write(baf2.toByteArray()); fos2.close(); } catch (IOException e) { Log.d("ImageManager", "Error tulis : " + e); } } private double[] initZigZag(double[][] result) { zigZag[0] = result[0][0]; // 0,0 zigZag[1] = result[0][1]; // 0,1 zigZag[2] = result[1][0]; // 1,0 zigZag[3] = result[2][0]; // 2,0 zigZag[4] = result[1][1]; // 1,1 zigZag[5] = result[0][2]; // 0,2 zigZag[6] = result[0][3]; // 0,3 zigZag[7] = result[1][2]; // 1,2 zigZag[8] = result[2][1]; // 2,1 zigZag[9] = result[3][0]; // 3,0 zigZag[10] = result[4][0]; // 4,0 zigZag[11] = result[3][1]; // 3,1 zigZag[12] = result[2][2]; // 2,2 zigZag[13] = result[1][3]; // 1,3 zigZag[14] = result[0][4]; // 0,4 zigZag[15] = result[0][5]; // 0,5 zigZag[16] = result[1][4]; // 1,4 zigZag[17] = result[2][3]; // 2,3 zigZag[18] = result[3][2]; // 3,2 zigZag[19] = result[4][1]; // 4,1 zigZag[20] = result[5][0]; // 5,0 zigZag[21] = result[6][0]; // 6,0 zigZag[22] = result[5][1]; // 5,1 zigZag[23] = result[4][2]; // 4,2 zigZag[24] = result[3][3]; // 3,3 zigZag[25] = result[2][4]; // 2,4 zigZag[26] = result[1][5]; // 1,5 zigZag[27] = result[0][6]; // 0,6 zigZag[28] = result[0][7]; // 0,7 zigZag[29] = result[1][6]; // 1,6 zigZag[30] = result[2][5]; // 2,5 zigZag[31] = result[3][4]; // 3,4 zigZag[32] = result[4][3]; // 4,3 zigZag[33] = result[5][2]; // 5,2 zigZag[34] = result[6][1]; // 6,1 zigZag[35] = result[7][0]; // 7,0 zigZag[36] = result[7][1]; // 7,1 zigZag[37] = result[6][2]; // 6,2 zigZag[38] = result[5][3]; // 5,3 zigZag[39] = result[4][4]; // 4,4 zigZag[40] = result[3][5]; // 3,5 zigZag[41] = result[2][6]; // 2,6 zigZag[42] = result[1][7]; // 1,7 zigZag[43] = result[2][7]; // 2,7 zigZag[44] = result[3][6]; // 3,6 zigZag[45] = result[4][5]; // 4,5 zigZag[46] = result[5][4]; // 5,4 zigZag[47] = result[6][3]; // 6,3 zigZag[48] = result[7][2]; // 7,2

    Universitas Sumatera Utara

  • zigZag[49] = result[7][3]; // 7,3 zigZag[50] = result[6][4]; // 6,4 zigZag[51] = result[5][5]; // 5,5 zigZag[52] = result[4][6]; // 4,6 zigZag[53] = result[3][7]; // 3,7 zigZag[54] = result[4][7]; // 4,7 zigZag[55] = result[5][6]; // 5,6 zigZag[56] = result[6][5]; // 6,5 zigZag[57] = result[7][4]; // 7,4 zigZag[58] = result[7][5]; // 7,5 zigZag[59] = result[6][6]; // 6,6 zigZag[60] = result[5][7]; // 5,7 zigZag[61] = result[6][7]; // 6,7 zigZag[62] = result[7][6]; // 7,6 zigZag[63] = result[7][7]; // 7,7 return zigZag; } double[][] formMatrix(double[] input) { for (int i = 0; i
  • }

    5. Kelas Downloadfile.java

    package febri_aulia_nugroho.tugasakhir.com; import java.io.BufferedInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; import org.apache.http.util.ByteArrayBuffer; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class DownloadFile extends Activity { Button Button01; EditText Edit01; TextView Text01; EditText Edit02; /** Called when the activity is first created. */ @Override

    Universitas Sumatera Utara

  • public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.download); Button01 = (Button)findViewById(R.id.Button01); Edit01 = (EditText)findViewById(R.id.EditText01); Text01 = (TextView)findViewById(R.id.TextView01); Edit02 = (EditText)findViewById(R.id.EditText02);

    Edit01.setText("http://10.0.2.2/DCT/downloaded.avi"); Button01.setOnClickListener(new OnClickListener(){ public void onClick(View v){ try{

    //DownloadFromUrl(Edit01.getText().toString().trim(),"downloaded.avi");

    DownloadFromUrl(Edit01.getText().toString().trim(),Edit02.getText().toString().trim());

    Text01.setText("File Have Been Downloaded"); } catch(Exception e) {

    ((EditText)findViewById(R.id.EditText01)).setText(e.toString()); } } }); }

    Universitas Sumatera Utara

  • public void DownloadFromUrl(String imageURL, String fileName) { ByteArrayBuffer baf = new ByteArrayBuffer(50); try { URL url = new URL(imageURL); File file = new File(fileName); URLConnection ucon = url.openConnection(); InputStream is = ucon.getInputStream();

    BufferedInputStream bis = new BufferedInputStream(is); int current = 0; //int i1 = 0; try {

    FileOutputStream fos = new FileOutputStream("/sdcard/" + file);

    while ((current = bis.read()) != -1) { baf.append((byte) current);

    //Log.d("ImageManager DownloadFromUrl LoG", i1 + " " + current); //i1++; } fos.write(baf.toByteArray()); fos.close(); } catch(Exception e) {

    FileOutputStream fos = new FileOutputStream("/sdcard/" + file); fos.write(baf.toByteArray()); fos.close(); }

    Universitas Sumatera Utara

  • } catch (IOException e) {

    Log.d("ImageManager", "Error DownloadFromUrl : " + e); } } }

    6. Kelas Upload.java

    package febri_aulia_nugroho.tugasakhir.com;

    import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class Upload extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.upload);

    Button button01 =(Button)findViewById(R.id.Button01);

    ((EditText)findViewById(R.id.EditText01)).setText(""); button01.setOnClickListener(new OnClickListener(){ public void onClick(View v){

    Universitas Sumatera Utara

  • try{ Uploader uploader = new Uploader();

    uploader.setUrlAndFile("http://10.0.2.2/DCT/receiver.php", ((EditText)findViewById(R.id.EditText01)).getText().toString(),(TextView)(findViewById(R.id.TextView01))); uploader.execute(); } catch(Exception e) {

    ((EditText)findViewById(R.id.EditText01)).setText(e.toString()); } } }); } }

    7. Receiver.php

  • 8. Kelas Uploader.java

    package febri_aulia_nugroho.tugasakhir.com;

    import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import android.os.AsyncTask; import android.widget.TextView;

    public class Uploader extends AsyncTask { URL connectURL; String params; String responseString; String fileName; byte[] dataToServer; FileInputStream fileInputStream; TextView info;

    void setUrlAndFile(String urlString, String fileName, TextView info) { this.info = info; try { System.out.println(fileName);

    fileInputStream = new FileInputStream(new File (fileName));

    Universitas Sumatera Utara

  • connectURL = new URL(urlString); } catch(Exception e) { publishProgress(e.toString()+"ais0"); } this.fileName = fileName; } synchronized void doUpload() { String lineEnd = "\r\n"; String twoHyphens = "--"; String boundary = "*****"; try { publishProgress("Uploading...");

    HttpURLConnection conn = (HttpURLConnection) connectURL.openConnection(); conn.setDoInput(true); conn.setDoOutput(true); conn.setUseCaches(false); conn.setRequestMethod("POST");

    conn.setRequestProperty("Connection", "Keep-Alive");

    conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);

    DataOutputStream dos = new DataOutputStream( conn.getOutputStream() );

    dos.writeBytes(twoHyphens + boundary + lineEnd);

    dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + fileName +"\"" + lineEnd); dos.writeBytes(lineEnd);

    Universitas Sumatera Utara

  • int bytesAvailable = fileInputStream.available(); int maxBufferSize = 1*1024*1024;

    int bufferSize = Math.min(bytesAvailable, maxBufferSize); byte[] buffer = new byte[bufferSize];

    int bytesRead = fileInputStream.read(buffer, 0, bufferSize); while (bytesRead > 0) { dos.write(buffer, 0, bufferSize);

    bytesAvailable = fileInputStream.available();

    bufferSize = Math.min(bytesAvailable, maxBufferSize);

    bytesRead = fileInputStream.read(buffer, 0, bufferSize); } dos.writeBytes(lineEnd); dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd); fileInputStream.close(); dos.flush(); InputStream is = conn.getInputStream(); int ch; StringBuffer buff = new StringBuffer(); while((ch=is.read())!=-1) {

    Universitas Sumatera Utara

  • buff.append((char)ch); } publishProgress(buff.toString()); dos.close(); } catch (Exception e) { publishProgress(e.toString()+"ais1"); } } @Override protected Object doInBackground(Object... arg0) { doUpload(); return null; } protected void onProgressUpdate(String... progress) { this.info.setText(progress[0]); } }

    9. Kelas DiscreteCosineTransform

    package febri_aulia_nugroho.tugasakhir.com; import android.widget.Toast; public class DiscreteCosineTransform { int N = 8; private double[][] dataOriginal = new double[N][N]; private double[][] M = new double[N][N]; private double[][] D = new double[N][N]; private double[][] Q = new double[N][N]; private double[][] outCom = new double[N][N]; //private double[][] R = new double[N][N]; //private double[][] outDec = new double[N][N]; private double[][] C = new double[N][N]; private double[][] CDec = new double[N][N]; private double[][] NDec = new double[N][N];

    Universitas Sumatera Utara

  • double[][] T = { { 0.3536, 0.3536, 0.3536, 0.3536, 0.3536, 0.3536, 0.3536, 0.3536 }, { 0.4904, 0.4157, 0.2778, 0.0975, -0.0975, -0.2778, -0.4157, -0.4904 }, { 0.4619, 0.1913, -0.1913, -0.4619, -0.4619, -0.1913, 0.1913, 0.4619 }, { 0.4157, -0.0975, -0.4904, -0.2778, -0.2778, 0.4904, 0.0975, -0.4157 }, { 0.3536, -0.3536, -0.3536, 0.3536, 0.3536, -0.3536, -0.3536, -0.3536 }, { 0.2778, -0.4904, -0.0975, 0.4157, -0.4157, -0.0975, 0.4904, -0.2778 }, { 0.1913, -0.4619, 0.4619, -0.1913, -0.1913, 0.4619, -0.4619, 0.1913 }, { 0.0975, -0.2778, 0.4157, -0.4904, 0.4904, -0.4157, 0.2778, -0.0975 }, }; double[][] Q10 = { { 80, 60, 50,80, 120, 200, 255, 255 }, { 55, 60, 70, 95, 130, 255, 255, 255, 255 }, { 70, 65, 80, 120, 200, 255, 255, 255, 255 }, { 70, 85, 110, 145, 255, 255, 255, 255, 255 }, { 90, 110, 185, 255, 255, 255, 255, 255, 255 }, { 120, 175, 255, 255, 255, 255, 255, 255, 255 }, { 245, 255, 255, 255, 255, 255, 255, 255, 255 }, { 255, 255, 255, 255, 255, 255, 255, 255, 255 }, }; double[][] Q50 = { { 16, 11, 10, 16, 24, 40, 51, 61 }, { 12, 12, 14, 19, 26, 58, 60, 55 }, { 14, 13, 16, 24, 40, 57, 69, 56 }, { 14, 17, 22, 29, 51, 87, 80, 62 }, { 18, 22, 37, 56, 68, 109, 103, 77 }, { 24, 35, 55, 64, 81, 104, 113, 92 }, { 49, 64, 78, 87, 102, 121, 120, 101 }, { 72, 92, 95, 98, 112, 100, 103, 99 }, }; double[][] Q90 = { { 3, 2, 2, 3, 5, 8, 10, 12 }, { 2, 2, 3, 4, 5, 12, 12, 11 }, { 3, 3, 3, 5, 8, 11, 14, 11 }, { 3, 3, 4, 6, 10, 17, 16, 12 }, { 4, 4, 7, 11, 14, 22, 21, 15 }, { 5, 7, 11, 13, 16, 12, 23, 18 }, { 10, 13, 16, 17, 21, 24, 24, 21 }, { 14, 18, 19, 20, 22, 20, 20, 20 }, }; public double[][] compress(double[][] dataOriginal, int levelQ) { setDataOriginal(dataOriginal); setM();

    Universitas Sumatera Utara

  • setD(); setQ(levelQ); setC(); double[][] outputC = getC(); return outputC; } public void setDataOriginal(double[][] param) { dataOriginal = param; } public double[][] getDataOriginal() { return dataOriginal; } public double[][] getT() { return this.T; } public double[][] getTT() { int i; int j; double[][] temp = new double[N][N]; //selesaikan temp = M x CT for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { temp[i][j] = T[j][i]; } } return temp; } public void setM() { int i; int j; double[][] tempResult = new double[N][N]; double[][] tempDataOriginal = getDataOriginal(); for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { tempResult[i][j] = tempDataOriginal[i][j] - 128; } } this.M = tempResult; } public double[][] getM() { return this.M; }

    Universitas Sumatera Utara

  • public void setD() { int i; int j; double[][] tempResult = new double[N][N]; double[][] tempM = this.getM(); double[][] tempCT = this.getTT(); double[][] tempT = this.getT(); for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { tempResult[i][j] = tempM[i][j] * tempCT[i][j]; } } for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { tempResult[i][j] = tempT[i][j] * tempResult[i][j]; } } this.D = tempResult; } public double[][] getD() { return this.D; } public void setQ(int levelQ) { if (levelQ == 10) { Q = this.Q10; } else if (levelQ == 50) { Q = this.Q50; } else if (levelQ == 90) { Q = this.Q90; } } public double[][] getQ() { return this.Q; } public void setC() { int i; int j; double[][] tempQ = this.getQ(); double[][] tempD = this.getD();

    Universitas Sumatera Utara

  • double[][] tempResult = new double[N][N]; for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { tempResult[i][j] = Math.round(tempD[i][j] / tempQ[i][j]); } } this.C = tempResult; } public double[][] getC() { return this.C; } public void show() { String s = ""; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { s = outCom[i][j] + ""; Toast.makeText(null, s, 2000).show(); } } } //====================================================================================================== // BEGIN: DEKOMPRESI //====================================================================================================== public void setCDec() { int i; int j; double[][] tempResult = new double[N][N]; double[][] tempDataOriginal = getDataOriginal(); for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { tempResult[i][j] = tempDataOriginal[i][j] - 128; } } this.CDec = tempResult; } public double[][] getCDec() { return this.CDec; } public void setR() { int i; int j; double[][] tempQ = this.getQ(); double[][] tempCDec = this.getCDec();

    Universitas Sumatera Utara

  • double[][] tempResult = new double[N][N]; for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { tempResult[i][j] = (tempQ[i][j] * tempCDec[i][j]); } } this.CDec = tempResult; } public double[][] getR() { return this.CDec; } public void setNDec() { int i; int j; double[][] tempT = this.getT(); double[][] tempR = this.getR(); double[][] tempTT = this.getTT(); double[][] tempResult = new double[N][N]; for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { tempResult[i][j] = tempR[i][j] * tempT[i][j]; } } for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { tempResult[i][j] = Math.round(tempTT[i][j] * tempResult[i][j]) - 128; } } this.NDec = tempResult; } public double[][] getNDec() { return this.NDec; } public double[][] decompress(double[][] dataOriginal, int levelQ) { setDataOriginal(dataOriginal); setQ(levelQ); setCDec(); setR(); setNDec();

    Universitas Sumatera Utara

  • double[][] output = getNDec(); return output; } //====================================================================================================== // END: DEKOMPRESI //======================================================================================================

    1. } Manifest Aplikasi

    Universitas Sumatera Utara

  • Universitas Sumatera Utara

  • LAMPIRAN 2

    Foto Pengujian Pada Mobile Phone berbasis Android 2.2

    Universitas Sumatera Utara

  • Universitas Sumatera Utara

  • Universitas Sumatera Utara

  • Universitas Sumatera Utara

  • Universitas Sumatera Utara

  • LAMPIRAN 3

    SKEMA JARINGAN PENGUJIAN

    Universitas Sumatera Utara