public void sendImage( BufferedImage img, HttpResponseBuffer response, String format )
throws OWSException, IOException {
response.setContentType( format );
ImageSerializer serializer = imageSerializers.get( format );
if ( serializer != null ) {
serializer.serialize( null, img, response.getOutputStream() );
return;
}
format = format.substring( format.indexOf( "/" ) + 1 );
if ( format.equals( "x-ms-bmp" ) ) {
format = "bmp";
}
if ( format.equals( "png; subtype=8bit" ) || format.equals( "png; mode=8bit" ) ) {
img = ColorQuantizer.quantizeImage( img, 256, false, false );
format = "png";
}
LOG.debug( "Sending in format " + format );
if ( !write( img, format, response.getOutputStream() ) ) {
throw new OWSException( get( "WMS.CANNOT_ENCODE_IMAGE", format ), OWSException.NO_APPLICABLE_CODE );
}
}