aboutsummaryrefslogtreecommitdiffstats
path: root/gl4java/utils/textures/PPMAsciiTextureLoader.java
blob: b8d1610b7939f9d02822a95008bfa51dd31118ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package gl4java.utils.textures;

import gl4java.*;

import java.awt.*;
import java.awt.image.*;
import java.awt.Color.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
import java.net.*;

/**
 * This is Class implements the PPM-Ascii
 * texture-loader !
 *
 * @see IOTextureLoader
 * @see TextureLoader
 */   
public class PPMAsciiTextureLoader
extends IOTextureLoader
{
	public PPMAsciiTextureLoader(GLFunc gl, GLUFunc glu)
	{
		super(gl, glu);
	}

	protected boolean readTexture(InputStream is)
	{
	  try {
                glFormat=GL_RGB;
            
		DataInputStream reader = new DataInputStream ( is );

		String lin=reader.readLine();	//P6
		String subLin=lin.substring(0,1);
		
		lin=reader.readLine();
		subLin=lin.substring(0,1);
	
		while (subLin.compareTo("#")==0)
		{
			lin=reader.readLine();
			subLin=lin.substring(0,1);
		}
		
		char[] dim=lin.toCharArray();

		int i=0;
		char car=lin.charAt(i);
		String blanco=new String(" ");
		Character C=new Character(car);
		car=C.charValue();
		while (C.isDigit(car))
		{
			i++;
			car=lin.charAt(i);
			C=new Character(car);
		}

		String alto=lin.substring(0,i);
		String ancho=lin.substring(i+1,lin.length());
 	
 		Integer hh=new Integer(alto);
		imageWidth=hh.intValue();
 		hh=new Integer(ancho);
		imageHeight=hh.intValue();
 
                pixel=new byte[imageWidth * imageHeight * getComponents()];

		lin=reader.readLine();		//255

	        reader.read(pixel, 0, pixel.length);

		reader.close();
	        setTextureSize();
	        return true;

	   } catch (Exception e) {
	        System.out.println("An exception occured, while loading a PPMAsciiTextureLoader");
	        System.out.println(e);
	        error=true;
	   }
	   return false;
	}

}