svn-gvsig-desktop / branches / v02_desarrollo / libraries / libCq CMS for java.old / src / org / cresques / io / RasterBuf.java @ 1533
History | View | Annotate | Download (1.97 KB)
1 |
/*
|
---|---|
2 |
* Created on 22-feb-2005
|
3 |
*/
|
4 |
package org.cresques.io; |
5 |
|
6 |
import java.awt.Point; |
7 |
import java.awt.image.DataBuffer; |
8 |
|
9 |
/**
|
10 |
* Rectangulo de pixeles. parecido a java.awt.image.Raster
|
11 |
* @author Luis W. Sevilla (sevilla_lui@gva.es)
|
12 |
*/
|
13 |
public class RasterBuf { |
14 |
private byte [][][] byteBuf; |
15 |
private short [][][] shortBuf; |
16 |
private int [][][] intBuf; |
17 |
private int width, height, bandNr; |
18 |
private int dataType; |
19 |
|
20 |
public RasterBuf(int dataType, int width, int height, int bandNr, Point orig) { |
21 |
this.dataType = dataType;
|
22 |
this.width = width;
|
23 |
this.height = height;
|
24 |
this.bandNr = bandNr;
|
25 |
if (dataType == DataBuffer.TYPE_BYTE) |
26 |
byteBuf = new byte[height][width][bandNr]; |
27 |
else if (dataType == DataBuffer.TYPE_SHORT | dataType == DataBuffer.TYPE_USHORT) |
28 |
shortBuf = new short[height][width][bandNr]; |
29 |
else if (dataType == DataBuffer.TYPE_INT) |
30 |
intBuf = new int[height][width][bandNr]; |
31 |
} |
32 |
|
33 |
public int getWidth() { return width; } |
34 |
|
35 |
public int getHeight() { return height; } |
36 |
|
37 |
public int getDataType() { return dataType; } |
38 |
|
39 |
public int getDataSize() { |
40 |
if (dataType == DataBuffer.TYPE_BYTE) |
41 |
return 1; |
42 |
else if (dataType == DataBuffer.TYPE_SHORT | dataType == DataBuffer.TYPE_USHORT) |
43 |
return 2; |
44 |
else if (dataType == DataBuffer.TYPE_INT) |
45 |
return 4; |
46 |
return 0; |
47 |
} |
48 |
|
49 |
public int sizeof() { |
50 |
return getDataSize()*width*height*bandNr;
|
51 |
} |
52 |
|
53 |
public byte [][] getLineByte(int y) { return byteBuf[y]; } |
54 |
|
55 |
public short [][] getLineShort(int y) { return shortBuf[y]; } |
56 |
|
57 |
public int [][] getLineInt(int y) { return intBuf[y]; } |
58 |
|
59 |
public void setPixelShort(int x, int y, int [] px) { |
60 |
for (int i=0; i<bandNr; i++) shortBuf[y][x][i] = (short) px[i]; |
61 |
} |
62 |
|
63 |
public void getPixelShort(int x, int y, int [] px) { |
64 |
for (int i=0; i<bandNr; i++) px[i] = shortBuf[y][x][i]; |
65 |
} |
66 |
|
67 |
public void setPixelInt(int x, int y, int [] px) { |
68 |
for (int i=0; i<bandNr; i++) intBuf[y][x][i] = px[i]; |
69 |
} |
70 |
|
71 |
public void getPixelInt(int x, int y, int [] px) { |
72 |
for (int i=0; i<bandNr; i++) px[i] = intBuf[y][x][i]; |
73 |
} |
74 |
} |