Program: 61585
Project: 61585
Buggy source:
public static void frameToImage(Timeline timeline,int frame,int time,RenderContext renderContext,SerializableImage image,Matrix transformation,ColorTransform colorTransform){
  double unzoom=SWF.unitDivisor;
  if (timeline.getFrameCount() <= frame) {
    return;
  }
  Frame frameObj=timeline.getFrame(frame);
  Graphics2D g=(Graphics2D)image.getGraphics();
  g.setPaint(frameObj.backgroundColor.toColor());
  g.fill(new Rectangle(image.getWidth(),image.getHeight()));
  g.setTransform(transformation.toTransform());
  List<Clip> clips=new ArrayList<>();
  List<Shape> prevClips=new ArrayList<>();
  int maxDepth=timeline.getMaxDepth();
  for (int i=1; i <= maxDepth; i++) {
    for (int c=0; c < clips.size(); c++) {
      if (clips.get(c).depth == i) {
        g.setClip(prevClips.get(c));
        prevClips.remove(c);
        clips.remove(c);
      }
    }
    if (!frameObj.layers.containsKey(i)) {
      continue;
    }
    DepthState layer=frameObj.layers.get(i);
    if (!timeline.swf.getCharacters().containsKey(layer.characterId)) {
      continue;
    }
    if (!layer.isVisible) {
      continue;
    }
    CharacterTag character=timeline.swf.getCharacter(layer.characterId);
    Matrix mat=new Matrix(layer.matrix);
    mat=mat.preConcatenate(transformation);
    if (colorTransform == null) {
      colorTransform=new ColorTransform();
    }
    ColorTransform clrTrans=colorTransform.clone();
    if (layer.colorTransForm != null && layer.blendMode <= 1) {
      clrTrans=colorTransform.merge(layer.colorTransForm);
    }
    boolean showPlaceholder=false;
    if (character instanceof DrawableTag) {
      DrawableTag drawable=(DrawableTag)character;
      Matrix drawMatrix=new Matrix();
      int drawableFrameCount=drawable.getNumFrames();
      if (drawableFrameCount == 0) {
        drawableFrameCount=1;
      }
      int dframe=(time + layer.time) % drawableFrameCount;
      if (character instanceof ButtonTag) {
        dframe=ButtonTag.FRAME_UP;
        if (renderContext.stateUnderCursor == layer) {
          if (renderContext.mouseButton > 0) {
            dframe=ButtonTag.FRAME_DOWN;
          }
 else {
            dframe=ButtonTag.FRAME_OVER;
          }
        }
      }
      RECT boundRect=drawable.getRect();
      ExportRectangle rect=new ExportRectangle(boundRect);
      rect=mat.transform(rect);
      Matrix m=mat.clone();
      if (layer.filters != null && layer.filters.size() > 0) {
        double deltaXMax=0;
        double deltaYMax=0;
        for (        FILTER filter : layer.filters) {
          double x=filter.getDeltaX();
          double y=filter.getDeltaY();
          deltaXMax=Math.max(x,deltaXMax);
          deltaYMax=Math.max(y,deltaYMax);
        }
        rect.xMin-=deltaXMax * unzoom;
        rect.xMax+=deltaXMax * unzoom;
        rect.yMin-=deltaYMax * unzoom;
        rect.yMax+=deltaYMax * unzoom;
      }
      rect.xMin-=1 * unzoom;
      rect.yMin-=1 * unzoom;
      rect.xMin=Math.max(0,rect.xMin);
      rect.yMin=Math.max(0,rect.yMin);
      int newWidth=(int)(rect.getWidth() / unzoom);
      int newHeight=(int)(rect.getHeight() / unzoom);
      int deltaX=(int)(rect.xMin / unzoom);
      int deltaY=(int)(rect.yMin / unzoom);
      newWidth=Math.min(image.getWidth() - deltaX,newWidth) + 1;
      newHeight=Math.min(image.getHeight() - deltaY,newHeight) + 1;
      if (newWidth <= 0 || newHeight <= 0) {
        continue;
      }
      m.translate(-rect.xMin,-rect.yMin);
      drawMatrix.translate(rect.xMin,rect.yMin);
      SerializableImage img=null;
      String cacheKey=null;
      if (drawable instanceof ShapeTag) {
        cacheKey=m.toString() + clrTrans.toString();
        img=renderContext.shapeCache.get(cacheKey);
      }
      if (img == null) {
        img=new SerializableImage(newWidth,newHeight,SerializableImage.TYPE_INT_ARGB);
        img.fillTransparent();
        drawable.toImage(dframe,layer.time + time,layer.ratio,renderContext,img,m,clrTrans);
        if (cacheKey != null) {
          renderContext.shapeCache.put(cacheKey,img);
        }
      }
      if (layer.filters != null) {
        for (        FILTER filter : layer.filters) {
          img=filter.apply(img);
        }
      }
      if (layer.blendMode > 1) {
        if (layer.colorTransForm != null) {
          img=layer.colorTransForm.apply(img);
        }
      }
      drawMatrix.translateX/=unzoom;
      drawMatrix.translateY/=unzoom;
      AffineTransform trans=drawMatrix.toTransform();
switch (layer.blendMode) {
case 0:
case 1:
        g.setComposite(AlphaComposite.SrcOver);
      break;
case 2:
    g.setComposite(AlphaComposite.SrcOver);
  break;
case 3:
g.setComposite(BlendComposite.Multiply);
break;
case 4:
g.setComposite(BlendComposite.Screen);
break;
case 5:
g.setComposite(BlendComposite.Lighten);
break;
case 6:
g.setComposite(BlendComposite.Darken);
break;
case 7:
g.setComposite(BlendComposite.Difference);
break;
case 8:
g.setComposite(BlendComposite.Add);
break;
case 9:
g.setComposite(BlendComposite.Subtract);
break;
case 10:
g.setComposite(BlendComposite.Invert);
break;
case 11:
g.setComposite(BlendComposite.Alpha);
break;
case 12:
g.setComposite(BlendComposite.Erase);
break;
case 13:
g.setComposite(BlendComposite.Overlay);
break;
case 14:
g.setComposite(BlendComposite.HardLight);
break;
default :
g.setComposite(AlphaComposite.SrcOver);
break;
}
if (layer.clipDepth > -1) {
BufferedImage mask=new BufferedImage(image.getWidth(),image.getHeight(),image.getType());
Graphics2D gm=(Graphics2D)mask.getGraphics();
gm.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
gm.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
gm.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
gm.setComposite(AlphaComposite.Src);
gm.setColor(new Color(0,0,0,0f));
gm.fillRect(0,0,image.getWidth(),image.getHeight());
gm.setTransform(trans);
gm.drawImage(img.getBufferedImage(),0,0,null);
Clip clip=new Clip(Helper.imageToShape(mask),layer.clipDepth);
clips.add(clip);
prevClips.add(g.getClip());
g.setTransform(AffineTransform.getTranslateInstance(0,0));
g.setClip(clip.shape);
}
 else {
g.setTransform(trans);
g.drawImage(img.getBufferedImage(),0,0,null);
}
}
 else if (character instanceof BoundedTag) {
showPlaceholder=true;
}
if (showPlaceholder) {
mat.translateX/=unzoom;
mat.translateY/=unzoom;
AffineTransform trans=mat.toTransform();
g.setTransform(trans);
BoundedTag b=(BoundedTag)character;
g.setPaint(new Color(255,255,255,128));
g.setComposite(BlendComposite.Invert);
RECT r=b.getRect();
int div=(int)unzoom;
g.drawString(character.toString(),r.Xmin / div + 3,r.Ymin / div + 15);
g.draw(new Rectangle(r.Xmin / div,r.Ymin / div,r.getWidth() / div,r.getHeight() / div));
g.drawLine(r.Xmin / div,r.Ymin / div,r.Xmax / div,r.Ymax / div);
g.drawLine(r.Xmax / div,r.Ymin / div,r.Xmin / div,r.Ymax / div);
g.setComposite(AlphaComposite.Dst);
}
}
g.setTransform(AffineTransform.getScaleInstance(1,1));
}

Fixed version (ground truth):
public static void frameToImage(Timeline timeline,int frame,int time,RenderContext renderContext,SerializableImage image,Matrix transformation,ColorTransform colorTransform){
  double unzoom=SWF.unitDivisor;
  if (timeline.getFrameCount() <= frame) {
    return;
  }
  Frame frameObj=timeline.getFrame(frame);
  Graphics2D g=(Graphics2D)image.getGraphics();
  g.setPaint(frameObj.backgroundColor.toColor());
  g.fill(new Rectangle(image.getWidth(),image.getHeight()));
  g.setTransform(transformation.toTransform());
  List<Clip> clips=new ArrayList<>();
  List<Shape> prevClips=new ArrayList<>();
  int maxDepth=timeline.getMaxDepth();
  for (int i=1; i <= maxDepth; i++) {
    for (int c=0; c < clips.size(); c++) {
      if (clips.get(c).depth == i) {
        g.setClip(prevClips.get(c));
        prevClips.remove(c);
        clips.remove(c);
      }
    }
    if (!frameObj.layers.containsKey(i)) {
      continue;
    }
    DepthState layer=frameObj.layers.get(i);
    if (!timeline.swf.getCharacters().containsKey(layer.characterId)) {
      continue;
    }
    if (!layer.isVisible) {
      continue;
    }
    CharacterTag character=timeline.swf.getCharacter(layer.characterId);
    Matrix mat=new Matrix(layer.matrix);
    mat=mat.preConcatenate(transformation);
    if (colorTransform == null) {
      colorTransform=new ColorTransform();
    }
    ColorTransform clrTrans=colorTransform.clone();
    if (layer.colorTransForm != null && layer.blendMode <= 1) {
      clrTrans=colorTransform.merge(layer.colorTransForm);
    }
    boolean showPlaceholder=false;
    if (character instanceof DrawableTag) {
      DrawableTag drawable=(DrawableTag)character;
      Matrix drawMatrix=new Matrix();
      int drawableFrameCount=drawable.getNumFrames();
      if (drawableFrameCount == 0) {
        drawableFrameCount=1;
      }
      int dframe=(time + layer.time) % drawableFrameCount;
      if (character instanceof ButtonTag) {
        dframe=ButtonTag.FRAME_UP;
        if (renderContext.stateUnderCursor == layer) {
          if (renderContext.mouseButton > 0) {
            dframe=ButtonTag.FRAME_DOWN;
          }
 else {
            dframe=ButtonTag.FRAME_OVER;
          }
        }
      }
      RECT boundRect=drawable.getRect();
      ExportRectangle rect=new ExportRectangle(boundRect);
      rect=mat.transform(rect);
      Matrix m=mat.clone();
      if (layer.filters != null && layer.filters.size() > 0) {
        double deltaXMax=0;
        double deltaYMax=0;
        for (        FILTER filter : layer.filters) {
          double x=filter.getDeltaX();
          double y=filter.getDeltaY();
          deltaXMax=Math.max(x,deltaXMax);
          deltaYMax=Math.max(y,deltaYMax);
        }
        rect.xMin-=deltaXMax * unzoom;
        rect.xMax+=deltaXMax * unzoom;
        rect.yMin-=deltaYMax * unzoom;
        rect.yMax+=deltaYMax * unzoom;
      }
      rect.xMin-=1 * unzoom;
      rect.yMin-=1 * unzoom;
      rect.xMin=Math.max(0,rect.xMin);
      rect.yMin=Math.max(0,rect.yMin);
      int newWidth=(int)(rect.getWidth() / unzoom);
      int newHeight=(int)(rect.getHeight() / unzoom);
      int deltaX=(int)(rect.xMin / unzoom);
      int deltaY=(int)(rect.yMin / unzoom);
      newWidth=Math.min(image.getWidth() - deltaX,newWidth) + 1;
      newHeight=Math.min(image.getHeight() - deltaY,newHeight) + 1;
      if (newWidth <= 0 || newHeight <= 0) {
        continue;
      }
      m.translate(-rect.xMin,-rect.yMin);
      drawMatrix.translate(rect.xMin,rect.yMin);
      SerializableImage img=null;
      String cacheKey=null;
      if (drawable instanceof ShapeTag) {
        cacheKey=((ShapeTag)drawable).getCharacterId() + m.toString() + clrTrans.toString();
        img=renderContext.shapeCache.get(cacheKey);
      }
      if (img == null) {
        img=new SerializableImage(newWidth,newHeight,SerializableImage.TYPE_INT_ARGB);
        img.fillTransparent();
        drawable.toImage(dframe,layer.time + time,layer.ratio,renderContext,img,m,clrTrans);
        if (cacheKey != null) {
          renderContext.shapeCache.put(cacheKey,img);
        }
      }
      if (layer.filters != null) {
        for (        FILTER filter : layer.filters) {
          img=filter.apply(img);
        }
      }
      if (layer.blendMode > 1) {
        if (layer.colorTransForm != null) {
          img=layer.colorTransForm.apply(img);
        }
      }
      drawMatrix.translateX/=unzoom;
      drawMatrix.translateY/=unzoom;
      AffineTransform trans=drawMatrix.toTransform();
switch (layer.blendMode) {
case 0:
case 1:
        g.setComposite(AlphaComposite.SrcOver);
      break;
case 2:
    g.setComposite(AlphaComposite.SrcOver);
  break;
case 3:
g.setComposite(BlendComposite.Multiply);
break;
case 4:
g.setComposite(BlendComposite.Screen);
break;
case 5:
g.setComposite(BlendComposite.Lighten);
break;
case 6:
g.setComposite(BlendComposite.Darken);
break;
case 7:
g.setComposite(BlendComposite.Difference);
break;
case 8:
g.setComposite(BlendComposite.Add);
break;
case 9:
g.setComposite(BlendComposite.Subtract);
break;
case 10:
g.setComposite(BlendComposite.Invert);
break;
case 11:
g.setComposite(BlendComposite.Alpha);
break;
case 12:
g.setComposite(BlendComposite.Erase);
break;
case 13:
g.setComposite(BlendComposite.Overlay);
break;
case 14:
g.setComposite(BlendComposite.HardLight);
break;
default :
g.setComposite(AlphaComposite.SrcOver);
break;
}
if (layer.clipDepth > -1) {
BufferedImage mask=new BufferedImage(image.getWidth(),image.getHeight(),image.getType());
Graphics2D gm=(Graphics2D)mask.getGraphics();
gm.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
gm.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
gm.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
gm.setComposite(AlphaComposite.Src);
gm.setColor(new Color(0,0,0,0f));
gm.fillRect(0,0,image.getWidth(),image.getHeight());
gm.setTransform(trans);
gm.drawImage(img.getBufferedImage(),0,0,null);
Clip clip=new Clip(Helper.imageToShape(mask),layer.clipDepth);
clips.add(clip);
prevClips.add(g.getClip());
g.setTransform(AffineTransform.getTranslateInstance(0,0));
g.setClip(clip.shape);
}
 else {
g.setTransform(trans);
g.drawImage(img.getBufferedImage(),0,0,null);
}
}
 else if (character instanceof BoundedTag) {
showPlaceholder=true;
}
if (showPlaceholder) {
mat.translateX/=unzoom;
mat.translateY/=unzoom;
AffineTransform trans=mat.toTransform();
g.setTransform(trans);
BoundedTag b=(BoundedTag)character;
g.setPaint(new Color(255,255,255,128));
g.setComposite(BlendComposite.Invert);
RECT r=b.getRect();
int div=(int)unzoom;
g.drawString(character.toString(),r.Xmin / div + 3,r.Ymin / div + 15);
g.draw(new Rectangle(r.Xmin / div,r.Ymin / div,r.getWidth() / div,r.getHeight() / div));
g.drawLine(r.Xmin / div,r.Ymin / div,r.Xmax / div,r.Ymax / div);
g.drawLine(r.Xmax / div,r.Ymin / div,r.Xmin / div,r.Ymax / div);
g.setComposite(AlphaComposite.Dst);
}
}
g.setTransform(AffineTransform.getScaleInstance(1,1));
}