/*
         * input kernel area naming convention:
         * -------------
         | A | B | C |
         | ----|---|---|
         | D | E | F | //input pixel is at position E
         | ----|---|---|
         | G | H | I |
         | -------------
         */

        private static void _ScalePixel(
            IScaler scaler,
            RotationDegree rotDeg,
            Kernel_3X3 ker,
            sPixel[] trg,
            int trgi,
            int trgWidth,
            byte blendInfo,      //result of preprocessing all four corners of pixel "e"
            IColorEq scalePixelColorEq,
            IColorDist scalePixelColorDist,
            OutputMatrix outputMatrix
            )
        {
            //int a = kernel._[Rot._[(0 << 2) + rotDeg]];
            var b = ker._[Rot._[(1 << 2) + (int)rotDeg]];
            var c = ker._[Rot._[(2 << 2) + (int)rotDeg]];
            var d = ker._[Rot._[(3 << 2) + (int)rotDeg]];
            var e = ker._[Rot._[(4 << 2) + (int)rotDeg]];
            var f = ker._[Rot._[(5 << 2) + (int)rotDeg]];
            var g = ker._[Rot._[(6 << 2) + (int)rotDeg]];
            var h = ker._[Rot._[(7 << 2) + (int)rotDeg]];
            var i = ker._[Rot._[(8 << 2) + (int)rotDeg]];

            var blend = BlendInfo.Rotate(blendInfo, rotDeg);

            if (BlendInfo.GetBottomR(blend) == BlendType.BlendNone)
            {
                return;
            }

            var eq   = scalePixelColorEq;
            var dist = scalePixelColorDist;

            bool doLineBlend;

            if (BlendInfo.GetBottomR(blend) >= BlendType.BlendDominant)
            {
                doLineBlend = true;
            }

            //make sure there is no second blending in an adjacent
            //rotation for this pixel: handles insular pixels, mario eyes
            //but support double-blending for 90? corners
            else if (BlendInfo.GetTopR(blend) != BlendType.BlendNone && !eq._(e, g))
            {
                doLineBlend = false;
            }

            else if (BlendInfo.GetBottomL(blend) != BlendType.BlendNone && !eq._(e, c))
            {
                doLineBlend = false;
            }

            //no full blending for L-shapes; blend corner only (handles "mario mushroom eyes")
            else if (eq._(g, h) && eq._(h, i) && eq._(i, f) && eq._(f, c) && !eq._(e, i))
            {
                doLineBlend = false;
            }

            else
            {
                doLineBlend = true;
            }

            //choose most similar color
            var px = dist._(e, f) <= dist._(e, h) ? f : h;

            var output = outputMatrix;

            output.Move(rotDeg, trgi);

            if (!doLineBlend)
            {
                scaler.BlendCorner(px, output);
                return;
            }

            //test sample: 70% of values max(fg, hc) / min(fg, hc)
            //are between 1.1 and 3.7 with median being 1.9
            var fg = dist._(f, g);
            var hc = dist._(h, c);

            var haveShallowLine = _CONFIGURATION.steepDirectionThreshold * fg <= hc && e != g && d != g;
            var haveSteepLine   = _CONFIGURATION.steepDirectionThreshold * hc <= fg && e != c && b != c;

            if (haveShallowLine)
            {
                if (haveSteepLine)
                {
                    scaler.BlendLineSteepAndShallow(px, output);
                }
                else
                {
                    scaler.BlendLineShallow(px, output);
                }
            }
            else
            {
                if (haveSteepLine)
                {
                    scaler.BlendLineSteep(px, output);
                }
                else
                {
                    scaler.BlendLineDiagonal(px, output);
                }
            }
        }
        /*
         *  input kernel area naming convention:
         *  -------------
         | A | B | C |
         |  ----|---|---|
         | D | E | F | //input pixel is at position E
         |  ----|---|---|
         | G | H | I |
         |  -------------
         |  blendInfo: result of preprocessing all four corners of pixel "e"
         */
        private void ScalePixel(IScaler scaler, int rotDeg, Kernel3x3 ker, int trgi, char blendInfo)
        {
            // int a = ker._[Rot._[(0 << 2) + rotDeg]];
            var b = ker._[Rot._[(1 << 2) + rotDeg]];
            var c = ker._[Rot._[(2 << 2) + rotDeg]];
            var d = ker._[Rot._[(3 << 2) + rotDeg]];
            var e = ker._[Rot._[(4 << 2) + rotDeg]];
            var f = ker._[Rot._[(5 << 2) + rotDeg]];
            var g = ker._[Rot._[(6 << 2) + rotDeg]];
            var h = ker._[Rot._[(7 << 2) + rotDeg]];
            var i = ker._[Rot._[(8 << 2) + rotDeg]];

            var blend = blendInfo.Rotate((RotationDegree)rotDeg);

            if ((BlendType)blend.GetBottomR() == BlendType.None)
            {
                return;
            }

            var eq   = _colorEqualizer;
            var dist = _colorDistance;

            bool doLineBlend;

            if (blend.GetBottomR() >= (char)BlendType.Dominant)
            {
                doLineBlend = true;
            }
            //make sure there is no second blending in an adjacent
            //rotation for this pixel: handles insular pixels, mario eyes
            //but support double-blending for 90� corners
            else if (blend.GetTopR() != (char)BlendType.None && !eq.IsColorEqual(e, g))
            {
                doLineBlend = false;
            }
            else if (blend.GetBottomL() != (char)BlendType.None && !eq.IsColorEqual(e, c))
            {
                doLineBlend = false;
            }
            //no full blending for L-shapes; blend corner only (handles "mario mushroom eyes")
            else if (eq.IsColorEqual(g, h) && eq.IsColorEqual(h, i) && eq.IsColorEqual(i, f) && eq.IsColorEqual(f, c) && !eq.IsColorEqual(e, i))
            {
                doLineBlend = false;
            }
            else
            {
                doLineBlend = true;
            }

            //choose most similar color
            var px = dist.DistYCbCr(e, f) <= dist.DistYCbCr(e, h) ? f : h;

            var out_ = _outputMatrix;

            out_.Move(rotDeg, trgi);

            if (!doLineBlend)
            {
                scaler.BlendCorner(px, out_);
                return;
            }

            //test sample: 70% of values max(fg, hc) / min(fg, hc)
            //are between 1.1 and 3.7 with median being 1.9
            var fg = dist.DistYCbCr(f, g);
            var hc = dist.DistYCbCr(h, c);

            var haveShallowLine = _cfg.SteepDirectionThreshold * fg <= hc && e != g && d != g;
            var haveSteepLine   = _cfg.SteepDirectionThreshold * hc <= fg && e != c && b != c;

            if (haveShallowLine)
            {
                if (haveSteepLine)
                {
                    scaler.BlendLineSteepAndShallow(px, out_);
                }
                else
                {
                    scaler.BlendLineShallow(px, out_);
                }
            }
            else
            {
                if (haveSteepLine)
                {
                    scaler.BlendLineSteep(px, out_);
                }
                else
                {
                    scaler.BlendLineDiagonal(px, out_);
                }
            }
        }
Пример #3
0
    /*
  input kernel area naming convention:
  -------------
  | A | B | C |
  ----|---|---|
  | D | E | F | //input pixel is at position E
  ----|---|---|
  | G | H | I |
  -------------
  */

    private static void _ScalePixel(
      IScaler scaler,
      RotationDegree rotDeg,
      Kernel_3X3 ker,
      sPixel[] trg,
      int trgi,
      int trgWidth,
      byte blendInfo,//result of preprocessing all four corners of pixel "e"
      IColorEq scalePixelColorEq,
      IColorDist scalePixelColorDist,
      OutputMatrix outputMatrix
      ) {
      //int a = kernel._[Rot._[(0 << 2) + rotDeg]];
      var b = ker._[Rot._[(1 << 2) + (int)rotDeg]];
      var c = ker._[Rot._[(2 << 2) + (int)rotDeg]];
      var d = ker._[Rot._[(3 << 2) + (int)rotDeg]];
      var e = ker._[Rot._[(4 << 2) + (int)rotDeg]];
      var f = ker._[Rot._[(5 << 2) + (int)rotDeg]];
      var g = ker._[Rot._[(6 << 2) + (int)rotDeg]];
      var h = ker._[Rot._[(7 << 2) + (int)rotDeg]];
      var i = ker._[Rot._[(8 << 2) + (int)rotDeg]];

      var blend = BlendInfo.Rotate(blendInfo, rotDeg);

      if (BlendInfo.GetBottomR(blend) == BlendType.BlendNone)
        return;

      var eq = scalePixelColorEq;
      var dist = scalePixelColorDist;

      bool doLineBlend;

      if (BlendInfo.GetBottomR(blend) >= BlendType.BlendDominant)
        doLineBlend = true;

        //make sure there is no second blending in an adjacent
      //rotation for this pixel: handles insular pixels, mario eyes
      //but support double-blending for 90? corners
      else if (BlendInfo.GetTopR(blend) != BlendType.BlendNone && !eq._(e, g))
        doLineBlend = false;

      else if (BlendInfo.GetBottomL(blend) != BlendType.BlendNone && !eq._(e, c))
        doLineBlend = false;

        //no full blending for L-shapes; blend corner only (handles "mario mushroom eyes")
      else if (eq._(g, h) && eq._(h, i) && eq._(i, f) && eq._(f, c) && !eq._(e, i))
        doLineBlend = false;

      else
        doLineBlend = true;

      //choose most similar color
      var px = dist._(e, f) <= dist._(e, h) ? f : h;

      var output = outputMatrix;
      output.Move(rotDeg, trgi);

      if (!doLineBlend) {
        scaler.BlendCorner(px, output);
        return;
      }

      //test sample: 70% of values max(fg, hc) / min(fg, hc)
      //are between 1.1 and 3.7 with median being 1.9
      var fg = dist._(f, g);
      var hc = dist._(h, c);

      var haveShallowLine = _CONFIGURATION.steepDirectionThreshold * fg <= hc && e != g && d != g;
      var haveSteepLine = _CONFIGURATION.steepDirectionThreshold * hc <= fg && e != c && b != c;

      if (haveShallowLine) {
        if (haveSteepLine)
          scaler.BlendLineSteepAndShallow(px, output);
        else
          scaler.BlendLineShallow(px, output);
      } else {
        if (haveSteepLine)
          scaler.BlendLineSteep(px, output);
        else
          scaler.BlendLineDiagonal(px, output);
      }
    }