gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / src / main / java / org / gvsig / raster / cache / buffer / impl / stripecache / vertical / ByteBand.java @ 992
History | View | Annotate | Download (4.23 KB)
1 |
package org.gvsig.raster.cache.buffer.impl.stripecache.vertical; |
---|---|
2 |
|
3 |
import org.gvsig.raster.cache.buffer.NoData; |
4 |
import org.gvsig.raster.cache.buffer.exception.InvalidPageNumberException; |
5 |
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException; |
6 |
import org.gvsig.raster.cache.buffer.impl.RasterBuffer; |
7 |
import org.gvsig.raster.cache.buffer.impl.stripecache.Cache; |
8 |
import org.gvsig.raster.cache.buffer.impl.stripecache.CacheBand; |
9 |
import org.gvsig.raster.cache.buffer.impl.stripecache.LRUAlgorithm; |
10 |
|
11 |
|
12 |
/**
|
13 |
* This class represent a byte band loaded in cache.
|
14 |
*
|
15 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
16 |
*/
|
17 |
public class ByteBand extends CacheBand { |
18 |
|
19 |
/**
|
20 |
* Create a empty band asociated to existing cache
|
21 |
* @param cache
|
22 |
* @param lru
|
23 |
* @param band
|
24 |
*/
|
25 |
public ByteBand(Cache cache, LRUAlgorithm lru, int band) { |
26 |
super(cache, lru, band);
|
27 |
this.setDataType(RasterBuffer.TYPE_BYTE);
|
28 |
} |
29 |
|
30 |
/*
|
31 |
* (non-Javadoc)
|
32 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.CacheBand#getNumberOfBlocks()
|
33 |
*/
|
34 |
@Override
|
35 |
public int getNumberOfBlocks() { |
36 |
return (int)Math.ceil((double)getWidth() / (double)getBlockSize()); |
37 |
} |
38 |
|
39 |
/*
|
40 |
* (non-Javadoc)
|
41 |
* @see org.gvsig.raster.cache.buffer.Band#isHorizontalBlock()
|
42 |
*/
|
43 |
public boolean isHorizontalBlock() { |
44 |
return false; |
45 |
} |
46 |
|
47 |
/*
|
48 |
* (non-Javadoc)
|
49 |
* @see org.gvsig.raster.buffer.RasterBand#assign(byte)
|
50 |
*/
|
51 |
public void assign(byte value) { |
52 |
for(int col = 0; col < getWidth(); col ++) { |
53 |
boolean beginCol = true; //Para acelerar solo comprobar? si la p?gina est? en cach? cada vez que empieza una columna |
54 |
for(int line = 0; line < getHeight(); line ++) { |
55 |
try {
|
56 |
if(beginCol) {
|
57 |
lru.cacheAccess(col, false);
|
58 |
beginCol = false;
|
59 |
} |
60 |
} catch (InvalidPageNumberException e) {
|
61 |
return;
|
62 |
} catch (InterruptedException e) { |
63 |
return;
|
64 |
} |
65 |
cache.getAccessPage().setElem(line, (col& cache.getOffset()), nBand, value); |
66 |
} |
67 |
} |
68 |
} |
69 |
|
70 |
/*
|
71 |
* (non-Javadoc)
|
72 |
* @see org.gvsig.raster.buffer.RasterBand#getByteBlock(int)
|
73 |
*/
|
74 |
public byte[][] getByteBlock(int block) { |
75 |
int col = block * getBlockSize();
|
76 |
try {
|
77 |
lru.cacheAccess(col, true);
|
78 |
} catch (InvalidPageNumberException e) {
|
79 |
return null; |
80 |
} catch (InterruptedException e) { |
81 |
return null; |
82 |
} |
83 |
return cache.getAccessPage().getBand(nBand).getByteBlock(block);
|
84 |
} |
85 |
|
86 |
/*
|
87 |
* (non-Javadoc)
|
88 |
* @see org.gvsig.raster.buffer.IRasterBand#setByteBlock(byte[][], int)
|
89 |
*/
|
90 |
public void setByteBlock(byte[][] data, int block) { |
91 |
int col = block * getBlockSize();
|
92 |
try {
|
93 |
lru.cacheAccess(col, true);
|
94 |
} catch (InvalidPageNumberException e) {
|
95 |
return;
|
96 |
} catch (InterruptedException e) { |
97 |
return;
|
98 |
} |
99 |
try {
|
100 |
cache.getAccessPage().getBand(nBand).setByteBlock(data, block); |
101 |
} catch (OperationNotSupportedException e) { |
102 |
//Solo buffers de solo lectura
|
103 |
} |
104 |
} |
105 |
|
106 |
/*
|
107 |
* (non-Javadoc)
|
108 |
* @see org.gvsig.raster.buffer.RasterBand#getByteLine(int)
|
109 |
*/
|
110 |
public byte[] getByteLine(int line) throws OperationNotSupportedException { |
111 |
throw new OperationNotSupportedException("Operation getByteLine not supported for a vertical band of cache"); |
112 |
} |
113 |
|
114 |
/*
|
115 |
* (non-Javadoc)
|
116 |
* @see org.gvsig.raster.buffer.RasterBand#getElemByte(int, int)
|
117 |
*/
|
118 |
public byte getElemByte(int line, int col) { |
119 |
if(exists(col)) {
|
120 |
return cache.getAccessPage().getElemByte(line, (col & cache.getOffset()), nBand);
|
121 |
} |
122 |
return getNoDataValue().isDefined() ? getNoDataValue().getValue().byteValue() : NoData.defaultByteNoDataValue;
|
123 |
} |
124 |
|
125 |
/*
|
126 |
* (non-Javadoc)
|
127 |
* @see org.gvsig.raster.buffer.RasterBand#setByteLine(byte[], int)
|
128 |
*/
|
129 |
public void setByteLine(byte[] data, int line) throws OperationNotSupportedException { |
130 |
throw new OperationNotSupportedException("Operation getByteLine not supported for a vertical band of cache"); |
131 |
} |
132 |
|
133 |
/*
|
134 |
* (non-Javadoc)
|
135 |
* @see org.gvsig.raster.buffer.RasterBand#setElem(int, int, byte)
|
136 |
*/
|
137 |
public void setElem(int line, int col, byte data) { |
138 |
if(exists(col)) {
|
139 |
cache.getAccessPage().setElem(line, (col & cache.getOffset()), nBand, data); |
140 |
} |
141 |
} |
142 |
|
143 |
/*
|
144 |
* (non-Javadoc)
|
145 |
* @see java.lang.Object#clone()
|
146 |
*/
|
147 |
public Object clone() { |
148 |
Cache cloneCache = (Cache)cache.clone(); |
149 |
LRUAlgorithm cloneLRU = new LRUAlgorithm(cloneCache);
|
150 |
return new ByteBand(cloneCache, cloneLRU, nBand); |
151 |
} |
152 |
} |