/**
   * Compute GLRLM.
   *
   * @param fastBitmap Image to be processed.
   * @return GLRLM.
   */
  public double[][] Compute(FastBitmap fastBitmap) {

    int maxGray = 255;
    if (autoGray) maxGray = ImageStatistics.Maximum(fastBitmap);

    int height = fastBitmap.getHeight();
    int width = fastBitmap.getWidth();

    double[][] runMatrix = new double[maxGray + 1][width + 1];

    switch (degree) {
      case Degree_0:
        for (int i = 0; i < height; i++) {
          int runs = 1;
          for (int j = 1; j < width; j++) {
            int g1 = fastBitmap.getGray(i, j - 1);
            int g2 = fastBitmap.getGray(i, j);
            if (g1 == g2) {
              runs++;
            } else {
              runMatrix[g1][runs]++;
              numPrimitives++;
              runs = 1;
            }
            if ((g1 == g2) && (j == width - 1)) {
              runMatrix[g1][runs]++;
            }
            if ((g1 != g2) && (j == width - 1)) {
              runMatrix[g2][1]++;
            }
          }
        }
        break;

      case Degree_45:

        // Compute I(0,0) and I(height,width)
        runMatrix[0][1]++;
        runMatrix[height - 1][width - 1]++;

        // Compute height
        for (int i = 1; i < height; i++) {
          int runs = 1;
          int steps = i;
          for (int j = 0; j < steps; j++) {
            int g1 = fastBitmap.getGray(i - j, j);
            int g2 = fastBitmap.getGray(i - j - 1, j + 1);
            if (g1 == g2) {
              runs++;
            } else {
              runMatrix[g1][runs]++;
              numPrimitives++;
              runs = 1;
            }
            if ((g1 == g2) && (j == steps - 1)) {
              runMatrix[g1][runs]++;
            }
            if ((g1 != g2) && (j == steps - 1)) {
              runMatrix[g2][1]++;
            }
          }
        }

        // Compute width
        for (int j = 1; j < width - 1; j++) {
          int runs = 1;
          int steps = height - j;
          for (int i = 1; i < steps; i++) {
            int g1 = fastBitmap.getGray(height - i, j + i - 1);
            int g2 = fastBitmap.getGray(height - i - 1, j + i);
            if (g1 == g2) {
              runs++;
            } else {
              runMatrix[g1][runs]++;
              numPrimitives++;
              runs = 1;
            }
            if ((g1 == g2) && (i == steps - 1)) {
              runMatrix[g1][runs]++;
            }
            if ((g1 != g2) && (i == steps - 1)) {
              runMatrix[g2][1]++;
            }
          }
        }
        break;

      case Degree_90:
        for (int j = 0; j < width; j++) {
          int runs = 1;
          for (int i = 0; i < height - 1; i++) {
            int g1 = fastBitmap.getGray(height - i - 1, j);
            int g2 = fastBitmap.getGray(height - i - 2, j);
            if (g1 == g2) {
              runs++;
            } else {
              runMatrix[g1][runs]++;
              numPrimitives++;
              runs = 1;
            }
            if ((g1 == g2) && (i == height - 2)) {
              runMatrix[g1][runs]++;
            }
            if ((g1 != g2) && (i == height - 2)) {
              runMatrix[g2][1]++;
            }
          }
        }
        break;

      case Degree_135:

        // Compute I(0,width) and I(height,0)
        runMatrix[0][width - 1]++;
        runMatrix[height - 1][0]++;

        // Compute height
        for (int i = 1; i < width; i++) {
          int runs = 1;
          int steps = i;
          int w = width - 1;
          for (int j = 0; j < steps; j++) {
            int g1 = fastBitmap.getGray(i - j, w);
            int g2 = fastBitmap.getGray(i - j - 1, --w);
            if (g1 == g2) {
              runs++;
            } else {
              runMatrix[g1][runs]++;
              numPrimitives++;
              runs = 1;
            }
            if ((g1 == g2) && (j == steps - 1)) {
              runMatrix[g1][runs]++;
            }
            if ((g1 != g2) && (j == steps - 1)) {
              runMatrix[g2][1]++;
            }
          }
        }
        // Compute width
        for (int j = 1; j < width - 1; j++) {
          int runs = 1;
          int steps = height - j;
          int w = width - 1 - j;
          for (int i = 1; i < steps; i++) {
            int g1 = fastBitmap.getGray(height - i, w);
            int g2 = fastBitmap.getGray(height - i - 1, --w);
            if (g1 == g2) {
              runs++;
            } else {
              runMatrix[g1][runs]++;
              numPrimitives++;
              runs = 1;
            }
            if ((g1 == g2) && (i == steps - 1)) {
              runMatrix[g1][runs]++;
            }
            if ((g1 != g2) && (i == steps - 1)) {
              runMatrix[g2][1]++;
            }
          }
        }
        break;
    }
    return runMatrix;
  }