public Rectangle getBounds(int repImg, int src, int tgt, int offx, int offy) {
   int minx = 0;
   int miny = 0;
   int maxx = 0;
   int maxy = 0;
   for (int i = 0; i < pieces.size(); i++) {
     PipAnimateFramePiece piece = pieces.get(i);
     boolean replace = false;
     if (piece.getImageID() == repImg && piece.getFrame() == src) {
       piece.setFrame(tgt);
       piece.setDx(piece.getDx() + offx);
       piece.setDy(piece.getDy() + offy);
       replace = true;
     }
     int px = piece.getDx();
     int py = piece.getDy();
     int pw = piece.getWidth();
     int ph = piece.getHeight();
     if (px < minx) {
       minx = px;
     }
     if (py < miny) {
       miny = py;
     }
     if (px + pw > maxx) {
       maxx = px + pw;
     }
     if (py + ph > maxy) {
       maxy = py + ph;
     }
     if (replace) {
       piece.setFrame(src);
       piece.setDx(piece.getDx() - offx);
       piece.setDy(piece.getDy() - offy);
     }
   }
   Rectangle rect = new Rectangle(minx, miny, maxx - minx, maxy - miny);
   if (rect.isEmpty()) {
     rect = new Rectangle(0, 0, 16, 16);
   }
   return rect;
 }
 public void adjustFrameIndex(Map<Integer, Integer> frameMap) {
   for (int i = 0; i < pieces.size(); i++) {
     PipAnimateFramePiece piece = pieces.get(i);
     int id = (piece.getImageID() << 16) | piece.getFrame();
     if (frameMap.containsKey(id)) {
       int newFrame = frameMap.get(id);
       piece.setImageID(newFrame >> 16);
       piece.setFrame(newFrame & 0xFFFF);
     }
   }
 }
 public void adjustFrameIndex(int image, Map<Integer, Integer> frameMap) {
   for (int i = 0; i < pieces.size(); i++) {
     PipAnimateFramePiece piece = pieces.get(i);
     if (piece.getImageID() == image) {
       Integer newFrame = frameMap.get(piece.getFrame());
       if (newFrame == null) {
         pieces.remove(i);
         i--;
       } else {
         piece.setFrame(newFrame.intValue());
       }
     }
   }
 }