Example #1
0
 public void cropAndCopy(
     Picture sourcePicture,
     int startSourceRow,
     int endSourceRow,
     int startSourceCol,
     int endSourceCol,
     int startDestRow,
     int startDestCol) {
   Pixel leftPixel = null;
   Pixel rightPixel = null;
   Pixel[][] pixels = this.getPixels2D();
   Color rightColor = null;
   Pixel[][] fromPixels = sourcePicture.getPixels2D();
   Pixel[][] toPixels = this.getPixels2D();
   Pixel fromPixel = null;
   Pixel toPixel = null;
   for (int fromRow = startSourceRow, toRow = endSourceRow;
       fromRow < fromPixels.length && toRow < toPixels.length;
       fromRow++, toRow++) {
     for (int fromCol = startSourceCol, toCol = endSourceCol;
         fromCol < fromPixels[0].length && toCol < toPixels[0].length;
         fromCol++, toCol++) {
       fromPixel = fromPixels[fromRow][fromCol];
       toPixel = toPixels[toRow][toCol];
       toPixel.setColor(fromPixel.getColor());
     }
   }
 }
Example #2
0
  private void repositionStartEnd() {
    counter = 0;

    dx = end.getPoint().x - start.getPoint().x;

    dz = (end.getInverseDepth() - start.getInverseDepth()) / dx;
    du =
        (end.getPerspectiveCorrectTexturePoint().x - start.getPerspectiveCorrectTexturePoint().x)
            / dx;
    dv =
        (end.getPerspectiveCorrectTexturePoint().y - start.getPerspectiveCorrectTexturePoint().y)
            / dx;
    dl = (end.getLightning() - start.getLightning()) / dx;

    xend = end.getPoint().x;

    myPixel.x = (int) start.getPoint().x;
    myInverseZInStepPixels = start.getInverseDepth();
    light = start.getLightning();

    myPerspectiveCorrectedUInStepPixels = start.getPerspectiveCorrectTexturePoint().x;
    myPerspectiveCorrectedVInStepPixels = start.getPerspectiveCorrectTexturePoint().y;

    myUInStepPixels = myPerspectiveCorrectedUInStepPixels / myInverseZInStepPixels;
    myVInStepPixels = myPerspectiveCorrectedVInStepPixels / myInverseZInStepPixels;

    if (affineStep == 1) {
      myPixel.invZ = start.getInverseDepth();
      perspectiveCorrectedU = start.getPerspectiveCorrectTexturePoint().x;
      perspectiveCorrectedV = start.getPerspectiveCorrectTexturePoint().y;
    }
  }
Example #3
0
 /** Method to set the blue to 0 */
 public void zeroBlue() {
   Pixel[][] pixels = this.getPixels2D();
   for (Pixel[] rowArray : pixels) {
     for (Pixel pixelObj : rowArray) {
       pixelObj.setBlue(0);
     }
   }
 }
Example #4
0
 public void keepOnlyBlue() {
   Pixel[][] pixels = this.getPixels2D();
   for (Pixel[] rowArray : pixels) {
     for (Pixel pixelObj : rowArray) {
       pixelObj.setRed(0);
       pixelObj.setGreen(0);
     }
   }
 }
  /**
   * Function that prints all the class variables to the console, including the path traveled by the
   * pointer during the trial.
   */
  public void printInfoWithPath() {
    printInfoWithoutPath();

    System.out.println("The path was as follows:");
    for (int i = 0; i < path.size(); i++) {
      Pixel ponto = path.get(i);
      System.out.println("< " + ponto.getXCoordinate() + " , " + ponto.getYCoordinate() + " > ->");
    }
  }
Example #6
0
  // set green 255
  public void maxGreen() {
    Pixel[][] pixels = this.getPixels2D();
    for (Pixel[] rowArray : pixels) {
      for (Pixel pixelObj : rowArray) {

        pixelObj.setGreen(255);
      }
    }
  }
Example #7
0
 public void fixUnderwater() {
   Pixel[][] pixels = this.getPixels2D();
   for (Pixel[] rowArray : pixels) {
     for (Pixel pixelObj : rowArray) {
       if (pixelObj.getBlue() > 160 && pixelObj.getRed() < 25) {
         pixelObj.setBlue(pixelObj.getBlue() + 35);
       }
     }
   }
 }
Example #8
0
  // changes the image to a Grayscale
  public void Grayscale() {
    Pixel[][] pixels = this.getPixels2D();
    for (Pixel[] rowArray : pixels) {
      for (Pixel pixelObj : rowArray) {

        int average = (int) pixelObj.getAverage();
        pixelObj.setGreen(average);
        pixelObj.setBlue(average);
        pixelObj.setRed(average);
      }
    }
  }
Example #9
0
  private void swapPix(Pixel pixel1, Pixel pixel2) {
    int tmpPixPos;
    double tmpPixVal;

    tmpPixPos = pixel1.pos;
    pixel1.pos = pixel2.pos;
    pixel2.pos = tmpPixPos;

    tmpPixVal = pixel1.value;
    pixel1.value = pixel2.value;
    pixel2.value = tmpPixVal;
  }
Example #10
0
  /*
  ****************** CHECKLIST ******************************
  [x] change the colors within the box specified by the parameters
  [x] the new Color in each Pixel MUST depend BOTH (a) on that particular Pixel's previous Color and (b) on the value of the amount parameter

  */
  public boolean ManipBoxUniformly(int xMin, int yMin, int xMax, int yMax, double amount) {
    for (int x = xMin; x < xMax - 1; x++) {
      for (int y = yMin; y < yMax - 1; y++) {

        amount -= 0.0000001;
        if (amount < 0.1) amount = 0.2;
        Pixel p = this.getPixel(x, y);
        int B = (int) (p.getGreen() * (amount));
        p.setGreen(B);
      }
    }
    return true;
  }
Example #11
0
 public void mirrorVerticalRightToLeft() {
   Pixel[][] pixels = this.getPixels2D();
   Pixel leftPixel = null;
   Pixel rightPixel = null;
   int pictureWidth = pixels[0].length;
   for (int row = 0; row < pixels.length; row++) {
     for (int col = pixels[0].length - 1; col > pictureWidth / 2; col--) {
       rightPixel = pixels[row][col];
       leftPixel = pixels[row][(pictureWidth / 2) - (col - pictureWidth / 2)];
       leftPixel.setColor(rightPixel.getColor());
     }
   }
 }
Example #12
0
 public void mirrorHorizontalBotToTop() {
   Pixel[][] pixels = this.getPixels2D();
   Pixel topPixel = null;
   Pixel bottomPixel = null;
   int width = pixels[0].length;
   for (int col = 0; col < width; col++) {
     for (int row = 0; row < pixels.length / 2; row++) {
       topPixel = pixels[row][col];
       bottomPixel = pixels[(pixels.length) - 1 - row][col];
       topPixel.setColor(bottomPixel.getColor());
     }
   }
 }
Example #13
0
 // implements max red to only the right side of the image
 public void rightRed() {
   Pixel[][] pixels = this.getPixels2D();
   Pixel leftPixel = null;
   Pixel rightPixel = null;
   int width = pixels[0].length;
   for (int row = 0; row < pixels.length; row++) {
     for (int col = 0; col < width / 2; col++) {
       leftPixel = pixels[row][col];
       rightPixel = pixels[row][width - 1 - col];
       rightPixel.setRed(255);
     }
   }
 }
Example #14
0
 /**
  * Method that mirrors the picture around a vertical mirror in the center of the picture from left
  * to right
  */
 public void mirrorVertical() {
   Pixel[][] pixels = this.getPixels2D();
   Pixel leftPixel = null;
   Pixel rightPixel = null;
   int width = pixels[0].length;
   for (int row = 0; row < pixels.length; row++) {
     for (int col = 0; col < width / 2; col++) {
       leftPixel = pixels[row][col];
       rightPixel = pixels[row][width - 1 - col];
       rightPixel.setColor(leftPixel.getColor());
     }
   }
 }
Example #15
0
 public void mirrorArms() {
   int mirrorPoint = 205;
   Pixel leftPixel = null;
   Pixel rightPixel = null;
   Pixel[][] pixels = this.getPixels2D();
   for (int row = 152; row < 200; row++) {
     for (int col = 92; col < mirrorPoint; col++) {
       leftPixel = pixels[row][col];
       rightPixel = pixels[row][mirrorPoint - col + mirrorPoint];
       rightPixel.setColor(leftPixel.getColor());
     }
   }
 }
Example #16
0
 public void mirrorGull() {
   int mirrorPoint = 352;
   Pixel leftPixel = null;
   Pixel rightPixel = null;
   Pixel[][] pixels = this.getPixels2D();
   for (int row = 233; row < 323; row++) {
     for (int col = 235; col < mirrorPoint; col++) {
       leftPixel = pixels[row][col];
       rightPixel = pixels[row][mirrorPoint - col + mirrorPoint];
       rightPixel.setColor(leftPixel.getColor());
     }
   }
 }
Example #17
0
 public void mirrorVerticalBottomToTop() {
   Pixel[][] pixels = this.getPixels2D();
   Pixel topPixel = null;
   Pixel bottomPixel = null;
   int width = pixels[0].length;
   int height = pixels.length;
   for (int row = 0; row < pixels.length; row++) {
     for (int col = 0; col < width; col++) {
       topPixel = pixels[height - 1 - row][col];
       bottomPixel = pixels[row][col];
       bottomPixel.setColor(topPixel.getColor());
     }
   }
 }
Example #18
0
  public void randomColor() {
    Pixel[][] pixels = this.getPixels2D();
    for (Pixel[] row : pixels) {
      for (Pixel currentPixel : row) {
        int randomRed, randomBlue, randomGreen;
        randomRed = (int) (Math.random() * 256);
        randomBlue = (int) (Math.random() * 256);
        randomGreen = (int) (Math.random() * 256);

        currentPixel.setBlue(randomBlue);
        currentPixel.setRed(randomRed);
        currentPixel.setGreen(randomGreen);
      }
    }
  }
Example #19
0
 /**
  * copy from the passed fromPic to the specified startRow and startCol in the current picture
  *
  * @param fromPic the picture to copy from
  * @param startRow the start row to copy to
  * @param startCol the start col to copy to
  */
 public void copy(Picture fromPic, int startRow, int startCol) {
   Pixel fromPixel = null;
   Pixel toPixel = null;
   Pixel[][] toPixels = this.getPixels2D();
   Pixel[][] fromPixels = fromPic.getPixels2D();
   for (int fromRow = 0, toRow = startRow;
       fromRow < fromPixels.length && toRow < toPixels.length;
       fromRow++, toRow++) {
     for (int fromCol = 0, toCol = startCol;
         fromCol < fromPixels[0].length && toCol < toPixels[0].length;
         fromCol++, toCol++) {
       fromPixel = fromPixels[fromRow][fromCol];
       toPixel = toPixels[toRow][toCol];
       toPixel.setColor(fromPixel.getColor());
     }
   }
 }
  /**
   * Method to display pixel information for the passed x and y
   *
   * @param pictureX the x value in the picture
   * @param pictureY the y value in the picture
   */
  private void displayPixelInformation(int pictureX, int pictureY) {
    // check that this x and y are in range
    if (isLocationInPicture(pictureX, pictureY)) {
      // save the current x and y index
      colIndex = pictureX;
      rowIndex = pictureY;

      // get the pixel at the x and y
      Pixel pixel = new Pixel(picture, colIndex, rowIndex);

      // set the values based on the pixel
      colValue.setText(Integer.toString(colIndex + numberBase));
      rowValue.setText(Integer.toString(rowIndex + numberBase));
      rValue.setText("R: " + pixel.getRed());
      gValue.setText("G: " + pixel.getGreen());
      bValue.setText("B: " + pixel.getBlue());
      colorPanel.setBackground(new Color(pixel.getRed(), pixel.getGreen(), pixel.getBlue()));

    } else {
      clearInformation();
    }

    // notify the image display of the current x and y
    imageDisplay.setCurrentX((int) (colIndex * zoomFactor));
    imageDisplay.setCurrentY((int) (rowIndex * zoomFactor));
  }
Example #21
0
  /** Mirror just part of a picture of a temple */
  public void mirrorTemple() {
    int mirrorPoint = 276;
    Pixel leftPixel = null;
    Pixel rightPixel = null;
    int count = 0;
    Pixel[][] pixels = this.getPixels2D();

    // loop through the rows
    for (int row = 27; row < 97; row++) {
      // loop from 13 to just before the mirror point
      for (int col = 13; col < mirrorPoint; col++) {

        leftPixel = pixels[row][col];
        rightPixel = pixels[row][mirrorPoint - col + mirrorPoint];
        rightPixel.setColor(leftPixel.getColor());
      }
    }
  }
Example #22
0
  public void mirrorArms() {
    int mirrorPoint = 298;
    Pixel leftPixel = null;
    Pixel rightPixel = null;
    int count = 0;
    Pixel[][] pixels = this.getPixels2D();

    // loop through the rows
    for (int row = 153; row < 192; row++) {
      // loop from 13 to just before the mirror point
      for (int col = 100; col < mirrorPoint; col++) {

        leftPixel = pixels[row][col];
        rightPixel = pixels[mirrorPoint - row][col];
        rightPixel.setColor(leftPixel.getColor());
      }
    }
  }
Example #23
0
  // Makes the right half of the picture mirror the left
  public static void mirror(Picture pict) {
    int mirrorPoint = pict.getWidth() / 2; // calculating the midpoint
    Pixel leftPixel = null; // the left pixel to copy from
    Pixel rightPixel = null; // the right pixel to copy to

    // loop through the rows
    for (int y = 0; y < pict.getHeight(); y++) {
      // loop from 0 to just before the mirror point
      for (int x = 0; x < mirrorPoint; x++) {
        // Getting the left and right pixels
        leftPixel = pict.getPixel(x, y);
        rightPixel = pict.getPixel(pict.getWidth() - 1 - x, y);

        // Setting the right pixel to the left pixel's color
        rightPixel.setColor(leftPixel.getColor());
      }
    }
  }
Example #24
0
  /**
   * Method that will copy all of the passed source picture into the current picture object
   *
   * @param sourcePicture the picture object to copy
   */
  public void copyPicture(SimplePicture sourcePicture) {
    Pixel sourcePixel = null;
    Pixel targetPixel = null;

    // loop through the columns
    for (int sourceX = 0, targetX = 0;
        sourceX < sourcePicture.getWidth() && targetX < this.getWidth();
        sourceX++, targetX++) {
      // loop through the rows
      for (int sourceY = 0, targetY = 0;
          sourceY < sourcePicture.getHeight() && targetY < this.getHeight();
          sourceY++, targetY++) {
        sourcePixel = sourcePicture.getPixel(sourceX, sourceY);
        targetPixel = this.getPixel(targetX, targetY);
        targetPixel.setColor(sourcePixel.getColor());
      }
    }
  }
  public boolean compareImages(Image image1, Image image2, Rectangle rect, String attach) {
    if (image1 == null || image2 == null) return false;

    boolean matched = false;

    Iterator iter1 = handlePixels(image1, rect);
    Iterator iter2 = handlePixels(image2, rect);

    while (iter1.hasNext() && iter2.hasNext()) {
      Pixel pixel = (Pixel) iter1.next();
      if (pixel.equals((Pixel) iter2.next())) {
        matched = true;
      } else {
        matched = false;
      }
    }
    if (matched) return true;
    return false;
  }
Example #26
0
 public void negate() {
   Pixel[][] pixels = this.getPixels2D();
   for (Pixel[] rowArray : pixels) {
     for (Pixel pixelObj : rowArray) {
       pixelObj.setRed(255 - pixelObj.getRed());
       pixelObj.setGreen(255 - pixelObj.getGreen());
       pixelObj.setBlue(255 - pixelObj.getBlue());
     }
   }
 }
Example #27
0
 public void grayscale() {
   Pixel[][] pixels = this.getPixels2D();
   for (Pixel[] rowArray : pixels) {
     for (Pixel pixelObj : rowArray) {
       int ave = (pixelObj.getRed() + pixelObj.getGreen() + pixelObj.getBlue()) / 3;
       pixelObj.setBlue(ave);
       pixelObj.setRed(ave);
       pixelObj.setGreen(ave);
     }
   }
 }
Example #28
0
  public static Segment getInstance(
      Vertex2D aStartVertex,
      Vertex2D anEndVertex,
      int aPixelIndex,
      Texture2 aTexture,
      int anXStep) {
    Segment result;
    if (countFree == 0) {
      result = new Segment();
    } else {
      result = STACK[--countFree];
    }
    result.start = aStartVertex;
    result.end = anEndVertex;
    result.texture = aTexture;
    result.myPixel.texture = aTexture;
    result.myPixel.index = aPixelIndex;

    result.repositionStartEnd();

    return result;
  }
  /**
   * Create the color information panel
   *
   * @param labelFont the font to use for labels
   * @return the color information panel
   */
  private JPanel createColorInfoPanel(Font labelFont) {
    // create a color info panel
    JPanel colorInfoPanel = new JPanel();
    colorInfoPanel.setLayout(new FlowLayout());

    // get the pixel at the x and y
    Pixel pixel = new Pixel(picture, colIndex, rowIndex);

    // create the labels
    rValue = new JLabel("R: " + pixel.getRed());
    gValue = new JLabel("G: " + pixel.getGreen());
    bValue = new JLabel("B: " + pixel.getBlue());

    // create the sample color panel and label
    colorLabel = new JLabel("Color at location: ");
    colorPanel = new JPanel();
    colorPanel.setBorder(new LineBorder(Color.black, 1));

    // set the color sample to the pixel color
    colorPanel.setBackground(pixel.getColor());

    // set the font
    rValue.setFont(labelFont);
    gValue.setFont(labelFont);
    bValue.setFont(labelFont);
    colorLabel.setFont(labelFont);
    colorPanel.setPreferredSize(new Dimension(25, 25));

    // add items to the color information panel
    colorInfoPanel.add(rValue);
    colorInfoPanel.add(gValue);
    colorInfoPanel.add(bValue);
    colorInfoPanel.add(colorLabel);
    colorInfoPanel.add(colorPanel);

    return colorInfoPanel;
  }
Example #30
0
 public void negate() {
   Pixel[][] pixels = this.getPixels2D();
   for (Pixel[] rowArray : pixels) {
     for (Pixel pixelObj : rowArray) {
       int a = pixelObj.getRed();
       int b = pixelObj.getBlue();
       int c = pixelObj.getGreen();
       pixelObj.setRed(255 - a);
       pixelObj.setBlue(255 - b);
       pixelObj.setGreen(255 - c);
     }
   }
 }