Revision 8601 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

View differences:

DefaultRasterLegend.java
37 37
import org.gvsig.raster.lib.buffer.api.exceptions.BufferOperationException;
38 38
import org.gvsig.raster.lib.buffer.api.operations.Operation;
39 39
import org.gvsig.raster.lib.buffer.api.operations.OperationList;
40
import org.gvsig.raster.lib.buffer.impl.operations.linearstretchenhancement.LinearStretchEnhancementOperation;
40 41
import org.gvsig.raster.lib.buffer.spi.OperationListManager;
41 42
import org.gvsig.raster.lib.legend.api.RasterLegend;
42 43
import org.gvsig.raster.lib.legend.api.Transparency;
......
248 249
                // Draw buffer
249 250
                Image image = null;
250 251
                try {
251

  
252
                    Buffer filteredBuffer = getFilters().execute(bufferToDraw);
253
                    ColorInterpretation colorInterpretationAfterFilters = (ColorInterpretation) filters.getThrownDynValue(ColorTableOperation.OUTPUT_COLOR_INTERPRETATION_PARAM);
254
                    if(colorInterpretationAfterFilters==null){
252
                    Object oColorInterpretation = null;
253
                    Buffer filteredBuffer = bufferToDraw;
254
                    filteredBuffer = getFilters().execute(bufferToDraw);
255
                    oColorInterpretation = getFilters().getThrownDynValue(ColorTableOperation.OUTPUT_COLOR_INTERPRETATION_PARAM);
256
                    ColorInterpretation colorInterpretationAfterFilters = null;
257
                    if (oColorInterpretation != null) {
258
                        colorInterpretationAfterFilters = (ColorInterpretation) oColorInterpretation;
259
                    }
260
                    if (colorInterpretationAfterFilters == null) {
255 261
                        colorInterpretationAfterFilters = colorInterpretation;
256 262
                    }
257 263

  
258
                if (colorInterpretationAfterFilters.isPalette()) {
259
                    DynObject colorTableOperationParameters = bufferManager.createOperationParameters(ColorTableOperationFactory.NAME);
260
                    colorTableOperationParameters.setDynValue(ColorTableOperation.COLOR_INTERPRETATION_PARAM, colorInterpretationAfterFilters);
261
                    colorTableOperationParameters.setDynValue(ColorTableOperation.COPY_UNPROCESSED_BANDS_PARAM, true);
262
                    Buffer rgbBuffer = bufferManager.execute(ColorTableOperationFactory.NAME, filteredBuffer, colorTableOperationParameters);
263
                    image = drawRGBBuffer(
264
                        graphics,
265
                        rgbBuffer,
266
                        (ColorInterpretation)colorTableOperationParameters.getDynValue(ColorTableOperation.OUTPUT_COLOR_INTERPRETATION_PARAM),
267
                        transparency,
268
                        filters);
264
                    if (colorInterpretationAfterFilters.isPalette()) {
265
                        DynObject colorTableOperationParameters =
266
                            bufferManager.createOperationParameters(ColorTableOperationFactory.NAME);
267
                        colorTableOperationParameters.setDynValue(ColorTableOperation.COLOR_INTERPRETATION_PARAM,
268
                            colorInterpretationAfterFilters);
269
                        colorTableOperationParameters.setDynValue(ColorTableOperation.COPY_UNPROCESSED_BANDS_PARAM,
270
                            true);
271
                        Buffer rgbBuffer =
272
                            bufferManager.execute(ColorTableOperationFactory.NAME, filteredBuffer,
273
                                colorTableOperationParameters);
274
                        image =
275
                            drawRGBBuffer(graphics, rgbBuffer,
276
                                (ColorInterpretation) colorTableOperationParameters
277
                                    .getDynValue(ColorTableOperation.OUTPUT_COLOR_INTERPRETATION_PARAM), transparency,
278
                                getFilters());
269 279

  
270
                } else if (colorInterpretationAfterFilters.hasAnyGrayBand()) {
271
                    // Draw buffer with gray scale
280
                    } else if (colorInterpretationAfterFilters.hasAnyGrayBand()) {
281
                        // Draw buffer with gray scale
272 282
                        image = drawGrayBuffer(graphics, bufferToDraw, transparency, filters);
273
//                } else if (this.colorInterpretation.isRGBA() || this.colorInterpretation.isRGB()
274
//                    || this.colorInterpretation.isBGR() || this.colorInterpretation.hasRGBBands()) {
275
                } else if (colorInterpretationAfterFilters.hasAnyRGBBand()) {
276
                    // Draw RGB, RGBA or BGR buffer without color table
277
                    image = drawRGBBuffer(graphics, filteredBuffer, colorInterpretationAfterFilters, transparency, filters);
278
                } else if (colorInterpretationAfterFilters.hasAnyHSLBand()) {
279
                    // Draw HSL buffer without color table
280
//                    image = drawHSLBuffer(graphics, bufferToDraw, colorInterpretation, transparency, filters);
283
                        // } else if (this.colorInterpretation.isRGBA() ||
284
                        // this.colorInterpretation.isRGB()
285
                        // || this.colorInterpretation.isBGR() ||
286
                        // this.colorInterpretation.hasRGBBands()) {
287
                    } else if (colorInterpretationAfterFilters.hasAnyRGBBand()) {
288
                        // Draw RGB, RGBA or BGR buffer without color table
289
                        image =
290
                            drawRGBBuffer(graphics, filteredBuffer, colorInterpretationAfterFilters, transparency,
291
                                filters);
292
                    } else if (colorInterpretationAfterFilters.hasAnyHSLBand()) {
293
                        // Draw HSL buffer without color table
294
                        // image = drawHSLBuffer(graphics, bufferToDraw,
295
                        // colorInterpretation, transparency, filters);
281 296

  
282
                    DynObject hSLToRGBOperationParameters = bufferManager.createOperationParameters(HSLToRGBOperationFactory.NAME);
283
                    hSLToRGBOperationParameters.setDynValue(HSLToRGBOperation.COLOR_INTERPRETATION_PARAM, colorInterpretationAfterFilters);
284
                    hSLToRGBOperationParameters.setDynValue(HSLToRGBOperation.COPY_UNPROCESSED_BANDS_PARAM, true);
285
                    Buffer rgbBuffer = bufferManager.execute(ColorTableOperationFactory.NAME, filteredBuffer, hSLToRGBOperationParameters);
286
                    image = drawRGBBuffer(
287
                        graphics,
288
                        rgbBuffer,
289
                        (ColorInterpretation)hSLToRGBOperationParameters.getDynValue(ColorTableOperation.OUTPUT_COLOR_INTERPRETATION_PARAM),
290
                        transparency,
291
                        filters);
297
                        DynObject hSLToRGBOperationParameters =
298
                            bufferManager.createOperationParameters(HSLToRGBOperationFactory.NAME);
299
                        hSLToRGBOperationParameters.setDynValue(HSLToRGBOperation.COLOR_INTERPRETATION_PARAM,
300
                            colorInterpretationAfterFilters);
301
                        hSLToRGBOperationParameters.setDynValue(HSLToRGBOperation.COPY_UNPROCESSED_BANDS_PARAM, true);
302
                        Buffer rgbBuffer =
303
                            bufferManager.execute(ColorTableOperationFactory.NAME, filteredBuffer,
304
                                hSLToRGBOperationParameters);
305
                        image =
306
                            drawRGBBuffer(graphics, rgbBuffer,
307
                                (ColorInterpretation) hSLToRGBOperationParameters
308
                                    .getDynValue(ColorTableOperation.OUTPUT_COLOR_INTERPRETATION_PARAM), transparency,
309
                                filters);
292 310

  
311
                    } else if (colorInterpretationAfterFilters.hasAnyCMYKBand()) {
312
                        // Draw CMYK buffer without color table
313
                        image = drawCMYKBuffer(graphics, bufferToDraw, colorInterpretation, transparency, filters);
293 314

  
294
                } else if (colorInterpretationAfterFilters.hasAnyCMYKBand()) {
295
                    // Draw CMYK buffer without color table
296
                    image = drawCMYKBuffer(graphics, bufferToDraw, colorInterpretation, transparency, filters);
315
                        DynObject cmykToRGBOperationParameters =
316
                            bufferManager.createOperationParameters(CMYKToRGBOperationFactory.NAME);
317
                        cmykToRGBOperationParameters.setDynValue(CMYKToRGBOperation.COLOR_INTERPRETATION_PARAM,
318
                            colorInterpretationAfterFilters);
319
                        cmykToRGBOperationParameters.setDynValue(CMYKToRGBOperation.COPY_UNPROCESSED_BANDS_PARAM, true);
320
                        Buffer rgbBuffer =
321
                            bufferManager.execute(ColorTableOperationFactory.NAME, filteredBuffer,
322
                                cmykToRGBOperationParameters);
323
                        image =
324
                            drawRGBBuffer(graphics, rgbBuffer,
325
                                (ColorInterpretation) cmykToRGBOperationParameters
326
                                    .getDynValue(ColorTableOperation.OUTPUT_COLOR_INTERPRETATION_PARAM), transparency,
327
                                filters);
297 328

  
298
                    DynObject cmykToRGBOperationParameters = bufferManager.createOperationParameters(CMYKToRGBOperationFactory.NAME);
299
                    cmykToRGBOperationParameters.setDynValue(CMYKToRGBOperation.COLOR_INTERPRETATION_PARAM, colorInterpretationAfterFilters);
300
                    cmykToRGBOperationParameters.setDynValue(CMYKToRGBOperation.COPY_UNPROCESSED_BANDS_PARAM, true);
301
                    Buffer rgbBuffer = bufferManager.execute(ColorTableOperationFactory.NAME, filteredBuffer, cmykToRGBOperationParameters);
302
                    image = drawRGBBuffer(
303
                        graphics,
304
                        rgbBuffer,
305
                        (ColorInterpretation)cmykToRGBOperationParameters.getDynValue(ColorTableOperation.OUTPUT_COLOR_INTERPRETATION_PARAM),
306
                        transparency,
307
                        filters);
329
                    } else if (colorInterpretationAfterFilters.hasAnyYCBCRBand()) {
330
                        // TODO: Hacer un filtro YCBCRToRGB y llamarlo como en
331
                        // los de arriba
308 332

  
309

  
310

  
311
                } else if (colorInterpretationAfterFilters.hasAnyYCBCRBand()) {
312
                    //TODO: Hacer un filtro  YCBCRToRGB y llamarlo como en los de arriba
313

  
314
                    // Draw YCBCR buffer without color table
315
                    image = drawYCBCRBuffer(graphics, bufferToDraw, colorInterpretation, transparency, filters);
316
                }
333
                        // Draw YCBCR buffer without color table
334
                        image = drawYCBCRBuffer(graphics, bufferToDraw, colorInterpretation, transparency, filters);
335
                    }
317 336
                } catch (BufferOperationException e) {
318 337
                    LOG.warn("Buffer can't be converted to byte buffer", e);
319 338
                    taskStatus.abort();
......
978 997
    private Buffer convertToByteBuffer(Buffer buffer) throws BufferOperationException {
979 998
        int[] types = buffer.getBandTypes();
980 999
        boolean mustConvert = false;
1000
        List<Integer> bandsToProcess = new ArrayList<Integer>();
981 1001
        for (int i = 0; i < types.length; i++) {
982 1002
            if(types[i]!=BufferManager.TYPE_BYTE){
1003
                bandsToProcess.add(i);
983 1004
                mustConvert = true;
984
                break;
1005
//                break;
985 1006
            }
986 1007
        }
987 1008
        if(mustConvert){
988 1009
            BufferManager bufferManager = BufferLocator.getBufferManager();
989 1010
            DynObject parameters = bufferManager.createOperationParameters("LinearStretchEnhancement");
1011
            parameters.setDynValue(LinearStretchEnhancementOperation.BANDS_TO_PROCESS_PARAM, bandsToProcess);
990 1012
//            parameters.setDynValue(LinearStretchEnhancementOperation.TAIL_TRIM_PARAM, true);
991 1013
//            parameters.setDynValue(LinearStretchEnhancementOperation.TAIL_TRIM_PERCENT_PARAM, 20.0);
992 1014
            return bufferManager.execute("LinearStretchEnhancement", buffer, parameters);
......
1085 1107
    @Override
1086 1108
    public void saveToState(PersistentState state) throws PersistenceException {
1087 1109
        state.set(COLOR_INTERPRETATION_PERSISTENCE_FIELD, this.getColorInterpretation());
1088
        state.set(FILTERS_PERSISTENCE_FIELD, this.filters);
1110
        state.set(FILTERS_PERSISTENCE_FIELD, this.getFilters());
1089 1111
    }
1090 1112

  
1091 1113
    @Override
......
1117 1139
        ColorInterpretation clonedColorInterpretation = (ColorInterpretation)this.getColorInterpretation().clone();
1118 1140
        cloned.setColorInterpretation(clonedColorInterpretation);
1119 1141
        //FIXME:
1120
        //cloned.setTransparency((Transparency)this.getTransparency().clone());
1121
        //cloned.setFilters(getFilters());
1142
//        cloned.setTransparency((Transparency)this.getTransparency().clone());
1143
//        cloned.setFilters(getFilters());
1122 1144

  
1123 1145
        return cloned;
1124 1146
    }

Also available in: Unified diff