Revision 6317 org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.legend/org.gvsig.raster.lib.legend.impl/src/main/java/org/gvsig/raster/lib/legend/impl/DefaultColorInterpretation.java

View differences:

DefaultColorInterpretation.java
27 27
    public static final String PERSISTENCE_DESCRIPTION =
28 28
        "Persitence color interpretation definition description";
29 29

  
30
    private static final String COLOR_INTERPRETATION_PERSISTENCE_FIELD = "colorInterpertation";
30
    private static final String COLOR_INTERPRETATION_PERSISTENCE_FIELD = "colorInterpretation";
31 31

  
32 32
    private String[] colorInterpretation = null;
33 33

  
......
40 40

  
41 41
    /**
42 42
     *
43
     * @param colorInterpretations
43
     * @param bandColorInterpretations
44 44
     */
45
    public DefaultColorInterpretation(String[] colorInterpretations) {
45
    public DefaultColorInterpretation(String[] bandColorInterpretations) {
46 46

  
47
        for (int i = 0; i < colorInterpretations.length; i++) {
48
            if (!isColorInterpretationValid(colorInterpretations[i])) {
47
        for (int i = 0; i < bandColorInterpretations.length; i++) {
48
            if (!isColorInterpretationValid(bandColorInterpretations[i])) {
49 49
                throw new IllegalArgumentException(String.format(
50
                    "%1s color interpretation is not valid", colorInterpretations[i]));
50
                    "%1s color interpretation is not valid", bandColorInterpretations[i]));
51 51
            }
52 52
        }
53 53

  
54
        this.colorInterpretation = new String[colorInterpretations.length];
55
        System.arraycopy(colorInterpretations, 0, this.colorInterpretation, 0,
54
        this.colorInterpretation = new String[bandColorInterpretations.length];
55
        System.arraycopy(bandColorInterpretations, 0, this.colorInterpretation, 0,
56 56
            this.colorInterpretation.length);
57 57
    }
58 58

  
......
69 69
    }
70 70

  
71 71
    /**
72
     * @param colorInterpretation
72
     * @param bandColorInterpretation
73 73
     */
74
    public DefaultColorInterpretation(String colorInterpretation) {
74
    public DefaultColorInterpretation(String bandColorInterpretation) {
75 75

  
76
        if (colorInterpretation.equals(RGB)) {
76
        if (bandColorInterpretation.equals(RGB)) {
77 77
            this.colorInterpretation = new String[] { RED_BAND, GREEN_BAND, BLUE_BAND };
78
        } else if (colorInterpretation.equals(BGR)) {
78
        } else if (bandColorInterpretation.equals(BGR)) {
79 79
            this.colorInterpretation = new String[] { BLUE_BAND, GREEN_BAND, RED_BAND };
80
        } else if (colorInterpretation.equals(ARGB)) {
80
        } else if (bandColorInterpretation.equals(ARGB)) {
81 81
            this.colorInterpretation = new String[] { RED_BAND, GREEN_BAND, BLUE_BAND, ALPHA_BAND };
82
        } else if (colorInterpretation.equals(GRAYSCALE)) {
82
        } else if (bandColorInterpretation.equals(GRAYSCALE)) {
83 83
            this.colorInterpretation = new String[] { GRAY_BAND };
84
        }else if (colorInterpretation.equals(PALETTE)) {
84
        }else if (bandColorInterpretation.equals(PALETTE)) {
85 85
            this.colorInterpretation = new String[] { PALETTE_BAND };
86
        }else if (colorInterpretation.equals(HSL)) {
86
        }else if (bandColorInterpretation.equals(HSL)) {
87 87
            this.colorInterpretation = new String[] { HUE_BAND, SATURATION_BAND, LIGHTNESS_BAND };
88
        }else if (colorInterpretation.equals(CMYK)) {
88
        }else if (bandColorInterpretation.equals(CMYK)) {
89 89
            this.colorInterpretation = new String[] { CYAN_BAND, MAGENTA_BAND, YELLOW_BAND, BLACK_BAND };
90
        }else if (colorInterpretation.equals(YCBCR)) {
90
        }else if (bandColorInterpretation.equals(YCBCR)) {
91 91
            this.colorInterpretation = new String[] { YCBCR_Y_BAND, YCBCR_CB_BAND, YCBCR_CR_BAND };
92 92
        }
93 93

  
......
116 116
        return this.colorInterpretation.length;
117 117
    }
118 118

  
119
    private boolean isColorInterpretationValid(String colorInterpretation) {
120
        if (colorInterpretation.equals(RED_BAND)
121
            || colorInterpretation.equals(GREEN_BAND)
122
            || colorInterpretation.equals(BLUE_BAND)
123
            || colorInterpretation.equals(GRAY_BAND)
124
            || colorInterpretation.equals(PALETTE_BAND)
125
            || colorInterpretation.equals(HUE_BAND)
126
            || colorInterpretation.equals(SATURATION_BAND)
127
            || colorInterpretation.equals(LIGHTNESS_BAND)
128
            || colorInterpretation.equals(CYAN_BAND)
129
            || colorInterpretation.equals(MAGENTA_BAND)
130
            || colorInterpretation.equals(YELLOW_BAND)
131
            || colorInterpretation.equals(BLACK_BAND)
132
            || colorInterpretation.equals(YCBCR_Y_BAND)
133
            || colorInterpretation.equals(YCBCR_CB_BAND)
134
            || colorInterpretation.equals(YCBCR_CR_BAND)
135
            || colorInterpretation.equals(RED_BLUE_BAND)
136
            || colorInterpretation.equals(RED_GREEN_BAND)
137
            || colorInterpretation.equals(GREEN_BLUE_BAND)
138
            || colorInterpretation.equals(ALPHA_BAND)) {
119
    private boolean isColorInterpretationValid(String bandColorInterpretation) {
120
        if (bandColorInterpretation.equals(RED_BAND)
121
            || bandColorInterpretation.equals(GREEN_BAND)
122
            || bandColorInterpretation.equals(BLUE_BAND)
123
            || bandColorInterpretation.equals(GRAY_BAND)
124
            || bandColorInterpretation.equals(PALETTE_BAND)
125
            || bandColorInterpretation.equals(HUE_BAND)
126
            || bandColorInterpretation.equals(SATURATION_BAND)
127
            || bandColorInterpretation.equals(LIGHTNESS_BAND)
128
            || bandColorInterpretation.equals(CYAN_BAND)
129
            || bandColorInterpretation.equals(MAGENTA_BAND)
130
            || bandColorInterpretation.equals(YELLOW_BAND)
131
            || bandColorInterpretation.equals(BLACK_BAND)
132
            || bandColorInterpretation.equals(YCBCR_Y_BAND)
133
            || bandColorInterpretation.equals(YCBCR_CB_BAND)
134
            || bandColorInterpretation.equals(YCBCR_CR_BAND)
135
//            || colorInterpretation.equals(RED_BLUE_BAND)
136
//            || colorInterpretation.equals(RED_GREEN_BAND)
137
//            || colorInterpretation.equals(GREEN_BLUE_BAND)
138
            || bandColorInterpretation.equals(ALPHA_BAND)) {
139 139
            return true;
140 140
        }
141 141
        return false;
......
150 150
            if (colorInterpretation[i].equals(RED_BAND)
151 151
                || colorInterpretation[i].equals(GREEN_BAND)
152 152
                || colorInterpretation[i].equals(BLUE_BAND)
153
                || colorInterpretation[i].equals(RED_GREEN_BAND)
154
                || colorInterpretation[i].equals(RED_BLUE_BAND)
155
                || colorInterpretation[i].equals(GREEN_BLUE_BAND)
153
//                || colorInterpretation[i].equals(RED_GREEN_BAND)
154
//                || colorInterpretation[i].equals(RED_BLUE_BAND)
155
//                || colorInterpretation[i].equals(GREEN_BLUE_BAND)
156 156
                || colorInterpretation[i].equals(PALETTE_BAND)
157 157
                || colorInterpretation[i].equals(HUE_BAND)
158 158
                || colorInterpretation[i].equals(SATURATION_BAND)
......
231 231
    @Override
232 232
    public boolean isRGBA() {
233 233
        if (colorInterpretation != null) {
234
            if (colorInterpretation.length == 4 && isInterpretationDefinedAsColor(0)
235
                && isInterpretationDefinedAsColor(1) && isInterpretationDefinedAsColor(2)
236
                && isAlphaInterpretation(3)) {
234
            if (colorInterpretation.length == 4 && colorInterpretation[0] == RED_BAND
235
                && colorInterpretation[1] == GREEN_BAND && colorInterpretation[2] == BLUE_BAND
236
                && colorInterpretation[3] == ALPHA_BAND) {
237 237
                return true;
238 238
            }
239 239
        }
......
256 256
        return false;
257 257
    }
258 258

  
259
    private boolean isInterpretationDefinedAsColor(int band) {
260
        return isColorInterpretation(band)
261
            || isGrayInterpretation(band)
262
            || isPaletteInterpretation(band);
263
    }
264

  
265 259
    @Override
266 260
    public boolean isColorInterpretation(int band) {
267 261
        return colorInterpretation[band].equals(RED_BAND)
......
355 349

  
356 350
    }
357 351

  
358
    @Override
359
    public int[] buildRenderBands() {
360
        if (colorInterpretation == null) {
361
            return null;
362
        }
363
        int[] renderBands = new int[] { -1, -1, -1, -1 };
364
        for (int i = 0; i < colorInterpretation.length; i++) {
365
            if (colorInterpretation[i].equals(RED_BAND)) {
366
                renderBands[0] = i;
367
            }
368
            if (colorInterpretation[i].equals(GREEN_BAND)) {
369
                renderBands[1] = i;
370
            }
371
            if (colorInterpretation[i].equals(BLUE_BAND)) {
372
                renderBands[2] = i;
373
            }
374
            if (colorInterpretation[i].equals(ALPHA_BAND)) {
375
                renderBands[3] = i;
376
            }
377
            if (colorInterpretation[i].equals(GRAY_BAND)||colorInterpretation[i].equals(PALETTE_BAND)) {
378
                renderBands[0] = renderBands[1] = renderBands[2] = i;
379
            }
380
            if (colorInterpretation[i].equals(RED_GREEN_BAND)) {
381
                renderBands[0] = renderBands[1] = i;
382
            }
383
            if (colorInterpretation[i].equals(RED_BLUE_BAND)) {
384
                renderBands[0] = renderBands[2] = i;
385
            }
386
            if (colorInterpretation[i].equals(GREEN_BLUE_BAND)) {
387
                renderBands[1] = renderBands[2] = i;
388
            }
389
            //HLS
390
            if (colorInterpretation[i].equals(HUE_BAND)) {
391
                renderBands[0] = i;
392
            }
393
            if (colorInterpretation[i].equals(SATURATION_BAND)) {
394
                renderBands[1] = i;
395
            }
396
            if (colorInterpretation[i].equals(LIGHTNESS_BAND)) {
397
                renderBands[2] = i;
398
            }
399
            //CMYK
400
            if (colorInterpretation[i].equals(CYAN_BAND)) {
401
                renderBands[0] = i;
402
            }
403
            if (colorInterpretation[i].equals(MAGENTA_BAND)) {
404
                renderBands[1] = i;
405
            }
406
            if (colorInterpretation[i].equals(YELLOW_BAND)) {
407
                renderBands[2] = i;
408
            }
409
            if (colorInterpretation[i].equals(BLACK_BAND)) {
410
                renderBands[3] = i;
411
            }
412
            //YCBCR
413
            if (colorInterpretation[i].equals(YCBCR_Y_BAND)) {
414
                renderBands[0] = i;
415
            }
416
            if (colorInterpretation[i].equals(YCBCR_CB_BAND)) {
417
                renderBands[1] = i;
418
            }
419
            if (colorInterpretation[i].equals(YCBCR_CR_BAND)) {
420
                renderBands[2] = i;
421
            }
422
        }
423
        return renderBands;
424
    }
425

  
426 352
    public static void registerDefinition() {
427 353
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
428 354
        DynStruct definition = manager.getDefinition(PERSISTENCE_DEFINITION);

Also available in: Unified diff