Revision 6288

View differences:

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
23 23
package org.gvsig.fmap.dal.file.jimi;
24 24

  
25 25
import java.awt.image.ColorModel;
26
import java.awt.image.ImageConsumer;
27
import java.util.Hashtable;
26
import java.awt.image.ComponentColorModel;
27
import java.awt.image.IndexColorModel;
28
import java.nio.ByteBuffer;
28 29

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

  
31 33
import com.sun.jimi.core.ImageAccessException;
......
51 53
        this.jimiRasterImage=jimiRasterImage;
52 54
        rows=jimiRasterImage.getHeight();
53 55
        columns=jimiRasterImage.getWidth();
54
        bands=3;
55
        if ( jimiRasterImage.getColorModel().hasAlpha() ){
56
            bands=4;
57
        }
58
        buffer = new byte[bands][columns*rows];
59 56

  
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;
57
        ColorModel colorModel = jimiRasterImage.getColorModel();
58

  
59
        if (colorModel instanceof ComponentColorModel){
60
            if( jimiRasterImage instanceof IntRasterImage ) {
61
                dataType = BufferManager.TYPE_INT;
62
            } else if( jimiRasterImage instanceof ByteRasterImage ) {
63
                dataType = BufferManager.TYPE_BYTE;
64
            } else {
65
                dataType = BufferManager.TYPE_INT;
76 66
            }
67

  
68
            bands=3;
69
            if ( jimiRasterImage.getColorModel().hasAlpha() ){
70
                bands=4;
71
            }
72
            buffer = new byte[bands][columns*rows];
73

  
74
            for( int band=0; band<bands; band++) {
75
                switch (band) {
76
                case 0:
77
                    jimiRasterImage.getChannelRectangle(JimiRasterImage.CHANNEL_RED, 0, 0, columns, rows, buffer[band], 0, columns);
78
                    break;
79
                case 1:
80
                    jimiRasterImage.getChannelRectangle(JimiRasterImage.CHANNEL_GREEN, 0, 0, columns, rows, buffer[band], 0, columns);
81
                    break;
82
                case 2:
83
                    jimiRasterImage.getChannelRectangle(JimiRasterImage.CHANNEL_BLUE, 0, 0, columns, rows, buffer[band], 0, columns);
84
                    break;
85
                case 3:
86
                    jimiRasterImage.getChannelRectangle(JimiRasterImage.CHANNEL_ALPHA, 0, 0, columns, rows, buffer[band], 0, columns);
87
                    break;
88
                default:
89
                    break;
90
                }
91
            }
92
        }else if (colorModel instanceof IndexColorModel){
93
            bands=1;
94
            IndexColorModel indexColorModel = (IndexColorModel)colorModel;
95
            BufferManager bufferManager = BufferLocator.getBufferManager();
96
            int dataTypeSize = bufferManager.getDataTypeSize(dataType);
97
            buffer = new byte[bands][columns*rows* dataTypeSize];
98

  
99
            if( jimiRasterImage instanceof ByteRasterImage ) {
100
                dataType = BufferManager.TYPE_BYTE;
101
                ByteRasterImage byteRasterImage = ( ByteRasterImage )jimiRasterImage;
102
                byteRasterImage.getRectangle(0, 0, columns, rows, buffer[0], 0, columns);
103
            } else {
104
                dataType = BufferManager.TYPE_INT;
105
                IntRasterImage intRasterImage = ( IntRasterImage )jimiRasterImage;
106
                int[] intAuxArray=new int[columns*rows];
107
                intRasterImage.getRectangle(0, 0, columns, rows, intAuxArray, 0, columns);
108

  
109
                ByteBuffer byteBuffer=ByteBuffer.wrap(buffer[0]);
110
                for(int i=0;i<=intAuxArray.length;i=i){
111
                    byteBuffer.putInt(intAuxArray[i]);
112
                }
113
            }
114

  
77 115
        }
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
        }
116

  
117

  
118

  
119

  
85 120
    }
86 121

  
87 122
    public byte getValue(int row, int column, int band) {
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.app/org.gvsig.raster.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
40 40
        <include>org.gvsig:org.gvsig.fmap.mapcontext.raster.api</include>
41 41
        <include>org.gvsig:org.gvsig.fmap.mapcontext.raster.impl</include>
42 42
        <include>org.gvsig:org.gvsig.fmap.dal.file.jimi</include>
43
        <include>org.gvsig:org.gvsig.fmap.dal.file.jimi.legend</include>
43 44
      </includes>
44 45
    </dependencySet>
45 46
  </dependencySets>
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.app/org.gvsig.raster.app.mainplugin/pom.xml
72 72
  </dependency>
73 73
  <dependency>
74 74
   <groupId>org.gvsig</groupId>
75
   <artifactId>org.gvsig.fmap.dal.file.jimi.legend</artifactId>
76
  </dependency>
77
  <dependency>
78
   <groupId>org.gvsig</groupId>
75 79
   <artifactId>org.gvsig.andami</artifactId>
76 80
  </dependency>
77 81
  <dependency>
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.fmap.mapcontext.raster/org.gvsig.fmap.mapcontext.raster.impl/src/main/java/org/gvsig/fmap/mapcontext/raster/impl/DefaultRasterLayer.java
63 63
import org.gvsig.raster.lib.legend.api.RasterLegendLocator;
64 64
import org.gvsig.raster.lib.legend.api.RasterLegendManager;
65 65
import org.gvsig.tools.ToolsLocator;
66
import org.gvsig.tools.dynobject.exception.DynMethodException;
67
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException;
66 68
import org.gvsig.tools.exception.BaseException;
67 69
import org.gvsig.tools.task.Cancellable;
68 70
import org.gvsig.tools.task.SimpleTaskStatus;
......
94 96
     */
95 97
    public DefaultRasterLayer() throws LoadLayerException{
96 98
        super();
97
//        MapContextManager mapContextManager
98
//        = MapContextLocator.getMapContextManager();
99
        //Set the legend
100
//        IRasterLegend legend
101
//                = (IRasterLegend) mapContextManager.getLegend(store);
102

  
103 99
    }
104 100

  
105 101
    /**
......
158 154
            throw new LoadLayerException("Store already created");
159 155
        }else{
160 156
            this.store=(RasterStore)dataStore;
161
            if(legend==null){
162
                RasterLegendManager legendManager =
163
                    RasterLegendLocator.getRasterLegendManager();
164
                int bandCount;
165
                try {
166
                    bandCount = store.getRasterSet().getBandCount();
167
                } catch (DataException e) {
168
                    throw new LegendLayerException(this.getName());
169
                }
157
            initLegend();
158
        }
159
    }
170 160

  
171
                String colors;
172
                switch (bandCount) {
173
                case 1:
174
                    colors = ColorInterpretation.GRAYSCALE;
175
                    break;
176
                case 3:
177
                    colors = ColorInterpretation.RGB;
178
                    break;
179
                case 4:
180
                    colors = ColorInterpretation.ARGB;
181
                    break;
182
                default:
183
                    colors = ColorInterpretation.RGB;
184
                    break;
185
                }
186
                if (bandCount == 3) {
161
    /**
162
     * Initializes the legend if it is not initalized yet
163
     * @throws LegendLayerException
164
     */
165
    private void initLegend() throws LegendLayerException{
166
        RasterLegend legend=null;
167
        if(legend==null){
168
            //Should be done like this but must be corrected mapContextManager
169
//          MapContextManager mapContextManager
170
//          = MapContextLocator.getMapContextManager();
171
          //Set the legend
172
//          IRasterLegend legend
173
//                  = (IRasterLegend) mapContextManager.getLegend(store);
187 174

  
188
                }
189
                ColorInterpretation colorInterpretation =
190
                    legendManager.createColorInterpretation(colors);
191
                RasterLegend legend =
192
                    legendManager.createLegend(colorInterpretation);
175
            //Should be moved to mapContextManager
176
            try {
177
                legend = (RasterLegend) store.invokeDynMethod("getLegend", null);
178
            } catch (DynMethodNotSupportedException e) {
179
                logger.debug("This store {} does not provide a legend.",
180
                    store.getName());
181
            } catch (DynMethodException e) {
182
                logger.error(
183
                        "Can't load the specific legend provided for the store {}.",
184
                        store.getName(), e);
185
            }
193 186

  
194
                if (legend == null) {
195
                    throw new LegendLayerException(this.getName());
196
                }
197 187

  
198
                this.setLegend(legend);
188
            if (legend == null) {
189
                throw new LegendLayerException(this.getName());
199 190
            }
191

  
192
            this.setLegend(legend);
200 193
        }
201 194
    }
202 195

  
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.fmap.dal.file.jimi.legend/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.fmap.dal.file.jimi.legend.JimiLegendLibrary
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.fmap.dal.file.jimi.legend/src/main/java/org/gvsig/fmap/dal/file/jimi/legend/JimiLegendLibrary.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 IVER T.I. S.A.   {{Task}}
26
*/
27

  
28
/**
29
 *
30
 */
31
package org.gvsig.fmap.dal.file.jimi.legend;
32

  
33
import org.gvsig.fmap.dal.DALLibrary;
34
import org.gvsig.fmap.dal.file.jimi.JimiLibrary;
35
import org.gvsig.fmap.dal.file.jimi.JimiRasterStoreProvider;
36
import org.gvsig.metadata.MetadataLibrary;
37
import org.gvsig.metadata.MetadataLocator;
38
import org.gvsig.tools.dynobject.DynClass;
39
import org.gvsig.tools.library.AbstractLibrary;
40
import org.gvsig.tools.library.LibraryException;
41

  
42
/**
43
 * @author dmartinez
44
 *
45
 */
46
public class JimiLegendLibrary extends AbstractLibrary {
47

  
48
    @Override
49
    public void doRegistration() {
50
        registerAsServiceOf(DALLibrary.class);
51
        require(JimiLibrary.class);
52
        require(MetadataLibrary.class);
53
        require(DALLibrary.class);
54
    }
55

  
56
	@Override
57
	protected void doInitialize() throws LibraryException {
58
	}
59

  
60
	@Override
61
	protected void doPostInitialize() throws LibraryException {
62
		DynClass metadataDefinition = (DynClass) MetadataLocator.getMetadataManager()
63
			.getDefinition(JimiRasterStoreProvider.METADATA_DEFINITION_NAME);
64
		JimiGetLegend.register(metadataDefinition);
65
//		JimiGetTableColor.register(metadataDefinition);
66
//		JimiGetColorInterpretation.register(metadataDefinition);
67
	}
68
}
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.fmap.dal.file.jimi.legend/src/main/java/org/gvsig/fmap/dal/file/jimi/legend/JimiGetColorInterpretation.java
1
package org.gvsig.fmap.dal.file.jimi.legend;
2

  
3

  
4
public class JimiGetColorInterpretation {
5

  
6
}
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.fmap.dal.file.jimi.legend/src/main/java/org/gvsig/fmap/dal/file/jimi/legend/JimiGetTableColor.java
1
package org.gvsig.fmap.dal.file.jimi.legend;
2

  
3

  
4
public class JimiGetTableColor {
5

  
6
}
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.fmap.dal.file.jimi.legend/src/main/java/org/gvsig/fmap/dal/file/jimi/legend/JimiGetLegend.java
1
package org.gvsig.fmap.dal.file.jimi.legend;
2

  
3
import org.gvsig.fmap.dal.exception.OpenException;
4
import org.gvsig.fmap.dal.file.jimi.JimiRasterStoreProvider;
5
import org.gvsig.fmap.dal.raster.spi.RasterStoreProvider;
6
import org.gvsig.raster.lib.legend.api.ColorInterpretation;
7
import org.gvsig.raster.lib.legend.api.RasterLegend;
8
import org.gvsig.raster.lib.legend.api.RasterLegendLocator;
9
import org.gvsig.raster.lib.legend.api.RasterLegendManager;
10
import org.gvsig.tools.ToolsLocator;
11
import org.gvsig.tools.dynobject.DynClass;
12
import org.gvsig.tools.dynobject.DynMethod;
13
import org.gvsig.tools.dynobject.DynObject;
14
import org.gvsig.tools.dynobject.exception.DynMethodException;
15
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException;
16

  
17
public class JimiGetLegend implements DynMethod {
18

  
19
    private static Integer code = null;
20
    final public static String DYNMETHOD_GETLEGEND_NAME = "getLegend";
21

  
22
    static void register(DynClass storeClass) {
23
        if (code != null) {
24
            return;
25
        }
26
        code = ToolsLocator.getDynObjectManager()
27
                .registerDynMethod(storeClass, new JimiGetLegend());
28

  
29
    }
30

  
31
    @Override
32
    public int getCode() throws DynMethodNotSupportedException {
33
        return code;
34
    }
35

  
36
    @Override
37
    public String getDescription() {
38
        return "Jimi Legend";
39
    }
40

  
41
    @Override
42
    public String getName() {
43
        return DYNMETHOD_GETLEGEND_NAME;
44
    }
45

  
46
    @Override
47
    public Object invoke(DynObject self, Object[] args)
48
            throws DynMethodException {
49
//        try {
50
             JimiRasterStoreProvider jimiProvider=(JimiRasterStoreProvider)self;
51

  
52
             RasterLegendManager legendManager=RasterLegendLocator.getRasterLegendManager();
53
             ColorInterpretation colorInterpretation =
54
                 legendManager.createColorInterpretation(ColorInterpretation.RGB);
55

  
56
             RasterLegend legend= legendManager.createLegend(colorInterpretation);
57

  
58
             return legend;
59

  
60
//        } catch (DynMethodNotSupportedException e) {
61
//            //FIXME
62
//            throw new RuntimeException(e);
63
//        }
64
    }
65

  
66
    @Override
67
    public Object clone() throws CloneNotSupportedException {
68
        return super.clone();
69
    }
70
}
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.fmap.dal.file.jimi.legend/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
  <modelVersion>4.0.0</modelVersion>
3
  <parent>
4
    <groupId>org.gvsig</groupId>
5
    <artifactId>org.gvsig.raster</artifactId>
6
    <version>2.4.1-SNAPSHOT</version>
7
  </parent>
8
  <artifactId>org.gvsig.fmap.dal.file.jimi.legend</artifactId>
9
  <name>org.gvsig.fmap.dal.file.jimi.legend</name>
10
  <description>Legend provider for jimi files</description>
11

  
12
  <dependencies>
13
  <dependency>
14
   <groupId>org.gvsig</groupId>
15
   <artifactId>org.gvsig.fmap.dal.file.jimi</artifactId>
16
  </dependency>
17
    <dependency>
18
   <groupId>org.gvsig</groupId>
19
   <artifactId>org.gvsig.raster.lib.legend.api</artifactId>
20
  </dependency>
21
  </dependencies>
22
</project>
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/pom.xml
18 18
  <url>https://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster/trunk/org.gvsig.raster</url>
19 19
 </scm>
20 20

  
21
  <distributionManagement>
21
 <distributionManagement>
22 22
  <site>
23 23
   <id>gvsig-repository</id>
24 24
   <url>dav:https://devel.gvsig.org/sites/${project.artifactId}/${project.version}</url>
25 25
  </site>
26 26
 </distributionManagement>
27 27

  
28
   <build>
29
    <plugins>
30
      <plugin>
31
        <groupId>org.apache.maven.plugins</groupId>
32
        <artifactId>maven-release-plugin</artifactId>
33
        <configuration>
34
          <tagBase>https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster/tags</tagBase>
35
        </configuration>
36
      </plugin>
37
    </plugins>
38
  </build>
28
 <build>
29
  <plugins>
30
   <plugin>
31
    <groupId>org.apache.maven.plugins</groupId>
32
    <artifactId>maven-release-plugin</artifactId>
33
    <configuration>
34
     <tagBase>https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster/tags</tagBase>
35
    </configuration>
36
   </plugin>
37
  </plugins>
38
 </build>
39 39

  
40 40
 <repositories>
41 41
  <repository>
......
59 59
 <modules>
60 60
  <module>org.gvsig.raster.lib</module>
61 61
  <module>org.gvsig.fmap.dal.raster</module>
62
  <module>org.gvsig.fmap.dal.file.jimi</module>
63 62
  <module>org.gvsig.fmap.mapcontext.raster</module>
64 63
  <module>org.gvsig.raster.app</module>
64
  <module>org.gvsig.fmap.dal.file.jimi</module>
65
  <module>org.gvsig.fmap.dal.file.jimi.legend</module>
65 66
 </modules>
66 67
 <dependencyManagement>
67 68
  <dependencies>
......
125 126
    <artifactId>org.gvsig.fmap.dal.file.jimi</artifactId>
126 127
    <version>2.4.1-SNAPSHOT</version>
127 128
   </dependency>
129
   <dependency>
130
    <groupId>org.gvsig</groupId>
131
    <artifactId>org.gvsig.fmap.dal.file.jimi.legend</artifactId>
132
    <version>2.4.1-SNAPSHOT</version>
133
   </dependency>
128 134
  </dependencies>
129 135
 </dependencyManagement>
130 136
</project>

Also available in: Unified diff