Exemple #1
0
        public DCTTile Merge(DCTTile tile, long distortion)//IEnumerable<DCTTile> tiles)
        {
            //int simdLength = Vector<int>.Count;
            var newDct = new[] { new int[64], new int[64], new int[64] };

            // Parallel.For(0, 3, i =>
            for (int i = 0; i < 3; i++)
            {
                //Array.Copy(_dcts[i], newDct[i], 64);
                //int count = 2;
                //foreach (var tile in tiles)
                //{
                //Parallel.For(0, 64, k =>
                for (int k = 0; k < 64; k++)
                {
                    newDct[i][k] = (_dcts[i][k] * MergeFactor + tile._dcts[i][k] * tile.MergeFactor) / (MergeFactor + tile.MergeFactor);
                }    //);
                     //  count++;
                     //}
                     //Parallel.For(0, 64, k =>
                     //{
                     //    newDct[i][k] /= 2;//count;
                     //});
            }//);
            return(new DCTTile(newDct)
            {
                MergeFactor = MergeFactor + tile.MergeFactor, Distortion = distortion
            });
        }
Exemple #2
0
        public long CompareNew(DCTTile b)
        {
            var results = new long[3];

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 64; j++)
                {
                    long diff = _dcts[i][j] - b._dcts[i][j];
                    diff       *= diff;
                    diff        = diff * Weights[j] / 32;
                    results[i] += diff;
                }
            }
            return((results[0] * 10 + results[1] * 4 + results[2] * 6) * 128 / 166);
        }
Exemple #3
0
        public long CompareComplete(DCTTile b)
        {
            var results = new long[3];

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 64; j++)
                {
                    long diff = _dcts[i][j] - b._dcts[i][j];
                    diff *= diff;
                    //if (diff < 0)
                    //    diff = -diff;
                    results[i] += diff;
                }
            }
            return(results[0] * 10 + results[1] * 4 + results[2] * 6);
        }
Exemple #4
0
        public long Compare(DCTTile b)
        {
            //int simdLength = Vector<int>.Count;
            //todo: weights for each dct coefficient
            var results = new long[3];

            for (int i = 0; i < 3; i++)//Parallel.For(0, 3, i =>
            {
                /*int[] diffs = new int[64];
                 * for (int j = 0; j < 64; j++)
                 * {
                 *  int diff = _dcts[i][j] - b._dcts[i][j];
                 *  if (diff < 0)
                 *      diff = -diff;
                 *  diffs[j] = diff;
                 * }*/

                //normalization
                //int myMax = _dcts[i].Max(a => a < 0 ? -a : a);
                //int bMax = b._dcts[i].Max(a => a < 0 ? -a : a);
                //int avg = (myMax + bMax) / 2;


                long diff00 = _dcts[i][0] - b._dcts[i][0];
                diff00 *= diff00;
                //if (diff00 < 0)
                //    diff00 = -diff00;
                long diff01 = _dcts[i][1] - b._dcts[i][1];
                diff01 *= diff01;
                // if (diff01 < 0)
                //    diff01 = -diff01;

                // int diff02 = _dcts[i][2] - b._dcts[i][2];
                //  if (diff02 < 0)
                //     diff02 = -diff02;

                long diff10 = _dcts[i][8] - b._dcts[i][8];
                diff10 *= diff10;
                // if (diff10 < 0)
                //   diff10 = -diff10;
                long diff11 = _dcts[i][9] - b._dcts[i][9];
                diff11 *= diff11;
                // if (diff11 < 0)
                //     diff11 = -diff11;

                // int diff20 = _dcts[i][16] - b._dcts[i][16];
                // if (diff20 < 0)
                //    diff20 = -diff20;
                results[i] = (diff00 * 5 + diff01 * 2 + diff10 * 2 + diff11) * 4 / 10;
                // results[i] = (diff00 * 5 + diff01 * 2 + diff10 * 2 + diff11 + diff02 + diff20) * 4 / 12;*/
                //results[i] = (2 * diffs[0] + diffs[1] + diffs[2] + diffs[3] + diffs[8] + diffs[16] + diffs[24]) / 2;

                /*for (int y = 0; y < 2; y++)
                 * {
                 *  for(int x = 0; x < 2; x++)
                 *  {
                 *      int diff = _dcts[i][y * 8 + x] - b._dcts[i][y * 8 + x];
                 *      if (diff < 0)
                 *          diff = -diff;
                 *      results[i] += diff;
                 *  }
                 * }*/
            }//);
            return(results[0] * 10 + results[1] * 4 + results[2] * 6);
        }