Example usage for java.awt Transparency OPAQUE

List of usage examples for java.awt Transparency OPAQUE

Introduction

In this page you can find the example usage for java.awt Transparency OPAQUE.

Prototype

int OPAQUE

To view the source code for java.awt Transparency OPAQUE.

Click Source Link

Document

Represents image data that is guaranteed to be completely opaque, meaning that all pixels have an alpha value of 1.0.

Usage

From source file:org.geoserver.wms.wms_1_1_1.GetMapIntegrationTest.java

@Test
public void testPng8Opaque() throws Exception {
    MockHttpServletResponse response = getAsServletResponse("wms?bbox=" + bbox + "&styles=&layers=" + layers
            + "&Format=image/png8" + "&request=GetMap" + "&width=550" + "&height=250" + "&srs=EPSG:4326");
    assertEquals("image/png; mode=8bit", response.getContentType());
    assertEquals("inline; filename=sf-states.png", response.getHeader("Content-Disposition"));

    InputStream is = getBinaryInputStream(response);
    BufferedImage bi = ImageIO.read(is);
    IndexColorModel cm = (IndexColorModel) bi.getColorModel();
    assertEquals(Transparency.OPAQUE, cm.getTransparency());
    assertEquals(-1, cm.getTransparentPixel());
}

From source file:org.geoserver.wms.wms_1_1_1.GetMapIntegrationTest.java

@Test
public void testTransparentPaletteOpaqueOutput() throws Exception {
    String url = "wms?LAYERS=" + getLayerId(MockData.TASMANIA_DEM) + "&styles=demTranslucent&"
            + "FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1" + "&REQUEST=GetMap&SRS=EPSG%3A4326"
            + "&BBOX=145,-43,146,-41&WIDTH=100&HEIGHT=200&bgcolor=0xFF0000";
    BufferedImage bi = getAsImage(url, "image/png");

    ColorModel cm = bi.getColorModel();
    assertTrue(cm instanceof IndexColorModel);
    assertEquals(Transparency.OPAQUE, cm.getTransparency());

    // grab a pixel in the low left corner, should be red (BG color)
    int[] pixel = new int[1];
    bi.getRaster().getPixel(4, 196, pixel);
    int[] color = new int[3];
    cm.getComponents(pixel[0], color, 0);
    assertEquals(255, color[0]);/*  w  ww.j  av a  2s  .  c o  m*/
    assertEquals(0, color[1]);
    assertEquals(0, color[2]);

    // a pixel high enough to be solid, should be fully green
    bi.getRaster().getPixel(56, 49, pixel);
    cm.getComponents(pixel[0], color, 0);
    assertEquals(0, color[0]);
    assertEquals(255, color[1]);
    assertEquals(0, color[2]);
}

From source file:org.geoserver.wps.gs.GeorectifyCoverage.java

@DescribeResults({
        @DescribeResult(name = "result", description = "Georectified raster", type = GridCoverage2D.class),
        @DescribeResult(name = "path", description = "Pathname of the generated raster on the server", type = String.class) })
public Map<String, Object> execute(
        @DescribeParameter(name = "data", description = "Input raster") GridCoverage2D coverage,
        @DescribeParameter(name = "gcp", description = "List of Ground control points.  Points are specified as [x,y] or [x,y,z].") String gcps,
        @DescribeParameter(name = "bbox", description = "Bounding box for output", min = 0) Envelope bbox,
        @DescribeParameter(name = "targetCRS", description = "Coordinate reference system to use for the output raster") CoordinateReferenceSystem crs,
        @DescribeParameter(name = "width", description = "Width of output raster in pixels", min = 0) Integer width,
        @DescribeParameter(name = "height", description = "Height of output raster in pixels", min = 0) Integer height,
        @DescribeParameter(name = "warpOrder", min = 0, description = "Order of the warping polynomial (1 to 3)") Integer warpOrder,
        @DescribeParameter(name = "transparent", min = 0, description = "Force output to have transparent background") Boolean transparent,
        @DescribeParameter(name = "store", min = 0, description = "Indicates whether to keep the output file after processing") Boolean store,
        @DescribeParameter(name = "outputPath", min = 0, description = "Pathname where the output file is stored") String outputPath)
        throws IOException {

    GeoTiffReader reader = null;/* w w w  .j a  va2  s  .c om*/
    List<File> removeFiles = new ArrayList<File>();
    String location = null;
    try {
        File tempFolder = config.getTempFolder();
        File loggingFolder = config.getLoggingFolder();

        // do we have to add the alpha channel?
        boolean forceTransparent = false;
        if (transparent == null) {
            transparent = true;
        }
        ColorModel cm = coverage.getRenderedImage().getColorModel();
        if (cm.getTransparency() == Transparency.OPAQUE && transparent) {
            forceTransparent = true;
        }

        // //
        //
        // STEP 1: Getting the dataset to be georectified
        //
        // //
        final Object fileSource = coverage.getProperty(GridCoverage2DReader.FILE_SOURCE_PROPERTY);
        if (fileSource != null && fileSource instanceof String) {
            location = (String) fileSource;
        }
        if (location == null) {
            RenderedImage image = coverage.getRenderedImage();
            if (forceTransparent) {
                ImageWorker iw = new ImageWorker(image);
                iw.forceComponentColorModel();
                final ImageLayout tempLayout = new ImageLayout(image);
                tempLayout.unsetValid(ImageLayout.COLOR_MODEL_MASK).unsetValid(ImageLayout.SAMPLE_MODEL_MASK);
                RenderedImage alpha = ConstantDescriptor.create(Float.valueOf(image.getWidth()),
                        Float.valueOf(image.getHeight()), new Byte[] { Byte.valueOf((byte) 255) },
                        new RenderingHints(JAI.KEY_IMAGE_LAYOUT, tempLayout));
                iw.addBand(alpha, false);
                image = iw.getRenderedImage();
                cm = image.getColorModel();
            }
            File storedImageFile = storeImage(image, tempFolder);
            location = storedImageFile.getAbsolutePath();
            removeFiles.add(storedImageFile);
        }

        // //
        //
        // STEP 2: Adding Ground Control Points
        //
        // //
        final int gcpNum[] = new int[1];
        final String gcp = parseGcps(gcps, gcpNum);
        File vrtFile = addGroundControlPoints(location, gcp, config.getGdalTranslateParameters());
        if (vrtFile == null || !vrtFile.exists() || !vrtFile.canRead()) {
            throw new IOException("Unable to get a valid file with attached Ground Control Points");
        }
        removeFiles.add(vrtFile);

        // //
        //
        // STEP 3: Warping
        //
        // //
        File warpedFile = warpFile(vrtFile, bbox, crs, width, height, warpOrder, tempFolder, loggingFolder,
                config.getExecutionTimeout(), config.getGdalWarpingParameters());
        if (warpedFile == null || !warpedFile.exists() || !warpedFile.canRead()) {
            throw new IOException("Unable to get a valid georectified file");
        }

        boolean expand = false;
        if (cm instanceof IndexColorModel) {
            expand = true;
        } else if (cm instanceof ComponentColorModel && cm.getNumComponents() == 1
                && cm.getComponentSize()[0] == 1) {
            expand = true;
        }
        if (expand) {
            removeFiles.add(warpedFile);
            warpedFile = expandRgba(warpedFile.getAbsolutePath());
        }

        // if we have the output path move the final file there
        if (Boolean.TRUE.equals(store) && outputPath != null) {
            File output = new File(outputPath);
            if (output.exists()) {
                if (!output.delete()) {
                    throw new WPSException("Output file " + outputPath + " exists but cannot be overwritten");
                }
            } else {
                File parent = output.getParentFile();
                if (!parent.exists()) {
                    if (!parent.mkdirs()) {
                        throw new WPSException("Output file parent directory " + parent.getAbsolutePath()
                                + " does not exist and cannot be created");
                    }
                }
            }
            if (!warpedFile.renameTo(output)) {
                throw new WPSException("Could not move " + warpedFile.getAbsolutePath() + " to " + outputPath
                        + ", it's likely a permission issue");
            }
            warpedFile = output;
        }

        // mark the output file for deletion at the end of request
        if (resourceManager != null && !Boolean.TRUE.equals(store)) {
            resourceManager.addResource(new WPSFileResource(warpedFile));
        }

        // //
        //
        // FINAL STEP: Returning the warped gridcoverage
        //
        // //
        reader = new GeoTiffReader(warpedFile);
        GridCoverage2D cov = addLocationProperty(reader.read(null), warpedFile);

        Map<String, Object> result = new HashMap<String, Object>();
        result.put("result", cov);
        result.put("path", warpedFile.getAbsolutePath());
        return result;
    } finally {
        if (reader != null) {
            try {
                reader.dispose();
            } catch (Throwable t) {
                // Does nothing
            }
        }

        for (File file : removeFiles) {
            deleteFile(file);
        }
    }
}

From source file:org.hippoecm.frontend.plugins.gallery.imageutil.ImageUtils.java

public static BufferedImage scaleImage(BufferedImage img, int xOffset, int yOffset, int sourceWidth,
        int sourceHeight, int targetWidth, int targetHeight, Object hint, boolean highQuality) {

    if (sourceWidth <= 0 || sourceHeight <= 0 || targetWidth <= 0 || targetHeight <= 0) {
        return null;
    }// ww  w  .j  a v a2  s  . c o  m

    int type = (img.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB
            : BufferedImage.TYPE_INT_ARGB;

    BufferedImage result = img;
    if (xOffset != 0 || yOffset != 0 || sourceWidth != img.getWidth() || sourceHeight != img.getHeight()) {
        result = result.getSubimage(xOffset, yOffset, sourceWidth, sourceHeight);
    }

    int width, height;

    if (highQuality) {
        // Use the multiple step technique: start with original size, then scale down in multiple passes with
        // drawImage() until the target size is reached
        width = img.getWidth();
        height = img.getHeight();
    } else {
        // Use one-step technique: scale directly from original size to target size with a single drawImage() call
        width = targetWidth;
        height = targetHeight;
    }

    do {
        if (highQuality && width > targetWidth) {
            width /= 2;
        }
        width = Math.max(width, targetWidth);

        if (highQuality && height > targetHeight) {
            height /= 2;
        }
        height = Math.max(height, targetHeight);

        BufferedImage tmp = new BufferedImage(width, height, type);

        Graphics2D g2 = tmp.createGraphics();
        g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint);
        g2.drawImage(result, 0, 0, width, height, null);
        g2.dispose();

        result = tmp;
    } while (width != targetWidth || height != targetHeight);

    return result;
}

From source file:org.hippoecm.frontend.plugins.gallery.imageutil.ImageUtils.java

/**
 * Converts image raster data to a JPEG with RGB color space. Only images with color space CMYK and YCCK are
 * converted, other images are left untouched.
 *
 * Rationale: Java's ImageIO can't process 4-component images and Java2D can't apply AffineTransformOp either,
 * so we have to convert raster data to a JPG with RGB color space.
 *
 * The technique used in this method is due to Mark Stephens, and free for any use. See
 * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4799903 or
 * http://www.mail-archive.com/java2d-interest@capra.eng.sun.com/msg03247.html
 *
 * @param is the image data/*ww w .j  a  v a2 s .c  om*/
 * @param colorModel the color model of the image
 * @return the RGB version of the supplied image
 */
public static InputStream convertToRGB(InputStream is, ColorModel colorModel)
        throws IOException, UnsupportedImageException {
    if (colorModel != ColorModel.CMYK && colorModel != ColorModel.YCCK) {
        return is;
    }

    // Get an ImageReader.
    ImageInputStream input = ImageIO.createImageInputStream(is);

    try {
        Iterator<ImageReader> readers = ImageIO.getImageReaders(input);
        if (readers == null || !readers.hasNext()) {
            throw new UnsupportedImageException("No ImageReaders found");
        }

        ImageReader reader = readers.next();
        reader.setInput(input);
        Raster raster = reader.readRaster(0, reader.getDefaultReadParam());

        int w = raster.getWidth();
        int h = raster.getHeight();
        byte[] rgb = new byte[w * h * 3];

        switch (colorModel) {
        case YCCK: {
            float[] Y = raster.getSamples(0, 0, w, h, 0, (float[]) null);
            float[] Cb = raster.getSamples(0, 0, w, h, 1, (float[]) null);
            float[] Cr = raster.getSamples(0, 0, w, h, 2, (float[]) null);
            float[] K = raster.getSamples(0, 0, w, h, 3, (float[]) null);

            for (int i = 0, imax = Y.length, base = 0; i < imax; i++, base += 3) {
                float k = 220 - K[i], y = 255 - Y[i], cb = 255 - Cb[i], cr = 255 - Cr[i];

                double val = y + 1.402 * (cr - 128) - k;
                val = (val - 128) * .65f + 128;
                rgb[base] = val < 0.0 ? (byte) 0 : val > 255.0 ? (byte) 0xff : (byte) (val + 0.5);

                val = y - 0.34414 * (cb - 128) - 0.71414 * (cr - 128) - k;
                val = (val - 128) * .65f + 128;
                rgb[base + 1] = val < 0.0 ? (byte) 0 : val > 255.0 ? (byte) 0xff : (byte) (val + 0.5);

                val = y + 1.772 * (cb - 128) - k;
                val = (val - 128) * .65f + 128;
                rgb[base + 2] = val < 0.0 ? (byte) 0 : val > 255.0 ? (byte) 0xff : (byte) (val + 0.5);
            }
            break;
        }
        case CMYK: {
            int[] C = raster.getSamples(0, 0, w, h, 0, (int[]) null);
            int[] M = raster.getSamples(0, 0, w, h, 1, (int[]) null);
            int[] Y = raster.getSamples(0, 0, w, h, 2, (int[]) null);
            int[] K = raster.getSamples(0, 0, w, h, 3, (int[]) null);

            for (int i = 0, imax = C.length, base = 0; i < imax; i++, base += 3) {
                int c = 255 - C[i];
                int m = 255 - M[i];
                int y = 255 - Y[i];
                int k = 255 - K[i];
                float kk = k / 255f;

                rgb[base] = (byte) (255 - Math.min(255f, c * kk + k));
                rgb[base + 1] = (byte) (255 - Math.min(255f, m * kk + k));
                rgb[base + 2] = (byte) (255 - Math.min(255f, y * kk + k));
            }
            break;
        }
        }

        // from other image types we know InterleavedRaster's can be
        // manipulated by AffineTransformOp, so create one of those.
        raster = Raster.createInterleavedRaster(new DataBufferByte(rgb, rgb.length), w, h, w * 3, 3,
                new int[] { 0, 1, 2 }, null);

        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        java.awt.image.ColorModel cm = new ComponentColorModel(cs, false, true, Transparency.OPAQUE,
                DataBuffer.TYPE_BYTE);
        BufferedImage convertedImage = new BufferedImage(cm, (WritableRaster) raster, true, null);

        ByteArrayOutputStream os = new ByteArrayOutputStream();
        ImageIO.write(convertedImage, "jpg", os);

        return new ByteArrayInputStream(os.toByteArray());
    } finally {
        IOUtils.closeQuietly(is);
        if (input != null) {
            input.close();
        }
    }
}

From source file:org.jamwiki.parser.image.ImageProcessor.java

/**
 *
 *///from   w ww  .  j av  a 2s.  c  om
private static BufferedImage resizeImage(BufferedImage tmp, int targetWidth, int targetHeight)
        throws IOException {
    int type = (tmp.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB
            : BufferedImage.TYPE_INT_ARGB;
    int width = tmp.getWidth();
    int height = tmp.getHeight();
    BufferedImage resized = tmp;
    do {
        width /= 2;
        if (width < targetWidth) {
            width = targetWidth;
        }
        height /= 2;
        if (height < targetHeight) {
            height = targetHeight;
        }
        tmp = new BufferedImage(width, height, type);
        Graphics2D g2 = tmp.createGraphics();
        g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2.drawImage(resized, 0, 0, width, height, null);
        g2.dispose();
        resized = tmp;
    } while (width != targetWidth || height != targetHeight);
    return resized;
}

From source file:org.jimcat.services.imagemanager.ImageUtil.java

/**
 * get a BufferedImageType of the given image used to replicate
 * //from   w  w w .j  a  v a  2  s  . c o m
 * @param img
 * @return the type of the buffered image
 */
private static int getImageType(BufferedImage img) {
    if (img.getTransparency() == Transparency.OPAQUE) {
        return BufferedImage.TYPE_INT_RGB;
    }
    return BufferedImage.TYPE_INT_ARGB;
}

From source file:org.medici.bia.controller.manuscriptviewer.IIPImageServerController.java

/**
 * Convenience method that returns a scaled instance of the provided
 * {@code BufferedImage}./*from  w ww  .j av a 2  s .c  o m*/
 * 
 * @param img
 *            the original image to be scaled
 * @param targetWidth
 *            the desired width of the scaled instance, in pixels
 * @param targetHeight
 *            the desired height of the scaled instance, in pixels
 * @param hint
 *            one of the rendering hints that corresponds to
 *            {@code RenderingHints.KEY_INTERPOLATION} (e.g.
 *            {@code RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR},
 *            {@code RenderingHints.VALUE_INTERPOLATION_BILINEAR},
 *            {@code RenderingHints.VALUE_INTERPOLATION_BICUBIC})
 * @param higherQuality
 *            if true, this method will use a multi-step scaling technique
 *            that provides higher quality than the usual one-step technique
 *            (only useful in downscaling cases, where {@code targetWidth}
 *            or {@code targetHeight} is smaller than the original
 *            dimensions, and generally only when the {@code BILINEAR} hint
 *            is specified)
 * @return a scaled version of the original {@code BufferedImage}
 * 
 *         This method has been taken from :
 *         http://today.java.net/pub/a/today
 *         /2007/04/03/perils-of-image-getscaledinstance.html
 * 
 * 
 */
public BufferedImage getScaledInstance(BufferedImage img, int targetWidth, int targetHeight, Object hint,
        boolean higherQuality) {
    int type = (img.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB
            : BufferedImage.TYPE_INT_ARGB;
    BufferedImage ret = (BufferedImage) img;
    int width = 0;
    int height = 0;
    if (higherQuality) {
        // Use multi-step technique: start with original size, then
        // scale down in multiple passes with drawImage()
        // until the target size is reached
        width = img.getWidth();
        height = img.getHeight();
    } else {
        // Use one-step technique: scale directly from original
        // size to target size with a single drawImage() call
        width = targetWidth;
        height = targetHeight;
    }

    do {
        if (higherQuality && width > targetWidth) {
            width /= 2;
            if (width < targetWidth) {
                width = targetWidth;
            }
        }

        if (higherQuality && height > targetHeight) {
            height /= 2;
            if (height < targetHeight) {
                height = targetHeight;
            }
        }

        BufferedImage tmp = new BufferedImage(width, height, type);
        Graphics2D g2 = tmp.createGraphics();
        g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint);
        g2.drawImage(ret, 0, 0, width, height, null);
        g2.dispose();

        ret = tmp;
    } while (width != targetWidth || height != targetHeight);

    return ret;
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java

private void setPaint(final boolean invert, final double xoffset, final double yoffset, final boolean fill) {
    if (paint instanceof Color) {
        final Color color = (Color) paint;
        final int alpha = color.getAlpha();
        if (fill) {
            if (alpha != currentFillGState) {
                currentFillGState = alpha;
                PdfGState gs = fillGState[alpha];
                if (gs == null) {
                    gs = new PdfGState();
                    gs.setFillOpacity(alpha / 255.00f);
                    fillGState[alpha] = gs;
                }/*  w w w.  j  a  v a2s.co m*/
                cb.setGState(gs);
            }
            cb.setColorFill(color);
        } else {
            if (alpha != currentStrokeGState) {
                currentStrokeGState = alpha;
                PdfGState gs = strokeGState[alpha];
                if (gs == null) {
                    gs = new PdfGState();
                    gs.setStrokeOpacity(alpha / 255.0f);
                    strokeGState[alpha] = gs;
                }
                cb.setGState(gs);
            }
            cb.setColorStroke(color);
        }
    } else if (paint instanceof GradientPaint) {
        final GradientPaint gp = (GradientPaint) paint;
        final Point2D p1 = gp.getPoint1();
        transform.transform(p1, p1);
        final Point2D p2 = gp.getPoint2();
        transform.transform(p2, p2);
        final Color c1 = gp.getColor1();
        final Color c2 = gp.getColor2();
        final PdfShading shading = PdfShading.simpleAxial(cb.getPdfWriter(), (float) p1.getX(),
                normalizeY((float) p1.getY()), (float) p2.getX(), normalizeY((float) p2.getY()), c1, c2);
        final PdfShadingPattern pat = new PdfShadingPattern(shading);
        if (fill) {
            cb.setShadingFill(pat);
        } else {
            cb.setShadingStroke(pat);
        }
    } else if (paint instanceof TexturePaint) {
        try {
            final TexturePaint tp = (TexturePaint) paint;
            final BufferedImage img = tp.getImage();
            final Rectangle2D rect = tp.getAnchorRect();
            final com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(img, null);
            final PdfPatternPainter pattern = cb.createPattern(image.getWidth(), image.getHeight());
            final AffineTransform inverse = this.normalizeMatrix();
            inverse.translate(rect.getX(), rect.getY());
            inverse.scale(rect.getWidth() / image.getWidth(), -rect.getHeight() / image.getHeight());
            final double[] mx = new double[6];
            inverse.getMatrix(mx);
            pattern.setPatternMatrix((float) mx[0], (float) mx[1], (float) mx[2], (float) mx[3], (float) mx[4],
                    (float) mx[5]);
            image.setAbsolutePosition(0, 0);
            pattern.addImage(image);
            if (fill) {
                cb.setPatternFill(pattern);
            } else {
                cb.setPatternStroke(pattern);
            }

        } catch (Exception ex) {
            if (fill) {
                cb.setColorFill(Color.gray);
            } else {
                cb.setColorStroke(Color.gray);
            }
        }
    } else {
        try {
            int type = BufferedImage.TYPE_4BYTE_ABGR;
            if (paint.getTransparency() == Transparency.OPAQUE) {
                type = BufferedImage.TYPE_3BYTE_BGR;
            }
            final BufferedImage img = new BufferedImage((int) width, (int) height, type);
            final Graphics2D g = (Graphics2D) img.getGraphics();
            g.transform(transform);
            final AffineTransform inv = transform.createInverse();
            Shape fillRect = new Rectangle2D.Double(0, 0, img.getWidth(), img.getHeight());
            fillRect = inv.createTransformedShape(fillRect);
            g.setPaint(paint);
            g.fill(fillRect);
            if (invert) {
                final AffineTransform tx = new AffineTransform();
                tx.scale(1, -1);
                tx.translate(-xoffset, -yoffset);
                g.drawImage(img, tx, null);
            }
            g.dispose();
            // g = null;
            final com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(img, null);
            final PdfPatternPainter pattern = cb.createPattern(width, height);
            image.setAbsolutePosition(0, 0);
            pattern.addImage(image);
            if (fill) {
                cb.setPatternFill(pattern);
            } else {
                cb.setPatternStroke(pattern);
            }
        } catch (Exception ex) {
            if (fill) {
                cb.setColorFill(Color.gray);
            } else {
                cb.setColorStroke(Color.gray);
            }
        }
    }
}

From source file:org.photovault.dcraw.RawImage.java

/**
 *     Get a 8 bit gamma corrected version of the image.
 * @param minWidth Minimum width for the image that will be rendered
 * @param minHeight Minimum height for the image that will be rendered
 * @param isLowQualityAcceptable If true, renderer may use optimizations that
 * trade off image quality for speed./*from w w  w  .  j  a v a 2 s.  c  o m*/
 * @return The corrected image
 */
public RenderableOp getCorrectedImage(int minWidth, int minHeight, boolean isLowQualityAcceptable) {

    int maxSubsample = 1;
    if (minWidth > 0 && minHeight > 0) {
        while (width >= minWidth * 2 * maxSubsample && height >= minHeight * 2 * maxSubsample) {
            maxSubsample *= 2;
        }
    }
    if (rawImage == null || maxSubsample < subsample) {
        // dcraw.setHalfSize( isHalfSizeEnough );
        if (maxSubsample == 1 && subsample > 1) {
            // The image has been loaded with 1/2 resolution so reloading
            // cannot be avoided
            closeRaw();
        }
        subsample = maxSubsample;
        loadRawImage();
        correctedImage = null;
    }
    if (correctedImage == null) {
        RenderingHints nonCachedHints = new RenderingHints(JAI.KEY_TILE_CACHE, null);

        // TODO: Why setting color model as a rendering hint produces black image???
        RawConvDescriptor.register();
        ParameterBlock pb = new ParameterBlockJAI("RawConv");
        pb.setSource(wbAdjustedRawImage, 0);
        pb.set(white, 0);
        pb.set(black, 1);
        pb.set(highlightCompression, 2);
        rawConverter = JAI.createRenderable("RawConv", pb, nonCachedHints);
        rawConverter.setProperty("org.photovault.opname", "raw_toneadj_image");
        applyExposureSettings();

        // Convert from linear to gamma corrected
        createGammaLut();
        LookupTableJAI jailut = new LookupTableJAI(gammaLut);
        correctedImage = LookupDescriptor.createRenderable(rawConverter, jailut, null);
        correctedImage.setProperty("org.photovault.opname", "gamma_lut_image");
        // Store the color model of the image
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        cm = new ComponentColorModel(cs, new int[] { 8, 8, 8 }, false, false, Transparency.OPAQUE,
                DataBuffer.TYPE_BYTE);

    }
    return correctedImage;
}