List of usage examples for java.awt.image BufferedImage getColorModel
public ColorModel getColorModel()
From source file:petascope.wcst.transaction.executeTransaction.java
/** * Performs the action "Add", as part of the Transaction operation * * @param identifier/* w w w . j a v a2 s . c om*/ * @param references * @throws wcs.server.core.WCSTException */ private void actionAddCoverage(String identifier, List references) throws WCSTException, WCPSException, PetascopeException { log.trace("Executing action AddCoverage ..."); // Obtain the references ReferenceType pixelsRef, descRef, summRef; pixelsRef = getPixelsRef(references); descRef = getDescriptionRef(references); summRef = getSummaryRef(references); // References check. We are adding a coverage, mandatory are: pixels, description if (pixelsRef == null) { throw new WCSTException(ExceptionCode.MissingParameterValue, "Reference role='" + getUrnCode("pixels") + "'"); } if (descRef == null) { throw new WCSTException(ExceptionCode.MissingParameterValue, "Reference role='" + getUrnCode("description") + "'"); } log.trace("Loading reference: coverage pixels ..."); BufferedImage img = loadPixelsReference(pixelsRef); log.trace("Loading reference: coverage description ..."); CoverageDescriptionType desc = loadDescriptionReference(identifier, descRef); CoverageSummaryType summ = null; if (summRef != null) { log.trace("Loading reference: coverage summary ..."); summ = loadSummaryReference(summRef); } log.trace("Done loading references !"); /** * (1) Check coverage name */ boolean changeId = false; if (newCoverages.contains(identifier)) { throw new WCSTException(ExceptionCode.InvalidParameterValue, "Identifier: You cannot use the same identifier twice."); } if (metaDb.existsCoverageName(identifier)) { changeId = true; log.warn("Changing coverage identifier since coverage '" + identifier + "' already exists !"); } // Generate new coverage name ? while (changeId) { identifier = "coverage_" + Integer.toString((new Random()).nextInt()); changeId = metaDb.existsCoverageName(identifier); } /** * (2) Do the actual processing. Stores the image in rasdaman. */ try { /* Currently we only support one-band (gray-scale) images. */ if (img.getColorModel().getNumComponents() != 1) { throw new WCSTException(ExceptionCode.MultiBandImagesNotSupported, "This server currently only supports one-band images (grayscale). " + "This coverage has " + img.getColorModel().getNumComponents() + " bands."); } insertImageIntoRasdaman(identifier, img); } catch (Exception e) { throw new WCSTException(ExceptionCode.InternalComponentError, "Error while inserting image in rasdaman.", e); } /** * (3) Build the metadata object and store it in the db. */ Metadata m = createNewCoverageMetadata(identifier, img); m = updateMetadataWithDescription(m, desc); /* Top level descriptions overwrite other metadata sources */ if (summ != null) { m = updateMetadataWithSummary(m, summ); } metaDb.insertNewCoverageMetadata(m, false); /** * (4) Indicate success: Add this ID to the output XML document */ CodeType id = new CodeType(); id.setValue(identifier); output.getIdentifier().add(id); log.trace("Finished action Add !"); }
From source file:lucee.runtime.img.Image.java
private void _writeOut(ImageOutputStream ios, String format, float quality, boolean noMeta) throws IOException, ExpressionException { if (quality < 0 || quality > 1) throw new IOException( "quality has an invalid value [" + quality + "], value has to be between 0 and 1"); if (StringUtil.isEmpty(format)) format = this.format; if (StringUtil.isEmpty(format)) throw new IOException("missing format"); BufferedImage im = image(); //IIOMetadata meta = noMeta?null:metadata(format); IIOMetadata meta = noMeta ? null : getMetaData(null); ImageWriter writer = null;// w w w.j a v a 2 s. com ImageTypeSpecifier type = ImageTypeSpecifier.createFromRenderedImage(im); Iterator<ImageWriter> iter = ImageIO.getImageWriters(type, format); if (iter.hasNext()) { writer = iter.next(); } if (writer == null) throw new IOException("no writer for format [" + format + "] available, available writer formats are [" + ListUtil.arrayToList(ImageUtil.getWriterFormatNames(), ",") + "]"); ImageWriteParam iwp = null; if ("jpg".equalsIgnoreCase(format)) { ColorModel cm = im.getColorModel(); if (cm.hasAlpha()) im = jpgImage(im); JPEGImageWriteParam jiwp = new JPEGImageWriteParam(Locale.getDefault()); jiwp.setOptimizeHuffmanTables(true); iwp = jiwp; } else iwp = writer.getDefaultWriteParam(); setCompressionModeEL(iwp, ImageWriteParam.MODE_EXPLICIT); setCompressionQualityEL(iwp, quality); writer.setOutput(ios); try { writer.write(meta, new IIOImage(im, null, meta), iwp); } finally { writer.dispose(); ios.flush(); } }
From source file:ucar.unidata.idv.ui.ImageGenerator.java
private static boolean isNotBlank(BufferedImage image) { // yes, i know this is bonkers. yes, the next step is to try sampling // to avoid iterating over each pixel. // tests on my linux machine typically find a non-blank pixel within the // first 100 iterations, and fewer than 5 retries to get a non-blank // *image* (typically 1-2 retries though) DataBuffer buf = image.getRaster().getDataBuffer(); ColorModel model = image.getColorModel(); boolean result = false; int i;/* w w w . ja v a 2 s. co m*/ for (i = 0; i < buf.getSize(); i++) { // it's apparently not sufficient to simply grab the value directly; // Linux seems to store the "blank" value as -16777216 (-2^24, which // makes a lot of sense for images), while on OS X the blank value // is simply 0. i suspect the getRGB stuff is a candidate for // inlining by the JIT, but profiling is needed. int rgb = model.getRGB(buf.getElem(i)); if (rgb != -16777216) { logger.trace("found non-blank value '{}' at index {}", rgb, i); result = true; break; } } logger.trace("{} iterations to return {}", i, result); return result; }