Statistics
| Revision:

gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / deprecated / buffer / impl / memory / ByteBand.java @ 1939

History | View | Annotate | Download (2.25 KB)

1
package org.gvsig.raster.cache.buffer.impl.memory;
2

    
3
import org.gvsig.raster.cache.buffer.Buffer;
4

    
5

    
6
/**
7
 * This class represent a byte band loaded in memory.
8
 * 
9
 * @author Nacho Brodin (nachobrodin@gmail.com)
10
 */
11
public class ByteBand extends MemoryBand {
12
        public byte[][]         buf = null;
13
        
14
        public ByteBand(int width, int height, int nBand, boolean malloc) {
15
                super(width, height, nBand);
16
                this.setDataType(Buffer.TYPE_BYTE);
17
                if(malloc)
18
                        buf = new byte[height][width];
19
        }
20

    
21

    
22
        /*
23
         * (non-Javadoc)
24
         * @see org.gvsig.raster.buffer.RasterBand#assign(byte)
25
         */
26
        public void assign(byte value) {
27
                for (int i = 0; i < buf.length; i++) {
28
                        for (int j = 0; j < buf[i].length; j++) {
29
                                buf[i][j] = value;
30
                        }
31
                }                
32
        }
33
        
34
        /*
35
         * (non-Javadoc)
36
         * @see org.gvsig.raster.buffer.RasterBand#getByteBlock(int)
37
         */
38
        public byte[][] getByteBlock(int block) {
39
                return buf;
40
        }
41
        
42
        /*
43
         * (non-Javadoc)
44
         * @see org.gvsig.raster.buffer.memory.RasterMemoryBand#setByteBlock(byte[][], int)
45
         */
46
        public void setByteBlock(byte[][] data, int block) {
47
                this.buf = data;
48
        }
49

    
50
        /*
51
         * (non-Javadoc)
52
         * @see org.gvsig.raster.buffer.RasterBand#getByteLine(int)
53
         */
54
        public byte[] getByteLine(int line) {
55
                return buf[line];
56
        }
57

    
58

    
59
        /*
60
         * (non-Javadoc)
61
         * @see org.gvsig.raster.buffer.RasterBand#getElemByte(int, int)
62
         */
63
        public byte getElemByte(int line, int col) {
64
                return buf[line][col];
65
        }
66

    
67
        /*
68
         * (non-Javadoc)
69
         * @see org.gvsig.raster.buffer.RasterBand#setByteLine(byte[], int)
70
         */
71
        public void setByteLine(byte[] data, int line) {
72
                buf[line] = data;
73
        }
74

    
75
        /*
76
         * (non-Javadoc)
77
         * @see org.gvsig.raster.buffer.RasterBand#setElem(int, int, byte)
78
         */
79
        public void setElem(int line, int col, byte data) {
80
                buf[line][col] = data;
81
        }
82
        
83
        /*
84
         * (non-Javadoc)
85
         * @see org.fv.raster.buffer.memory.MemoryBand#free()
86
         */
87
        public void free() {
88
                buf = null;
89
        }
90
        
91
        /*
92
         * (non-Javadoc)
93
         * @see org.fv.raster.buffer.memory.MemoryBand#clone()
94
         */
95
        public MemoryBand clone() {
96
                if(buf == null)
97
                        return new ByteBand(getWidth(), getHeight(), getBandNumber(), false);
98
                ByteBand bb = new ByteBand(getWidth(), getHeight(), getBandNumber(), true);
99
                for(int row = 0; row < buf.length; row ++) {
100
                        for(int col = 0; col < buf[0].length; col ++) {
101
                                bb.setElem(row, col, buf[row][col]);
102
                        }
103
                }                
104
                return bb;
105
        }
106
}