Statistics
| Revision:

svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / io / raster / RasterBuf.java @ 2312

History | View | Annotate | Download (4.04 KB)

1
/*
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
 * Rectangulo de pixeles. parecido a java.awt.image.Raster
30
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
31
 */
32
public class RasterBuf implements IRaster {
33
        private byte  [][][] byteBuf;
34
        private short [][][] shortBuf;
35
        private int   [][][] intBuf;
36
        private int width, height, bandNr;
37
        private int dataType;
38
        
39
        /**
40
         * Constructor
41
         * @param dataType Tipo de dato
42
         * @param width Ancho
43
         * @param height Alto
44
         * @param bandNr Banda
45
         * @param orig
46
         */
47
        public RasterBuf(int dataType, int width, int height, int bandNr, Point orig) {
48
                this.dataType = dataType;
49
                this.width = width;
50
                this.height = height;
51
                this.bandNr = bandNr;
52
                if (dataType == TYPE_BYTE)
53
                        byteBuf  = new byte[height][width][bandNr];
54
                else if (dataType == TYPE_SHORT | dataType == TYPE_USHORT)
55
                        shortBuf = new short[height][width][bandNr];
56
                else if (dataType == TYPE_INT)
57
                        intBuf   = new int[height][width][bandNr];
58
        }
59
        
60
        /* (non-Javadoc)
61
         * @see org.cresques.io.raster.IRaster#getWidth()
62
         */
63
        public int getWidth() { return width; }
64
        
65
        /* (non-Javadoc)
66
         * @see org.cresques.io.raster.IRaster#getHeight()
67
         */
68
        public int getHeight() { return height; }
69
        
70
        /* (non-Javadoc)
71
         * @see org.cresques.io.raster.IRaster#getBandNr()
72
         */
73
        public int getBandNr() { return bandNr; }
74
        
75
        /* (non-Javadoc)
76
         * @see org.cresques.io.raster.IRaster#getDataType()
77
         */
78
        public int getDataType() { return dataType; }
79
        
80
        /**
81
         * Obtiene el tipo de dato
82
         * @return Tipo de dato
83
         */
84
        public int getDataSize() {
85
                if (dataType == TYPE_BYTE)
86
                        return 1;
87
                else if (dataType == TYPE_SHORT | dataType == TYPE_USHORT)
88
                        return 2;
89
                else if (dataType == TYPE_INT)
90
                        return 4;
91
                return 0;
92
        }
93
        
94
        /**
95
         * Obtiene el tama?o del buffer
96
         * @return tama?o del buffer
97
         */
98
        public int sizeof() {
99
                return getDataSize()*width*height*bandNr;
100
        }
101
        
102
        public byte [][] getLineByte(int y) {        return byteBuf[y]; }
103
        
104
        public short [][] getLineShort(int y) {        return shortBuf[y]; }
105
        
106
        public int [][] getLineInt(int y) {        return intBuf[y]; }
107

    
108
        public void getElemShort(int x, int y, int [] px) {
109
                for (int i=0; i<bandNr; i++) px[i] = shortBuf[y][x][i];
110
        }
111

    
112
        public void getElemInt(int x, int y, int [] px) {
113
                for (int i=0; i<bandNr; i++) px[i] = intBuf[y][x][i];
114
        }
115
        
116
        public void setElemShort(int x, int y, int [] px) {
117
                for (int i=0; i<bandNr; i++) shortBuf[y][x][i] = (short) px[i];
118
        }
119
        
120
        public void setElemInt(int x, int y, int [] px) {
121
                for (int i=0; i<bandNr; i++) intBuf[y][x][i] = px[i];
122
        }
123

    
124
        /* (non-Javadoc)
125
         * @see org.cresques.io.raster.IRaster#getElemInt(int, int, int)
126
         */
127
        public int getElemInt(int x, int y, int band) {
128
                return intBuf[y][x][band];
129
        }
130
        
131
        /**
132
         * Convierte un tipo de dato a cadena
133
         * @param type Tipo de dato
134
         * @return cadena  que representa el tipo de dato
135
         */
136
        public static String typesToString(int type){
137
                switch(type){
138
                        case RasterBuf.TYPE_IMAGE:return new String("Image");
139
                        case RasterBuf.TYPE_BYTE:return new String("Byte");
140
                        case RasterBuf.TYPE_DOUBLE:return new String("Double");
141
                        case RasterBuf.TYPE_FLOAT:return new String("Float");
142
                        case RasterBuf.TYPE_INT:
143
                        case RasterBuf.TYPE_USHORT:
144
                        case RasterBuf.TYPE_SHORT:return new String("Short");
145
                }
146
                return null;
147
        }
148
}