Java Code Examples for java.awt.image.WritableRaster#getMinX()

The following examples show how to use java.awt.image.WritableRaster#getMinX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RGBCompositeContext.java    From scrimage with Apache License 2.0 6 votes vote down vote up
public void compose(Raster src, Raster dstIn, WritableRaster dstOut) {
    float alpha = this.alpha;

    int[] srcPix = null;
    int[] dstPix = null;

    int x = dstOut.getMinX();
    int w = dstOut.getWidth();
    int y0 = dstOut.getMinY();
    int y1 = y0 + dstOut.getHeight();

    for (int y = y0; y < y1; y++) {
        srcPix = src.getPixels(x, y, w, 1, srcPix);
        dstPix = dstIn.getPixels(x, y, w, 1, dstPix);
        composeRGB(srcPix, dstPix, alpha);
        dstOut.setPixels(x, y, w, 1, dstPix);
    }
}
 
Example 2
Source File: SimpleAbstractMergeStrategy.java    From geowave with Apache License 2.0 6 votes vote down vote up
protected void mergeRasters(
    final RasterTile<T> thisTile,
    final RasterTile<T> nextTile,
    final WritableRaster thisRaster,
    final WritableRaster nextRaster) {
  final int maxX = nextRaster.getMinX() + nextRaster.getWidth();
  final int maxY = nextRaster.getMinY() + nextRaster.getHeight();
  for (int b = 0; b < nextRaster.getNumBands(); b++) {
    for (int x = nextRaster.getMinX(); x < maxX; x++) {
      for (int y = nextRaster.getMinY(); y < maxY; y++) {
        final double thisSample = thisRaster.getSampleDouble(x, y, b);

        final double nextSample = nextRaster.getSampleDouble(x, y, b);
        thisRaster.setSample(x, y, b, getSample(x, y, b, thisSample, nextSample));
      }
    }
  }
}
 
Example 3
Source File: AdditiveComposite.java    From mrgeo with Apache License 2.0 6 votes vote down vote up
@Override
public void compose(Raster src, Raster dstIn, WritableRaster dstOut)
{
  int minX = dstOut.getMinX();
  int minY = dstOut.getMinY();
  int maxX = minX + dstOut.getWidth();
  int maxY = minY + dstOut.getHeight();

  for (int y = minY; y < maxY; y++)
  {
    for (int x = minX; x < maxX; x++)
    {
      dstOut.setSample(x, y, 0, src.getSample(x, y, 0) + dstIn.getSample(x, y, 0));
    }
  }
}
 
Example 4
Source File: RGBComposite.java    From Pixelitor with GNU General Public License v3.0 6 votes vote down vote up
@Override
        public void compose(Raster src, Raster dstIn, WritableRaster dstOut) {
            float alpha = this.alpha;

            int[] srcPix = null;
            int[] dstPix = null;

            int x = dstOut.getMinX();
            int w = dstOut.getWidth();
            int y0 = dstOut.getMinY();
            int y1 = y0 + dstOut.getHeight();

            for (int y = y0; y < y1; y++) {
                srcPix = src.getPixels(x, y, w, 1, srcPix);
                dstPix = dstIn.getPixels(x, y, w, 1, dstPix);
//                int srclength = srcPix.length;
//                int dstlength = dstPix.length;
//                if(srclength > dstlength) {
//                    continue;
//                }
                // System.out.println("RGBComposite$RGBCompositeContext.compose dstlength = " + dstlength + ", srclength = " + srclength);
                composeRGB(srcPix, dstPix, alpha);
                dstOut.setPixels(x, y, w, 1, dstPix);
            }
        }
 
Example 5
Source File: PasteAction.java    From Pixelitor with GNU General Public License v3.0 6 votes vote down vote up
private void pasteImage(BufferedImage pastedImage) {
    // pastedImage = ImageUtils.toCompatibleImage(pastedImage);

    int type = pastedImage.getType();
    if (type != TYPE_INT_ARGB_PRE) {
        // needs conversion in the case of
        // images pasted from other apps
        // TODO why not convert to sys compatible image?
        pastedImage = ImageUtils.convertToARGB_PRE(pastedImage, true);
    } else {
        // if a layer was pasted from Pixelitor,
        // then we get back here the same object reference
        try {
            pastedImage = ImageUtils.copyImage(pastedImage);
        } catch (IllegalArgumentException ex) {
            WritableRaster raster = pastedImage.getRaster();
            int minX = raster.getMinX();
            int minY = raster.getMinY();
            System.out.println("PasteAction.actionPerformed minX = " + minX + ", minY = " + minY);
            throw ex;
        }
    }

    destination.paste(pastedImage);
}
 
Example 6
Source File: MaskComposite.java    From mrgeo with Apache License 2.0 5 votes vote down vote up
@Override
  public void compose(Raster src, Raster dstIn, WritableRaster dstOut)
  {
    int minX = dstOut.getMinX();
    int minY = dstOut.getMinY();
    int maxX = minX + dstOut.getWidth();
    int maxY = minY + dstOut.getHeight();

    for (int y = minY; y < maxY; y++)
    {
      for (int x = minX; x < maxX; x++)
      {
        double srcValue = src.getSampleDouble(x, y, 0);
        // If the source value is set to the srcMaskedValue, then write out
        // the maskedValue. Otherwise, write out the unmaskedValue.
        if (((srcMaskedValue - EPSILON) <= srcValue) && (srcValue <= (srcMaskedValue + EPSILON)))
        {
//            dstOut.setSample(x, y, 0, maskedValue);
          dstOut.setSample(x, y, 0, maskedValue);
        }
        else
        {
          dstOut.setSample(x, y, 0, unmaskedValue);
        }
      }
    }
  }
 
Example 7
Source File: GeoWaveBasicRasterIT.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public void merge(
    final RasterTile<MergeCounter> thisTile,
    final RasterTile<MergeCounter> nextTile,
    final SampleModel sampleModel) {
  if (nextTile instanceof ServerMergeableRasterTile) {
    final WritableRaster nextRaster =
        Raster.createWritableRaster(sampleModel, nextTile.getDataBuffer(), null);
    final WritableRaster thisRaster =
        Raster.createWritableRaster(sampleModel, thisTile.getDataBuffer(), null);
    final MergeCounter mergeCounter = thisTile.getMetadata();
    // we're merging, this is the incremented new number of merges
    final int newNumMerges =
        mergeCounter.getNumMerges() + nextTile.getMetadata().getNumMerges() + 1;

    // we've merged 1 more tile than the total number of merges (ie.
    // if we've performed 1 merge, we've seen 2 tiles)
    final int totalTiles = newNumMerges + 1;
    final int maxX = nextRaster.getMinX() + nextRaster.getWidth();
    final int maxY = nextRaster.getMinY() + nextRaster.getHeight();
    for (int x = nextRaster.getMinX(); x < maxX; x++) {
      for (int y = nextRaster.getMinY(); y < maxY; y++) {
        for (int b = 0; (b + 1) < nextRaster.getNumBands(); b += 2) {
          final double thisSample = thisRaster.getSampleDouble(x, y, b);
          final double nextSample = nextRaster.getSampleDouble(x, y, b);

          final double sum = thisSample + nextSample;
          final double average = sum / totalTiles;
          thisRaster.setSample(x, y, b, sum);
          thisRaster.setSample(x, y, b + 1, average);
        }
      }
    }
    thisTile.setMetadata(new MergeCounter(newNumMerges));
  }
}
 
Example 8
Source File: AdditiveCompositeDouble.java    From mrgeo with Apache License 2.0 5 votes vote down vote up
@Override
public void compose(Raster src, Raster dstIn, WritableRaster dstOut)
{
  int minX = dstOut.getMinX();
  int minY = dstOut.getMinY();
  int maxX = minX + dstOut.getWidth();
  int maxY = minY + dstOut.getHeight();

  //log.debug("minX,minY,maxX,maxY: " + minX + "," + minY + "," + maxX + "," + maxY);
  for (int y = minY; y < maxY; y++)
  {
    for (int x = minX; x < maxX; x++)
    {
      double d = dstIn.getSampleDouble(x, y, 0);
      if (isNodataNaN)
      {
        if (Double.isNaN(d))
        {
          d = 0;
        }
      }
      else
      {
        if (FloatUtils.isEqual(d, nodata))
        {
          d = 0;
        }
      }
      double sample = (src.getSampleDouble(x, y, 0) * weight) + d;

      dstOut.setSample(x, y, 0, sample);
    }
  }
}
 
Example 9
Source File: TIFFDecompressor.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Reformats bit-discontiguous data into the {@code DataBuffer}
 * of the supplied {@code WritableRaster}.
 */
private static void reformatDiscontiguousData(byte[] buf,
                                              int[] bitsPerSample,
                                              int stride,
                                              int w,
                                              int h,
                                              WritableRaster raster)
    throws IOException {

    // Get SampleModel info.
    SampleModel sm = raster.getSampleModel();
    int numBands = sm.getNumBands();

    // Initialize input stream.
    ByteArrayInputStream is = new ByteArrayInputStream(buf);
    ImageInputStream iis = new MemoryCacheImageInputStream(is);

    // Reformat.
    long iisPosition = 0L;
    int y = raster.getMinY();
    for(int j = 0; j < h; j++, y++) {
        iis.seek(iisPosition);
        int x = raster.getMinX();
        for(int i = 0; i < w; i++, x++) {
            for(int b = 0; b < numBands; b++) {
                long bits = iis.readBits(bitsPerSample[b]);
                raster.setSample(x, y, b, (int)bits);
            }
        }
        iisPosition += stride;
    }
}
 
Example 10
Source File: OmsInsolation.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
protected WritableRaster normalVector( WritableRaster pitWR, double res ) {

        int minX = pitWR.getMinX();
        int minY = pitWR.getMinY();
        int rows = pitWR.getHeight();
        int cols = pitWR.getWidth();

        RandomIter pitIter = RandomIterFactory.create(pitWR, null);
        /*
         * Initializa the Image of the normal vector in the central point of the
         * cells, which have 3 components so the Image have 3 bands..
         */
        SampleModel sm = RasterFactory.createBandedSampleModel(5, cols, rows, 3);
        WritableRaster tmpNormalVectorWR = CoverageUtilities.createWritableRaster(cols, rows, null, sm, 0.0);
        WritableRandomIter tmpNormalIter = RandomIterFactory.createWritable(tmpNormalVectorWR, null);
        /*
         * apply the corripio's formula (is the formula (3) in the article)
         */
        for( int j = minY; j < minX + rows - 1; j++ ) {
            for( int i = minX; i < minX + cols - 1; i++ ) {
                double zij = pitIter.getSampleDouble(i, j, 0);
                double zidxj = pitIter.getSampleDouble(i + 1, j, 0);
                double zijdy = pitIter.getSampleDouble(i, j + 1, 0);
                double zidxjdy = pitIter.getSampleDouble(i + 1, j + 1, 0);
                double firstComponent = res * (zij - zidxj + zijdy - zidxjdy);
                double secondComponent = res * (zij + zidxj - zijdy - zidxjdy);
                double thirthComponent = 2 * (res * res);
                double den = Math.sqrt(firstComponent * firstComponent + secondComponent * secondComponent + thirthComponent
                        * thirthComponent);
                tmpNormalIter.setPixel(i, j, new double[]{firstComponent / den, secondComponent / den, thirthComponent / den});

            }
        }
        pitIter.done();

        return tmpNormalVectorWR;

    }
 
Example 11
Source File: OmsHillshade.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
protected WritableRaster normalVector( WritableRaster pitWR, double res ) {
    int minX = pitWR.getMinX();
    int minY = pitWR.getMinY();
    int rows = pitWR.getHeight();
    int cols = pitWR.getWidth();

    RandomIter pitIter = RandomIterFactory.create(pitWR, null);
    /*
     * Initialize the Image of the normal vector in the central point of the
     * cells, which have 3 components so the Image have 3 bands..
     */
    SampleModel sm = RasterFactory.createBandedSampleModel(5, cols, rows, 3);
    WritableRaster tmpNormalVectorWR = CoverageUtilities.createWritableRaster(cols, rows, null, sm, 0.0);
    WritableRandomIter tmpNormaIter = RandomIterFactory.createWritable(tmpNormalVectorWR, null);
    /*
     * apply the corripio's formula (is the formula (3) in the article)
     */
    for( int j = minY; j < minX + rows - 1; j++ ) {
        for( int i = minX; i < minX + cols - 1; i++ ) {
            double zij = pitIter.getSampleDouble(i, j, 0);
            double zidxj = pitIter.getSampleDouble(i + 1, j, 0);
            double zijdy = pitIter.getSampleDouble(i, j + 1, 0);
            double zidxjdy = pitIter.getSampleDouble(i + 1, j + 1, 0);
            double firstComponent = 0.5 * res * (zij - zidxj + zijdy - zidxjdy);
            double secondComponent = 0.5 * res * (zij + zidxj - zijdy - zidxjdy);
            double thirthComponent = (res * res);
            double den = Math.sqrt(firstComponent * firstComponent + secondComponent * secondComponent + thirthComponent
                    * thirthComponent);
            tmpNormaIter.setPixel(i, j, new double[]{firstComponent / den, secondComponent / den, thirthComponent / den});

        }
    }
    pitIter.done();

    return tmpNormalVectorWR;

}
 
Example 12
Source File: TIFFDecompressor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reformats bit-discontiguous data into the {@code DataBuffer}
 * of the supplied {@code WritableRaster}.
 */
private static void reformatDiscontiguousData(byte[] buf,
                                              int[] bitsPerSample,
                                              int stride,
                                              int w,
                                              int h,
                                              WritableRaster raster)
    throws IOException {

    // Get SampleModel info.
    SampleModel sm = raster.getSampleModel();
    int numBands = sm.getNumBands();

    // Initialize input stream.
    ByteArrayInputStream is = new ByteArrayInputStream(buf);
    ImageInputStream iis = new MemoryCacheImageInputStream(is);

    // Reformat.
    long iisPosition = 0L;
    int y = raster.getMinY();
    for(int j = 0; j < h; j++, y++) {
        iis.seek(iisPosition);
        int x = raster.getMinX();
        for(int i = 0; i < w; i++, x++) {
            for(int b = 0; b < numBands; b++) {
                long bits = iis.readBits(bitsPerSample[b]);
                raster.setSample(x, y, b, (int)bits);
            }
        }
        iisPosition += stride;
    }
}
 
Example 13
Source File: GaussianComposite.java    From mrgeo with Apache License 2.0 4 votes vote down vote up
@Override
public void compose(Raster src, Raster dstIn, WritableRaster dstOut)
{
  int minX = dstOut.getMinX();
  int minY = dstOut.getMinY();
  int maxX = minX + dstOut.getWidth();
  int maxY = minY + dstOut.getHeight();

  //System.out.println(minX + ", " + minY + " - " + maxX + ", " + maxY);
  // calculate the area of the ellipse
  double area = Math.PI * (major / 2.0) * (minor / 2.0);

  // the final pixel multiplier, to be combined with the gaussian
  double multiplier = weight / area;

  for (int y = minY; y < maxY; y++)
  {
    for (int x = minX; x < maxX; x++)
    {
      double d = dstIn.getSampleDouble(x, y, 0);
      double s = src.getSampleDouble(x, y, 0);

      double sample;

      if (isNodataNaN)
      {
        if (Double.isNaN(s))
        {
          sample = d;
        }
        else
        {
          // do the gaussian...
          sample = calculateGaussian(s, x - dstIn.getSampleModelTranslateX(),
              y - dstIn.getSampleModelTranslateY(), multiplier);
        }
      }
      else
      {
        if (FloatUtils.isEqual(s, nodata))
        {
          sample = d;
        }
        else
        {
          // do the gaussian...
          sample = calculateGaussian(s, x - dstIn.getSampleModelTranslateX(),
              y - dstIn.getSampleModelTranslateY(), multiplier);
        }
      }

      dstOut.setSample(x, y, 0, sample);
    }
  }
}
 
Example 14
Source File: MinCompositeDouble.java    From mrgeo with Apache License 2.0 4 votes vote down vote up
@Override
public void compose(Raster src, Raster dstIn, WritableRaster dstOut)
{
  int minX = dstOut.getMinX();
  int minY = dstOut.getMinY();
  int maxX = minX + dstOut.getWidth();
  int maxY = minY + dstOut.getHeight();

  //log.debug("minX,minY,maxX,maxY: " + minX + "," + minY + "," + maxX + "," + maxY);
  for (int y = minY; y < maxY; y++)
  {
    for (int x = minX; x < maxX; x++)
    {
      double d = dstIn.getSampleDouble(x, y, 0);
      double s = src.getSampleDouble(x, y, 0) * weight;

      double sample;

      if (isNodataNaN)
      {
        if (Double.isNaN(d))
        {
          sample = s;
        }
        else if (Double.isNaN(s))
        {
          sample = d;
        }
        else if (s < d)
        {
          sample = s;
        }
        else
        {
          sample = d;
        }
      }
      else
      {
        if (FloatUtils.isEqual(d, nodata))
        {
          sample = s;
        }
        else if (FloatUtils.isEqual(s, nodata))
        {
          sample = d;
        }
        else if (s < d)
        {
          sample = s;
        }
        else
        {
          sample = d;
        }
      }

      dstOut.setSample(x, y, 0, sample);
    }
  }
}
 
Example 15
Source File: MaxCompositeDouble.java    From mrgeo with Apache License 2.0 4 votes vote down vote up
@Override
public void compose(Raster src, Raster dstIn, WritableRaster dstOut)
{
  int minX = dstOut.getMinX();
  int minY = dstOut.getMinY();
  int maxX = minX + dstOut.getWidth();
  int maxY = minY + dstOut.getHeight();

  //log.debug("minX,minY,maxX,maxY: " + minX + "," + minY + "," + maxX + "," + maxY);
  for (int y = minY; y < maxY; y++)
  {
    for (int x = minX; x < maxX; x++)
    {
      double d = dstIn.getSampleDouble(x, y, 0);
      double s = src.getSampleDouble(x, y, 0) * weight;

      double sample;

      if (isNodataNaN)
      {
        if (Double.isNaN(d))
        {
          sample = s;
        }
        else if (Double.isNaN(s))
        {
          sample = d;
        }
        else if (s > d)
        {
          sample = s;
        }
        else
        {
          sample = d;
        }
      }
      else
      {
        if (FloatUtils.isEqual(d, nodata))
        {
          sample = s;
        }
        else if (FloatUtils.isEqual(s, nodata))
        {
          sample = d;
        }
        else if (s > d)
        {
          sample = s;
        }
        else
        {
          sample = d;
        }
      }

      dstOut.setSample(x, y, 0, sample);
    }
  }
}
 
Example 16
Source File: OmsSkyview.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
@Execute
public void process() throws Exception {
    checkNull(inElev);
    // extract some attributes of the map
    HashMap<String, Double> attribute = CoverageUtilities.getRegionParamsFromGridCoverage(inElev);
    double dx = attribute.get(CoverageUtilities.XRES);
    CoverageUtilities.getRegionParamsFromGridCoverage(inElev);
    // extract the raster.
    RenderedImage pitTmpRI = inElev.getRenderedImage();
    WritableRaster pitWR = CoverageUtilities.replaceNovalue(pitTmpRI, -9999.0);
    pitTmpRI = null;
    minX = pitWR.getMinX();
    minY = pitWR.getMinY();
    rows = pitWR.getHeight();
    cols = pitWR.getWidth();

    WritableRaster skyWR = skyviewfactor(pitWR, dx);

    int maxY = minY + rows;
    int maxX = minX + cols;
    for( int y = minY + 2; y < maxY - 2; y++ ) {
        for( int x = minX + 2; x < maxX - 2; x++ ) {
            if (pitWR.getSampleDouble(x, y, 0) == -9999.0) {
                skyWR.setSample(x, y, 0, doubleNovalue);
            }
        }
    }
    for( int y = minY; y < maxY; y++ ) {
        skyWR.setSample(0, y, 0, doubleNovalue);
        skyWR.setSample(1, y, 0, doubleNovalue);
        skyWR.setSample(cols - 2, y, 0, doubleNovalue);
        skyWR.setSample(cols - 1, y, 0, doubleNovalue);
    }

    for( int x = minX + 2; x < maxX - 2; x++ ) {
        skyWR.setSample(x, 0, 0, doubleNovalue);
        skyWR.setSample(x, 1, 0, doubleNovalue);
        skyWR.setSample(x, rows - 2, 0, doubleNovalue);
        skyWR.setSample(x, rows - 1, 0, doubleNovalue);
    }
    outSky = CoverageUtilities.buildCoverage("skyview factor", skyWR, attribute, inElev.getCoordinateReferenceSystem());

}
 
Example 17
Source File: PDDeviceCMYK.java    From sambox with Apache License 2.0 4 votes vote down vote up
@Override
protected BufferedImage toRGBImageAWT(WritableRaster raster, ColorSpace colorSpace)
{
    if (usePureJavaCMYKConversion)
    {
        BufferedImage dest = new BufferedImage(raster.getWidth(), raster.getHeight(),
                BufferedImage.TYPE_INT_RGB);
        ColorSpace destCS = dest.getColorModel().getColorSpace();
        WritableRaster destRaster = dest.getRaster();
        float[] srcValues = new float[4];
        float[] lastValues = new float[] { -1.0f, -1.0f, -1.0f, -1.0f };
        float[] destValues = new float[3];
        int width = raster.getWidth();
        int startX = raster.getMinX();
        int height = raster.getHeight();
        int startY = raster.getMinY();
        for (int x = startX; x < width + startX; x++)
        {
            for (int y = startY; y < height + startY; y++)
            {
                raster.getPixel(x, y, srcValues);
                // check if the last value can be reused
                if (!Arrays.equals(lastValues, srcValues))
                {
                    for (int k = 0; k < 4; k++)
                    {
                        lastValues[k] = srcValues[k];
                        srcValues[k] = srcValues[k] / 255f;
                    }
                    // use CIEXYZ as intermediate format to optimize the color conversion
                    destValues = destCS.fromCIEXYZ(colorSpace.toCIEXYZ(srcValues));
                    for (int k = 0; k < destValues.length; k++)
                    {
                        destValues[k] = destValues[k] * 255f;
                    }
                }
                destRaster.setPixel(x, y, destValues);
            }
        }
        return dest;
    }
    else
    {
        return super.toRGBImageAWT(raster, colorSpace);
    }
}
 
Example 18
Source File: NoDataMergeStrategy.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public void merge(
    final RasterTile<NoDataMetadata> thisTile,
    final RasterTile<NoDataMetadata> nextTile,
    final SampleModel sampleModel) {

  // this strategy aims for latest tile with data values, but where there
  // is no data in the latest and there is data in the earlier tile, it
  // fills the data from the earlier tile

  // if next tile is null or if this tile does not have metadata, just
  // keep this tile as is
  if ((nextTile != null) && (thisTile.getMetadata() != null)) {
    final NoDataMetadata thisTileMetadata = thisTile.getMetadata();
    final NoDataMetadata nextTileMetadata = nextTile.getMetadata();

    final WritableRaster thisRaster =
        Raster.createWritableRaster(sampleModel, thisTile.getDataBuffer(), null);
    final WritableRaster nextRaster =
        Raster.createWritableRaster(sampleModel, nextTile.getDataBuffer(), null);
    final int maxX = thisRaster.getMinX() + thisRaster.getWidth();
    final int maxY = thisRaster.getMinY() + thisRaster.getHeight();
    boolean recalculateMetadata = false;
    for (int b = 0; b < thisRaster.getNumBands(); b++) {
      for (int x = thisRaster.getMinX(); x < maxX; x++) {
        for (int y = thisRaster.getMinY(); y < maxY; y++) {
          if (thisTileMetadata.isNoData(
              new SampleIndex(x, y, b),
              thisRaster.getSampleDouble(x, y, b))) {
            final double sample = nextRaster.getSampleDouble(x, y, b);
            if ((nextTileMetadata == null)
                || !nextTileMetadata.isNoData(new SampleIndex(x, y, b), sample)) {
              // we only need to recalculate metadata if
              // the raster is overwritten,
              // otherwise just use this raster's
              // metadata
              recalculateMetadata = true;
              thisRaster.setSample(x, y, b, sample);
            }
          }
        }
      }
    }
    if (recalculateMetadata) {
      thisTile.setMetadata(
          NoDataMetadataFactory.mergeMetadata(
              thisTileMetadata,
              thisRaster,
              nextTileMetadata,
              nextRaster));
    }
  }
}
 
Example 19
Source File: PDDeviceCMYK.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
@Override
protected BufferedImage toRGBImageAWT(WritableRaster raster, ColorSpace colorSpace)
{
    if (usePureJavaCMYKConversion)
    {
        BufferedImage dest = new BufferedImage(raster.getWidth(), raster.getHeight(),
                BufferedImage.TYPE_INT_RGB);
        ColorSpace destCS = dest.getColorModel().getColorSpace();
        WritableRaster destRaster = dest.getRaster();
        float[] srcValues = new float[4];
        float[] lastValues = new float[] { -1.0f, -1.0f, -1.0f, -1.0f };
        float[] destValues = new float[3];
        int width = raster.getWidth();
        int startX = raster.getMinX();
        int height = raster.getHeight();
        int startY = raster.getMinY();
        for (int x = startX; x < width + startX; x++)
        {
            for (int y = startY; y < height + startY; y++)
            {
                raster.getPixel(x, y, srcValues);
                // check if the last value can be reused
                if (!Arrays.equals(lastValues, srcValues))
                {
                    for (int k = 0; k < 4; k++)
                    {
                        lastValues[k] = srcValues[k];
                        srcValues[k] = srcValues[k] / 255f;
                    }
                    // use CIEXYZ as intermediate format to optimize the color conversion
                    destValues = destCS.fromCIEXYZ(colorSpace.toCIEXYZ(srcValues));
                    for (int k = 0; k < destValues.length; k++)
                    {
                        destValues[k] = destValues[k] * 255f;
                    }
                }
                destRaster.setPixel(x, y, destValues);
            }
        }
        return dest;
    }
    else
    {
        return super.toRGBImageAWT(raster, colorSpace);
    }
}
 
Example 20
Source File: MiscCompositeContext.java    From scrimage with Apache License 2.0 4 votes vote down vote up
public void compose(Raster src, Raster dstIn, WritableRaster dstOut) {
    float a = 0, ac = 0;
    float alpha = this.alpha;
    int t;

    int[] srcPix = null;
    int[] dstPix = null;

    int x = dstOut.getMinX();
    int w = dstOut.getWidth();

    int y0 = dstOut.getMinY();
    int y1 = y0 + dstOut.getHeight();

    for (int y = y0; y < y1; y++) {
        srcPix = src.getPixels(x, y, w, 1, srcPix);
        dstPix = dstIn.getPixels(x, y, w, 1, dstPix);
        int i = 0;
        int end = w * 4;

        while (i < end) {
            int sr = srcPix[i];
            int dir = dstPix[i];
            int sg = srcPix[i + 1];
            int dig = dstPix[i + 1];
            int sb = srcPix[i + 2];
            int dib = dstPix[i + 2];
            int sa = srcPix[i + 3];
            int dia = dstPix[i + 3];
            int dor, dog, dob, doa;

            switch (rule) {
                case MiscComposite.ADD:
                default:
                    dor = dir + sr;
                    if (dor > 255)
                        dor = 255;
                    dog = dig + sg;
                    if (dog > 255)
                        dog = 255;
                    dob = dib + sb;
                    if (dob > 255)
                        dob = 255;
                    break;

                case MiscComposite.SUBTRACT:
                    dor = dir - sr;
                    if (dor < 0)
                        dor = 0;
                    dog = dig - sg;
                    if (dog < 0)
                        dog = 0;
                    dob = dib - sb;
                    if (dob < 0)
                        dob = 0;
                    break;

            }

            a = alpha * sa / 255f;
            ac = 1 - a;

            dstPix[i] = (int) (a * dor + ac * dir);
            dstPix[i + 1] = (int) (a * dog + ac * dig);
            dstPix[i + 2] = (int) (a * dob + ac * dib);
            dstPix[i + 3] = (int) (sa * alpha + dia * ac);
            i += 4;
        }
        dstOut.setPixels(x, y, w, 1, dstPix);

    }
}