@SuppressWarnings("deprecation")
	public PPM(String filename) throws IOException, UnsupportedEncodingException {
		FileInputStream fis = new FileInputStream(filename);

		// XXX: The source data to the StreamTokenizer can't buffered, since we
		// only need a few lines of the beginning of the file, and all remain
		// data must be processed later. Even a InputStreamReader does some
		// internal buffering, so we must use a deprecated constructor, create
		// our own Reader or create some methods to simulate a StreamTokenizer.
		// Easy way chosen :-)
		StreamTokenizer st = new StreamTokenizer(fis);
		st.commentChar('#');

		/*
		 * PPM file format:
		 * 
		 * # --> Comments allowed anywere before binary data P3|P6 -->
		 * ASCII/Binary WIDTH --> image width, in ascii HEIGHT --> image height,
		 * in ascii COLORS --> num colors, in ascii [data] --> if P6, data in
		 * binary, 3 RGB bytes per pixel
		 */

		st.nextToken();
		if (!st.sval.equals("P6"))
			throw new UnsupportedEncodingException("Not a P6 (binary) PPM");

		st.nextToken();
		dim.width = (int) Math.round(st.nval);
		st.nextToken();
		dim.height = (int) Math.round(st.nval);
		data = new int[dim.width * dim.height];

		st.nextToken();
		int maxVal = (int) Math.round(st.nval);
		if (maxVal != 255)
			throw new UnsupportedEncodingException("Not a 255 color PPM");

		// Binary data cann be buffered
		InputStream in = new BufferedInputStream(fis);
		int numPixels = dim.width * dim.height;

		picture = new Color[dim.height][dim.width];
		pictureBean = new ColorBean[dim.height][dim.width];
		// PrintWriter out = new PrintWriter(new
		// FileWriter("./outputfile.txt"));
		for (int i = 0; i < numPixels; i++) {
			int r = in.read();
			int g = in.read();
			int b = in.read();

			if (r == -1 || g == -1 || b == -1)
				throw new IOException("EOF:" + r + " " + g + " " + b);

			data[i] = rgb(r, g, b);

			picture[(int) Math.ceil(i / dim.width)][i % dim.width] = new Color(r, g, b);
			pictureBean[(int) Math.ceil(i / dim.width)][i % dim.width] = new ColorBean(r, g, b);

			// out.println(rgb(r, g, b));

		}
		// out.close();
		in.close();
	}