コード例 #1
0
ファイル: Algorithm.java プロジェクト: skycook/imgrgb
  public void place(Color c) throws Exception {
    // find next coordinates in image
    Pixel p;
    if (pixelsAdded == 0) {
      p = Main.Image[Main.START_Y * Main.WIDTH + Main.START_X];
    } else if (pixelsAdded == MULT_SEED_DELAY) {
      p = Main.Image[(Main.START_Y + Main.HEIGHT / 2) * Main.WIDTH + Main.START_X + Main.WIDTH / 3];
    } else {
      p = placeImpl(c);
    }

    assert (p.isEmpty);
    p.isEmpty = false;
    p.color = c;

    pixelsAdded++;
    changeQueue(p);
  }
コード例 #2
0
  // TODO how to calculate minimum-difference pixels?
  @Override
  protected void changeQueue(Pixel p) {
    // recalculate neighbors
    for (Pixel np : p.neighbors) {
      if (np.isEmpty) {
        int r = 0, g = 0, b = 0, n = 0;
        for (Pixel nnp : np.neighbors) {
          if (!nnp.isEmpty) {
            r += nnp.color.getRed();
            g += nnp.color.getGreen();
            b += nnp.color.getBlue();
            n++;
          }
        }

        np.nonEmptyNeigh++;

        r /= n;
        g /= n;
        b /= n;

        Color avg = new Color(r, g, b);

        Color newBlock =
            new Color(
                r >> blockOffset & blockMask,
                g >> blockOffset & blockMask,
                b >> blockOffset & blockMask);
        int blockIndex =
            newBlock.getRed() * rOffset
                + newBlock.getGreen() * gOffset
                + newBlock.getBlue() * bOffset;

        if (!np.inQueue) {
          np.block = blockIndex;
          np.inQueue = true;
          pixelBlocks[blockIndex].add(np);
        } else if (blockIndex != np.block) {
          if (!pixelBlocks[np.block].remove(np)) {
            System.out.println(
                "Couldn't remove pixel "
                    + np
                    + ", even though it should be in block "
                    + blockIndex
                    + " !");
          }

          np.inQueue = true;
          np.block = blockIndex;
          pixelBlocks[blockIndex].add(np);
        }

        np.avg = avg;
      }
    }
  }