svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / io / raster / RasterBuf.java @ 4578
History | View | Annotate | Download (4.71 KB)
1 | 2809 | nacho | /*
|
---|---|---|---|
2 | * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
||
3 | *
|
||
4 | * Copyright (C) 2004-5.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
19 | *
|
||
20 | * For more information, contact:
|
||
21 | *
|
||
22 | * cresques@gmail.com
|
||
23 | */
|
||
24 | package org.cresques.io.raster; |
||
25 | |||
26 | import java.awt.Point; |
||
27 | |||
28 | |||
29 | /**
|
||
30 | * Rectangulo de pixeles. parecido a java.awt.image.Raster
|
||
31 | * @author Luis W. Sevilla (sevilla_lui@gva.es)
|
||
32 | */
|
||
33 | public class RasterBuf implements IRaster { |
||
34 | private byte[][][] byteBuf; |
||
35 | private short[][][] shortBuf; |
||
36 | private int[][][] intBuf; |
||
37 | private int width; |
||
38 | private int height; |
||
39 | private int bandNr; |
||
40 | private int dataType; |
||
41 | |||
42 | /**
|
||
43 | * Constructor
|
||
44 | * @param dataType Tipo de dato
|
||
45 | * @param width Ancho
|
||
46 | * @param height Alto
|
||
47 | * @param bandNr Banda
|
||
48 | * @param orig
|
||
49 | */
|
||
50 | public RasterBuf(int dataType, int width, int height, int bandNr, Point orig) { |
||
51 | this.dataType = dataType;
|
||
52 | this.width = width;
|
||
53 | this.height = height;
|
||
54 | this.bandNr = bandNr;
|
||
55 | |||
56 | if (dataType == TYPE_BYTE) {
|
||
57 | byteBuf = new byte[height][width][bandNr]; |
||
58 | } else if ((dataType == TYPE_SHORT) | (dataType == TYPE_USHORT)) { |
||
59 | shortBuf = new short[height][width][bandNr]; |
||
60 | } else if (dataType == TYPE_INT) { |
||
61 | intBuf = new int[height][width][bandNr]; |
||
62 | } |
||
63 | } |
||
64 | |||
65 | /* (non-Javadoc)
|
||
66 | * @see org.cresques.io.raster.IRaster#getWidth()
|
||
67 | */
|
||
68 | public int getWidth() { |
||
69 | return width;
|
||
70 | } |
||
71 | |||
72 | /* (non-Javadoc)
|
||
73 | * @see org.cresques.io.raster.IRaster#getHeight()
|
||
74 | */
|
||
75 | public int getHeight() { |
||
76 | return height;
|
||
77 | } |
||
78 | |||
79 | /* (non-Javadoc)
|
||
80 | * @see org.cresques.io.raster.IRaster#getBandNr()
|
||
81 | */
|
||
82 | public int getBandNr() { |
||
83 | return bandNr;
|
||
84 | } |
||
85 | |||
86 | /* (non-Javadoc)
|
||
87 | * @see org.cresques.io.raster.IRaster#getDataType()
|
||
88 | */
|
||
89 | public int getDataType() { |
||
90 | return dataType;
|
||
91 | } |
||
92 | |||
93 | /**
|
||
94 | * Obtiene el tipo de dato
|
||
95 | * @return Tipo de dato
|
||
96 | */
|
||
97 | public int getDataSize() { |
||
98 | if (dataType == TYPE_BYTE) {
|
||
99 | return 1; |
||
100 | } else if ((dataType == TYPE_SHORT) | (dataType == TYPE_USHORT)) { |
||
101 | return 2; |
||
102 | } else if (dataType == TYPE_INT) { |
||
103 | return 4; |
||
104 | } |
||
105 | |||
106 | return 0; |
||
107 | } |
||
108 | |||
109 | /**
|
||
110 | * Obtiene el tama?o del buffer
|
||
111 | * @return tama?o del buffer
|
||
112 | */
|
||
113 | public int sizeof() { |
||
114 | return getDataSize() * width * height * bandNr;
|
||
115 | } |
||
116 | |||
117 | public byte[][] getLineByte(int y) { |
||
118 | return byteBuf[y];
|
||
119 | } |
||
120 | |||
121 | public short[][] getLineShort(int y) { |
||
122 | return shortBuf[y];
|
||
123 | } |
||
124 | |||
125 | public int[][] getLineInt(int y) { |
||
126 | return intBuf[y];
|
||
127 | } |
||
128 | |||
129 | public void getElemShort(int x, int y, int[] px) { |
||
130 | for (int i = 0; i < bandNr; i++) |
||
131 | px[i] = shortBuf[y][x][i]; |
||
132 | } |
||
133 | |||
134 | public void getElemInt(int x, int y, int[] px) { |
||
135 | for (int i = 0; i < bandNr; i++) |
||
136 | px[i] = intBuf[y][x][i]; |
||
137 | } |
||
138 | |||
139 | public void setElemShort(int x, int y, int[] px) { |
||
140 | for (int i = 0; i < bandNr; i++) |
||
141 | shortBuf[y][x][i] = (short) px[i];
|
||
142 | } |
||
143 | |||
144 | public void setElemInt(int x, int y, int[] px) { |
||
145 | for (int i = 0; i < bandNr; i++) |
||
146 | intBuf[y][x][i] = px[i]; |
||
147 | } |
||
148 | |||
149 | /* (non-Javadoc)
|
||
150 | * @see org.cresques.io.raster.IRaster#getElemInt(int, int, int)
|
||
151 | */
|
||
152 | public int getElemInt(int x, int y, int band) { |
||
153 | return intBuf[y][x][band];
|
||
154 | } |
||
155 | |||
156 | /**
|
||
157 | * Convierte un tipo de dato a cadena
|
||
158 | * @param type Tipo de dato
|
||
159 | * @return cadena que representa el tipo de dato
|
||
160 | */
|
||
161 | public static String typesToString(int type) { |
||
162 | switch (type) {
|
||
163 | case RasterBuf.TYPE_IMAGE:
|
||
164 | return new String("Image"); |
||
165 | |||
166 | case RasterBuf.TYPE_BYTE:
|
||
167 | return new String("Byte"); |
||
168 | |||
169 | case RasterBuf.TYPE_DOUBLE:
|
||
170 | return new String("Double"); |
||
171 | |||
172 | case RasterBuf.TYPE_FLOAT:
|
||
173 | return new String("Float"); |
||
174 | |||
175 | case RasterBuf.TYPE_INT:
|
||
176 | case RasterBuf.TYPE_USHORT:
|
||
177 | case RasterBuf.TYPE_SHORT:
|
||
178 | return new String("Short"); |
||
179 | } |
||
180 | |||
181 | return null; |
||
182 | } |
||
183 | } |