User Tools

Site Tools


cs276:scaleup
// copy(source, dest, xoffset, yoffset)
// copies the source image to the destination, offset in the
// x and y directions by xoffset, yoffset, respectively
 
void copy (PImage src, PImage dest, int xoff, int yoff) {
  src.loadPixels();
  dest.loadPixels();
  for (int row = 0, drow = yoff; row < src.height; drow++, row++) {
    for (int col = 0, dcol = xoff; col < src.width; dcol++, col++) {
      color c = src.get((int) col, (int) row);
      dest.set((int) dcol, (int) drow, c);
    }
  }
  dest.updatePixels();
}
 
// scaleUpImage(source, dest)
// This works by writing every pixel of the source twice
// into the array of the destination; again, be careful that 
// the sizes of the pixel arrays are compatible
 
void scaleUpImage(PImage source, PImage dest) {
  source.loadPixels();
  dest.loadPixels();
  for (float row = 0, drow = 0; row < source.height; drow++, row += 0.5) {
    for (float col = 0, dcol = 0; col < source.width; dcol++, col += 0.5) {
      color c = source.get((int) col, (int) row);
      dest.set((int) dcol, (int) drow, c);
    }
  }
  dest.updatePixels();
}
cs276/scaleup.txt · Last modified: 2007/10/05 14:08 by scarl