Ejemplo n.º 1
0
        /*
         * input kernel area naming convention:
         * -----------------
         | A | B | C | D |
         | ----|---|---|---|
         | E | F | G | H | //evalute the four corners between F, G, J, K
         | ----|---|---|---| //input pixel is at position F
         | I | J | K | L |
         | ----|---|---|---|
         | M | N | O | P |
         | -----------------
         */

        //detect blend direction
        private static void _PreProcessCorners(Kernel_4X4 kernel, BlendResult blendResult, IColorDist preProcessCornersColorDist)
        {
            blendResult.Reset();

            if ((kernel.f == kernel.g && kernel.j == kernel.k) || (kernel.f == kernel.j && kernel.g == kernel.k))
            {
                return;
            }

            var dist = preProcessCornersColorDist;

            var weight = 4;
            var jg     = dist._(kernel.i, kernel.f) + dist._(kernel.f, kernel.c) + dist._(kernel.n, kernel.k) + dist._(kernel.k, kernel.h) + weight * dist._(kernel.j, kernel.g);
            var fk     = dist._(kernel.e, kernel.j) + dist._(kernel.j, kernel.o) + dist._(kernel.b, kernel.g) + dist._(kernel.g, kernel.l) + weight * dist._(kernel.f, kernel.k);

            if (jg < fk)
            {
                var dominantGradient = _CONFIGURATION.dominantDirectionThreshold * jg < fk;
                if (kernel.f != kernel.g && kernel.f != kernel.j)
                {
                    blendResult.f = dominantGradient ? BlendType.BlendDominant : BlendType.BlendNormal;
                }

                if (kernel.k != kernel.j && kernel.k != kernel.g)
                {
                    blendResult.k = dominantGradient ? BlendType.BlendDominant : BlendType.BlendNormal;
                }
            }
            else if (fk < jg)
            {
                var dominantGradient = _CONFIGURATION.dominantDirectionThreshold * fk < jg;
                if (kernel.j != kernel.f && kernel.j != kernel.k)
                {
                    blendResult.j = dominantGradient ? BlendType.BlendDominant : BlendType.BlendNormal;
                }

                if (kernel.g != kernel.f && kernel.g != kernel.k)
                {
                    blendResult.g = dominantGradient ? BlendType.BlendDominant : BlendType.BlendNormal;
                }
            }
        }
Ejemplo n.º 2
0
        //detect blend direction
        private void PreProcessCorners(Kernel4x4 ker)
        {
            _blendResult.Reset();

            if ((ker.F == ker.G && ker.J == ker.K) || (ker.F == ker.J && ker.G == ker.K))
            {
                return;
            }

            var dist = _colorDistance;

            const int weight = 4;
            var       jg     = dist.DistYCbCr(ker.I, ker.F) + dist.DistYCbCr(ker.F, ker.C) + dist.DistYCbCr(ker.N, ker.K) + dist.DistYCbCr(ker.K, ker.H) + weight * dist.DistYCbCr(ker.J, ker.G);
            var       fk     = dist.DistYCbCr(ker.E, ker.J) + dist.DistYCbCr(ker.J, ker.O) + dist.DistYCbCr(ker.B, ker.G) + dist.DistYCbCr(ker.G, ker.L) + weight * dist.DistYCbCr(ker.F, ker.K);

            if (jg < fk)
            {
                var dominantGradient = _cfg.DominantDirectionThreshold * jg < fk;
                if (ker.F != ker.G && ker.F != ker.J)
                {
                    _blendResult.F = (char)(dominantGradient ? BlendType.Dominant : BlendType.Normal);
                }
                if (ker.K != ker.J && ker.K != ker.G)
                {
                    _blendResult.K = (char)(dominantGradient ? BlendType.Dominant : BlendType.Normal);
                }
            }
            else if (fk < jg)
            {
                var dominantGradient = _cfg.DominantDirectionThreshold * fk < jg;
                if (ker.J != ker.F && ker.J != ker.K)
                {
                    _blendResult.J = (char)(dominantGradient ? BlendType.Dominant : BlendType.Normal);
                }
                if (ker.G != ker.F && ker.G != ker.K)
                {
                    _blendResult.G = (char)(dominantGradient ? BlendType.Dominant : BlendType.Normal);
                }
            }
        }
Ejemplo n.º 3
0
    /*
  input kernel area naming convention:
  -----------------
  | A | B | C | D |
  ----|---|---|---|
  | E | F | G | H | //evalute the four corners between F, G, J, K
  ----|---|---|---| //input pixel is at position F
  | I | J | K | L |
  ----|---|---|---|
  | M | N | O | P |
  -----------------
  */

    //detect blend direction
    private static void _PreProcessCorners(Kernel_4X4 kernel, BlendResult blendResult, IColorDist preProcessCornersColorDist) {
      blendResult.Reset();

      if ((kernel.f == kernel.g && kernel.j == kernel.k) || (kernel.f == kernel.j && kernel.g == kernel.k))
        return;

      var dist = preProcessCornersColorDist;

      var weight = 4;
      var jg = dist._(kernel.i, kernel.f) + dist._(kernel.f, kernel.c) + dist._(kernel.n, kernel.k) + dist._(kernel.k, kernel.h) + weight * dist._(kernel.j, kernel.g);
      var fk = dist._(kernel.e, kernel.j) + dist._(kernel.j, kernel.o) + dist._(kernel.b, kernel.g) + dist._(kernel.g, kernel.l) + weight * dist._(kernel.f, kernel.k);

      if (jg < fk) {

        var dominantGradient = _CONFIGURATION.dominantDirectionThreshold * jg < fk;
        if (kernel.f != kernel.g && kernel.f != kernel.j)
          blendResult.f = dominantGradient ? BlendType.BlendDominant : BlendType.BlendNormal;

        if (kernel.k != kernel.j && kernel.k != kernel.g)
          blendResult.k = dominantGradient ? BlendType.BlendDominant : BlendType.BlendNormal;

      } else if (fk < jg) {

        var dominantGradient = _CONFIGURATION.dominantDirectionThreshold * fk < jg;
        if (kernel.j != kernel.f && kernel.j != kernel.k)
          blendResult.j = dominantGradient ? BlendType.BlendDominant : BlendType.BlendNormal;

        if (kernel.g != kernel.f && kernel.g != kernel.k)
          blendResult.g = dominantGradient ? BlendType.BlendDominant : BlendType.BlendNormal;

      }
    }