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);
}
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 + ")");
}
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());
}
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);
}
}
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());
}
Aggregations