/**
 * PixelImage.java
 * 
 * Copyright (c) 2015 Kenji Sasaki
 * Released under the MIT license.
 * https://github.com/npedotnet/npe-image-library/blob/master/LICENSE
 * 
 * This file is a part of npe-image-library.
 * https://github.com/npedotnet/npe-image-library
 *
 * For more details, see npe-image-library wiki.
 * https://github.com/npedotnet/npe-image-library/wiki
 * 
 */

package net.npe.image;

public class PixelImage {
	
	/**
	 * constructor.
	 * @param pixels image pixels
	 * @param width image width
	 * @param height image height
	 * @param format pixel format
	 */
	public PixelImage(int [] pixels, int width, int height, PixelFormat format) {
		this.pixels = pixels;
		this.width = width;
		this.height = height;
		this.format = format;
	}
	
	/**
	 * get pixel array.
	 * @return pixel array
	 */
	public int [] getPixels() { return pixels; }
	
	/**
	 * get image width.
	 * @return image width
	 */
	public int getWidth() { return width; }
	
	/**
	 * get image height.
	 * @return image height
	 */
	public int getHeight() { return height; }
	
	/**
	 * get pixel format.
	 * @return pixel format
	 */
	public PixelFormat getFormat() { return format; }
	
	/**
	 * change format (not yet implemented)
	 * @param format pixel format
	 */
	public void changeFormat(PixelFormat format) {
		// TODO implementation
	}

	/**
	 * multiply alpha (not yet implemented)
	 * @param alpha alpha is 0.0 to 1.0
	 */
	public void multiplyAlpha(float alpha) {
		// TODO implementation
	}
	
	/**
	 * multiply alpha (not yet implemented)
	 * @param alpha alpha is 0 to 255
	 */
	public void multiplyAlpha(int alpha) {
		multiplyAlpha(alpha / 255.f);
	}
	
	protected PixelImage() {
		this(null, 0, 0, null);
	}
	
	protected int [] pixels;
	protected int width;
	protected int height;
	protected PixelFormat format;

}

@@ -1189,38 +1189,16 @@
 e format
- (not yet implemented)
 %0A%09 * @pa
@@ -1276,38 +1276,364 @@
 at) %7B%0A%09%09
-// TODO implementation
+if(this.format != format) %7B%0A%09%09%09for(int i=0; i%3Cwidth*height; i++) %7B%0A%09%09%09%09int red = this.format.getRed(pixels%5Bi%5D);%0A%09%09%09%09int green = this.format.getGreen(pixels%5Bi%5D);%0A%09%09%09%09int blue = this.format.getBlue(pixels%5Bi%5D);%0A%09%09%09%09int alpha = this.format.getAlpha(pixels%5Bi%5D);%0A%09%09%09%09pixels%5Bi%5D = format.getPixel(red, green, blue, alpha);%0A%09%09%09%7D%0A%09%09%09this.format = format;%0A%09%09%7D
 %0A%09%7D%0A%0A%09/*
@@ -1652,38 +1652,16 @@
 ly alpha
- (not yet implemented)
 %0A%09 * @pa
@@ -1743,30 +1743,227 @@
 %7B%0A%09%09
-// TODO implementation
+int rgbMask = ~format.getAlphaMask();%0A%09%09for(int i=0; i%3Cwidth*height; i++) %7B%0A%09%09%09int a = (int)(255 * alpha * (format.getAlpha(pixels%5Bi%5D) / 255.f));%0A%09%09%09pixels%5Bi%5D = (pixels%5Bi%5D & rgbMask) %7C (a %3C%3C format.getAlphaShift());%0A%09%09%7D
 %0A%09%7D%0A
@@ -1991,30 +1991,8 @@
 lpha
- (not yet implemented)
 %0A%09 *
@@ -2097,32 +2097,524 @@
  / 255.f);%0A%09%7D%0A%09%0A
+%09/**%0A%09 * set alpha%0A%09 * @param alpha alpha is 0 to 255%0A%09 */%0A%09public void setAlpha(int alpha) %7B%0A%09%09int rgbMask = ~format.getAlphaMask();%0A%09%09for(int i=0; i%3Cwidth*height; i++) %7B%0A%09%09%09pixels%5Bi%5D = (pixels%5Bi%5D & rgbMask) %7C (alpha %3C%3C format.getAlphaShift());%0A%09%09%7D%0A%09%7D%0A%09%0A%09/**%0A%09 * remove transparency.%0A%09 */%0A%09public void removeTransparency() %7B%0A%09%09int alphaMask = format.getAlphaMask();%0A%09%09int rgbMask = ~alphaMask;%0A%09%09for(int i=0; i%3Cwidth*height; i++) %7B%0A%09%09%09pixels%5Bi%5D = (pixels%5Bi%5D & rgbMask) %7C alphaMask;%0A%09%09%7D%0A%09%7D%0A%09%0A
 %09protected Pixel

Add change format and alpha operation methods.