Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / cutting / WriterBufferServer.java @ 11384

History | View | Annotate | Download (4.44 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.rastertools.cutting;
20

    
21
import org.gvsig.gui.beans.incrementabletask.IIncrementable;
22
import org.gvsig.raster.dataset.IBuffer;
23
import org.gvsig.raster.dataset.IDataWriter;
24

    
25
/**
26
 * Sirve los datos desde un IBuffer para el driver de escritura de bloques de 
27
 * cach?.
28
 * 
29
 * @author Nacho Brodin (nachobrodin@gmail.com)
30
 */
31
public class WriterBufferServer implements IDataWriter, IIncrementable{
32
        private IBuffer                 buffer = null;
33
        private int                         row = 0;
34
        private int                                block = 0;
35

    
36
        public WriterBufferServer() {
37
        }
38

    
39
        public WriterBufferServer(IBuffer buffer) {
40
                setBuffer(buffer);
41
        }
42
        
43
        public void setBuffer(IBuffer buffer) {
44
                this.buffer = buffer;
45
        }
46

    
47
        public int[] readARGBData(int sizeX, int sizeY, int nBand) {
48
                return null;
49
        }
50

    
51
        /*
52
         * (non-Javadoc)
53
         * @see org.gvsig.raster.dataset.IDataWriter#readByteData(int, int)
54
         */
55
        public byte[][] readByteData(int sizeX, int sizeY) {
56
                if(row == 0)
57
                        block = sizeY;
58
                int len = buffer.getWidth() * sizeY;
59
                byte[][] b = new byte[buffer.getBandCount()][len];
60
                for(int iBand = 0; iBand < buffer.getBandCount(); iBand ++)
61
                        for(int j = row; j < (row + sizeY); j ++)
62
                                for(int i = 0; i < buffer.getWidth(); i ++)
63
                                        b[iBand][(j % block) * buffer.getWidth() + i] = buffer.getElemByte(j, i, iBand);
64
                row += sizeY;
65
                return b;
66
        }
67

    
68
        /*
69
         * (non-Javadoc)
70
         * @see org.gvsig.raster.dataset.IDataWriter#readShortData(int, int)
71
         */
72
        public short[][] readShortData(int sizeX, int sizeY) {
73
                if(row == 0)
74
                        block = sizeY;
75
                int len = buffer.getWidth() * sizeY;
76
                short[][] b = new short[buffer.getBandCount()][len];
77
                for(int iBand = 0; iBand < buffer.getBandCount(); iBand ++)
78
                        for(int j = row; j < (row + sizeY); j ++)
79
                                for(int i = 0; i < buffer.getWidth(); i ++)
80
                                        b[iBand][(j % block) * buffer.getWidth() + i] = buffer.getElemShort(j, i, iBand);
81
                row += sizeY;
82
                return b;
83
        }
84

    
85
        /*
86
         * (non-Javadoc)
87
         * @see org.gvsig.raster.dataset.IDataWriter#readIntData(int, int)
88
         */
89
        public int[][] readIntData(int sizeX, int sizeY) {
90
                if(row == 0)
91
                        block = sizeY;
92
                int len = buffer.getWidth() * sizeY;
93
                int[][] b = new int[buffer.getBandCount()][len];
94
                for(int iBand = 0; iBand < buffer.getBandCount(); iBand ++)
95
                        for(int j = row; j < (row + sizeY); j ++)
96
                                for(int i = 0; i < buffer.getWidth(); i ++)
97
                                        b[iBand][(j % block) * buffer.getWidth() + i] = buffer.getElemInt(j, i, iBand);
98
                row += sizeY;
99
                return b;
100
        }
101

    
102
        /*
103
         * (non-Javadoc)
104
         * @see org.gvsig.raster.dataset.IDataWriter#readFloatData(int, int)
105
         */
106
        public float[][] readFloatData(int sizeX, int sizeY) {
107
                if(row == 0)
108
                        block = sizeY;
109
                int len = buffer.getWidth() * sizeY;
110
                float[][] b = new float[buffer.getBandCount()][len];
111
                for(int iBand = 0; iBand < buffer.getBandCount(); iBand ++)
112
                        for(int j = row; j < (row + sizeY); j ++)
113
                                for(int i = 0; i < buffer.getWidth(); i ++)
114
                                        b[iBand][(j % block) * buffer.getWidth() + i] = buffer.getElemFloat(j, i, iBand);
115
                row += sizeY;
116
                return b;
117
        }
118

    
119
        /*
120
         * (non-Javadoc)
121
         * @see org.gvsig.raster.dataset.IDataWriter#readDoubleData(int, int)
122
         */
123
        public double[][] readDoubleData(int sizeX, int sizeY) {
124
                if(row == 0)
125
                        block = sizeY;
126
                int len = buffer.getWidth() * sizeY;
127
                double[][] b = new double[buffer.getBandCount()][len];
128
                for(int iBand = 0; iBand < buffer.getBandCount(); iBand ++)
129
                        for(int j = row; j < (row + sizeY); j ++)
130
                                for(int i = 0; i < buffer.getWidth(); i ++)
131
                                        b[iBand][(j % block) * buffer.getWidth() + i] = buffer.getElemDouble(j, i, iBand);
132
                row += sizeY;
133
                return b;
134
        }
135

    
136
        public String getLabel() {
137
                return "";
138
        }
139

    
140
        public String getLog() {
141
                return "";
142
        }
143

    
144
        public int getPercent() {
145
                return 0;
146
        }
147

    
148
        public String getTitle() {
149
                return "";
150
        }        
151
}