Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster / org.gvsig.fmap.dal.file.jimi / src / main / java / org / gvsig / fmap / dal / file / jimi / MemoryImage.java @ 6069

History | View | Annotate | Download (3.19 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2016 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.dal.file.jimi;
24

    
25
import java.awt.image.ColorModel;
26
import java.awt.image.ImageConsumer;
27
import java.util.Hashtable;
28

    
29
import org.gvsig.raster.lib.buffer.api.BufferManager;
30

    
31
import com.sun.jimi.core.ImageAccessException;
32
import com.sun.jimi.core.raster.ByteRasterImage;
33
import com.sun.jimi.core.raster.IntRasterImage;
34
import com.sun.jimi.core.raster.JimiRasterImage;
35

    
36
/**
37
 * Represents an image loaded in memory
38
 * @author dmartinezizquierdo
39
 *
40
 */
41
class MemoryImage{
42
    public int rows;
43
    public int columns;
44
    public int bands;
45
    public byte buffer[][];
46
    public int dataType;
47
    private JimiRasterImage jimiRasterImage;
48
    public boolean loaded;
49

    
50
    public MemoryImage(JimiRasterImage jimiRasterImage) throws ImageAccessException {
51
        this.jimiRasterImage=jimiRasterImage;
52
        rows=jimiRasterImage.getHeight();
53
        columns=jimiRasterImage.getWidth();
54
        bands=3;
55
        if ( jimiRasterImage.getColorModel().hasAlpha() ){
56
            bands=4;
57
        }
58
        buffer = new byte[bands][columns*rows];
59

    
60
        for( int band=0; band<bands; band++) {
61
            switch (band) {
62
            case 0:
63
                jimiRasterImage.getChannelRectangle(JimiRasterImage.CHANNEL_RED, 0, 0, columns, rows, buffer[band], 0, columns);
64
                break;
65
            case 1:
66
                jimiRasterImage.getChannelRectangle(JimiRasterImage.CHANNEL_GREEN, 0, 0, columns, rows, buffer[band], 0, columns);
67
                break;
68
            case 2:
69
                jimiRasterImage.getChannelRectangle(JimiRasterImage.CHANNEL_BLUE, 0, 0, columns, rows, buffer[band], 0, columns);
70
                break;
71
            case 3:
72
                jimiRasterImage.getChannelRectangle(JimiRasterImage.CHANNEL_ALPHA, 0, 0, columns, rows, buffer[band], 0, columns);
73
                break;
74
            default:
75
                break;
76
            }
77
        }
78
        if( jimiRasterImage instanceof IntRasterImage ) {
79
            dataType = BufferManager.TYPE_INT;
80
        } else if( jimiRasterImage instanceof ByteRasterImage ) {
81
            dataType = BufferManager.TYPE_BYTE;
82
        } else {
83
            dataType = BufferManager.TYPE_INT;
84
        }
85
    }
86

    
87
    public byte getValue(int row, int column, int band) {
88
        return buffer[band][row*columns + column];
89
    }
90

    
91
}
92