package net.sf.jasperreports.engine.util;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import net.sf.jasperreports.engine.JRException;

public abstract class JRAbstractImageEncoder implements JRImageEncoder {
  public byte[] encode(Image image, byte imageType) throws JRException {
    BufferedImage bi = null;
    if (image instanceof BufferedImage) {
      bi = (BufferedImage)image;
    } else {
      bi = new BufferedImage(image.getWidth(null), image.getHeight(null), (imageType == 1 || imageType == 3) ? 2 : 1);
      Graphics g = bi.createGraphics();
      g.drawImage(image, 0, 0, null);
      g.dispose();
    } 
    return encode(bi, imageType);
  }
  
  public abstract byte[] encode(BufferedImage paramBufferedImage, byte paramByte) throws JRException;
}
