Statistics
| Revision:

gvsig-raster / 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 / DefaultRasterLegend.java @ 6701

History | View | Annotate | Download (47.5 KB)

1
package org.gvsig.raster.lib.legend.impl;
2

    
3
import java.awt.Graphics;
4
import java.awt.Image;
5
import java.awt.geom.AffineTransform;
6
import java.awt.geom.NoninvertibleTransformException;
7
import java.awt.image.BufferedImage;
8

    
9
import org.cresques.cts.ICoordTrans;
10
import org.slf4j.Logger;
11
import org.slf4j.LoggerFactory;
12

    
13
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
14
import org.gvsig.fmap.geom.GeometryLocator;
15
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
16
import org.gvsig.fmap.geom.exception.CreateGeometryException;
17
import org.gvsig.fmap.geom.primitive.Envelope;
18
import org.gvsig.fmap.geom.primitive.Point;
19
import org.gvsig.fmap.mapcontext.ViewPort;
20
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
21
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener;
22
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
23
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
24
import org.gvsig.raster.lib.buffer.api.Band;
25
import org.gvsig.raster.lib.buffer.api.Buffer;
26
import org.gvsig.raster.lib.buffer.api.FilterList;
27
import org.gvsig.raster.lib.buffer.api.NoData;
28
import org.gvsig.raster.lib.buffer.api.exceptions.BufferException;
29
import org.gvsig.raster.lib.buffer.api.statistics.Statistics;
30
import org.gvsig.raster.lib.legend.api.ColorInterpretation;
31
import org.gvsig.raster.lib.legend.api.ColorTable;
32
import org.gvsig.raster.lib.legend.api.RasterLegend;
33
import org.gvsig.raster.lib.legend.api.Transparency;
34
import org.gvsig.tools.ToolsLocator;
35
import org.gvsig.tools.dispose.DisposeUtils;
36
import org.gvsig.tools.dynobject.DynStruct;
37
import org.gvsig.tools.locator.LocatorException;
38
import org.gvsig.tools.persistence.PersistenceManager;
39
import org.gvsig.tools.persistence.PersistentState;
40
import org.gvsig.tools.persistence.exception.PersistenceException;
41
import org.gvsig.tools.task.SimpleTaskStatus;
42
import org.gvsig.tools.task.TaskStatusManager;
43

    
44
/**
45
 * Default implementation of {@link RasterLegend}. This object can draw buffers
46
 * with a {@link ColorInterpretation}, {@link ColorTable} and {@link FilterList}
47
 *
48
 *
49
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
50
 *
51
 */
52
public class DefaultRasterLegend implements RasterLegend {
53

    
54
    private static final Logger LOG = LoggerFactory.getLogger(DefaultRasterLegend.class);
55

    
56
    private ColorInterpretation colorInterpretation;
57
    private ColorTable colorTable;
58
    private Transparency transparency;
59
    private FilterList filters;
60
    private boolean transparentNoData;
61

    
62
    /**
63
     * Persistence definition name
64
     */
65
    public static final String PERSISTENT_NAME = "RasterLegendPersistence";
66
    /**
67
     * Description of persistence definition
68
     */
69
    public static final String PERSISTENT_DESCRIPTION = "Persistence definition of raster legend";
70

    
71
    private final static String COLOR_TABLE_PERSISTENCE_FIELD = "colorTable";
72
    private final static String COLOR_INTERPRETATION_PERSISTENCE_FIELD = "colorInterpretation";
73
    private final static String FILTERS_PERSISTENCE_FIELD = "filters";
74

    
75
    /**
76
     * Empty constructor
77
     */
78
    public DefaultRasterLegend() {
79

    
80
    }
81

    
82
    /**
83
     * Default {@link RasterLegend} constructor
84
     *
85
     * @param colorInterpretation
86
     *            Color interpretation of legend
87
     */
88
    public DefaultRasterLegend(ColorInterpretation colorInterpretation) {
89
        this.colorInterpretation = colorInterpretation;
90
    }
91

    
92
    /**
93
     * Default {@link RasterLegend} constructor
94
     *
95
     * @param colorTable
96
     *            Color table of legend
97
     * @param colorInterpretation
98
     *            Color interpretation of legend
99
     * @param transparency
100
     *            Transparency of legend
101
     * @param filters
102
     *            Filters of legend
103
     */
104
    public DefaultRasterLegend(ColorInterpretation colorInterpretation, ColorTable colorTable,
105
        Transparency transparency, FilterList filters) {
106
        this.colorInterpretation = colorInterpretation;
107
        this.colorTable = colorTable;
108
        this.transparency = transparency;
109
        this.filters = filters;
110
    }
111

    
112
    @Override
113
    public void draw(Graphics graphics, Buffer buffer, ViewPort viewPort,
114
        SimpleTaskStatus taskStatus) {
115

    
116
        boolean isMyTask = false;
117
        if (taskStatus == null) {
118
            TaskStatusManager taskStatusManager = ToolsLocator.getTaskStatusManager();
119
            taskStatus =
120
                taskStatusManager.createDefaultSimpleTaskStatus("_drawing_buffer_XxellipsisxX");
121
            taskStatus.setAutoremove(true);
122
            taskStatus.add();
123
            isMyTask = true;
124
        } else {
125
            taskStatus.push();
126
        }
127

    
128
        taskStatus.setIndeterminate();
129

    
130
        if (this.colorInterpretation == null || !this.colorInterpretation.hasInterpretation()
131
            || this.colorInterpretation.isUndefined()) {
132
            taskStatus.abort();
133
            throw new IllegalStateException(
134
                "To draw buffer, raster legend has to have a color interpretation");
135
        }
136

    
137
        if ((this.colorInterpretation.isRGB() || this.colorInterpretation.isBGR() || this.colorInterpretation
138
            .isRGBA()|| this.colorInterpretation.isGray() || this.colorInterpretation.hasAnyRGBBand()) && this.colorTable != null) {
139
            taskStatus.abort();
140
            throw new IllegalStateException(
141
                "If color interpretation is RGB, RGBA or BGR, raster legend can not have a color table");
142
        }
143

    
144
        // Check if viewport projection is the same as buffer projection
145
        Buffer clip = null;
146
        Buffer interpolated = null;
147
        Buffer converted = null;
148
        Buffer interpolated2 = null;
149
        Buffer bufferToDraw = buffer;
150
        try {
151
            if (bufferToDraw != null && bufferToDraw.getColumns()>0 && bufferToDraw.getRows()>0) {
152

    
153
                if (!viewPort.getProjection().equals(bufferToDraw.getProjection())) {
154

    
155
                    // Convert extension to check if envelopes intersect
156
                    ICoordTrans coordTrans = viewPort.getProjection().getCT(bufferToDraw.getProjection());
157
                    ICoordTrans invertedCoordTrans = bufferToDraw.getProjection().getCT(viewPort.getProjection());
158
                    Envelope convertedEnvelope = viewPort.getAdjustedEnvelope().convert(coordTrans);
159
                    double viewPortPixelSizeX = viewPort.getAdjustedEnvelope().getLength(0) / viewPort.getImageWidth();
160
                    double viewPortPixelSizeY = viewPort.getAdjustedEnvelope().getLength(1) / viewPort.getImageHeight();
161
                    if (!convertedEnvelope.intersects(bufferToDraw.getEnvelope())) {
162
                        return;
163
                    }
164
                    try {
165
                        // Clip buffer with doubled converted envelope
166
                        clip = bufferToDraw.clip(convertedEnvelope);
167
                        Envelope bufferEnvelopeInViewPortCoords = clip.getEnvelope().convert(invertedCoordTrans);
168

    
169
                        double widthPixel = bufferEnvelopeInViewPortCoords.getLength(0) / viewPortPixelSizeX;
170
                        double heightPixel = bufferEnvelopeInViewPortCoords.getLength(1) / viewPortPixelSizeY;
171

    
172
                        interpolated =
173
                            clip.createInterpolated((int) Math.floor(heightPixel), (int) Math.floor(widthPixel),
174
                                Buffer.INTERPOLATION_NearestNeighbour, taskStatus);
175
                        // Convert interpolated clipped buffer
176
                        converted = interpolated.convert(invertedCoordTrans, taskStatus);
177

    
178
                        widthPixel = getWidthPixel(converted.getEnvelope(), viewPortPixelSizeX);
179
                        heightPixel = getHeightPixel(converted.getEnvelope(), viewPortPixelSizeY);
180

    
181
                        interpolated2 =
182
                            converted.createInterpolated((int) Math.floor(heightPixel), (int) Math.floor(widthPixel),
183
                                Buffer.INTERPOLATION_NearestNeighbour, taskStatus);
184

    
185
                        bufferToDraw = interpolated2;
186

    
187
                    } catch (BufferException | LocatorException | CreateEnvelopeException e) {
188
                        LOG.warn("Buffer can not be clipped, converted or interpolated", e);
189
                        taskStatus.abort();
190
                        return;
191
                    }
192
                } else if (viewPort.getAdjustedEnvelope().intersects(bufferToDraw.getEnvelope())) {
193

    
194
                    double widthPixel = 0;
195
                    double heightPixel = 0;
196
                    try {
197
                        // Clip and interpolate buffer with view port envelope
198
                        if (!bufferToDraw.getEnvelope().equals(viewPort.getAdjustedEnvelope())) {
199
                            clip = bufferToDraw.clip(viewPort.getAdjustedEnvelope());
200
                            bufferToDraw = clip;
201
                        }
202
                        widthPixel =
203
                            getWidthPixel(bufferToDraw.getEnvelope(), viewPort.getAdjustedEnvelope().getLength(0)
204
                                / viewPort.getImageWidth());
205
                        heightPixel =
206
                            getHeightPixel(bufferToDraw.getEnvelope(), viewPort.getAdjustedEnvelope().getLength(1)
207
                                / viewPort.getImageHeight());
208

    
209
                        interpolated =
210
                            bufferToDraw.createInterpolated((int) Math.floor(heightPixel),
211
                                (int) Math.floor(widthPixel), Buffer.INTERPOLATION_NearestNeighbour, taskStatus);
212
                        bufferToDraw = interpolated;
213
                    } catch (BufferException e) {
214
                        LOG.warn(
215
                            "Buffer can not be interpolated with [rows: {} , columns: {}, method: {}]",
216
                            new String[] { String.valueOf((int) Math.floor(heightPixel)),
217
                                String.valueOf((int) Math.floor(widthPixel)),
218
                                String.valueOf(Buffer.INTERPOLATION_NearestNeighbour) });
219
                        taskStatus.abort();
220
                        return;
221
                    }
222
                } else {
223
                    // Do nothing view port envelope does not intersect with
224
                    // buffer
225
                    return;
226
                }
227
            }
228

    
229
            if (bufferToDraw != null && bufferToDraw.getColumns()>0 && bufferToDraw.getRows()>0) {
230

    
231
                // Draw buffer
232
                Image image = null;
233
                if (this.colorInterpretation.hasAnyGrayBand()) {
234
                    // Draw buffer with gray scale
235
                    image = drawGrayBuffer(graphics, bufferToDraw, transparency, filters);
236
                } else if (this.colorInterpretation.hasAnyPaletteBand() && this.colorTable != null) {
237
                    // Draw buffer with table color
238
                    image = drawPaletteBuffer(graphics, bufferToDraw, colorTable, transparency, filters);
239
//                } else if (this.colorInterpretation.isRGBA() || this.colorInterpretation.isRGB()
240
//                    || this.colorInterpretation.isBGR() || this.colorInterpretation.hasRGBBands()) {
241
                } else if (this.colorInterpretation.hasAnyRGBBand()) {
242
                    // Draw RGB, RGBA or BGR buffer without color table
243
                    image = drawRGBBuffer(graphics, bufferToDraw, colorInterpretation, transparency, filters);
244
                } else if (this.colorInterpretation.hasAnyHSLBand()) {
245
                    // Draw HSL buffer without color table
246
                    image = drawHSLBuffer(graphics, bufferToDraw, colorInterpretation, transparency, filters);
247
                } else if (this.colorInterpretation.hasAnyCMYKBand()) {
248
                    // Draw CMYK buffer without color table
249
                    image = drawCMYKBuffer(graphics, bufferToDraw, colorInterpretation, transparency, filters);
250
                } else if (this.colorInterpretation.hasAnyYCBCRBand()) {
251
                    // Draw YCBCR buffer without color table
252
                    image = drawYCBCRBuffer(graphics, bufferToDraw, colorInterpretation, transparency, filters);
253
                }
254

    
255
                // Calculate where image has to be drawn
256
                double x = bufferToDraw.getEnvelope().getMinimum(0);
257
                double y = bufferToDraw.getEnvelope().getMaximum(1);
258
                AffineTransform affineTransform =
259
                    calculateAffineTransform(viewPort.getAdjustedEnvelope(), viewPort.getImageWidth(),
260
                        viewPort.getImageHeight());
261

    
262
                Point point;
263
                try {
264
                    point = GeometryLocator.getGeometryManager().createPoint(x, y, SUBTYPES.GEOM2D);
265
                    point.transform(affineTransform.createInverse());
266
                    graphics.drawImage(image, (int) Math.floor(point.getX()), (int) Math.floor(point.getY()), null);
267
                } catch (CreateGeometryException | NoninvertibleTransformException e) {
268
                    LOG.warn("Can not calculate the point of buffer in viewport image", e);
269
                    taskStatus.abort();
270
                    return;
271
                }
272
            }
273
        } catch (LocatorException | CreateEnvelopeException e1) {
274
            LOG.warn("Can not calculate the envelope of buffer", e1);
275
            taskStatus.abort();
276
            return;
277
        } finally {
278
            if (clip != null) {
279
                DisposeUtils.dispose(clip);
280
                clip = null;
281
            }
282
            if (interpolated != null) {
283
                DisposeUtils.dispose(interpolated);
284
                interpolated = null;
285
            }
286
            if (converted != null) {
287
                DisposeUtils.dispose(converted);
288
                converted = null;
289
            }
290
            if (interpolated2 != null) {
291
                DisposeUtils.dispose(interpolated2);
292
                interpolated2 = null;
293
            }
294
            if (bufferToDraw == null && bufferToDraw != buffer) {
295
                DisposeUtils.dispose(bufferToDraw);
296
                bufferToDraw = null;
297
            }
298

    
299
            if (!isMyTask) {
300
                taskStatus.pop();
301
            }
302
        }
303
    }
304

    
305
    private AffineTransform calculateAffineTransform(Envelope envelope, double imageWidth,
306
        double imageHeight) {
307
        double pixelSizeX = envelope.getLength(0) / imageWidth;
308
        double rotationX = 0;
309
        double x = envelope.getMinimum(0);
310
        double rotationY = 0;
311
        double pixelSizeY = -envelope.getLength(1) / imageHeight;
312
        double y = envelope.getMaximum(1);
313
        return new AffineTransform(pixelSizeX, rotationY, rotationX, pixelSizeY, x, y);
314
    }
315

    
316
    private double getWidthPixel(Envelope envelope, double dist1pixel) {
317
        double widthEnvelope = envelope.getLength(0);
318
        return widthEnvelope / dist1pixel;
319
    }
320

    
321
    private double getHeightPixel(Envelope envelope, double dist1pixel) {
322
        double heightEnvelope = envelope.getLength(1);
323
        return heightEnvelope / dist1pixel;
324
    }
325

    
326

    
327

    
328
    private Image drawRGBBuffer(Graphics graphics, Buffer buffer,
329
        ColorInterpretation colorInterpretation, Transparency transparency, FilterList filters) {
330

    
331
        BufferedImage image = null;
332

    
333
        if (colorInterpretation.isRGB() || colorInterpretation.isRGBA() || colorInterpretation.hasAnyRGBBand()) {
334
            image =
335
                new BufferedImage(buffer.getColumns(), buffer.getRows(),
336
                    BufferedImage.TYPE_INT_ARGB);
337
        } else if (colorInterpretation.isBGR()) {
338
            image =
339
                new BufferedImage(buffer.getColumns(), buffer.getRows(), BufferedImage.TYPE_INT_BGR);
340
        }
341

    
342
        if (image == null) {
343
            throw new IllegalStateException(
344
                "Color interpretation is not RGB,RGBA or BGR and buffer was be drawn without color table");
345
        }
346

    
347
        int redBandIndex = colorInterpretation.getBand(ColorInterpretation.RED_BAND);
348
        int greenBandIndex = colorInterpretation.getBand(ColorInterpretation.GREEN_BAND);
349
        int blueBandIndex = colorInterpretation.getBand(ColorInterpretation.BLUE_BAND);
350

    
351
        Band redBand = null;
352
        if(redBandIndex>=0){
353
            redBand = buffer.getBand(redBandIndex);
354
        }
355
        Band greenBand = null;
356
        if(greenBandIndex>=0){
357
            greenBand = buffer.getBand(greenBandIndex);
358
        }
359
        Band blueBand = null;
360
        if(blueBandIndex>=0){
361
            blueBand = buffer.getBand(blueBandIndex);
362
        }
363
        Band alphaBand = null;
364
        if (colorInterpretation.hasAlphaBand()) {
365
            int alphaBandIndex =
366
                colorInterpretation.getBand(ColorInterpretation.ALPHA_BAND);
367
            alphaBand = buffer.getBand(alphaBandIndex);
368
        }
369
//        Statistics statistics = buffer.getStatistics(null);
370
//        double[] max = statistics.getMax(); //Para pruebas con el rango de cada banda
371
//        double[] min = statistics.getMin(); //Para pruebas con el rango de cada banda
372
//        double maximum = statistics.getMaximun();  //Para pruebas con el rango conjunto de todas las bandas
373
//        double minimum = statistics.getMinimun(); //Para pruebas con el rango conjunto de todas las bandas
374

    
375

    
376
        for (int i = 0; i < buffer.getRows(); i++) {
377
            for (int j = 0; j < buffer.getColumns(); j++) {
378
//                Number redValue = (Number) redBand.get(i, j);
379
//                Number greenValue = (Number) greenBand.get(i, j);
380
//                Number blueValue = (Number) blueBand.get(i, j);
381

    
382
                /*FIXME:
383
                 * Aqu? necesitamos pasar los valores originales de la capa al rango de valores del tipo byte.
384
                 * Para hacer esto tendr?amos varias opciones:
385
                 *
386
                 * 1.- Como hace el raster viejo, una conversi?n lineal entre el rango de valores de la capa [MIN, MAX]
387
                 *     y el rango de valores de tipo byte [0 - 255] para lo cual necesitar?amos llamar aqu? a las estad?sticas.
388
                 *
389
                 * 2.- Una conversi?n lineal entre el rango de valores del tipo del Number concreto (p. ej. Short [-32768 - 32767],
390
                 *     Int [-2^31 - 2^31-1], etc...) y el rango de valores de tipo byte [0 - 255], pero cuando los valores
391
                 *     fueran relativamente peque?os se concentrar?an todos en el 0 y la capa saldr?a completamente negra.
392
                 *
393
                 * 3.- Una conversi?n logaritmica entre el rango de valores del tipo del Number concreto (p. ej. Short [-32768 - 32767],
394
                 *     Int [-2^31 - 2^31-1], etc...) y el rango de valores de tipo byte [0 - 255], esto evitar?a la
395
                 *     concentraci?n de la mayor?a de valores en el 0.
396
                 *
397
                 * 4.- Y una mejor opci?n ser?a la conversi?n (linear o logaritm?tca, por decidir) entre el rango de valores
398
                 *     del "sensor" con el que se han tomado los datos y el rango de valores de tipo byte [0 - 255], pero
399
                 *     , por lo menos por ahora, no tenemos informaci?n sobre el sensor.
400
                 *
401
                 * Hago pruebas de las tres primeras opciones, comentarizando dos y dejando activa la otra,
402
                 * pero es algo a pensar con detenimiento.
403
                 */
404

    
405
                int alphaByteValue = 255;
406
                int redByteValue = 0;
407
                if(redBand!=null){
408
                    Number redValue = (Number) redBand.get(i, j);
409
                    NoData noData = redBand.getNoData();
410
                    if(noData != null){
411
                        if(redValue.equals(noData.getValue())){
412
                            alphaByteValue = 0;
413
                            redByteValue = 0;
414
                        } else {
415
                            alphaByteValue = 255;
416
                            redByteValue = logarithmicConversionToByteRange(redValue);
417
                        }
418
                    } else {
419
                        redByteValue = logarithmicConversionToByteRange(redValue);
420
                    }
421
//                byte redByteValue = logarithmicConversionToByte(redValue,max[redBandIndex]);
422
//                byte redByteValue = linearConversionToByte(redValue);
423
//                    redByteValue = proportionalConversionToByte(redValue, max[redBandIndex], min[redBandIndex]);
424
//                byte redByteValue = proportionalConversionToByte(redValue, maximum, minimum); //1
425
                }
426
                int greenByteValue = 0;
427
                if(greenBand!=null){
428
                    Number greenValue = (Number) greenBand.get(i, j);
429
                    NoData noData = greenBand.getNoData();
430
                    if(noData != null){
431
                        if(greenValue.equals(noData.getValue())){
432
                            alphaByteValue = 0;
433
                            greenByteValue = 0;
434
                        } else {
435
                            alphaByteValue = 255;
436
                            greenByteValue = logarithmicConversionToByteRange(greenValue);
437
                        }
438
                    } else {
439
                        greenByteValue = logarithmicConversionToByteRange(greenValue);
440
                    }
441
//                byte greenByteValue = logarithmicConversionToByte(greenValue,max[greenBandIndex]);
442
//                byte greenByteValue = linearConversionToByte(greenValue);
443
//                    greenByteValue = proportionalConversionToByte(greenValue, max[greenBandIndex], min[greenBandIndex]);
444
//                byte greenByteValue = proportionalConversionToByte(greenValue, maximum, minimum);
445
                }
446
                int blueByteValue = 0;
447
                if(blueBand!=null){
448
                    Number blueValue = (Number) blueBand.get(i, j);
449
                    NoData noData = blueBand.getNoData();
450
                    if(noData != null){
451
                        if(blueValue.equals(noData.getValue())){
452
                            alphaByteValue = 0;
453
                            blueByteValue = 0;
454
                        } else {
455
                            alphaByteValue = 255;
456
                            blueByteValue = logarithmicConversionToByteRange(blueValue);
457
                        }
458
                    } else {
459
                        blueByteValue = logarithmicConversionToByteRange(blueValue);
460
                    }
461

    
462

    
463
//                byte blueByteValue = logarithmicConversionToByte(blueValue,max[blueBandIndex]);
464
//                byte blueByteValue = linearConversionToByte(blueValue);
465
//                    blueByteValue = proportionalConversionToByte(blueValue, max[blueBandIndex], min[blueBandIndex]);
466
//                byte blueByteValue = proportionalConversionToByte(blueValue, maximum, minimum);
467
                }
468

    
469

    
470
                if (alphaByteValue!=0 && alphaBand != null) {
471
                    Number alphaValue = (Number) alphaBand.get(i, j);
472
                    int alphaBandIndex = colorInterpretation.getBand(ColorInterpretation.ALPHA_BAND);
473
//                    alphaByteValue = logarithmicConversionToByte(alphaValue);
474
                    NoData noData = alphaBand.getNoData();
475
                    if(noData != null){
476
                        if(alphaValue.equals(noData.getValue())){
477
                            alphaByteValue = 0;
478
                        } else {
479
                            alphaByteValue = logarithmicConversionToByteRange(alphaValue);
480
                        }
481
                    } else {
482
                        alphaByteValue = logarithmicConversionToByteRange(alphaValue);
483
                    }
484

    
485
//                    alphaByteValue = logarithmicConversionToByte(alphaValue,max[alphaBandIndex]);
486
//                    alphaByteValue = linearConversionToByte(alphaValue);
487
//                    alphaByteValue = proportionalConversionToByte(alphaValue, max[alphaBandIndex], min[alphaBandIndex]);
488
//                    alphaByteValue = proportionalConversionToByte(alphaValue, maximum, minimum);
489
//                    LOG.info("alphaValue = "+alphaValue+ " alphaByteValue = "+alphaByteValue);
490
                }
491

    
492
                if (alphaByteValue!=0 && transparency != null) {
493
                    // Apply defined transparency ranges
494

    
495
                    int newAlpha =
496
                        transparency.getTransparencyRangeAlpha(redByteValue,
497
                            greenByteValue, blueByteValue);
498
                    alphaByteValue = getNewAlpha(alphaByteValue, newAlpha);
499

    
500
                    // Apply general transparency
501
                    int transparencyValue = transparency.getAlpha();
502
                    alphaByteValue = getNewAlpha(alphaByteValue, transparencyValue);
503
                }
504

    
505
                if (filters != null) {
506
                    // TODO Apply filters
507
                }
508

    
509
                int intRGB = 0;
510
                if (colorInterpretation.hasAnyRGBBand()) {//colorInterpretation.isRGB() || colorInterpretation.isRGBA()) {
511
                    intRGB = (((byte)alphaByteValue & 0xFF) << 24) | // alpha
512
                        (((byte)redByteValue & 0xFF) << 16) | // red
513
                        (((byte)greenByteValue & 0xFF) << 8) | // green
514
                        (((byte)blueByteValue & 0xFF)); // blue String.format("%X", b)
515
//                    intRGB = ((alphaByteValue & 0xFF) << 24) | // alpha
516
//                        ((redByteValue & 0xFF) << 16) | // red
517
//                        ((greenByteValue & 0xFF) << 8) | // green
518
//                        ((blueByteValue & 0xFF) << 0); // blue String.format("%X", b)
519
                } else if (colorInterpretation.isBGR()) {
520
                    intRGB = (((byte)blueByteValue & 0xFF) << 16 | // blue
521
                        (((byte)greenByteValue & 0xFF) << 8) | // green
522
                        (((byte)redByteValue & 0xFF))); // red
523

    
524
                }
525
                image.setRGB(j, i, intRGB);
526
            }
527
        }
528
        return image;
529
    }
530

    
531
    /**
532
     * Conversi?n logaritmica de los valores del dominio de entrada a valores del dominio de BYTE
533
     * para poder ser representados en RGB.
534
     *
535
     * @param n
536
     * @return
537
     */
538
    private int logarithmicConversionToByteRange(Number n) {
539
        int b = 0;
540
        if (n instanceof Byte) {
541
            b = n.byteValue();
542
            if(b<0){
543
                b=256+b;
544
            }
545
        } else if (n instanceof Short) {
546
            // Because Math.log(Short.MAX_VALUE-Short.MIN_VALUE)/Math.log(256) = 2;
547
            b = (new Double(Math.round(Math.pow(n.shortValue(), 1d / 2d)))).intValue();
548
        } else if (n instanceof Integer) {
549
            // Because
550
            // Math.log(Integer.MAX_VALUE/256-Integer.MIN_VALUE/256)/Math.log(256) = 4;
551
            b = (new Double(Math.round(Math.pow(n.intValue(), 1d / 4d)))).intValue();
552
        } else if (n instanceof Float) {
553
            // Because Math.log(Float.MAX_VALUE-Float.MIN_VALUE)/Math.log(256) = 16;
554
            double root = 16d; // Math.log(Float.MAX_VALUE-Float.MIN_VALUE)/Math.log(256);
555
            b = (new Double(Math.round(Math.pow(n.floatValue(), 1d / root)))).intValue();
556
        } else if (n instanceof Double) {
557
            // Because Math.log(Double.MAX_VALUE-Double.MIN_VALUE)/Math.log(256) = 128;
558
            double root = 128d;
559
            b = (new Double(Math.round(Math.pow(n.doubleValue(), 1d / root)))).intValue();
560
        }
561
        return b;
562
    }
563

    
564
    /**
565
     * Conversi?n logaritmica de los valores del dominio de entrada a valores del dominio de BYTE
566
     * para poder ser representados en RGB.
567
     * Aplica un factor de correcci?n que depende de los valores de entrada.
568
     *
569
     * @param n
570
     * @param max
571
     * @return
572
     */
573
    private int logarithmicConversionToByteRange(Number n, double max) {
574
        int b = 0;
575
        if (n instanceof Byte) {
576
            b = n.byteValue();
577
            if(b<0){
578
                b=256+b;
579
            }
580
        } else if (n instanceof Short) {
581
            short value = n.shortValue();
582
            double factor = Short.MAX_VALUE / max;
583
            // Because Math.log(Short.MAX_VALUE-Short.MIN_VALUE)/Math.log(256) = 2;
584
            double root = 2d;
585
            b = (new Double(Math.round(Math.pow(value, 1d / root)*factor))).intValue();
586
        } else if (n instanceof Integer) {
587
            int value = n.intValue();
588
            double factor = Integer.MAX_VALUE / max;
589
            // Because Math.log(Integer.MAX_VALUE/256-Integer.MIN_VALUE/256)/Math.log(256) = 4;
590
            double root = 4d;
591
            b = (new Double(Math.round(Math.pow(value, 1d / root)*factor))).intValue();
592
        } else if (n instanceof Float) {
593
            float value = n.floatValue();
594
            double factor = Float.MAX_VALUE / max;
595
            // Because Math.log(Float.MAX_VALUE-Float.MIN_VALUE)/Math.log(256) = 16;
596
            double root = 16d;
597
            b = (new Double(Math.round(Math.pow(value, 1d / root)*factor))).intValue();
598
        } else if (n instanceof Double) {
599
            double value = n.doubleValue();
600
            double factor = Double.MAX_VALUE / max;
601
            // Because Math.log(Double.MAX_VALUE-Double.MIN_VALUE)/Math.log(256) = 128;
602
            double root = 128d;
603
            b = (new Double(Math.round(Math.pow(value, 1d / root)*factor))).intValue();
604
        }
605
        return b;
606
    }
607

    
608
    /**
609
     * Conversi?n lineal de los valores del dominio de entrada a valores del dominio de BYTE
610
     * para poder ser representados en RGB.
611
     *
612
     * @param n
613
     * @return
614
     */
615
    private int linearConversionToByteRange(Number n){
616
        int b=0;
617
        if(n instanceof Byte){
618
            b = n.byteValue();
619
            if(b<0){
620
                b=256+b;
621
            }
622

    
623
        } else if(n instanceof Short){
624
            // 65536/256 = 256
625
            b = (new Double(n.shortValue()/256)).intValue();
626
        } else if(n instanceof Integer){
627
            //  (Integer.MAX_VALUE-Integer.MIN_VALUE)/256 = 16777215
628
            b = (new Double(n.intValue()/16777215)).intValue();
629
        } else if(n instanceof Float){
630
            //  (Float.MAX_VALUE-Float.MIN_VALUE)/256 = 1.3292279E36
631
            b = (new Double(n.floatValue()/1.3292279E36)).intValue();
632
        } else if(n instanceof Double){
633
            //  (Double.MAX_VALUE-Double.MIN_VALUE)/256 = 7.022238808055921E305;
634
            b = (new Double(n.doubleValue()/7.022238808055921E305)).intValue();
635
        }
636
        return b;
637
    }
638

    
639
    /**
640
     * Conversi?n lineal de los valores de entrada a valores del dominio de BYTE
641
     * para poder ser representados en RGB.
642
     * Depende del rango de valores del buffer a representar.
643
     *
644
     * @param n
645
     * @param maximum
646
     * @param minimum
647
     * @return
648
     */
649
    private int proportionalConversionToByteRange(Number n, double maximum, double minimum){
650
        int b=0;
651
        double ratio = (maximum-minimum)/256;
652
        if(n instanceof Byte){
653
            b = n.byteValue();
654
            if(b<0){
655
                b=256+b;
656
            }
657
        } else if(n instanceof Short){
658
            // 65536/256 = 256
659
            b = (new Double((n.shortValue()-minimum)/ratio)).intValue();
660
        } else if(n instanceof Integer){
661
            //  (Integer.MAX_VALUE-Integer.MIN_VALUE)/256 = 16777215
662
            b = (new Double((n.intValue()-minimum)/ratio)).intValue();
663
        } else if(n instanceof Float){
664
            //  (Float.MAX_VALUE-Float.MIN_VALUE)/256 = 1.3292279E36
665
            b = (new Double((n.floatValue()-minimum)/ratio)).intValue();
666
        } else if(n instanceof Double){
667
            //  (Double.MAX_VALUE-Double.MIN_VALUE)/256 = 7.022238808055921E305;
668
            b = (new Double((n.doubleValue()-minimum)/ratio)).intValue();
669
        }
670
        return b;
671
    }
672

    
673

    
674
    private Image drawHSLBuffer(Graphics graphics, Buffer buffer,
675
        ColorInterpretation colorInterpretation,Transparency transparency,
676
        FilterList filters) {
677

    
678
        BufferedImage image = null;
679

    
680
        image =
681
            new BufferedImage(buffer.getColumns(), buffer.getRows(),
682
                BufferedImage.TYPE_INT_ARGB);
683

    
684
        int hueBandIndex = colorInterpretation.getBand(ColorInterpretation.HUE_BAND);
685
        int saturationBandIndex = colorInterpretation.getBand(ColorInterpretation.SATURATION_BAND);
686
        int lightBandIndex = colorInterpretation.getBand(ColorInterpretation.LIGHTNESS_BAND);
687

    
688

    
689
        Band hueBand = buffer.getBand(hueBandIndex);
690
        Band saturationBand = buffer.getBand(saturationBandIndex);
691
        Band lightBand = buffer.getBand(lightBandIndex);
692

    
693

    
694
        for (int i = 0; i < buffer.getRows(); i++) {
695
            for (int j = 0; j < buffer.getColumns(); j++) {
696
                Number hueValue = (Number) hueBand.get(i, j);
697
                Number saturationValue = (Number) saturationBand.get(i, j);
698
                Number lightValue = (Number) lightBand.get(i, j);
699

    
700
                Number[] rgbaValues=ColorUtils.fromHSLtoRGBA(hueValue.floatValue(), saturationValue.floatValue(), lightValue.floatValue());
701

    
702
                Integer alphaValue =rgbaValues[3].intValue();
703
                if (transparency != null) {
704
                    // Apply defined transparency ranges
705

    
706
                    alphaValue = alphaValue.byteValue() & 0xFF;
707
                    int newAlpha =
708
                        transparency.getTransparencyRangeAlpha(rgbaValues[0].byteValue(),
709
                            rgbaValues[1].byteValue(), rgbaValues[2].byteValue());
710
                    alphaValue = getNewAlpha(alphaValue.intValue(), newAlpha);
711

    
712
                    // Apply general transparency
713
                    int transparencyValue = transparency.getAlpha();
714
                    alphaValue = getNewAlpha(alphaValue.intValue(), transparencyValue);
715
                }
716

    
717
                if (filters != null) {
718
                    // TODO Apply filters
719
                }
720

    
721
                int intRGB = 0;
722
                intRGB = ((alphaValue.byteValue() & 0xFF) << 24) | // alpha
723
                    ((rgbaValues[0].byteValue() & 0xFF) << 16) | // red
724
                    ((rgbaValues[1].byteValue() & 0xFF) << 8) | // green
725
                    ((rgbaValues[2].byteValue() & 0xFF) << 0); // blue
726
                image.setRGB(j, i, intRGB);
727
            }
728
        }
729
        return image;
730
    }
731

    
732
    private Image drawCMYKBuffer(Graphics graphics, Buffer buffer,
733
        ColorInterpretation colorInterpretation,Transparency transparency,
734
        FilterList filters) {
735

    
736
        BufferedImage image = null;
737

    
738
        image =
739
            new BufferedImage(buffer.getColumns(), buffer.getRows(),
740
                BufferedImage.TYPE_INT_ARGB);
741

    
742
        int cyanBandIndex = colorInterpretation.getBand(ColorInterpretation.CYAN_BAND);
743
        int magentaBandIndex = colorInterpretation.getBand(ColorInterpretation.MAGENTA_BAND);
744
        int yellowBandIndex = colorInterpretation.getBand(ColorInterpretation.YELLOW_BAND);
745
        int blackBandIndex = colorInterpretation.getBand(ColorInterpretation.BLACK_BAND);
746

    
747

    
748
        Band cyanBand = buffer.getBand(cyanBandIndex);
749
        Band magentaBand = buffer.getBand(magentaBandIndex);
750
        Band yellowBand = buffer.getBand(yellowBandIndex);
751
        Band blackBand = buffer.getBand(blackBandIndex);
752

    
753
        for (int i = 0; i < buffer.getRows(); i++) {
754
            for (int j = 0; j < buffer.getColumns(); j++) {
755
                Number cyanValue = (Number) cyanBand.get(i, j);
756
                Number magentaValue = (Number) magentaBand.get(i, j);
757
                Number yellowValue = (Number) yellowBand.get(i, j);
758
                Number blackValue = (Number) blackBand.get(i, j);
759

    
760

    
761

    
762
                Number[] rgbValues=ColorUtils.fromCMYKtoRGB(
763
                    cyanValue.floatValue(),
764
                    magentaValue.floatValue(),
765
                    yellowValue.floatValue(),
766
                    blackValue.floatValue()
767
                    );
768

    
769
                Integer alphaValue =255;
770
                if (transparency != null) {
771
                    // Apply defined transparency ranges
772

    
773
                    alphaValue = alphaValue.byteValue() & 0xFF;
774
                    int newAlpha =
775
                        transparency.getTransparencyRangeAlpha(rgbValues[0].byteValue(),
776
                            rgbValues[1].byteValue(), rgbValues[2].byteValue());
777
                    alphaValue = getNewAlpha(alphaValue.intValue(), newAlpha);
778

    
779
                    // Apply general transparency
780
                    int transparencyValue = transparency.getAlpha();
781
                    alphaValue = getNewAlpha(alphaValue.intValue(), transparencyValue);
782
                }
783

    
784
                if (filters != null) {
785
                    // TODO Apply filters
786
                }
787

    
788
                int intRGB = 0;
789
                intRGB = ((alphaValue.byteValue() & 0xFF) << 24) | // alpha
790
                    ((rgbValues[0].byteValue() & 0xFF) << 16) | // red
791
                    ((rgbValues[1].byteValue() & 0xFF) << 8) | // green
792
                    ((rgbValues[2].byteValue() & 0xFF) << 0); // blue
793
                image.setRGB(j, i, intRGB);
794
            }
795
        }
796
        return image;
797
    }
798

    
799
    private Image drawYCBCRBuffer(Graphics graphics, Buffer buffer,
800
        ColorInterpretation colorInterpretation,Transparency transparency,
801
        FilterList filters) {
802

    
803
        BufferedImage image = null;
804

    
805
        image =
806
            new BufferedImage(buffer.getColumns(), buffer.getRows(),
807
                BufferedImage.TYPE_INT_ARGB);
808

    
809
        int yIndex = colorInterpretation.getBand(ColorInterpretation.YCBCR_Y_BAND);
810
        int cbBandIndex = colorInterpretation.getBand(ColorInterpretation.YCBCR_CB_BAND);
811
        int crBandIndex = colorInterpretation.getBand(ColorInterpretation.YCBCR_CR_BAND);
812

    
813

    
814
        Band yBand = buffer.getBand(yIndex);
815
        Band cbBand = buffer.getBand(cbBandIndex);
816
        Band crBand = buffer.getBand(crBandIndex);
817

    
818
        for (int i = 0; i < buffer.getRows(); i++) {
819
            for (int j = 0; j < buffer.getColumns(); j++) {
820
                Number yValue = (Number) yBand.get(i, j);
821
                Number cbValue = (Number) cbBand.get(i, j);
822
                Number crValue = (Number) crBand.get(i, j);
823

    
824
                Number[] rgbValues=ColorUtils.fromYCBCRtoRGB(
825
                    yValue.floatValue(),
826
                    cbValue.floatValue(),
827
                    crValue.floatValue()
828
                    );
829

    
830
                Integer alphaValue =255;
831
                if (transparency != null) {
832
                    // Apply defined transparency ranges
833

    
834
                    alphaValue = alphaValue.byteValue() & 0xFF;
835
                    int newAlpha =
836
                        transparency.getTransparencyRangeAlpha(rgbValues[0].byteValue(),
837
                            rgbValues[1].byteValue(), rgbValues[2].byteValue());
838
                    alphaValue = getNewAlpha(alphaValue.intValue(), newAlpha);
839

    
840
                    // Apply general transparency
841
                    int transparencyValue = transparency.getAlpha();
842
                    alphaValue = getNewAlpha(alphaValue.intValue(), transparencyValue);
843
                }
844

    
845
                if (filters != null) {
846
                    // TODO Apply filters
847
                }
848

    
849
                int intRGB = 0;
850
                intRGB = ((alphaValue.byteValue() & 0xFF) << 24) | // alpha
851
                    ((rgbValues[0].byteValue() & 0xFF) << 16) | // red
852
                    ((rgbValues[1].byteValue() & 0xFF) << 8) | // green
853
                    ((rgbValues[2].byteValue() & 0xFF) << 0); // blue
854
                image.setRGB(j, i, intRGB);
855
            }
856
        }
857
        return image;
858
    }
859

    
860
    /**
861
     * Method to draw gray buffers
862
     * @param graphics
863
     * @param buffer
864
     * @param filters
865
     * @return
866
     */
867
    private Image drawGrayBuffer(Graphics graphics, Buffer buffer, Transparency transparency, FilterList filters) {
868

    
869
        BufferedImage image = null;
870

    
871
        image =
872
            new BufferedImage(buffer.getColumns(), buffer.getRows(), BufferedImage.TYPE_INT_ARGB);
873

    
874
        Band greyBand = buffer.getBand(0);
875

    
876
        Statistics statistics = buffer.getStatistics(null);
877
//        double maximum = statistics.getMaximun();// ver drawRGBBuffer
878
//        double minimum = statistics.getMinimun();
879

    
880

    
881
        for (int i = 0; i < buffer.getRows(); i++) {
882
            for (int j = 0; j < buffer.getColumns(); j++) {
883
                int greyByteValue = 0;
884
                int alphaByteValue = (byte)255;
885
                Number greyValue = (Number) greyBand.get(i, j);
886
                NoData noData = greyBand.getNoData();
887
                if(noData != null){
888
                    if(greyValue.equals(noData.getValue())){
889
                        alphaByteValue = 0;
890
                        greyByteValue = 0;
891
                    } else {
892
                        alphaByteValue = 255;
893
                        greyByteValue = logarithmicConversionToByteRange(greyValue);
894
                    }
895
                } else {
896
                    greyByteValue = logarithmicConversionToByteRange(greyValue);
897
                }
898
//                byte greyByteValue = linearConversionToByte(greyValue);
899
//                byte greyByteValue = proportionalConversionToByte(greyValue, maximum, minimum); // 1
900
//                byte greyByteValue = logarithmicConversionToByte(greyValue);
901
//                byte greyByteValue = logarithmicConversionToByte(greyValue, maximum);
902

    
903
                if (alphaByteValue != 0 && transparency != null) {
904
                    // Apply defined transparency ranges
905

    
906
//                    alphaByteValue = alphaValue.byteValue() & 0xFF;
907
                    int newAlpha = transparency.getTransparencyRangeAlpha(greyByteValue, greyByteValue, greyByteValue);
908
                    alphaByteValue = getNewAlpha(alphaByteValue, newAlpha);
909

    
910
                    // Apply general transparency
911
                    int transparencyValue = transparency.getAlpha();
912
                    alphaByteValue = getNewAlpha(alphaByteValue, transparencyValue);
913
                }
914

    
915
                if (filters != null) {
916
                    // TODO Apply filters
917
                }
918

    
919
                int intARGB = (((byte)alphaByteValue & 0xFF) << 24) | // alpha
920
                    (((byte)greyByteValue & 0xFF)<< 16) | // red
921
                    (((byte)greyByteValue & 0xFF)<< 8) | // green
922
                    (((byte)greyByteValue & 0xFF)); // blue
923

    
924
                image.setRGB(j, i, intARGB);
925
            }
926
        }
927
        return image;
928
    }
929

    
930
    private Image drawPaletteBuffer(Graphics graphics, Buffer buffer, ColorTable colorTable,
931
        Transparency transparency, FilterList filters) {
932

    
933
        BufferedImage image =
934
            new BufferedImage(buffer.getColumns(), buffer.getRows(), BufferedImage.TYPE_INT_ARGB);
935

    
936
        for (int i = 0; i < buffer.getRows(); i++) {
937
            for (int j = 0; j < buffer.getColumns(); j++) {
938

    
939
                Object value = buffer.getBand(0).get(i, j);
940
                byte[] rgba = colorTable.getRGBA(value);
941

    
942
                if (transparency != null) {
943
                    // Apply defined transparency ranges
944
                    int alpha = rgba[3] & 0xFF;
945
                    int newAlpha =
946
                        transparency.getTransparencyRangeAlpha(rgba[0], rgba[1], rgba[2]);
947
                    alpha = getNewAlpha(alpha, newAlpha);
948

    
949
                    // Apply general transparency
950
                    int transparencyValue = transparency.getAlpha();
951
                    rgba[3] = (byte) getNewAlpha(alpha, transparencyValue);
952
                }
953

    
954
                if (filters != null) {
955
                    // TODO Apply filters
956
                }
957

    
958
                int intARGB = ((rgba[3] & 0xFF) << 24) | // alpha
959
                    ((rgba[0] & 0xFF) << 16) | // red
960
                    ((rgba[1] & 0xFF) << 8) | // green
961
                    ((rgba[2] & 0xFF) << 0); // blue
962

    
963
                image.setRGB(j, i, intARGB);
964
            }
965
        }
966
        return image;
967
    }
968

    
969
    private int getNewAlpha(int alpha, int newAlpha) {
970
//        if(alpha<0){
971
//            alpha = 256+alpha;
972
//        }
973
//        if(newAlpha<0){
974
//            newAlpha = 256+newAlpha;
975
//        }
976
        return (int) Math.round(alpha * (newAlpha / 255d));
977
    }
978

    
979
    public ColorTable getColorTable() {
980
        return this.colorTable;
981
    }
982

    
983
    @Override
984
    public void setColorTable(ColorTable colorTable) {
985
        ColorInterpretation colorInterpretation = this.getColorInterpretation();
986

    
987
        if (colorInterpretation != null
988
            && (colorInterpretation.isRGB() || colorInterpretation.isBGR() || colorInterpretation
989
                .isRGBA())) {
990
            throw new IllegalArgumentException(
991
                "Can not set color table when color interpretation is RGB, BGR or RGBA");
992
        }
993

    
994
        this.colorTable = colorTable;
995
    }
996

    
997
    @Override
998
    public ColorInterpretation getColorInterpretation() {
999
        return this.colorInterpretation;
1000
    }
1001

    
1002
    @Override
1003
    public void setColorInterpretation(ColorInterpretation colorInterpretation) {
1004

    
1005
        if (this.colorTable != null
1006
            && (colorInterpretation.isRGB() || colorInterpretation.isBGR() || colorInterpretation
1007
                .isRGBA())) {
1008
            throw new IllegalArgumentException(
1009
                "Can not set color interpreation RGB, RGBA or BGR if legend has a color table specifed");
1010
        }
1011

    
1012
        this.colorInterpretation = colorInterpretation;
1013
    }
1014

    
1015
    @Override
1016
    public FilterList getFilters() {
1017
        return this.filters;
1018
    }
1019

    
1020
    @Override
1021
    public void setFilters(FilterList filterList) {
1022
        this.filters = filterList;
1023
    }
1024

    
1025
    /**
1026
     *
1027
     */
1028
    public static void registerPersistence() {
1029
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
1030
        DynStruct definition = manager.getDefinition(PERSISTENT_NAME);
1031
        if (definition == null) {
1032
            definition =
1033
                manager.addDefinition(DefaultRasterLegend.class, PERSISTENT_NAME,
1034
                    PERSISTENT_DESCRIPTION, null, null);
1035
            definition.addDynFieldObject(COLOR_TABLE_PERSISTENCE_FIELD).setMandatory(false)
1036
                .setClassOfValue(ColorTable.class);
1037
            definition.addDynFieldObject(COLOR_INTERPRETATION_PERSISTENCE_FIELD).setMandatory(false)
1038
                .setClassOfValue(ColorInterpretation.class);
1039
            definition.addDynFieldObject(FILTERS_PERSISTENCE_FIELD).setMandatory(false)
1040
                .setClassOfValue(FilterList.class);
1041
        }
1042
    }
1043

    
1044
    @Override
1045
    public void saveToState(PersistentState state) throws PersistenceException {
1046
        state.set(COLOR_TABLE_PERSISTENCE_FIELD, this.getColorTable());
1047
        state.set(COLOR_INTERPRETATION_PERSISTENCE_FIELD, this.getColorInterpretation());
1048
        state.set(FILTERS_PERSISTENCE_FIELD, this.filters);
1049
    }
1050

    
1051
    @Override
1052
    public void loadFromState(PersistentState state) throws PersistenceException {
1053
        this.setColorTable((ColorTable) state.get(COLOR_TABLE_PERSISTENCE_FIELD));
1054
        this.setColorInterpretation((ColorInterpretation) state
1055
            .get(COLOR_INTERPRETATION_PERSISTENCE_FIELD));
1056
        this.setFilters((FilterList) state.get(FILTERS_PERSISTENCE_FIELD));
1057
    }
1058

    
1059
    @Override
1060
    public void setTransparency(Transparency transparency) {
1061
        this.transparency = transparency;
1062
    }
1063

    
1064
    @Override
1065
    public Transparency getTransparency() {
1066
        return this.transparency;
1067
    }
1068

    
1069
    @Override
1070
    public ISymbol getDefaultSymbol() {
1071
        return null;
1072
    }
1073

    
1074
    @Override
1075
    public Object clone() throws CloneNotSupportedException {
1076
        // TODO Auto-generated method stub
1077
        return super.clone();
1078
    }
1079

    
1080
    @Override
1081
    public ILegend cloneLegend() {
1082
        try {
1083
            return (RasterLegend)this.clone();
1084
        } catch (Exception e) {
1085
            throw new RuntimeException("Can't clone the legend", e);
1086
        }
1087
    }
1088

    
1089
    @Override
1090
    public void addLegendListener(LegendContentsChangedListener listener) {
1091
        // TODO Auto-generated method stub
1092

    
1093
    }
1094

    
1095
    @Override
1096
    public void removeLegendListener(LegendContentsChangedListener listener) {
1097
        // TODO Auto-generated method stub
1098

    
1099
    }
1100

    
1101
    @Override
1102
    public void fireDefaultSymbolChangedEvent(SymbolLegendEvent event) {
1103
        // TODO Auto-generated method stub
1104

    
1105
    }
1106

    
1107
    @Override
1108
    public LegendContentsChangedListener[] getListeners() {
1109
        return null;
1110
    }
1111

    
1112
    @Override
1113
    public void setTransparentNoData(boolean noDataTransparent) {
1114
        this.transparentNoData=noDataTransparent;
1115

    
1116
    }
1117

    
1118
    @Override
1119
    public boolean areTransparentNoData() {
1120
        return this.transparentNoData;
1121
    }
1122

    
1123
}