Revision 9523 branches/piloto3d/libraries/libCq CMS for java.old/src/org/cresques/io/EcwFile.java
EcwFile.java | ||
---|---|---|
28 | 28 |
import java.awt.Point; |
29 | 29 |
import java.awt.image.BufferedImage; |
30 | 30 |
import java.awt.image.PixelGrabber; |
31 |
import java.io.File; |
|
32 | 31 |
|
33 | 32 |
import org.cresques.cts.ICoordTrans; |
34 | 33 |
import org.cresques.cts.IProjection; |
34 |
import org.cresques.io.data.BandList; |
|
35 |
import org.cresques.io.data.RasterBuf; |
|
36 |
import org.cresques.io.exceptions.SupersamplingNotSupportedException; |
|
35 | 37 |
import org.cresques.px.Extent; |
36 | 38 |
|
37 | 39 |
import com.ermapper.ecw.JNCSException; |
... | ... | |
82 | 84 |
private String errorMessage = null; |
83 | 85 |
private boolean multifile = false; |
84 | 86 |
private Extent v = null; |
85 |
|
|
86 | 87 |
|
87 | 88 |
// Ultimo porcentaje de refresco. Se carga en el update y se |
88 | 89 |
// actualiza en el refreshUpdate |
... | ... | |
95 | 96 |
extent = new Extent(); |
96 | 97 |
|
97 | 98 |
try { |
98 |
|
|
99 |
if (!new File(fName).exists() && !fName.startsWith("ecwp:")){ |
|
100 |
System.err.println("No se puede abrir el archivo"); |
|
101 |
return; |
|
102 |
} |
|
103 |
|
|
99 |
System.err.println("Abriendo "+fName); |
|
104 | 100 |
file = new JNCSFile(fName, false); |
105 |
load();
|
|
101 |
load();
|
|
106 | 102 |
//readGeoInfo(fName); |
107 | 103 |
bandCount = file.numBands; |
108 | 104 |
|
... | ... | |
704 | 700 |
|
705 | 701 |
image.setRGB(startX, startY, w, h, line, offset, scansize); |
706 | 702 |
} |
707 |
|
|
708 |
|
|
703 |
|
|
709 | 704 |
/* (non-Javadoc) |
710 | 705 |
* @see org.cresques.io.GeoRasterFile#updateImage(int, int, org.cresques.cts.ICoordTrans, java.awt.Image, int origBand, int destBand) |
711 | 706 |
*/ |
... | ... | |
740 | 735 |
} |
741 | 736 |
|
742 | 737 |
fullSize = new Dimension(width, height); |
743 |
|
|
738 |
|
|
744 | 739 |
ChunkFrame[] frames = ChunkFrame.computeFrames(file, v, fullSize, extent); |
745 | 740 |
|
746 | 741 |
if (frames.length == 1) { |
... | ... | |
787 | 782 |
int[] shr = new int[3]; |
788 | 783 |
boolean order = true; |
789 | 784 |
|
785 |
|
|
790 | 786 |
if (img == null) { //Caso en el que se crea un Image |
791 | 787 |
EcwFile.nUpdate = 1; |
792 | 788 |
|
... | ... | |
812 | 808 |
pRGBArray = changeBands(order, pRGBArray, mascara, shl, shr); |
813 | 809 |
setRGBLine((BufferedImage) ecwImage, f.pos.x, f.pos.y + line, f.width, 1, pRGBArray, 0, f.width); |
814 | 810 |
} |
811 |
|
|
815 | 812 |
} //Chuncks |
816 | 813 |
|
817 | 814 |
applyAlpha(ecwImage); |
818 | 815 |
|
819 | 816 |
if (frames[0].mustResize && !this.multifile) |
820 |
return resizeImageII(fullSize, ecwImage);
|
|
817 |
return resizeAndResampleImage(fullSize, ecwImage);
|
|
821 | 818 |
|
822 | 819 |
lastRefreshPercent = file.getPercentComplete(); |
823 | 820 |
|
... | ... | |
847 | 844 |
applyAlpha(img); |
848 | 845 |
|
849 | 846 |
if (frames[0].mustResize && (nUpdate == 3) && this.multifile) { |
850 |
return resizeImageII(fullSize, img); |
|
847 |
return resizeAndResampleImage(fullSize, img); |
|
848 |
}else{ |
|
849 |
isSupersampling = false; |
|
850 |
this.stepArrayX = this.stepArrayY = null; |
|
851 | 851 |
} |
852 | 852 |
|
853 | 853 |
lastRefreshPercent = file.getPercentComplete(); |
... | ... | |
875 | 875 |
return img; |
876 | 876 |
} |
877 | 877 |
|
878 |
private Image resizeImageII(Dimension sz, Image image) { |
|
878 |
/** |
|
879 |
* Esta funci?n calcula los arrays de steps en X e Y para que cuando hay supersampleo |
|
880 |
* se aplique el filtro solo a la esquina superior izquierda de cada pixel. |
|
881 |
*/ |
|
882 |
private void calcArraySteps(int width, int height, double stepX, double stepY, double offsetX, double offsetY){ |
|
883 |
isSupersampling = true; |
|
884 |
int w = (int) (Math.ceil(((double)width) * stepX) + 1); |
|
885 |
this.stepArrayX = new int[w]; |
|
886 |
for (double j = Math.abs(offsetX); j < w; j += stepX) |
|
887 |
stepArrayX[(int)(j)] ++; |
|
888 |
int h = (int) (Math.ceil(((double)height) * stepY) + 1); |
|
889 |
this.stepArrayY = new int[h]; |
|
890 |
for (double j = Math.abs(offsetY); j < h; j += stepY) |
|
891 |
stepArrayY[(int)(j)] ++; |
|
892 |
} |
|
893 |
|
|
894 |
/** |
|
895 |
* Obtiene una ventana de datos de la imagen a partir de coordenadas reales. |
|
896 |
* No aplica supersampleo ni subsampleo sino que devuelve una matriz de igual tama?o a los |
|
897 |
* pixeles de disco. |
|
898 |
* @param x Posici?n X superior izquierda |
|
899 |
* @param y Posici?n Y superior izquierda |
|
900 |
* @param w Ancho en coordenadas reales |
|
901 |
* @param h Alto en coordenadas reales |
|
902 |
* @param rasterBuf Buffer de datos |
|
903 |
* @param bandList |
|
904 |
* @return Buffer de datos |
|
905 |
*/ |
|
906 |
public RasterBuf getWindowRaster(double x, double y, double w, double h, BandList bandList, RasterBuf rasterBuf) { |
|
907 |
Extent selectedExtent = new Extent(x, y, x + w, y - h); |
|
908 |
setView(selectedExtent); |
|
909 |
int wPx = rasterBuf.getWidth(); |
|
910 |
int hPx = rasterBuf.getHeight(); |
|
911 |
try{ |
|
912 |
int[] bl = new int[3]; |
|
913 |
bl[0] = 0;bl[1] = 1;bl[2] = 2; |
|
914 |
file.setView(file.numBands, bl, selectedExtent.minX(), selectedExtent.maxY(), selectedExtent.maxX(), selectedExtent.minY(), wPx, hPx); |
|
915 |
int width = (int)((w * file.width) / extent.width()); |
|
916 |
int height = (int)((h * file.height) / extent.height()); |
|
917 |
rasterBuf = new RasterBuf(RasterBuf.TYPE_BYTE, wPx, hPx, bandList.getDrawableBandsCount(), true); |
|
918 |
|
|
919 |
int[] pRGBArray = new int[width]; |
|
920 |
for (int line = 0; line < rasterBuf.getHeight(); line++) { |
|
921 |
file.readLineRGBA(pRGBArray); |
|
922 |
for(int col = 0; col < pRGBArray.length; col ++){ |
|
923 |
rasterBuf.setElemByte(line, col, 0, (byte)(pRGBArray[col] & 0x000000ff)); |
|
924 |
rasterBuf.setElemByte(line, col, 1, (byte)((pRGBArray[col] & 0x0000ff00) >> 8)); |
|
925 |
rasterBuf.setElemByte(line, col, 2, (byte)((pRGBArray[col] & 0x00ff0000) >> 16)); |
|
926 |
} |
|
927 |
} |
|
928 |
}catch(JNCSInvalidSetViewException exc){ |
|
929 |
exc.printStackTrace(); |
|
930 |
}catch (JNCSFileNotOpenException e) { |
|
931 |
e.printStackTrace(); |
|
932 |
}catch (JNCSException ex) { |
|
933 |
ex.printStackTrace(); |
|
934 |
} |
|
935 |
|
|
936 |
return rasterBuf; |
|
937 |
} |
|
938 |
|
|
939 |
/** |
|
940 |
* Obtiene una ventana de datos de la imagen a partir de coordenadas pixel. |
|
941 |
* No aplica supersampleo ni subsampleo sino que devuelve una matriz de igual tama?o a los |
|
942 |
* pixeles de disco. |
|
943 |
* @param x Posici?n X superior izquierda |
|
944 |
* @param y Posici?n Y superior izquierda |
|
945 |
* @param w Ancho en coordenadas reales |
|
946 |
* @param h Alto en coordenadas reales |
|
947 |
* @param rasterBuf Buffer de datos |
|
948 |
* @param bandList |
|
949 |
* @return Buffer de datos |
|
950 |
*/ |
|
951 |
public RasterBuf getWindowRaster(int x, int y, int w, int h, BandList bandList, RasterBuf rasterBuf) { |
|
952 |
double initX = file.originX + ((x * extent.width()) / file.width); |
|
953 |
double initY = file.originY - ((y * extent.height()) / file.height); |
|
954 |
double width = ((w * extent.width()) / file.width); |
|
955 |
double height = ((h * extent.height()) / file.height); |
|
956 |
return getWindowRaster(initX, initY, width, height, bandList, rasterBuf); |
|
957 |
} |
|
958 |
|
|
959 |
/** |
|
960 |
* |
|
961 |
* @param sz |
|
962 |
* @param image |
|
963 |
* @return |
|
964 |
*/ |
|
965 |
private Image resizeAndResampleImage(Dimension sz, Image image) { |
|
879 | 966 |
int w = (int)sz.getWidth(); |
880 | 967 |
int h = (int)sz.getHeight(); |
881 | 968 |
Image buffImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
... | ... | |
898 | 985 |
|
899 | 986 |
double scaleW = (double)((double)(image.getWidth(null) - decr) / (double)w); |
900 | 987 |
double scaleH = (double)((double)(image.getHeight(null) - decr) / (double)h); |
988 |
this.calcArraySteps(w, h, scaleW, scaleH, offsetX, offsetY); |
|
901 | 989 |
for (int y1 = 0; y1 < h; y1++){ |
902 | 990 |
ySrc = (int) ((y1 * scaleH) + offsetY); |
903 | 991 |
for (int x1 = 0; x1 < w; x1++){ |
... | ... | |
985 | 1073 |
//TODO Nacho: Implementar getBlockSize de EcwFile |
986 | 1074 |
return 1; |
987 | 1075 |
} |
988 |
|
|
1076 |
|
|
989 | 1077 |
/** |
990 | 1078 |
* Calcula la transformaci?n que se produce sobre la vista cuando la imagen tiene un fichero .rmf |
991 | 1079 |
* asociado. En Ecw el origen de coordenadas en Y es el valor m?ximo y decrece hasta el m?nimo. |
Also available in: Unified diff