Search in sources :

Example 1 with Produces

use of org.polymap.core.data.pipeline.Produces in project polymap4-core by Polymap4.

the class ImageDecodeProcessor method endOfProcessing.

/**
 * Decode image on EOP.
 */
@Produces(EndOfProcessing.class)
@Consumes(EndOfProcessing.class)
public void endOfProcessing(EndOfProcessing eop, ProcessorContext context) throws Exception {
    long start = System.currentTimeMillis();
    ByteArrayOutputStream data = (ByteArrayOutputStream) context.get("data");
    // Image image = Toolkit.getDefaultToolkit().createImage( data.toByteArray() );
    BufferedImage image = ImageIO.read(new ByteArrayInputStream(data.toByteArray()));
    // load image data
    // new javax.swing.ImageIcon( image ).getImage();
    context.sendResponse(new ImageResponse(image));
    context.put("data", null);
    log.info("Decode: ready. (" + (System.currentTimeMillis() - start) + "ms)");
    context.sendResponse(ProcessorResponse.EOP);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedImage(java.awt.image.BufferedImage) Produces(org.polymap.core.data.pipeline.Produces) Consumes(org.polymap.core.data.pipeline.Consumes)

Example 2 with Produces

use of org.polymap.core.data.pipeline.Produces in project polymap4-core by Polymap4.

the class ImageEncodeProcessor method encodeImageResponse.

@Consumes(ImageResponse.class)
@Produces({ EncodedImageResponse.class, EndOfProcessing.class })
public void encodeImageResponse(ImageResponse response, ProcessorContext context) throws Exception {
    Timer timer = new Timer();
    // chunked reponse output stream
    ChunkedResponseOutputStream out = new ChunkedResponseOutputStream(context) {

        protected ProcessorResponse createResponse(byte[] buf, int buflen) {
            // log.debug( "sending: buflen= " + buflen );
            return new EncodedImageResponse(buf, buflen);
        }
    };
    // load image data
    // new javax.swing.ImageIcon( image ).getImage();
    String format = (String) context.get("format");
    if ("image/jpeg".equals(format)) {
        imageioEncodeJPEG(response.getImage(), out);
    } else {
        opEncodePNG(response.getImage(), out);
    }
    log.debug("encode: ready. (" + timer.elapsedTime() + "ms)");
    out.flush();
    context.sendResponse(ProcessorResponse.EOP);
    log.debug("...all data sent. (" + out.getTotalSent() + " bytes " + format + ")");
}
Also used : Timer(org.polymap.core.runtime.Timer) ChunkedResponseOutputStream(org.polymap.core.data.util.ChunkedResponseOutputStream) Consumes(org.polymap.core.data.pipeline.Consumes) Produces(org.polymap.core.data.pipeline.Produces)

Example 3 with Produces

use of org.polymap.core.data.pipeline.Produces in project polymap4-core by Polymap4.

the class ImageGrayscaleProcessor method handleEncodedImage.

// @Consumes(ImageResponse.class)
// @Produces(ImageResponse.class)
// public void handleImage( ImageResponse r, ProcessorContext context ) throws Exception {
// context.sendResponse( new ImageResponse( grayscale( r.getImage() ) ) );
// }
@Consumes(EncodedImageResponse.class)
@Produces(EncodedImageResponse.class)
public void handleEncodedImage(EncodedImageResponse r, ProcessorContext context) throws Exception {
    ByteArrayOutputStream buf = (ByteArrayOutputStream) context.get("buf");
    if (buf == null) {
        context.put("buf", buf = new ByteArrayOutputStream());
    }
    buf.write(r.getChunk(), 0, r.getChunkSize());
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Consumes(org.polymap.core.data.pipeline.Consumes) Produces(org.polymap.core.data.pipeline.Produces)

Example 4 with Produces

use of org.polymap.core.data.pipeline.Produces in project polymap4-core by Polymap4.

the class ImageGrayscaleProcessor method eop.

@Consumes({ EndOfProcessing.class })
@Produces({ EndOfProcessing.class })
public void eop(ProcessorResponse r, ProcessorContext context) throws Exception {
    ByteArrayOutputStream buf = (ByteArrayOutputStream) context.get("buf");
    if (buf != null) {
        Image image = Toolkit.getDefaultToolkit().createImage(buf.toByteArray());
        Image gray = grayscale(image);
        ImageEncodeProcessor encodeProcessor = new ImageEncodeProcessor();
        encodeProcessor.encodeImageResponse(new ImageResponse(gray), context);
    } else {
        context.sendResponse(r);
    }
}
Also used : ImageEncodeProcessor(org.polymap.core.data.image.ImageEncodeProcessor) ImageResponse(org.polymap.core.data.image.ImageResponse) EncodedImageResponse(org.polymap.core.data.image.EncodedImageResponse) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) Consumes(org.polymap.core.data.pipeline.Consumes) Produces(org.polymap.core.data.pipeline.Produces)

Example 5 with Produces

use of org.polymap.core.data.pipeline.Produces in project polymap4-core by Polymap4.

the class FeatureRenameProcessor method featuresRequest.

@Produces(GetFeaturesRequest.class)
public void featuresRequest(GetFeaturesRequest request, ProcessorContext context) throws Exception {
    Query transformed = transformQuery(request.getQuery(), context);
    context.sendRequest(new GetFeaturesRequest(transformed));
}
Also used : GetFeaturesRequest(org.polymap.core.data.feature.GetFeaturesRequest) Query(org.geotools.data.Query) Produces(org.polymap.core.data.pipeline.Produces)

Aggregations

Produces (org.polymap.core.data.pipeline.Produces)11 Consumes (org.polymap.core.data.pipeline.Consumes)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Query (org.geotools.data.Query)3 BufferedImage (java.awt.image.BufferedImage)2 GetFeatureTypeResponse (org.polymap.core.data.feature.GetFeatureTypeResponse)2 Image (java.awt.Image)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)1 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)1 Feature (org.opengis.feature.Feature)1 Property (org.opengis.feature.Property)1 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)1 GetBoundsRequest (org.polymap.core.data.feature.GetBoundsRequest)1 GetFeaturesRequest (org.polymap.core.data.feature.GetFeaturesRequest)1 GetFeaturesResponse (org.polymap.core.data.feature.GetFeaturesResponse)1 GetFeaturesSizeRequest (org.polymap.core.data.feature.GetFeaturesSizeRequest)1 EncodedImageResponse (org.polymap.core.data.image.EncodedImageResponse)1 ImageEncodeProcessor (org.polymap.core.data.image.ImageEncodeProcessor)1