Revision 2669 branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/io/raster/LinearEnhancementImageFilter.java

View differences:

LinearEnhancementImageFilter.java
1 1
/*
2 2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 * 
4
 * Copyright (C) 2004-5. 
5 3
 *
4
 * Copyright (C) 2004-5.
5
 *
6 6
 * This program is free software; you can redistribute it and/or
7 7
 * modify it under the terms of the GNU General Public License
8 8
 * as published by the Free Software Foundation; either version 2
......
18 18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19 19
 *
20 20
 * For more information, contact:
21
 * 
21
 *
22 22
 * cresques@gmail.com
23 23
 */
24 24
package org.cresques.io.raster;
......
26 26
import java.awt.Image;
27 27
import java.awt.image.BufferedImage;
28 28

  
29

  
29 30
/**
30 31
 * Realzado Lineal (Amplitude Rescaling) para objetos Image.
31 32
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
32 33
 * @author Nacho Brodin (brodin_ign@gva.es)
33 34
 */
34
public 	class LinearEnhancementImageFilter extends LinearEnhancementFilter {
35
	
36
	/**
37
	 * Constructor
38
	 */
39
	public LinearEnhancementImageFilter(){
40
		super();
41
	}
42
	
43
	/* (non-Javadoc)
44
	 * @see org.cresques.io.raster.IRasterFilter#pre()
45
	 */
46
	public void pre(){
47
		//Obtenci?n de par?metros
48
		this.image = (Image)params.get("raster");
49
		this.stats = (RasterStats)params.get("stats");
50
		this.removeExtrema = ((Boolean)params.get("remove")).booleanValue();
51
		this.filename = (String)params.get("filename");
52
		height = image.getHeight(null);
53
		width = image.getWidth(null);
54
		super.pre();
55
	}
56
	
57
	/* (non-Javadoc)
58
	 * @see org.cresques.io.raster.IRasterFilter#process(int, int)
59
	 */
60
	public void process(int x, int y) {
61
		int pt = ((BufferedImage) image).getRGB(x,y);
62
		int []px4 = {
63
			((pt & 0xff000000) >> 24) & 0xff, ((pt & 0xff0000) >> 16) & 0xff,
64
			((pt & 0xff00) >> 8) & 0xff, pt & 0xff};
65
			
66
		for (int i=0; i<3; i++) {
67
			if (px4[i+1] > maxBandValue[i])
68
				px4[i+1] = maxBandValue[i];
69
			else if (px4[i+1] < minBandValue[i] )
70
					px4[i+1] = minBandValue[i];
71
			px4[i+1] = (((int) (((double)px4[i+1])*scale[i] + offset[i])) & 0xff);
72
		}
73
		((BufferedImage) image).setRGB(x,y, (
74
			(px4[0] << 24) & 0xff000000 | (px4[1] << 16) & 0xff0000 |
75
			(px4[2] << 8)  & 0xff00 | (px4[3] & 0xff) ));
76
	}
77
	
78
	/* (non-Javadoc)
79
	 * @see org.cresques.io.raster.IRasterFilter#getResult(java.lang.String)
80
	 */
81
	public Object getResult(String name) {
82
		if(name.equals("raster"))
83
			return (Object)this.image;
84
		else 
85
			return null;
86
	}
87
	
88
	/* (non-Javadoc)
89
	 * @see org.cresques.io.raster.IRasterFilter#getInRasterDataType()
90
	 */
91
	public int getInRasterDataType(){
92
		return RasterBuf.TYPE_IMAGE;
93
	}
94
	
95
	/* (non-Javadoc)
96
	 * @see org.cresques.io.raster.IRasterFilter#getOutRasterDataType()
97
	 */
98
	public int getOutRasterDataType(){
99
		return RasterBuf.TYPE_IMAGE;
100
	}
101
	
102
	/* (non-Javadoc)
103
	 * @see org.cresques.io.raster.IRasterFilter#post()
104
	 */
105
	public void post(){};
106
	
107
	/* (non-Javadoc)
108
	 * @see org.cresques.io.raster.RasterFilter#processLine(int)
109
	 */
110
	public void processLine(int y){};
111
}
35
public class LinearEnhancementImageFilter extends LinearEnhancementFilter {
36
    /**
37
     * Constructor
38
     */
39
    public LinearEnhancementImageFilter() {
40
        super();
41
    }
112 42

  
43
    /* (non-Javadoc)
44
     * @see org.cresques.io.raster.IRasterFilter#pre()
45
     */
46
    public void pre() {
47
        //Obtenci?n de par?metros
48
        this.image = (Image) params.get("raster");
49
        this.stats = (RasterStats) params.get("stats");
50
        this.removeExtrema = ((Boolean) params.get("remove")).booleanValue();
51
        this.filename = (String) params.get("filename");
52
        height = image.getHeight(null);
53
        width = image.getWidth(null);
54
        super.pre();
55
    }
113 56

  
57
    /* (non-Javadoc)
58
     * @see org.cresques.io.raster.IRasterFilter#process(int, int)
59
     */
60
    public void process(int x, int y) {
61
        int pt = ((BufferedImage) image).getRGB(x, y);
62
        int[] px4 = {
63
                        ((pt & 0xff000000) >> 24) & 0xff,
64
                        ((pt & 0xff0000) >> 16) & 0xff,
65
                        ((pt & 0xff00) >> 8) & 0xff, pt & 0xff
66
                    };
67

  
68
        for (int i = 0; i < 3; i++) {
69
            if (px4[i + 1] > maxBandValue[i]) {
70
                px4[i + 1] = maxBandValue[i];
71
            } else if (px4[i + 1] < minBandValue[i]) {
72
                px4[i + 1] = minBandValue[i];
73
            }
74

  
75
            px4[i + 1] = (((int) ((((double) px4[i + 1]) * scale[i]) +
76
                         offset[i])) & 0xff);
77
        }
78

  
79
        ((BufferedImage) image).setRGB(x, y,
80
                                       (((px4[0] << 24) & 0xff000000) |
81
                                       ((px4[1] << 16) & 0xff0000) |
82
                                       ((px4[2] << 8) & 0xff00) |
83
                                       (px4[3] & 0xff)));
84
    }
85

  
86
    /* (non-Javadoc)
87
     * @see org.cresques.io.raster.IRasterFilter#getResult(java.lang.String)
88
     */
89
    public Object getResult(String name) {
90
        if (name.equals("raster")) {
91
            return (Object) this.image;
92
        } else {
93
            return null;
94
        }
95
    }
96

  
97
    /* (non-Javadoc)
98
     * @see org.cresques.io.raster.IRasterFilter#getInRasterDataType()
99
     */
100
    public int getInRasterDataType() {
101
        return RasterBuf.TYPE_IMAGE;
102
    }
103

  
104
    /* (non-Javadoc)
105
     * @see org.cresques.io.raster.IRasterFilter#getOutRasterDataType()
106
     */
107
    public int getOutRasterDataType() {
108
        return RasterBuf.TYPE_IMAGE;
109
    }
110

  
111
    /* (non-Javadoc)
112
     * @see org.cresques.io.raster.IRasterFilter#post()
113
     */
114
    public void post() {
115
    }
116

  
117
    /* (non-Javadoc)
118
     * @see org.cresques.io.raster.RasterFilter#processLine(int)
119
     */
120
    public void processLine(int y) {
121
    }
122
}

Also available in: Unified diff