// Path: src/org/sleeksnap/util/Utils.java
// public static class ImageUtil {
// 
// 	/**
// 	 * Check whether an image has alpha pixels
// 	 * 
// 	 * @param image
// 	 *            The image
// 	 * @return True, if the image has alpha pixels
// 	 */
// 	public static boolean hasAlpha(Image image) {
// 		// If buffered image, the color model is readily available
// 		if (image instanceof BufferedImage) {
// 			BufferedImage bimage = (BufferedImage) image;
// 			return bimage.getColorModel().hasAlpha();
// 		}
// 
// 		// Use a pixel grabber to retrieve the image's color model;
// 		// grabbing a single pixel is usually sufficient
// 		PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
// 		try {
// 			pg.grabPixels();
// 		} catch (InterruptedException e) {
// 		}
// 
// 		// Get the image's color model
// 		ColorModel cm = pg.getColorModel();
// 		if (cm == null) {
// 			return false;
// 		}
// 		return cm.hasAlpha();
// 	}
// 
// 	/**
// 	 * Convert an image into a Base64 string
// 	 * 
// 	 * @param image
// 	 *            The image
// 	 * @return The base64 encoded image data
// 	 * @throws IOException
// 	 *             If an error occurred
// 	 */
// 	public static String toBase64(BufferedImage image) throws IOException {
// 		ByteArrayOutputStream output = new ByteArrayOutputStream();
// 		ImageIO.write(image, "PNG", output);
// 		return DatatypeConverter.printBase64Binary(output.toByteArray());
// 	}
// 
// 	/**
// 	 * Convert a regular image to a buffered image
// 	 * 
// 	 * @param image
// 	 *            The image
// 	 * @return The buffered image
// 	 */
// 	public static BufferedImage toBufferedImage(Image image) {
// 		if (image instanceof BufferedImage) {
// 			return (BufferedImage) image;
// 		}
// 
// 		// This code ensures that all the pixels in the image are loaded
// 		image = new ImageIcon(image).getImage();
// 
// 		// Determine if the image has transparent pixels; for this method's
// 		// implementation, see Determining If an Image Has Transparent
// 		// Pixels
// 		boolean hasAlpha = hasAlpha(image);
// 
// 		// Create a buffered image with a format that's compatible with the
// 		// screen
// 		BufferedImage bimage = null;
// 		GraphicsEnvironment ge = GraphicsEnvironment
// 				.getLocalGraphicsEnvironment();
// 		try {
// 			// Determine the type of transparency of the new buffered image
// 			int transparency = Transparency.OPAQUE;
// 			if (hasAlpha) {
// 				transparency = Transparency.BITMASK;
// 			}
// 
// 			// Create the buffered image
// 			GraphicsDevice gs = ge.getDefaultScreenDevice();
// 			GraphicsConfiguration gc = gs.getDefaultConfiguration();
// 			bimage = gc.createCompatibleImage(image.getWidth(null),
// 					image.getHeight(null), transparency);
// 		} catch (HeadlessException e) {
// 			// The system does not have a screen
// 		}
// 
// 		if (bimage == null) {
// 			// Create a buffered image using the default color model
// 			int type = BufferedImage.TYPE_INT_RGB;
// 			if (hasAlpha) {
// 				type = BufferedImage.TYPE_INT_ARGB;
// 			}
// 			bimage = new BufferedImage(image.getWidth(null),
// 					image.getHeight(null), type);
// 		}
// 
// 		// Copy image to buffered image
// 		Graphics g = bimage.createGraphics();
// 
// 		// Paint the image onto the buffered image
// 		g.drawImage(image, 0, 0, null);
// 		g.dispose();
// 
// 		return bimage;
// 	}
// 
// 	/**
// 	 * Get an image as a ByteArrayInputStream
// 	 * 
// 	 * @param image
// 	 *            The image
// 	 * @return The inputstream
// 	 * @throws IOException
// 	 *             If an error occurred while writing or reading
// 	 */
// 	public static InputStream toInputStream(BufferedImage image)
// 			throws IOException {
// 		ByteArrayOutputStream output = new ByteArrayOutputStream();
// 		ImageIO.write(image, "PNG", output);
// 		return new ByteArrayInputStream(output.toByteArray());
// 	}
// }


import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import org.sleeksnap.util.Utils.ImageUtil;
/**
 * Sleeksnap, the open source cross-platform screenshot uploader
 * Copyright (C) 2012 Nikki <nikki@nikkii.us>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.sleeksnap.upload;



/**
 * An Image based Upload
 * 
 * @author Nikki
 *
 */
public class ImageUpload implements Upload {
	
	/**
	 * The BufferedImage we are uploading
	 */
	private BufferedImage image;
	
	public ImageUpload(BufferedImage image) {
		this.image = image;
	}

	@Override
	public InputStream asInputStream() throws IOException {
// Path: src/org/sleeksnap/util/Utils.java
// public static class ImageUtil {
// 
// 	/**
// 	 * Check whether an image has alpha pixels
// 	 * 
// 	 * @param image
// 	 *            The image
// 	 * @return True, if the image has alpha pixels
// 	 */
// 	public static boolean hasAlpha(Image image) {
// 		// If buffered image, the color model is readily available
// 		if (image instanceof BufferedImage) {
// 			BufferedImage bimage = (BufferedImage) image;
// 			return bimage.getColorModel().hasAlpha();
// 		}
// 
// 		// Use a pixel grabber to retrieve the image's color model;
// 		// grabbing a single pixel is usually sufficient
// 		PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
// 		try {
// 			pg.grabPixels();
// 		} catch (InterruptedException e) {
// 		}
// 
// 		// Get the image's color model
// 		ColorModel cm = pg.getColorModel();
// 		if (cm == null) {
// 			return false;
// 		}
// 		return cm.hasAlpha();
// 	}
// 
// 	/**
// 	 * Convert an image into a Base64 string
// 	 * 
// 	 * @param image
// 	 *            The image
// 	 * @return The base64 encoded image data
// 	 * @throws IOException
// 	 *             If an error occurred
// 	 */
// 	public static String toBase64(BufferedImage image) throws IOException {
// 		ByteArrayOutputStream output = new ByteArrayOutputStream();
// 		ImageIO.write(image, "PNG", output);
// 		return DatatypeConverter.printBase64Binary(output.toByteArray());
// 	}
// 
// 	/**
// 	 * Convert a regular image to a buffered image
// 	 * 
// 	 * @param image
// 	 *            The image
// 	 * @return The buffered image
// 	 */
// 	public static BufferedImage toBufferedImage(Image image) {
// 		if (image instanceof BufferedImage) {
// 			return (BufferedImage) image;
// 		}
// 
// 		// This code ensures that all the pixels in the image are loaded
// 		image = new ImageIcon(image).getImage();
// 
// 		// Determine if the image has transparent pixels; for this method's
// 		// implementation, see Determining If an Image Has Transparent
// 		// Pixels
// 		boolean hasAlpha = hasAlpha(image);
// 
// 		// Create a buffered image with a format that's compatible with the
// 		// screen
// 		BufferedImage bimage = null;
// 		GraphicsEnvironment ge = GraphicsEnvironment
// 				.getLocalGraphicsEnvironment();
// 		try {
// 			// Determine the type of transparency of the new buffered image
// 			int transparency = Transparency.OPAQUE;
// 			if (hasAlpha) {
// 				transparency = Transparency.BITMASK;
// 			}
// 
// 			// Create the buffered image
// 			GraphicsDevice gs = ge.getDefaultScreenDevice();
// 			GraphicsConfiguration gc = gs.getDefaultConfiguration();
// 			bimage = gc.createCompatibleImage(image.getWidth(null),
// 					image.getHeight(null), transparency);
// 		} catch (HeadlessException e) {
// 			// The system does not have a screen
// 		}
// 
// 		if (bimage == null) {
// 			// Create a buffered image using the default color model
// 			int type = BufferedImage.TYPE_INT_RGB;
// 			if (hasAlpha) {
// 				type = BufferedImage.TYPE_INT_ARGB;
// 			}
// 			bimage = new BufferedImage(image.getWidth(null),
// 					image.getHeight(null), type);
// 		}
// 
// 		// Copy image to buffered image
// 		Graphics g = bimage.createGraphics();
// 
// 		// Paint the image onto the buffered image
// 		g.drawImage(image, 0, 0, null);
// 		g.dispose();
// 
// 		return bimage;
// 	}
// 
// 	/**
// 	 * Get an image as a ByteArrayInputStream
// 	 * 
// 	 * @param image
// 	 *            The image
// 	 * @return The inputstream
// 	 * @throws IOException
// 	 *             If an error occurred while writing or reading
// 	 */
// 	public static InputStream toInputStream(BufferedImage image)
// 			throws IOException {
// 		ByteArrayOutputStream output = new ByteArrayOutputStream();
// 		ImageIO.write(image, "PNG", output);
// 		return new ByteArrayInputStream(output.toByteArray());
// 	}
// }


// Path: src/org/sleeksnap/upload/ImageUpload.java
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import org.sleeksnap.util.Utils.ImageUtil;

/**
 * Sleeksnap, the open source cross-platform screenshot uploader
 * Copyright (C) 2012 Nikki <nikki@nikkii.us>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.sleeksnap.upload;



/**
 * An Image based Upload
 * 
 * @author Nikki
 *
 */
public class ImageUpload implements Upload {
	
	/**
	 * The BufferedImage we are uploading
	 */
	private BufferedImage image;
	
	public ImageUpload(BufferedImage image) {
		this.image = image;
	}

	@Override
	public InputStream asInputStream() throws IOException {
		return ImageUtil.toInputStream(image);