Revision 20200

View differences:

trunk/libraries/libjni-ecw/libjni-ecw/CMakeModules/ModuleInstall.cmake
1
# INSTALL and SOURCE_GROUP commands for OSG/OT/Producer Modules
2

  
3
# Required Vars:
4
# ${LIB_NAME}
5
# ${LIB_PUBLIC_HEADERS}
6

  
7
SET(INSTALL_INCDIR include)
8
SET(INSTALL_BINDIR bin)
9
IF(WIN32)
10
	SET(INSTALL_BINDIR .)
11
    SET(INSTALL_LIBDIR .)
12
    SET(INSTALL_ARCHIVEDIR lib)
13
ELSE(WIN32)
14
	SET(INSTALL_BINDIR .)
15
    SET(INSTALL_LIBDIR .)
16
    SET(INSTALL_ARCHIVEDIR lib)
17
ENDIF(WIN32)
18

  
19
SET(HEADERS_GROUP "Header Files")
20

  
21
SOURCE_GROUP(
22
    ${HEADERS_GROUP}
23
    FILES ${LIB_PUBLIC_HEADERS}
24
)
25

  
26

  
27
INSTALL(
28
    TARGETS ${LIB_NAME}
29
    RUNTIME DESTINATION ${INSTALL_BINDIR}
30
    LIBRARY DESTINATION ${INSTALL_LIBDIR}
31
    ARCHIVE DESTINATION ${INSTALL_ARCHIVEDIR}
32
)
33

  
34

  
35

  
36
# FIXME: Do not run for OS X framework
37
#INSTALL(
38
#    FILES        ${LIB_PUBLIC_HEADERS}
39
#    DESTINATION ${INSTALL_INCDIR}/${LIB_NAME}
40
#)
trunk/libraries/libjni-ecw/libjni-ecw/CMakeModules/FindECW.cmake
1
# Locate ecw
2
# This module defines
3
# ECW_LIBRARY
4
# ECW_FOUND, if false, do not try to link to gdal 
5
# ECW_INCLUDE_DIR, where to find the headers
6
#
7
# $ECW_DIR is an environment variable that would
8
# correspond to the ./configure --prefix=$ECW_DIR
9
#
10
# Created by Robert Osfield. 
11

  
12
FIND_PATH(ECW_INCLUDE_DIR 
13
	NAMES ECW.h NCSError.h NCSErrors.h
14
	PATHS
15
    ${ECW_DIR}/include
16
    $ENV{ECW_DIR}/include
17
    $ENV{ECW_DIR}
18
    ~/Library/Frameworks
19
    /Library/Frameworks
20
    /usr/local/include
21
    /usr/include
22
    /usr/include/ecw
23
    /sw/include # Fink
24
    /opt/local/include # DarwinPorts
25
    /opt/csw/include # Blastwave
26
    /opt/include
27
    [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/include
28
    /usr/freeware/include
29
    #"C:/libecwj2-3.3/Source/include"
30
    "C:/Archivos de programa/Earth Resource Mapping/ECW SDK/include"
31
    "C:/Earth Resource Mapping/ECW SDK/include"
32
    "C:/ECW SDK/include"
33
    "C:/ecw/include"
34
)
35

  
36
FIND_LIBRARY(ECW_LIBRARY 
37
    NAMES NCSEcw
38
    PATHS
39
    ${ECW_DIR}/lib
40
    $ENV{ECW_DIR}/lib
41
    $ENV{ECW_DIR}
42
    ~/Library/Frameworks
43
    /Library/Frameworks
44
    /usr/local/lib
45
    /usr/lib
46
    /sw/lib
47
    /opt/local/lib
48
    /opt/csw/lib
49
    /opt/lib
50
    [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/lib
51
    /usr/freeware/lib64
52
    "C:/Archivos de programa/Earth Resource Mapping/ECW SDK/lib"
53
    "C:/Earth Resource Mapping/ECW SDK/lib"
54
    "C:/ECW SDK/lib/vc71"
55
    "C:/ECW SDK/lib"
56
    "C:/ecw/lib"
57
)
58

  
59
FIND_LIBRARY(ECW_LIBRARY2 
60
    NAMES NCSEcwC
61
    PATHS
62
    ${ECW_DIR}/lib
63
    $ENV{ECW_DIR}/lib
64
    $ENV{ECW_DIR}
65
    ~/Library/Frameworks
66
    /Library/Frameworks
67
    /usr/local/lib
68
    /usr/lib
69
    /sw/lib
70
    /opt/local/lib
71
    /opt/csw/lib
72
    /opt/lib
73
    [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/lib
74
    /usr/freeware/lib64
75
    "C:/Archivos de programa/Earth Resource Mapping/ECW SDK/lib"
76
    "C:/Earth Resource Mapping/ECW SDK/lib"
77
    "C:/ECW SDK/lib/vc71"
78
    "C:/ECW SDK/lib"
79
    "C:/ecw/lib"
80
)
81

  
82
FIND_LIBRARY(ECW_LIBRARY3 
83
    NAMES NCSUtil
84
    PATHS
85
    ${ECW_DIR}/lib
86
    $ENV{ECW_DIR}/lib
87
    $ENV{ECW_DIR}
88
    ~/Library/Frameworks
89
    /Library/Frameworks
90
    /usr/local/lib
91
    /usr/lib
92
    /sw/lib
93
    /opt/local/lib
94
    /opt/csw/lib
95
    /opt/lib
96
    [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/lib
97
    /usr/freeware/lib64
98
    "C:/Archivos de programa/Earth Resource Mapping/ECW SDK/lib"
99
    "C:/Earth Resource Mapping/ECW SDK/lib"
100
    "C:/ECW SDK/lib/vc71"
101
    "C:/ECW SDK/lib"
102
    "C:/ecw/lib"
103
)
104

  
105
FIND_LIBRARY(ECW_LIBRARY4 
106
    NAMES NCSCnet NCScnetS
107
    PATHS
108
    ${ECW_DIR}/lib
109
    $ENV{ECW_DIR}/lib
110
    $ENV{ECW_DIR}
111
    ~/Library/Frameworks
112
    /Library/Frameworks
113
    /usr/local/lib
114
    /usr/lib
115
    /sw/lib
116
    /opt/local/lib
117
    /opt/csw/lib
118
    /opt/lib
119
    [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/lib
120
    /usr/freeware/lib64
121
)
122

  
123
SET(ECW_FOUND "NO")
124
IF(ECW_LIBRARY AND ECW_INCLUDE_DIR)
125
    SET(ECW_FOUND "YES")
126
ENDIF(ECW_LIBRARY AND ECW_INCLUDE_DIR)
127

  
trunk/libraries/libjni-ecw/libjni-ecw/CMakeLists.txt
1
project(jecw)
2

  
3
# Looking for arch extension!
4
SET(LIB_POSTFIX "32")
5
IF(UNIX)
6
	IF(NOT APPLE)
7
		IF(CMAKE_SIZEOF_VOID_P MATCHES "8")
8
      		SET(LIB_POSTFIX "64")
9
  		ENDIF(CMAKE_SIZEOF_VOID_P MATCHES "8")
10
	ENDIF(NOT APPLE)
11
ELSE(UNIX)
12
	IF(CMAKE_SYSTEM_NAME MATCHES Windows)
13
		IF(CMAKE_CL_64)
14
      		SET(LIB_POSTFIX "64")
15
		ENDIF(CMAKE_CL_64)	
16
	ENDIF(CMAKE_SYSTEM_NAME MATCHES Windows)
17
ENDIF(UNIX)
18

  
19
SET(platform_dir)
20
IF(WIN32)
21
	IF(NOT CYGWIN)
22
		SET(platform_dir "w${LIB_POSTFIX}")
23
	ENDIF(NOT CYGWIN)
24
ENDIF(WIN32)
25
IF(UNIX)
26
	IF(APPLE)
27
		SET(platform_dir "mac")
28
	ELSE(APPLE)
29
		SET(platform_dir "linux")
30
	ENDIF(APPLE)
31
ENDIF(UNIX)
32

  
33
IF(UNIX)
34
	SET(CMAKE_CXX_FLAGS_RELEASE "-O -DNDEBUG")
35
	SET(CMAKE_C_FLAGS_RELEASE "-O -DNDEBUG")
36
ENDIF(UNIX)
37

  
38
SET(GVSIG_BINARIES_PATH "${CMAKE_SOURCE_DIR}/../binaries/${platform_dir}/raster/ecw")
39

  
40
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")
41
FILE(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/lib-dist)
42
#FILE(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/bin-dist)
43

  
44
set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/lib-dist)
45
#set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin-dist)
46
#set(CMAKE_SKIP_RPATH TRUE)
47
IF(APPLE)
48
	SET(CMAKE_INSTALL_NAME_DIR @executable_path/../Resources/NativeLibs CACHE STRING "Executable Path for MacOS X" FORCE)
49
  	MARK_AS_ADVANCED(CMAKE_INSTALL_NAME_DIR)
50
ENDIF(APPLE)
51

  
52

  
53
SET(CMAKE_INSTALL_PREFIX ${GVSIG_BINARIES_PATH} CACHE STRING "Forcing install path" FORCE)
54
MARK_AS_ADVANCED(CMAKE_INSTALL_PREFIX)
55

  
56
# This is for an advanced option to give aggressive warnings
57
# under different compilers. If yours is not implemented, this option
58
# will not be made available.
59
IF(CMAKE_COMPILER_IS_GNUCXX)
60
    # To be complete, we might also do GNUCC flags,
61
    # but everything here is C++ code.
62
    # -Wshadow and -Woverloaded-virtual are also interesting flags, but OSG
63
    # returns too many hits.
64
    # FYI, if we do implement GNUCC, then -Wmissing-prototypes in another
65
    # interesting C-specific flag.
66
    # Also, there is a bug in gcc 4.0. Under C++, -pedantic will create
67
    # errors instead of warnings for certain issues, including superfluous
68
    # semicolons and commas, and the use of long long. -fpermissive seems
69
    # to be the workaround.
70
    SET(AGGRESSIVE_WARNING_FLAGS "-Wall -Wparentheses -Wformat=2 -Wno-long-long -Wno-import -pedantic -Wreturn-type -Wmissing-braces -Wunknown-pragmas -Wunused -fpermissive")
71
ELSE(CMAKE_COMPILER_IS_GNUCXX)
72
    IF(MSVC)
73
        # FIXME: What are good aggressive warning flags for Visual Studio?
74
        # And do we need to further subcase this for different versions of VS?
75
        # CMake variables: MSVC60, MSVC70, MSVC71, MSVC80, CMAKE_COMPILER_2005
76
        SET(AGGRESSIVE_WARNING_FLAGS "/Wall /W4")
77

  
78

  
79
    ELSE(MSVC)
80
        # CMake lacks an elseif, so other non-gcc, non-VS compilers need
81
        # to be listed below. If unhandled, OSG_AGGRESSIVE_WARNING_FLAGS should
82
        # remain unset.
83
    ENDIF(MSVC)
84
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
85

  
86
# This part is for the CMake menu option to toggle the warnings on/off.
87
# This will only be made available if we set values for OSG_AGGRESSIVE_WARNING_FLAGS.
88
IF(AGGRESSIVE_WARNING_FLAGS)
89
    OPTION(USE_AGGRESSIVE_WARNINGS "Enable to activate aggressive warnings" OFF)
90
    MARK_AS_ADVANCED(USE_AGGRESSIVE_WARNINGS)
91

  
92
    IF(USE_AGGRESSIVE_WARNINGS)
93
        IF(NOT "${OLD_CMAKE_CXX_FLAGS_WAS_SET}")
94
            SET(OLD_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE INTERNAL "Old CXX flags")
95
            SET(OLD_CMAKE_CXX_FLAGS_WAS_SET 1 CACHE INTERNAL "Old CXX flags was set")
96
            SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${AGGRESSIVE_WARNING_FLAGS}" CACHE STRING "Flags used by the compiler during all build types." FORCE)
97
        ENDIF(NOT "${OLD_CMAKE_CXX_FLAGS_WAS_SET}")
98
    ELSE(USE_AGGRESSIVE_WARNINGS)
99
        # FIXME: This will lose any changes made after OLD_CMAKE_CXX_FLAGS was
100
        # set. The better way would be to parse the string and remove each
101
        # option explicitly.
102
        IF("${OLD_CMAKE_CXX_FLAGS_WAS_SET}")
103
            SET(CMAKE_CXX_FLAGS "${OLD_CMAKE_CXX_FLAGS}" CACHE STRING "Flags used by the compiler during all build types." FORCE)
104
            SET(OLD_CMAKE_CXX_FLAGS_WAS_SET 0 CACHE INTERNAL "Old CXX flags was set")
105
        ENDIF("${OLD_CMAKE_CXX_FLAGS_WAS_SET}")
106
    ENDIF(USE_AGGRESSIVE_WARNINGS)
107
ENDIF(AGGRESSIVE_WARNING_FLAGS)
108

  
109
# Set defaults for Universal Binaries. We want 32-bit Intel/PPC on 10.4
110
# and 32/64-bit Intel/PPC on >= 10.5. Anything <= 10.3 doesn't support.
111
IF(APPLE)
112
    # These are just defaults/recommendations, but how we want to build
113
    # out of the box. But the user needs to be able to change these options.
114
    # So we must only set the values the first time CMake is run, or we
115
    # will overwrite any changes the user sets.
116
    # FORCE is used because the options are not reflected in the UI otherwise.
117
    # Seems like a good place to add version specific compiler flags too.
118
    IF(NOT CONFIG_HAS_BEEN_RUN_BEFORE)
119
        # This is really fragile, but CMake doesn't provide the OS system
120
        # version information we need. (Darwin versions can be changed
121
        # independently of OS X versions.)
122
        # It does look like CMake handles the CMAKE_OSX_SYSROOT automatically.
123
        IF(EXISTS /Developer/SDKs/10.5.sdk)
124
            SET(CMAKE_OSX_ARCHITECTURES "ppc;i386;ppc64;x86_64" CACHE STRING "Build architectures for OSX" FORCE)
125
            SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.5 -ftree-vectorize -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE)
126
        ELSE(EXISTS /Developer/SDKs/10.5.sdk)
127
            IF(EXISTS /Developer/SDKs/MacOSX10.4u.sdk)
128
                SET(CMAKE_OSX_ARCHITECTURES "ppc;i386" CACHE STRING "Build architectures for OSX" FORCE)
129
                SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.4 -ftree-vectorize -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE)
130
            ELSE(EXISTS /Developer/SDKs/MacOSX10.4u.sdk)
131
                # No Universal Binary support
132
                # Should break down further to set the -mmacosx-version-min,
133
                # but the SDK detection is too unreliable here.
134
            ENDIF(EXISTS /Developer/SDKs/MacOSX10.4u.sdk)
135
        ENDIF(EXISTS /Developer/SDKs/10.5.sdk)
136
    ENDIF(NOT CONFIG_HAS_BEEN_RUN_BEFORE)
137
ENDIF(APPLE)
138

  
139

  
140
SET(JECW_VERSION "0.0.5" CACHE STRING "JECW_VERSION")
141

  
142
find_package(JNI) 
143
find_package(ECW) 
144

  
145
link_directories(${LIBRARY_OUTPUT_PATH})
146

  
147
add_subdirectory(src/main/native/jecw)
148

  
149
# This needs to be run very last so other parts of the scripts can take
150
# advantage of this.
151
IF(NOT CONFIG_HAS_BEEN_RUN_BEFORE)
152
    SET(CONFIG_HAS_BEEN_RUN_BEFORE 1 CACHE INTERNAL "Flag to track whether this is the first time running CMake or if CMake has been configured before")
153
ENDIF(NOT CONFIG_HAS_BEEN_RUN_BEFORE)
154

  
155

  
trunk/libraries/libjni-ecw/libjni-ecw/build.xml
1
	<project name="libjni-ecw" default="main" basedir=".">
2
	<description>
3
		Compila la librería jecw
4
	</description>
5
		
6
	<property name="src-java" location="src/main/java" />
7
	<property name="src-tet-java" location="src/test/java" />
8
	<property name="jar-dist" location="jar-dist" />
9
	<property name="build" location="bin/" />
10
	<property name="cmake_build" location="BMCMake/" />
11
	<property environment="env"/>
12
	<condition property="jecw_version" value="0.0.5">
13
		<os family="unix"/>
14
	</condition>
15
	<condition property="jecw_version" value="005">
16
		<os family="windows"/>
17
	</condition>
18
	<property name="jecw-jar" location="jecw-0.0.5.jar" />
19
	<condition property="cmake_generator" value="'Unix Makefiles'">
20
		<os family="unix"/>
21
	</condition>
22
	<condition property="cmake_generator" value="'NMake Makefiles'">
23
		<os family="windows"/>
24
	</condition>		
25

  
26
	<target name="main" description="compile java code, make jars, prepare and compile natives" depends="clean,jar,prepare-natives,compile-natives">
27
	</target>
28

  
29
	<target name="jar" description="makes jar file">
30
		<mkdir dir="${build}" />
31
		<javac srcdir="${src-java}" destdir="${build}" />
32
		<mkdir dir="${jar-dist}" />
33
		<jar jarfile="${jecw-jar}" basedir="${build}" includes="com/ermapper/**,es/gva/cit/jecwcompress/**" />
34
		<move file="${jecw-jar}" todir="${jar-dist}" />
35
	</target>
36

  
37
	<target name="prepare-natives" description="prepares the natives to be compiled">
38
		<mkdir dir="${cmake_build}"/>
39
		<delete file="${cmake_build}/CMakeCache.txt"/>
40
		<exec dir="${cmake_build}" executable="cmake">
41
			<arg line=".." />
42
			<arg line="-G${cmake_generator}" />
43
			<arg line="-DCMAKE_BUILD_TYPE=Release" />
44
			<arg line="-DJECW_VERSION=${jecw_version}" />
45
		</exec>
46
	</target>
47

  
48
	<target name="compile-natives" description="compiles natives">
49
		<exec dir="${cmake_build}" executable="make" os="Linux">
50
			<arg line="install" />
51
		</exec>
52
		<exec dir="${cmake_build}" executable="nmake" os="Windows 98,Windows 2000,Windows XP,Windows NT (Unknown)">
53
			<arg line="install" />
54
		</exec>
55
	</target>
56

  
57
		
58
	<target name="clean" description="clean distribution">
59
		<delete dir="jar-dist"/>
60
		<delete dir="lib-dist"/>
61
		<delete dir="BMCMake"/>
62
		<delete dir="bin"/>
63
	</target>
64

  
65
</project>
trunk/libraries/libjni-ecw/libjni-ecw/.classpath
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="src" path="src/main/java"/>
4
	<classpathentry kind="src" path="src/main/resources"/>
5
	<classpathentry kind="src" path="src/test/java"/>
6
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
7
	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3.8.1"/>
8
	<classpathentry kind="output" path="bin"/>
9
</classpath>
trunk/libraries/libjni-ecw/libjni-ecw/.project
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>libjni-ecw</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
	</buildSpec>
14
	<natures>
15
		<nature>org.eclipse.jdt.core.javanature</nature>
16
	</natures>
17
</projectDescription>
trunk/libraries/libjni-ecw/libjni-ecw/src/test/java/com/ermapper/ecw/TestReadEcw.java
1
package com.ermapper.ecw;
2

  
3
import junit.framework.TestCase;
4

  
5
public class TestReadEcw extends TestCase{
6

  
7
	private JNCSFile 				file = null;
8
	
9
	private String 					fileName = "miniraster30x30.jp2";
10
	private String 					baseDir = "./test-images/";
11
	private String 					file1 = baseDir + fileName;
12
	
13
	private int						numBands = 0;
14
	private int 					width = 0;
15
	private int						height = 0;
16
	private String					projection = null;
17
	
18
	
19
	public void start(){
20
		setUp();
21
		testStack();
22
	}
23
	
24
	public void setUp(){
25
		try {
26
			System.out.println("***** TEST DE ACCESO A ECW *****");
27
			System.out.println("     IMAGEN: " + fileName + "\n");
28
			file = new JNCSFile();
29
			file.open(file1, true);
30
			System.out.println("Acedo a algunos datos de la imagen: ");
31
			numBands = file.numBands;
32
			height = file.height;
33
			width = file.width;
34
			projection = file.projection;
35
			System.out.println("Número de bandas: " + numBands);
36
			System.out.println("Alto: " + height);
37
			System.out.println("Ancho: " + width);
38
			System.out.println("Proyección: " + projection);
39
			
40
		} catch (JNCSException e) {
41
			e.printStackTrace();
42
		}
43
	}
44
	
45
	public void testStack(){
46
		
47
	}
48
	
49
}
trunk/libraries/libjni-ecw/libjni-ecw/src/test/java/com/ermapper/ecw/TestCompressImage.java
1
package com.ermapper.ecw;
2

  
3
import junit.framework.TestCase;
4
import es.gva.cit.jecwcompress.CompressFormat;
5
import es.gva.cit.jecwcompress.EcwException;
6
import es.gva.cit.jecwcompress.JniObject;
7
import es.gva.cit.jecwcompress.NCSEcwCompressClient;
8
import es.gva.cit.jecwcompress.ReadCallBack;
9

  
10
public class TestCompressImage extends TestCase{
11

  
12
	private JNCSFile 				file = null;
13
	
14
	private String 					fileName = "miniraster30x30.jp2";
15
	private String					outFileName = "compressTestOutput.jp2";
16
	private String 					baseDir = "./test-images/";
17
	private String 					file1 = baseDir + fileName;
18
	private String					outFile = baseDir + outFileName;
19
	
20
	private NCSEcwCompressClient 	client = null;
21
	private Read 					lectura=null;
22
	
23
	private int						numBands = 0;
24
	private int						xSize = 0;
25
	private int						ySize = 0;
26
	
27
	
28
	public void start(){
29
		setUp();
30
		testStack();
31
	}
32
	
33
	public void setUp(){
34
		try {
35
			file = new JNCSFile();
36
			file.open(file1, true);
37
			numBands = file.numBands;
38
			xSize = file.width;
39
			ySize = file.height;
40
		} catch (JNCSException e) {
41
		} 
42
		
43

  
44
		  try{
45
		  	client = new NCSEcwCompressClient();
46
		  
47
		  	client.setOutputFilename(outFile);  	
48
		  	client.setInputFilename(file1);
49
		    client.setTargetCompress(new Double(10.0));
50
		    client.setInOutSizeX(xSize);
51
		    client.setInOutSizeY(ySize);
52
		    client.setInputBands(numBands);
53
		    
54
		    client.setCompressFormat(CompressFormat.COMPRESS_NONE);
55
			
56
			client.setProjection("WGS84");
57
			client.setCellIncrementX(file.cellIncrementX);
58
			client.setCellIncrementY(file.cellIncrementY);
59
			client.setOriginX(file.originX);
60
			client.setOriginY(file.originY);
61
			client.setCellSizeUnits(1);
62
		
63
			lectura = new Read(file, client, 0, ySize, xSize, ySize);
64
			client.NCSEcwCompressOpen(false);
65
			client.NCSEcwCompress(lectura);
66
			client.NCSEcwCompressClose();
67
		  			
68
		  }catch(EcwException e){
69
			  assertNotNull(client);
70
		  }
71
		
72
	}
73
	
74
	public void testStack(){
75
		
76
	}
77
}
78

  
79
/**
80
*
81
* Para la lectura hay que hacer una clase que extienda de JniObject e implemente ReadCallBack
82
* . Esto obliga a crear un m?todo loadBuffer. En el hay que meter la funcionalidad para que
83
* llene el buffer. El buffer esta en la clase cliente y tendr? una longitud de 
84
* ancho de una l?nea * n?mero de bandas
85
*/
86

  
87
class Read extends JniObject implements ReadCallBack {
88
	
89
	private JNCSFile miecw=null;
90
	private NCSEcwCompressClient client=null;
91
	private int width, height;
92
	private int ulX, ulY;
93
	private int[] readBandsFromECW = null;
94
	private int[] inputRow = null;
95
	
96
	public Read(JNCSFile ecw, NCSEcwCompressClient client,int ulx, int uly, int width, int height){
97
		this.miecw = ecw;
98
		this.client = client;
99
		this.width = width;
100
		this.height = height;
101
		this.ulX = ulx;
102
		this.ulY = uly;
103
		readBandsFromECW = new int[Math.max(miecw.numBands, 3)];
104
		inputRow = new int[miecw.width];
105
	}
106

  
107
	public void loadBuffer(){
108
		try {
109
			readBandsFromECW = new int[]{0, 1, 2};
110
			miecw.setView(miecw.numBands, readBandsFromECW, miecw.originX, miecw.originY + (miecw.cellIncrementY * nNextLine),
111
					miecw.originX + (miecw.cellIncrementX * miecw.width), 
112
					miecw.originY + (miecw.cellIncrementY * (nNextLine + 1)), 
113
					miecw.width, 1);
114

  
115
			miecw.readLineRGBA(inputRow);
116
			for(int col=0 ; col<inputRow.length ; col++){				
117
				client.buffer[col+(width*0)]=(byte)Math.abs(((inputRow[col] & 0x00ff0000) >> 16));
118
				client.buffer[col+(width*1)]=(byte)Math.abs(((inputRow[col] & 0x0000ff00) >> 8));
119
				client.buffer[col+(width*2)]=(byte)Math.abs((inputRow[col] & 0x000000ff));
120
			}
121
		} catch (JNCSFileNotOpenException e) {
122
		} catch (JNCSInvalidSetViewException e) {
123
		} catch (JNCSException e) {
124
		}
125
	}
126

  
127
	public void updatePercent(){
128
		System.out.println(client.getPercent()+"%");
129
	}
130
}
trunk/libraries/libjni-ecw/libjni-ecw/src/main/native/jecw/CMakeLists.txt
1
set(LIB_NAME jecw)
2

  
3
FILE(GLOB LIB_PUBLIC_HEADERS "${HEADER_PATH}/*.h")
4
FILE(GLOB LIB_COMMON_FILES "*.c*")
5

  
6
IF(WIN32)
7
	SET_SOURCE_FILES_PROPERTIES(${LIB_COMMON_FILES} PROPERTIES LANGUAGE CXX)
8
ENDIF(WIN32)
9

  
10
include_directories(
11
	${JAVA_INCLUDE_PATH}
12
	${JAVA_INCLUDE_PATH2}
13
	${ECW_INCLUDE_DIR}
14
)
15

  
16
add_library(${LIB_NAME} SHARED
17
	${LIB_PUBLIC_HEADERS}
18
	${LIB_COMMON_FILES}
19
)
20

  
21
IF(WIN32)
22
	target_link_libraries(${LIB_NAME}
23
		${ECW_LIBRARY}
24
		${ECW_LIBRARY2}
25
		${ECW_LIBRARY3}
26
	)
27
ELSEIF(WIN32)
28
	target_link_libraries(${LIB_NAME}
29
		${ECW_LIBRARY}
30
		${ECW_LIBRARY2}
31
		${ECW_LIBRARY3}
32
		$(ECW_LIBRARY4)
33
	)
34
ENDIF(WIN32)
35

  
36

  
37
if(APPLE)
38
SET_TARGET_PROPERTIES(${LIB_NAME}
39
	PROPERTIES
40
	SUFFIX .jnilib)
41
endif(APPLE)
42

  
43
INCLUDE(ModuleInstall OPTIONAL)
44

  
45
SET_TARGET_PROPERTIES(jecw PROPERTIES VERSION "${JECW_VERSION}")
46
IF(UNIX)
47
	SET_TARGET_PROPERTIES(jecw PROPERTIES OUTPUT_NAME "jecw${VERSION}")
48
ENDIF(UNIX)
49
IF(WIN32)
50
	SET_TARGET_PROPERTIES(jecw PROPERTIES OUTPUT_NAME "jecw${JECW_VERSION}")
51
ENDIF(WIN32)
52

  
53

  
54
IF(UNIX AND NOT APPLE)
55
	SET_TARGET_PROPERTIES ( ${LIB_NAME} PROPERTIES LINK_FLAGS "-Wl,-E")
56
ENDIF(UNIX AND NOT APPLE)
57

  
trunk/libraries/libjni-ecw/libjni-ecw/src/main/native/jecw/ncsecwcompressclient_wrapper.c
1
/**********************************************************************
2
 * $Id: ncsecwcompressclient_wrapper.c 4274 2006-03-06 07:32:00Z nacho $
3
 *
4
 * Name:     bsb_interfaz.c
5
 * Project:  JGDAL. Interface java to gdal (Frank Warmerdam).
6
 * Purpose:  Interface functions to manage bsb files. This include gdal
7
 * 			code but it doesn't use the gdal API.
8
 * Author:   Nacho Brodin, brodin_ign@gva.es
9
 *
10
 **********************************************************************/
11
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
12
*
13
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
14
*
15
* This program is free software; you can redistribute it and/or
16
* modify it under the terms of the GNU General Public License
17
* as published by the Free Software Foundation; either version 2
18
* of the License, or (at your option) any later version.
19
*
20
* This program is distributed in the hope that it will be useful,
21
* but WITHOUT ANY WARRANTY; without even the implied warranty of
22
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
* GNU General Public License for more details.
24
*
25
* You should have received a copy of the GNU General Public License
26
* along with this program; if not, write to the Free Software
27
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
28
*
29
* For more information, contact:
30
*
31
*  Generalitat Valenciana
32
*   Conselleria d'Infraestructures i Transport
33
*   Av. Blasco Ib??ez, 50
34
*   46010 VALENCIA
35
*   SPAIN
36
*
37
*      +34 963862235
38
*   gvsig@gva.es
39
*      www.gvsig.gva.es
40
*
41
*    or
42
*
43
*   IVER T.I. S.A
44
*   Salamanca 50
45
*   46005 Valencia
46
*   Spain
47
*
48
*   +34 963163400
49
*   dac@iver.es
50
*/
51

  
52
#include <jni.h>
53
#include <string.h>
54
#include <malloc.h>
55
#include "NCSECWCompressClient.h"
56

  
57
typedef struct ReadInfo {
58
	//NCSFileView 	*pNCSFileView;
59
	UINT8 			**ppInputBandBufferArray;
60
	UINT32 			nPercentComplete;
61
	jclass			clase;
62
	jobject			*jclient;
63
	jobject			*jreadcall;
64
	JNIEnv 			*env;
65
	char 			pErrorBuffer[1024];
66
} ReadInfo;
67

  
68
static BOOLEAN 	callBackOn = TRUE;
69

  
70
/******************************************************************************/
71
//								ReadCallback
72
/******************************************************************************/
73

  
74

  
75
static BOOLEAN ReadCallback(NCSEcwCompressClient *pClient,
76
							UINT32 nNextLine,
77
							IEEE4 **ppOutputBandBufferArray)
78
{
79
	ReadInfo *pReadInfo = (ReadInfo *)pClient->pClientData;
80
	UINT32 nBand;
81
	jfieldID fid;
82
	jbyteArray jarray;
83
	JNIEnv *env=pReadInfo->env;
84
	int longitud;
85
	jclass clase_client;
86
	jclass clase_readcall;
87
	jmethodID metodo;
88

  
89
    if(callBackOn){
90
		clase_client = (env)->GetObjectClass(*(pReadInfo->jclient));
91
		clase_readcall = (env)->GetObjectClass(*(pReadInfo->jreadcall));
92
		
93
		//Ponemos el valor de la banda un n?mero de l?nea en el objeto cliente		
94
	
95
	  	fid = (env)->GetFieldID(clase_readcall, "nNextLine", "I");
96
	  	(env)->SetIntField(*(pReadInfo->jreadcall), fid, nNextLine); 
97
		   	
98
	   	//Ejecutamos la funci?n de java que carga el buffer
99
			
100
		metodo = (env)->GetMethodID(clase_readcall, "loadBuffer", "()V");
101
		(env)->CallVoidMethod(*(pReadInfo->jreadcall), metodo);
102
		
103
		//Obtenemos el array de bytes desde java
104
		
105
		fid = (env)->GetFieldID(clase_client, "buffer", "[B");
106
	    jarray =(jbyteArray)(env)->GetObjectField(*(pReadInfo->jclient), fid);  
107
	    longitud = (env)->GetArrayLength(jarray);
108
	    
109
	    (env)->GetByteArrayRegion(jarray,0,longitud,(jbyte *)pReadInfo->ppInputBandBufferArray[0]);
110
	        
111
		for(nBand = 0; nBand < pClient->nInputBands; nBand++) {
112
			UINT32 nCell;		
113
			UINT8 *pInputValue = pReadInfo->ppInputBandBufferArray[nBand];
114
			IEEE4 *pOutputValue = ppOutputBandBufferArray[nBand];
115
	    	
116
			// Compression needs input to be IEEE4
117
			for (nCell = 0; nCell < pClient->nInOutSizeX; nCell++) {
118
				*pOutputValue++ = (IEEE4)*pInputValue++;
119
			}
120
		
121
		}
122

  
123
		return(TRUE);	
124
    }else
125
    	return(FALSE);
126
}
127

  
128
/******************************************************************************/
129
//								StatusCallback
130
/******************************************************************************/
131
//Asigna el tanto por cien de imagen que lleva comprimido en una variable de java
132
//Ejecuta la funci?n updatePercent de java despues de actualizar la varible.
133

  
134
static void StatusCallback(NCSEcwCompressClient *pClient,
135
						   UINT32 nCurrentLine)
136
{
137
	ReadInfo 	*pReadInfo = (ReadInfo *)pClient->pClientData;
138
	UINT32 		nPercentComplete = (nCurrentLine * 100) / (pClient->nInOutSizeY - 1);
139
	jclass 		clase_client;
140
	jclass 		clase_readcall;
141
	JNIEnv 		*env=pReadInfo->env;
142
	jfieldID 	fid;
143
	jmethodID 	metodo;
144
	
145
	clase_client = (env)->GetObjectClass(*(pReadInfo->jclient));
146
	clase_readcall = (env)->GetObjectClass(*(pReadInfo->jreadcall));
147
	
148
	if (nPercentComplete != pReadInfo->nPercentComplete) {
149
		fid = (env)->GetFieldID(clase_client, "porcentaje", "I");
150
	  	(env)->SetIntField(*(pReadInfo->jclient), fid, nPercentComplete);
151
  		metodo = (env)->GetMethodID(clase_readcall, "updatePercent", "()V");
152
		(env)->CallVoidMethod(*(pReadInfo->jreadcall), metodo); 
153
		pReadInfo->nPercentComplete = nPercentComplete;
154
	}
155
}
156

  
157
/******************************************************************************/
158
//								NCSEcwCompressClient
159
/******************************************************************************/
160

  
161
JNIEXPORT jlong JNICALL Java_es_gva_cit_jecwcompress_NCSEcwCompressClient_NCSEcwCompressClientNat
162
  (JNIEnv *env, jobject obj){
163
  	
164
  	NCSEcwCompressClient 	*pClient;
165
  	jlong 					jresult = 0 ;
166
  	
167
  	if(pClient = NCSEcwCompressAllocClient()){
168
  		*(NCSEcwCompressClient **)&jresult = pClient;
169
  		return jresult;
170
  	}else
171
  		return -1;
172
  	
173
  }
174

  
175
/******************************************************************************/
176
//								NCSEcwCompressOpen
177
/******************************************************************************/
178

  
179
JNIEXPORT jint JNICALL Java_es_gva_cit_jecwcompress_NCSEcwCompressClient_NCSEcwCompressOpenNat
180
  (JNIEnv *env, jobject obj, jlong cPtr, jboolean bCalculateSizesOnly){
181
  	
182
  	NCSEcwCompressClient 	*pClient = (NCSEcwCompressClient *) 0 ;
183
  	NCSError 				eError;
184
  	jfieldID 				fid;
185
    jobject					obj_str;
186
    const char				*str;
187
    ReadInfo 				*compress_readInfo;
188
    jmethodID 				metodo;
189

  
190
    UINT8 *pReadBuffer,nBand;
191
    
192
  	pClient = *(NCSEcwCompressClient **)&cPtr;
193
  	if(pClient!=NULL){
194
  		
195
  		//Asignamos los valores de los campos de NCSEcwCompress
196
  		
197
  		jclass clase = (env)->GetObjectClass(obj);
198
  		  		
199
  		fid = (env)->GetFieldID(clase, "inputFilename", "Ljava/lang/String;");
200
  		obj_str = (env)->GetObjectField(obj, fid);
201
  		if(obj_str!=NULL){
202
			str = (env)->GetStringUTFChars((jstring)obj_str,0);
203
	  		strcpy(pClient->szInputFilename,str);
204
	  		str=NULL;
205
	  		(env)->ReleaseStringUTFChars((jstring)obj_str, str);
206
	  		//printf("inputFilename=%s\n",pClient->szInputFilename);
207
  		}
208
  		
209
  		fid = (env)->GetFieldID(clase, "outputFilename", "Ljava/lang/String;");
210
  		obj_str = (env)->GetObjectField(obj, fid);
211
  		if(obj_str!=NULL){
212
			str = (env)->GetStringUTFChars((jstring)obj_str,0);
213
	  		strcpy(pClient->szOutputFilename,str);
214
	  		str=NULL;
215
	  		(env)->ReleaseStringUTFChars((jstring)obj_str, str);
216
	  		//printf("outputFilename=%s\n",pClient->szOutputFilename);
217
  		}
218
  		  		
219
  		fid = (env)->GetFieldID(clase, "targetCompression", "D");
220
  		pClient->fTargetCompression = (IEEE4)(env)->GetDoubleField(obj, fid);
221
  		//printf("targetCompression=%f\n",pClient->fTargetCompression);
222
  		
223
  		fid = (env)->GetFieldID(clase, "eCompressFormat", "I");
224
  		pClient->eCompressFormat = (CompressFormat)(env)->GetIntField(obj, fid);
225
  		//printf("eCompressFormat=%d\n",pClient->eCompressFormat);
226
  		  		
227
  		fid = (env)->GetFieldID(clase, "eCompressHint", "I");
228
  		pClient->eCompressHint = (CompressHint)(env)->GetIntField(obj, fid);
229
  		//printf("eCompressHint=%d\n",pClient->eCompressHint);
230
  		
231
  		fid = (env)->GetFieldID(clase, "nBlockSizeX", "I");
232
  		pClient->nBlockSizeX = (env)->GetIntField(obj, fid);
233
  		//printf("nBlockSizeX=%d\n",pClient->nBlockSizeX);
234
  		
235
  		fid = (env)->GetFieldID(clase, "nBlockSizeY", "I");
236
  		pClient->nBlockSizeY = (env)->GetIntField(obj, fid);
237
  		//printf("nBlockSizeY=%d\n",pClient->nBlockSizeY);
238
  		
239
  		fid = (env)->GetFieldID(clase, "nInOutSizeX", "I");
240
  		pClient->nInOutSizeX = (env)->GetIntField(obj, fid);
241
  		//printf("nInOutSizeX=%d\n",pClient->nInOutSizeX);
242
  		
243
  		fid = (env)->GetFieldID(clase, "nInOutSizeY", "I");
244
  		pClient->nInOutSizeY = (env)->GetIntField(obj, fid);
245
  		//printf("nInOutSizeY=%d\n",pClient->nInOutSizeY);
246
  		
247
  		fid = (env)->GetFieldID(clase, "nInputBands", "I");
248
  		pClient->nInputBands = (env)->GetIntField(obj, fid);
249
  		//printf("nInputBands=%d\n",pClient->nInputBands);
250
  		
251
  		fid = (env)->GetFieldID(clase, "nOutputBands", "I");
252
  		pClient->nOutputBands = (env)->GetIntField(obj, fid);
253
		//printf("nOutputBands=%d\n",pClient->nOutputBands);
254
		
255
  		fid = (env)->GetFieldID(clase, "nInputSize", "J");
256
  		pClient->nInputSize = (env)->GetLongField(obj, fid);
257
  		//printf("nInputSize=%ld\n",pClient->nInputSize);
258
  		
259
  		fid = (env)->GetFieldID(clase, "fCellIncrementX", "D");
260
  		pClient->fCellIncrementX = (env)->GetDoubleField(obj, fid);
261
  		//printf("fCellIncrementX=%f\n",pClient->fCellIncrementX);
262
  		
263
  		fid = (env)->GetFieldID(clase, "fCellIncrementY", "D");
264
  		pClient->fCellIncrementY = (env)->GetDoubleField(obj, fid);
265
  		//printf("fCellIncrementY=%f\n",pClient->fCellIncrementY);
266
  		
267
  		fid = (env)->GetFieldID(clase, "fOriginX", "D");
268
  		pClient->fOriginX = (env)->GetDoubleField(obj, fid);
269
  		//printf("fOriginX=%f\n",pClient->fOriginX);
270
  		
271
  		fid = (env)->GetFieldID(clase, "fOriginY", "D");
272
  		pClient->fOriginY = (env)->GetDoubleField(obj, fid);
273
  		//printf("fOriginY=%f\n",pClient->fOriginY);
274
  		
275
  		fid = (env)->GetFieldID(clase, "eCellSizeUnits", "I");
276
  		pClient->fActualCompression = (IEEE4)(env)->GetIntField(obj, fid);
277
  		//printf("eCellSizeUnits=%d\n",pClient->fActualCompression);
278
  		
279
  		fid = (env)->GetFieldID(clase, "szDatum", "Ljava/lang/String;");
280
  		obj_str = (env)->GetObjectField(obj, fid);
281
  		if(obj_str!=NULL){
282
			str = (env)->GetStringUTFChars((jstring)obj_str,0);
283
	  		strcpy(pClient->szDatum,str);
284
	  		str=NULL;
285
	  		(env)->ReleaseStringUTFChars((jstring)obj_str, str);
286
	  		//printf("szDatum=%s\n",pClient->szDatum);
287
  		}
288
  		
289
  		fid = (env)->GetFieldID(clase, "szProjection", "Ljava/lang/String;");
290
  		obj_str = (env)->GetObjectField(obj, fid);
291
  		if(obj_str!=NULL){
292
			str = (env)->GetStringUTFChars((jstring)obj_str,0);
293
	  		strcpy(pClient->szProjection,str);
294
	  		str=NULL;
295
	  		(env)->ReleaseStringUTFChars((jstring)obj_str, str);
296
	  		//printf("szProjection=%s\n",pClient->szProjection);
297
  		}
298
  		
299
  		fid = (env)->GetFieldID(clase, "fActualCompression", "D");
300
  		pClient->fActualCompression = (IEEE4)(env)->GetDoubleField(obj, fid);
301
  		//printf("fActualCompression=%f\n",pClient->fActualCompression);
302
  		
303
  		fid = (env)->GetFieldID(clase, "fCompressionSeconds", "D");
304
  		pClient->fCompressionSeconds = (env)->GetDoubleField(obj, fid);
305
  		//printf("fCompressionSeconds=%f\n",pClient->fCompressionSeconds);
306
  		
307
  		fid = (env)->GetFieldID(clase, "fCompressionMBSec", "D");
308
  		pClient->fCompressionMBSec = (env)->GetDoubleField(obj, fid);
309
  		//printf("fCompressionMBSec=%f\n",pClient->fCompressionMBSec);
310
  		
311
  		fid = (env)->GetFieldID(clase, "nOutputSize", "J");
312
  		pClient->nOutputSize = (env)->GetLongField(obj, fid);
313
  		//printf("nOutputSize=%ld\n",pClient->nOutputSize);
314
  		
315
  		pClient->pReadCallback = ReadCallback;
316
		pClient->pStatusCallback = StatusCallback;
317
				
318
		//Inicializar el buffer que tendr? una l?nea de entrada x el n?m de bandas
319
		
320
		metodo = (env)->GetMethodID(clase, "initialize", "()V");
321
		(env)->CallIntMethod(obj,metodo);
322
			
323
		compress_readInfo = (ReadInfo *)malloc(sizeof(ReadInfo));
324
		
325
		pReadBuffer = (UINT8 *)malloc(sizeof(UINT8) *
326
								  pClient->nInOutSizeX *
327
								  pClient->nInputBands);
328
		compress_readInfo->ppInputBandBufferArray = (UINT8 **)malloc(sizeof(UINT8 *) *
329
								   pClient->nInputBands);
330
		for (nBand = 0; nBand < pClient->nInputBands; nBand++) {
331
			compress_readInfo->ppInputBandBufferArray[nBand] = pReadBuffer + 
332
			(nBand * pClient->nInOutSizeX * sizeof(UINT8));
333
		}
334
								  
335
		if (compress_readInfo->ppInputBandBufferArray == NULL) return 46;
336
		compress_readInfo->nPercentComplete = 0;
337
				
338
		pClient->pClientData = (void *)compress_readInfo;
339
		
340
	  	eError = NCSEcwCompressOpen(pClient, ((bCalculateSizesOnly==0)? FALSE : TRUE));
341
	  	
342
		return eError;
343
		
344
  	}
345
  	return -1;
346
  }
347
  
348
/******************************************************************************/
349
//								NCSEcwCompress
350
/******************************************************************************/
351
  
352
JNIEXPORT jint JNICALL Java_es_gva_cit_jecwcompress_NCSEcwCompressClient_NCSEcwCompressNat
353
  (JNIEnv *env, jobject obj, jlong cPtr, jobject obj_read){
354
  	
355
  	NCSEcwCompressClient 	*pClient = (NCSEcwCompressClient *) 0 ;
356
  	ReadInfo 				*compress_readInfo = (ReadInfo *) 0 ;
357
  	NCSError 				eError;
358
   
359
	pClient = *(NCSEcwCompressClient **)&cPtr;
360
	compress_readInfo = (ReadInfo *)pClient->pClientData;
361
	compress_readInfo->jclient=&obj;
362
	compress_readInfo->jreadcall=&obj_read;
363
	compress_readInfo->env=env;	
364
	
365
	eError = NCSEcwCompress(pClient);
366
	return eError;  	
367
  }
368
  
369
/******************************************************************************/
370
//								NCSEcwCompressClose
371
/******************************************************************************/
372
  
373
JNIEXPORT jint JNICALL Java_es_gva_cit_jecwcompress_NCSEcwCompressClient_NCSEcwCompressCloseNat
374
  (JNIEnv *env, jobject obj, jlong cPtr){
375
  	
376
  	NCSEcwCompressClient 	*pClient = (NCSEcwCompressClient *) 0 ;
377
  	NCSError 				eError;
378
    	
379
	pClient = *(NCSEcwCompressClient **)&cPtr;	
380
	eError = NCSEcwCompressClose(pClient);
381
	return eError;  	
382
  }  
383
  
384
/******************************************************************************/
385
//								NCSEcwCompressCancel
386
/******************************************************************************/
387
  
388
JNIEXPORT void JNICALL Java_es_gva_cit_jecwcompress_NCSEcwCompressClient_NCSEcwCompressCancelNat
389
  (JNIEnv *env, jobject obj, jlong cPtr){
390
  	callBackOn = FALSE;
391
  }
392
  
393
/******************************************************************************/
394
//								finalize
395
/******************************************************************************/
396
  
397
JNIEXPORT void JNICALL Java_es_gva_cit_jecwcompress_NCSEcwCompressClient_finalizeNat
398
  (JNIEnv *env, jobject obj, jlong cPtr){
399
  	
400
  	ReadInfo 				*compress_readInfo = (ReadInfo *) 0 ;
401
  	NCSEcwCompressClient 	*pClient = (NCSEcwCompressClient *) 0 ;
402
    int 					nBand;	
403
    
404
	pClient = *(NCSEcwCompressClient **)&cPtr;	
405
   	
406
  	//Liberamos la memoria
407
  	
408
  	compress_readInfo = (ReadInfo *)pClient->pClientData;
409
  	for (nBand = 0; nBand < pClient->nInputBands; nBand++) {
410
			free(compress_readInfo->ppInputBandBufferArray[nBand]);
411
	}
412
  	free(compress_readInfo->ppInputBandBufferArray);
413
  	free(pClient->pClientData);
414
  	pClient->pClientData = NULL;
415
  	NCSEcwCompressFreeClient(pClient);
416
  	
417
  }
418
  
trunk/libraries/libjni-ecw/libjni-ecw/src/main/native/jecw/ecw_jni.c
1
/********************************************************** 
2
** Copyright 1998 Earth Resource Mapping Ltd.
3
** This document contains proprietary source code of
4
** Earth Resource Mapping Ltd, and can only be used under
5
** one of the three licenses as described in the 
6
** license.txt file supplied with this distribution. 
7
** See separate license.txt file for license details 
8
** and conditions.
9
**
10
** This software is covered by US patent #6,442,298,
11
** #6,102,897 and #6,633,688.  Rights to use these patents 
12
** is included in the license agreements.
13
** 
14
** FILE:   	ecw_jni.c
15
** CREATED:	4 Jan 2000
16
** AUTHOR: 	Mark Sheridan
17
** PURPOSE:	Java wrappers for JNI usage of the ECW library in Java.
18
** EDITS:
19
** 
20
** [01] 01Nov00 mjs Rewrote to be JVM 1.1 compliant.
21
** [02] 08Mar04 mjs Removed old 1.1 spec stuff, now needs a 1.2 compatible virtual machine.
22
** [03] 01Oct05 nbt ECWOpenArray function to support name parameter in char array
23
**
24
*******************************************************/
25

  
26
#include "NCSErrors.h"
27
#include "NCSECWClient.h"
28
#include "NCSMalloc.h" 
29
#include "NCSUtil.h"
30
#include "NCSBuildNumber.h"
31
#include "JNCSFile.h"
32
#include "NCSFile.h"
33
#include "NCSDynamicLib.h"
34

  
35
//#ifndef JNI_VERSION_1_2
36
//#error You must compile this class against a 1.2 virtual machine specification
37
//#endif
38

  
39
static JavaVM *pJavaVirtualMachineInst = NULL;
40
struct NCSJNIFieldIDs *pGlobalJNCSFieldIDs = NULL;
41

  
42
typedef struct NCSJNIFieldIDs {
43
	jfieldID jIDNativeDataPointer;
44
	jfieldID jIDWidth;
45
	jfieldID jIDHeight;	
46
	jfieldID jIDNumberOfBands;
47
	jfieldID jIDCompressionRate;
48
	jfieldID jIDCellIncrementX;
49
	jfieldID jIDCellIncrementY;
50
	jfieldID jIDCellSizeUnits;
51
	jfieldID jIDOriginX;
52
	jfieldID jIDOriginY;
53
	jfieldID jIDDatum;
54
	jfieldID jIDProjection;
55
	jfieldID jIDFilename;
56
	jfieldID jIDIsOpen;
57
	jmethodID jIDRefreshUpdateMethod;
58
	jfieldID jIDFileType;
59
	jfieldID jIDFileMimeType;
60
} NCSJNIFieldIDs;
61

  
62
// This is the object specific data structure, its cached.
63
typedef struct NCSJNIInfo {
64
	//jobject  ECWFile;
65
	NCSFileView *pFileView;
66
} NCSJNIInfo;
67

  
68
void NCSJNIThrowException(JNIEnv *pEnv, const char *pSignature, const char *pMessage)
69
{
70
	jclass jExceptionClass = NULL;
71

  
72
	if ((pEnv)->ExceptionCheck()) {
73
		(pEnv)->ExceptionDescribe();
74
		(pEnv)->ExceptionClear();
75
	}
76

  
77
	jExceptionClass = (pEnv)->FindClass(pSignature);
78

  
79
	if (jExceptionClass != NULL) {
80
		(pEnv)->ThrowNew(jExceptionClass, pMessage); 
81
	}
82
	(pEnv)->DeleteLocalRef(jExceptionClass);
83
}
84

  
85
NCSError NCSCreateJNIInfoStruct(JNIEnv *pEnv, jobject ECWFile, NCSFileView *pNCSFileView, NCSJNIInfo **pReturn)
86
{
87
	NCSJNIInfo *pJNIInfo;
88
	//char *pErrorString = NULL;
89
	
90
	pJNIInfo = (NCSJNIInfo *)NCSMalloc(sizeof(NCSJNIInfo), TRUE);
91
	if (pJNIInfo != NULL)
92
	{
93
		pJNIInfo->pFileView = pNCSFileView;
94
		//pJNIInfo->ECWFile = (void *)(*pEnv)->NewGlobalRef(pEnv, ECWFile);
95
		*pReturn = pJNIInfo;
96
	}
97
	else
98
	{
99
		return NCS_COULDNT_ALLOC_MEMORY;
100
	}
101
	return NCS_SUCCESS;
102
}
103

  
104
/*
105
 * Class:     None
106
 * Method:    JNI_OnLoad
107
 * Signature: ()Z
108
 */
109

  
110
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *pJVM, void *reserved)
111
{
112
	JNIEnv *pEnv;
113

  
114
	if ((pJVM)->GetEnv((void **)&pEnv, JNI_VERSION_1_2)) {
115
		NCSJNIThrowException(pEnv, "java/lang/Exception", "JNCS classes require a version 1.2 or higher virtual machine.");
116
		return JNI_ERR;
117
	}
118
	else {
119
		pJavaVirtualMachineInst = pJVM;
120
#ifndef WIN32
121
		NCSecwInit();
122
#endif
123
	}
124
	return JNI_VERSION_1_2;
125
}
126

  
127

  
128
/*
129
 * Class:     None
130
 * Method:    JNI_OnUnload
131
 * Signature: ()Z
132
 */
133
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *pJVM, void *reserved)
134
{
135
#ifndef WIN32
136
		NCSecwShutdown();
137
#endif
138
		NCSFree((void *)pGlobalJNCSFieldIDs);
139
	return;
140
}
141

  
142
/*
143
 * Class:     com_ermapper_ecw_JNCSFile
144
 * Method:    NCSJNIInit
145
 * Signature: ()I
146
 */
147
JNIEXPORT jint JNICALL Java_com_ermapper_ecw_JNCSFile_NCSJNIInit
148
  (JNIEnv *pEnv, jclass ECWFileClass)
149
{
150
	NCSJNIFieldIDs *pJNIInfo = NULL;
151
	char *pErrorString = NULL;
152

  
153
	if (!pGlobalJNCSFieldIDs) {
154

  
155
		pJNIInfo = (NCSJNIFieldIDs *)NCSMalloc(sizeof(NCSJNIFieldIDs), TRUE);
156

  
157
		// Get all the field ids of the ECWFile object
158
		pJNIInfo->jIDNativeDataPointer	= (pEnv)->GetFieldID(ECWFileClass, "nativeDataPointer", "J" );
159
		pJNIInfo->jIDWidth				= (pEnv)->GetFieldID(ECWFileClass, "width", "I" );
160
		pJNIInfo->jIDHeight				= (pEnv)->GetFieldID(ECWFileClass, "height", "I" );
161
		pJNIInfo->jIDNumberOfBands		= (pEnv)->GetFieldID(ECWFileClass, "numBands", "I" );
162
		pJNIInfo->jIDCompressionRate	= (pEnv)->GetFieldID(ECWFileClass, "compressionRate", "D" );
163
		pJNIInfo->jIDCellIncrementX		= (pEnv)->GetFieldID(ECWFileClass, "cellIncrementX", "D" );
164
		pJNIInfo->jIDCellIncrementY		= (pEnv)->GetFieldID(ECWFileClass, "cellIncrementY", "D" );
165
		pJNIInfo->jIDCellSizeUnits		= (pEnv)->GetFieldID(ECWFileClass, "cellSizeUnits", "I" );
166
		pJNIInfo->jIDOriginX			= (pEnv)->GetFieldID(ECWFileClass, "originX", "D" );
167
		pJNIInfo->jIDOriginY			= (pEnv)->GetFieldID(ECWFileClass, "originY", "D" );
168
		pJNIInfo->jIDDatum				= (pEnv)->GetFieldID(ECWFileClass, "datum", "Ljava/lang/String;" );
169
		pJNIInfo->jIDProjection			= (pEnv)->GetFieldID(ECWFileClass, "projection", "Ljava/lang/String;" );
170
		pJNIInfo->jIDFilename			= (pEnv)->GetFieldID(ECWFileClass, "fileName", "Ljava/lang/String;" );
171
		pJNIInfo->jIDIsOpen				= (pEnv)->GetFieldID(ECWFileClass, "bIsOpen", "Z" );
172
		pJNIInfo->jIDRefreshUpdateMethod= (pEnv)->GetMethodID(ECWFileClass, "refreshUpdate", "(IIDDDD)V");
173

  
174
		//pJNIInfo->jIDFileType			= (pEnv)->GetFieldID(ECWFileClass, "fileType", "I" );
175
		//pJNIInfo->jIDFileMimeType		= (pEnv)->GetFieldID(ECWFileClass, "mimeType", "Ljava/lang/String;" );
176

  
177

  
178
		// Do some error checking
179
		if (!pJNIInfo->jIDNativeDataPointer)
180
			pErrorString = "Could not determine fieldID for 'nativeDataPointer' in ECWFile object.";
181
		if (!pJNIInfo->jIDWidth)
182
			pErrorString = "Could not determine fieldID for 'width' in ECWFile object.";
183
		if (!pJNIInfo->jIDHeight)
184
			pErrorString = "Could not determine fieldID for 'height' in ECWFile object.";
185
		if (!pJNIInfo->jIDNumberOfBands)
186
			pErrorString = "Could not determine fieldID for 'numBands' in ECWFile object.";
187
		if (!pJNIInfo->jIDCompressionRate)
188
			pErrorString = "Could not determine fieldID for 'compressionRate' in ECWFile object.";
189
		if (!pJNIInfo->jIDCellIncrementX)
190
			pErrorString = "Could not determine fieldID for 'cellIncrementX' in ECWFile object.";
191
		if (!pJNIInfo->jIDCellIncrementY)
192
			pErrorString = "Could not determine fieldID for 'cellIncrementY' in ECWFile object.";
193
		if (!pJNIInfo->jIDCellSizeUnits)
194
			pErrorString = "Could not determine fieldID for 'cellSizeUnits' in ECWFile object.";
195
		if (!pJNIInfo->jIDOriginX)
196
			pErrorString = "Could not determine fieldID for 'originX' in ECWFile object.";
197
		if (!pJNIInfo->jIDOriginY)
198
			pErrorString = "Could not determine fieldID for 'originY' in ECWFile object.";
199
		if (!pJNIInfo->jIDDatum)
200
			pErrorString = "Could not determine fieldID for 'datum' in ECWFile object.";
201
		if (!pJNIInfo->jIDProjection)
202
			pErrorString = "Could not determine fieldID for 'projection' in ECWFile object.";
203
		if (!pJNIInfo->jIDFilename)
204
			pErrorString = "Could not determine fieldID for 'fileName' in ECWFile object.";
205
		if (!pJNIInfo->jIDIsOpen)
206
			pErrorString = "Could not determine fieldID for 'bIsOpen' in ECWFile object.";
207
		/*if (!pJNIInfo->jIDFileType)
208
			pErrorString = "Could not determine fieldID for 'fileType' in ECWFile object.";
209
		if (!pJNIInfo->jIDFileMimeType)
210
			pErrorString = "Could not determine fieldID for 'mimeType' in ECWFile object.";*/
211
			
212
		if (pErrorString) {
213
#ifdef WIN32
214
			MessageBox(NULL, OS_STRING(pErrorString), TEXT("JNCSClass Library (JNI)"), MB_OK);
215
#else
216
			fprintf(stderr, "JNCSClass Library (JNI) : %s\n", pErrorString);
217
#endif
218
			NCSFormatErrorText(NCS_JNI_ERROR, pErrorString);
219
			return NCS_JNI_ERROR;
220
		}
221
		else {
222
			pGlobalJNCSFieldIDs = pJNIInfo;
223
			return NCS_SUCCESS;
224
		}
225
	}
226
	else {
227
		return NCS_SUCCESS;
228
	}
229
}
230

  
231
/*
232
 * There is so much that can go wrong in this call, that is why there is so much error checking.
233
 *
234
 * Class:     None
235
 * Method:    NCSJNIRefreshCallback
236
 * Signature: 
237
 */
238
NCSEcwReadStatus NCSJNIRefreshCallback(NCSFileView *pNCSFileView)
239
{
240
	NCSFileViewSetInfo	*pViewInfo;
241
	NCSJNIInfo *pJNIInfo;
242
	jint nError;
243
	JNIEnv *pEnv;
244
	jclass EcwObjectClass = NULL;
245
	jobject pECWFile = NULL;
246
	
247
	NCScbmGetViewInfo(pNCSFileView, &pViewInfo);
248

  
249
	// Must attach to the vm thread before calling any java methods.
250
	nError = (pJavaVirtualMachineInst)->AttachCurrentThread((void **)&pEnv, NULL);
251
	
252
	if (nError != 0) {
253
		char Message[] = "The ECW JNI interface could not attach to the current thread in\n"
254
						 "the Java virtual machine. Please refer to the Image Web Server\n"
255
						 "Java SDK documentation for more information about JVM threads.\n\n"
256
						 "Progressive imagery will not be available.";
257
#ifdef WIN32
258
		MessageBox(GetActiveWindow(), OS_STRING(Message), TEXT("JNCSFile VM Error"), MB_OK);
259
#else
260
		fprintf(stderr, "JNCSFile VM Error : %s\n", Message);
261
#endif
262
		return NCSECW_READ_FAILED;
263
	}
264

  
265
	// Make sure we got a view info struct.
266
	if (!pViewInfo) {
267
		NCSJNIThrowException(pEnv, "java/lang/Exception", "ECW JNI component could not obtain the NCSViewInfo pointer from the NCSFileView. No refreshUpdate() will occur.");
268
		(pJavaVirtualMachineInst)->DetachCurrentThread();
269
		return NCSECW_READ_FAILED;
270
	}
271

  
272
	// The file is the global reference stashed in the client data pointer.
273
	pECWFile = (jobject)pViewInfo->pClientData;
274
	
275
	// Check to make sure that the ECW object has not been free'd or garbaged collected. This is only valid for JNI 1.2
276
	if ((pEnv)->IsSameObject(pECWFile/*pViewInfo->pClientData*/, NULL) == JNI_TRUE) {
277
		(pJavaVirtualMachineInst)->DetachCurrentThread();
278
		return NCSECW_READ_FAILED;
279
	}
280

  
281
	// Use the valid reference to the object, to obtain the data pointer.
282
	pJNIInfo = (NCSJNIInfo *)(pEnv)->GetLongField((jobject)pViewInfo->pClientData, pGlobalJNCSFieldIDs->jIDNativeDataPointer);
283

  
284
	if (!pJNIInfo) {
285
		NCSJNIThrowException(pEnv, "java/lang/Exception", "The ECW JNI component could not obtain the client data pointer from the NCSViewInfo struct. No refreshUpdate() will occur.");
286
		(pJavaVirtualMachineInst)->DetachCurrentThread();
287
		return NCSECW_READ_FAILED;
288
	}
289
	
290
	EcwObjectClass = (pEnv)->GetObjectClass(pECWFile/*pJNIInfo->ECWFile*/);
291
	if (EcwObjectClass == NULL) {
292
		NCSJNIThrowException(pEnv, "java/lang/Exception", "The ECW JNI component could not determine the class signature of the ECW object.");
293
		(pJavaVirtualMachineInst)->DetachCurrentThread();
294
		return NCSECW_READ_FAILED;
295
	}
296

  
297
	(pEnv)->DeleteLocalRef(EcwObjectClass);
298

  
299
	//Call the  "refreshUpdate" method on this object, if it implements the JNCSProgressiveUpdate interface.
300
	if (pGlobalJNCSFieldIDs->jIDRefreshUpdateMethod) {
301
		(pEnv)->CallVoidMethod(	pECWFile, \
302
								pGlobalJNCSFieldIDs->jIDRefreshUpdateMethod, \
303
								pViewInfo->nSizeX, pViewInfo->nSizeY, \
304
								pViewInfo->fTopX, pViewInfo->fLeftY, \
305
								pViewInfo->fBottomX, pViewInfo->fRightY);
306
	}
307
	else {
308
		NCSJNIThrowException(pEnv, "java/lang/ClassNotFoundException", "'refreshUpdate' method not found. Derived classes must implement the interface 'JNCSProgressiveUpdate' to use progressive imagery.");
309
		(pJavaVirtualMachineInst)->DetachCurrentThread();
310
		return NCSECW_READ_FAILED;
311
	}
312

  
313
	(pJavaVirtualMachineInst)->DetachCurrentThread();
314

  
315
	return NCSECW_READ_OK;
316
}
317

  
318

  
319
/**
320
 * 
321
 */
322
int openFile(JNIEnv *pEnv, jobject *JNCSFile, jstring Filename, char *pFilename, jboolean bProgressive, NCSFileViewSetInfo *pNCSFileViewSetInfo, NCSFileView *pNCSFileView){
323
	NCSError nError;
324
		
325
	if (bProgressive) {
326
		nError = NCScbmOpenFileView((char *)pFilename, &pNCSFileView, NCSJNIRefreshCallback);
327
	}
328
	else {
329
		nError = NCScbmOpenFileView((char *)pFilename, &pNCSFileView, NULL);
330
	}
331

  
332

  
333
	if (NCS_FAILED(nError)) {
334
		// Return the short filename, since people dont like diplaying the full ecwp url
335
		char	*pProtocol, *pHost, *pECWFilename, *pShortFileName;
336
		int		nProtocolLength, nHostLength, nFilenameLength;
337

  
338
		NCSecwNetBreakdownUrl((char *)pFilename, &pProtocol, &nProtocolLength,
339
									 &pHost, &nHostLength,
340
									 &pECWFilename, &nFilenameLength);
341

  
342
		if (pECWFilename && nFilenameLength > 0 && (strstr(pECWFilename, "/") || strstr(pECWFilename, "\\")))
343
		{
344
			int len = strlen(pECWFilename), index = 0;
345
			for (index=len; index > 0; index--)
346
			{
347
				pShortFileName = &pECWFilename[index];
348
				if (pECWFilename[index] == '\\' || pECWFilename[index] == '/')
349
				{
350
					pShortFileName ++;
351
					break;
352
				}
353
			}
354
		}
355
		else 
356
		{
357
			pShortFileName = (char *)pFilename;
358
		}
359
		
360
		NCSFormatErrorText(NCS_FILE_OPEN_FAILED, pShortFileName, NCSGetLastErrorText(nError));
361
		return NCS_FILE_OPEN_FAILED;
362
	}
363
	else {
364
		NCSJNIInfo *pJNIInfo = NULL;
365
		char *pMimeType = NULL;
366
		NCSFileViewFileInfo	*pNCSFileInfo = NULL;
367
		
368
		nError = NCSCreateJNIInfoStruct(pEnv, (*JNCSFile), pNCSFileView, &pJNIInfo);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff