DCT.java
上传用户:mingda
上传日期:2017-06-20
资源大小:27691k
文件大小:12k
源码类别:

OA系统

开发平台:

Java

  1. // Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov  Date: 2002-12-05 9:38:45
  2. // Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
  3. // Decompiler options: packimports(3) 
  4. // Source File Name:   JpegEncoder.java
  5. package cn.com.fcsoft.chart.jpeg;
  6. class DCT
  7. {
  8.     public double[][] forwardDCT(float af[][])
  9.     {
  10.         double ad[][] = new double[N][N];
  11.         int i = 0;
  12.         do
  13.         {
  14.             int j = 0;
  15.             do
  16.                 ad[i][j] = (double)af[i][j] - 128D;
  17.             while(++j < 8);
  18.         } while(++i < 8);
  19.         i = 0;
  20.         do
  21.         {
  22.             double d = ad[i][0] + ad[i][7];
  23.             double d14 = ad[i][0] - ad[i][7];
  24.             double d2 = ad[i][1] + ad[i][6];
  25.             double d12 = ad[i][1] - ad[i][6];
  26.             double d4 = ad[i][2] + ad[i][5];
  27.             double d10 = ad[i][2] - ad[i][5];
  28.             double d6 = ad[i][3] + ad[i][4];
  29.             double d8 = ad[i][3] - ad[i][4];
  30.             double d16 = d + d6;
  31.             double d22 = d - d6;
  32.             double d18 = d2 + d4;
  33.             double d20 = d2 - d4;
  34.             ad[i][0] = d16 + d18;
  35.             ad[i][4] = d16 - d18;
  36.             double d24 = (d20 + d22) * 0.70710678100000002D;
  37.             ad[i][2] = d22 + d24;
  38.             ad[i][6] = d22 - d24;
  39.             d16 = d8 + d10;
  40.             d18 = d10 + d12;
  41.             d20 = d12 + d14;
  42.             double d32 = (d16 - d20) * 0.38268343300000002D;
  43.             double d26 = 0.54119609999999996D * d16 + d32;
  44.             double d30 = 1.3065629649999999D * d20 + d32;
  45.             double d28 = d18 * 0.70710678100000002D;
  46.             double d34 = d14 + d28;
  47.             double d36 = d14 - d28;
  48.             ad[i][5] = d36 + d26;
  49.             ad[i][3] = d36 - d26;
  50.             ad[i][1] = d34 + d30;
  51.             ad[i][7] = d34 - d30;
  52.         } while(++i < 8);
  53.         i = 0;
  54.         do
  55.         {
  56.             double d1 = ad[0][i] + ad[7][i];
  57.             double d15 = ad[0][i] - ad[7][i];
  58.             double d3 = ad[1][i] + ad[6][i];
  59.             double d13 = ad[1][i] - ad[6][i];
  60.             double d5 = ad[2][i] + ad[5][i];
  61.             double d11 = ad[2][i] - ad[5][i];
  62.             double d7 = ad[3][i] + ad[4][i];
  63.             double d9 = ad[3][i] - ad[4][i];
  64.             double d17 = d1 + d7;
  65.             double d23 = d1 - d7;
  66.             double d19 = d3 + d5;
  67.             double d21 = d3 - d5;
  68.             ad[0][i] = d17 + d19;
  69.             ad[4][i] = d17 - d19;
  70.             double d25 = (d21 + d23) * 0.70710678100000002D;
  71.             ad[2][i] = d23 + d25;
  72.             ad[6][i] = d23 - d25;
  73.             d17 = d9 + d11;
  74.             d19 = d11 + d13;
  75.             d21 = d13 + d15;
  76.             double d33 = (d17 - d21) * 0.38268343300000002D;
  77.             double d27 = 0.54119609999999996D * d17 + d33;
  78.             double d31 = 1.3065629649999999D * d21 + d33;
  79.             double d29 = d19 * 0.70710678100000002D;
  80.             double d35 = d15 + d29;
  81.             double d37 = d15 - d29;
  82.             ad[5][i] = d37 + d27;
  83.             ad[3][i] = d37 - d27;
  84.             ad[1][i] = d35 + d31;
  85.             ad[7][i] = d35 - d31;
  86.         } while(++i < 8);
  87.         return ad;
  88.     }
  89.     public DCT(int i)
  90.     {
  91.         N = 8;
  92.         QUALITY = 80;
  93.         quantum = new Object[2];
  94.         Divisors = new Object[2];
  95.         quantum_luminance = new int[N * N];
  96.         DivisorsLuminance = new double[N * N];
  97.         quantum_chrominance = new int[N * N];
  98.         DivisorsChrominance = new double[N * N];
  99.         initMatrix(i);
  100.     }
  101.     public int[] quantizeBlockExtreme(double ad[][], int i)
  102.     {
  103.         int ai[] = new int[N * N];
  104.         int l = 0;
  105.         int j = 0;
  106.         do
  107.         {
  108.             int k = 0;
  109.             do
  110.             {
  111.                 ai[l] = (int)Math.round(ad[j][k] / (double)((int[])quantum[i])[l]);
  112.                 l++;
  113.             } while(++k < 8);
  114.         } while(++j < 8);
  115.         return ai;
  116.     }
  117.     public int[] quantizeBlock(double ad[][], int i)
  118.     {
  119.         int ai[] = new int[N * N];
  120.         int l = 0;
  121.         int j = 0;
  122.         do
  123.         {
  124.             int k = 0;
  125.             do
  126.             {
  127.                 ai[l] = (int)Math.round(ad[j][k] * ((double[])Divisors[i])[l]);
  128.                 l++;
  129.             } while(++k < 8);
  130.         } while(++j < 8);
  131.         return ai;
  132.     }
  133.     private void initMatrix(int i)
  134.     {
  135.         double ad[] = {
  136.             1.0D, 1.3870398450000001D, 1.3065629649999999D, 1.1758756020000001D, 1.0D, 0.785694958D, 0.54119609999999996D, 0.275899379D
  137.         };
  138.         int j1 = i;
  139.         if(j1 <= 0)
  140.             j1 = 1;
  141.         if(j1 > 100)
  142.             j1 = 100;
  143.         if(j1 < 50)
  144.             j1 = 5000 / j1;
  145.         else
  146.             j1 = 200 - j1 * 2;
  147.         quantum_luminance[0] = 16;
  148.         quantum_luminance[1] = 11;
  149.         quantum_luminance[2] = 10;
  150.         quantum_luminance[3] = 16;
  151.         quantum_luminance[4] = 24;
  152.         quantum_luminance[5] = 40;
  153.         quantum_luminance[6] = 51;
  154.         quantum_luminance[7] = 61;
  155.         quantum_luminance[8] = 12;
  156.         quantum_luminance[9] = 12;
  157.         quantum_luminance[10] = 14;
  158.         quantum_luminance[11] = 19;
  159.         quantum_luminance[12] = 26;
  160.         quantum_luminance[13] = 58;
  161.         quantum_luminance[14] = 60;
  162.         quantum_luminance[15] = 55;
  163.         quantum_luminance[16] = 14;
  164.         quantum_luminance[17] = 13;
  165.         quantum_luminance[18] = 16;
  166.         quantum_luminance[19] = 24;
  167.         quantum_luminance[20] = 40;
  168.         quantum_luminance[21] = 57;
  169.         quantum_luminance[22] = 69;
  170.         quantum_luminance[23] = 56;
  171.         quantum_luminance[24] = 14;
  172.         quantum_luminance[25] = 17;
  173.         quantum_luminance[26] = 22;
  174.         quantum_luminance[27] = 29;
  175.         quantum_luminance[28] = 51;
  176.         quantum_luminance[29] = 87;
  177.         quantum_luminance[30] = 80;
  178.         quantum_luminance[31] = 62;
  179.         quantum_luminance[32] = 18;
  180.         quantum_luminance[33] = 22;
  181.         quantum_luminance[34] = 37;
  182.         quantum_luminance[35] = 56;
  183.         quantum_luminance[36] = 68;
  184.         quantum_luminance[37] = 109;
  185.         quantum_luminance[38] = 103;
  186.         quantum_luminance[39] = 77;
  187.         quantum_luminance[40] = 24;
  188.         quantum_luminance[41] = 35;
  189.         quantum_luminance[42] = 55;
  190.         quantum_luminance[43] = 64;
  191.         quantum_luminance[44] = 81;
  192.         quantum_luminance[45] = 104;
  193.         quantum_luminance[46] = 113;
  194.         quantum_luminance[47] = 92;
  195.         quantum_luminance[48] = 49;
  196.         quantum_luminance[49] = 64;
  197.         quantum_luminance[50] = 78;
  198.         quantum_luminance[51] = 87;
  199.         quantum_luminance[52] = 103;
  200.         quantum_luminance[53] = 121;
  201.         quantum_luminance[54] = 120;
  202.         quantum_luminance[55] = 101;
  203.         quantum_luminance[56] = 72;
  204.         quantum_luminance[57] = 92;
  205.         quantum_luminance[58] = 95;
  206.         quantum_luminance[59] = 98;
  207.         quantum_luminance[60] = 112;
  208.         quantum_luminance[61] = 100;
  209.         quantum_luminance[62] = 103;
  210.         quantum_luminance[63] = 99;
  211.         int k = 0;
  212.         do
  213.         {
  214.             int k1 = (quantum_luminance[k] * j1 + 50) / 100;
  215.             if(k1 <= 0)
  216.                 k1 = 1;
  217.             if(k1 > 255)
  218.                 k1 = 255;
  219.             quantum_luminance[k] = k1;
  220.         } while(++k < 64);
  221.         int i1 = 0;
  222.         int j = 0;
  223.         do
  224.         {
  225.             k = 0;
  226.             do
  227.             {
  228.                 DivisorsLuminance[i1] = 1.0D / ((double)quantum_luminance[i1] * ad[j] * ad[k] * 8D);
  229.                 i1++;
  230.             } while(++k < 8);
  231.         } while(++j < 8);
  232.         quantum_chrominance[0] = 17;
  233.         quantum_chrominance[1] = 18;
  234.         quantum_chrominance[2] = 24;
  235.         quantum_chrominance[3] = 47;
  236.         quantum_chrominance[4] = 99;
  237.         quantum_chrominance[5] = 99;
  238.         quantum_chrominance[6] = 99;
  239.         quantum_chrominance[7] = 99;
  240.         quantum_chrominance[8] = 18;
  241.         quantum_chrominance[9] = 21;
  242.         quantum_chrominance[10] = 26;
  243.         quantum_chrominance[11] = 66;
  244.         quantum_chrominance[12] = 99;
  245.         quantum_chrominance[13] = 99;
  246.         quantum_chrominance[14] = 99;
  247.         quantum_chrominance[15] = 99;
  248.         quantum_chrominance[16] = 24;
  249.         quantum_chrominance[17] = 26;
  250.         quantum_chrominance[18] = 56;
  251.         quantum_chrominance[19] = 99;
  252.         quantum_chrominance[20] = 99;
  253.         quantum_chrominance[21] = 99;
  254.         quantum_chrominance[22] = 99;
  255.         quantum_chrominance[23] = 99;
  256.         quantum_chrominance[24] = 47;
  257.         quantum_chrominance[25] = 66;
  258.         quantum_chrominance[26] = 99;
  259.         quantum_chrominance[27] = 99;
  260.         quantum_chrominance[28] = 99;
  261.         quantum_chrominance[29] = 99;
  262.         quantum_chrominance[30] = 99;
  263.         quantum_chrominance[31] = 99;
  264.         quantum_chrominance[32] = 99;
  265.         quantum_chrominance[33] = 99;
  266.         quantum_chrominance[34] = 99;
  267.         quantum_chrominance[35] = 99;
  268.         quantum_chrominance[36] = 99;
  269.         quantum_chrominance[37] = 99;
  270.         quantum_chrominance[38] = 99;
  271.         quantum_chrominance[39] = 99;
  272.         quantum_chrominance[40] = 99;
  273.         quantum_chrominance[41] = 99;
  274.         quantum_chrominance[42] = 99;
  275.         quantum_chrominance[43] = 99;
  276.         quantum_chrominance[44] = 99;
  277.         quantum_chrominance[45] = 99;
  278.         quantum_chrominance[46] = 99;
  279.         quantum_chrominance[47] = 99;
  280.         quantum_chrominance[48] = 99;
  281.         quantum_chrominance[49] = 99;
  282.         quantum_chrominance[50] = 99;
  283.         quantum_chrominance[51] = 99;
  284.         quantum_chrominance[52] = 99;
  285.         quantum_chrominance[53] = 99;
  286.         quantum_chrominance[54] = 99;
  287.         quantum_chrominance[55] = 99;
  288.         quantum_chrominance[56] = 99;
  289.         quantum_chrominance[57] = 99;
  290.         quantum_chrominance[58] = 99;
  291.         quantum_chrominance[59] = 99;
  292.         quantum_chrominance[60] = 99;
  293.         quantum_chrominance[61] = 99;
  294.         quantum_chrominance[62] = 99;
  295.         quantum_chrominance[63] = 99;
  296.         k = 0;
  297.         do
  298.         {
  299.             int l1 = (quantum_chrominance[k] * j1 + 50) / 100;
  300.             if(l1 <= 0)
  301.                 l1 = 1;
  302.             if(l1 >= 255)
  303.                 l1 = 255;
  304.             quantum_chrominance[k] = l1;
  305.         } while(++k < 64);
  306.         i1 = 0;
  307.         j = 0;
  308.         do
  309.         {
  310.             int l = 0;
  311.             do
  312.             {
  313.                 DivisorsChrominance[i1] = 1.0D / ((double)quantum_chrominance[i1] * ad[j] * ad[l] * 8D);
  314.                 i1++;
  315.             } while(++l < 8);
  316.         } while(++j < 8);
  317.         quantum[0] = quantum_luminance;
  318.         Divisors[0] = DivisorsLuminance;
  319.         quantum[1] = quantum_chrominance;
  320.         Divisors[1] = DivisorsChrominance;
  321.     }
  322.     public double[][] forwardDCTExtreme(float af[][])
  323.     {
  324.         double ad[][] = new double[N][N];
  325.         int i = 0;
  326.         do
  327.         {
  328.             int j = 0;
  329.             do
  330.             {
  331.                 int k = 0;
  332.                 do
  333.                 {
  334.                     int l = 0;
  335.                     do
  336.                         ad[i][j] += (double)af[k][l] * Math.cos(((double)(2 * k + 1) * (double)j * 3.1415926535897931D) / 16D) * Math.cos(((double)(2 * l + 1) * (double)i * 3.1415926535897931D) / 16D);
  337.                     while(++l < 8);
  338.                 } while(++k < 8);
  339.                 ad[i][j] *= 0.25D * (j != 0 ? 1.0D : 1.0D / Math.sqrt(2D)) * (i != 0 ? 1.0D : 1.0D / Math.sqrt(2D));
  340.             } while(++j < 8);
  341.         } while(++i < 8);
  342.         return ad;
  343.     }
  344.     public int N;
  345.     public int QUALITY;
  346.     public Object quantum[];
  347.     public Object Divisors[];
  348.     public int quantum_luminance[];
  349.     public double DivisorsLuminance[];
  350.     public int quantum_chrominance[];
  351.     public double DivisorsChrominance[];
  352. }