Search in sources :

Example 1 with Consumes

use of org.polymap.core.data.pipeline.Consumes 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 Consumes

use of org.polymap.core.data.pipeline.Consumes 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 Consumes

use of org.polymap.core.data.pipeline.Consumes 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 Consumes

use of org.polymap.core.data.pipeline.Consumes 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 Consumes

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

the class ImageDecodeProcessor method decodeImageResponse.

/**
 * Collect enoded image chunks.
 */
@Produces(ImageResponse.class)
@Consumes(EncodedImageResponse.class)
public void decodeImageResponse(EncodedImageResponse response, ProcessorContext context) throws Exception {
    ByteArrayOutputStream data = (ByteArrayOutputStream) context.get("data");
    if (data == null) {
        data = new ByteArrayOutputStream(64 * 1024);
        context.put("data", data);
    }
    data.write(response.getChunk(), 0, response.getChunkSize());
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Produces(org.polymap.core.data.pipeline.Produces) Consumes(org.polymap.core.data.pipeline.Consumes)

Aggregations

Consumes (org.polymap.core.data.pipeline.Consumes)5 Produces (org.polymap.core.data.pipeline.Produces)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 BufferedImage (java.awt.image.BufferedImage)2 Image (java.awt.Image)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 EncodedImageResponse (org.polymap.core.data.image.EncodedImageResponse)1 ImageEncodeProcessor (org.polymap.core.data.image.ImageEncodeProcessor)1 ImageResponse (org.polymap.core.data.image.ImageResponse)1 ChunkedResponseOutputStream (org.polymap.core.data.util.ChunkedResponseOutputStream)1 Timer (org.polymap.core.runtime.Timer)1