Package java.awt.image

Examples of java.awt.image.Raster


     * @return the tile as a Raster.
     */
    public SerializableState getTile(Long id, int tileX, int tileY)
        throws RemoteException {

  Raster r = getSource(id).getTile(tileX, tileY);
  return SerializerFactory.getState(r, null);
    }
View Full Code Here


      tcpl.setParameter(currParam, currValue);
        }
    }
      }

      Raster r = getSource(id).getTile(x, y);
      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      TileEncoder encoder = tef.createEncoder(stream, tcpl,
                r.getSampleModel());

      try {
    encoder.encode(r);
      } catch (java.io.IOException ioe) {
    throw new RuntimeException(ioe.getMessage());
View Full Code Here

            // (Bug ID 4253990)
            //

            //Fix 4694162: JPEGImageEncoder throws ClassCastException
            // Obtain the contiguous Raster.
            Raster ras;
            if(im.getNumXTiles() == 1 && im.getNumYTiles() == 1) {
                // Image is not tiled so just get a reference to the tile.
                ras = im.getTile(im.getMinTileX(), im.getMinTileY());
            } else {
                // Image is tiled so need to get a contiguous raster.

                // Create an interleaved raster for copying for 8-bit case.
                // This ensures that for RGB data the band offsets are {0,1,2}.
                // If the JPEG encoder encounters data with BGR offsets as
                // {2,1,0} then it will make yet another copy of the data
                // which might as well be averted here.
                WritableRaster target = sampleModel.getSampleSize(0) == 8 ?
                    Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
                                                   im.getWidth(),
                                                   im.getHeight(),
                                                   sampleModel.getNumBands(),
                                                   new Point(im.getMinX(),
                                                             im.getMinY())) :
                    null;

                // Copy the data.
                ras = im.copyData(target);
            }

            // Convert the Raster to a WritableRaster.
            WritableRaster wRas;
            if (ras instanceof WritableRaster) {
                wRas = (WritableRaster)ras;
            } else {
                wRas = Raster.createWritableRaster(ras.getSampleModel(),
                                                   ras.getDataBuffer(),
                                                   new Point(ras.getSampleModelTranslateX(),
                                                             ras.getSampleModelTranslateY()));
            }

            // Ensure that the WritableRaster has origin (0,0) and the
            // same dimensions as the image (if derived from a single
            // image tile, the tile dimensions might differ from the
View Full Code Here

        if (owner == null) {
            throw new IllegalArgumentException("Null owner");
        }

        // Eventual tile to be returned.
        Raster tile = null;

        // Get the tile's unique ID.
        Object tileID = tileKey(owner, tileX, tileY);

        // Set the computation flag and initialize or retrieve the tile cache.
View Full Code Here

        int yIDNew = yTiles[yLocal];

        if ((xIDNew != xID) || (yIDNew != yID) || (dataBuffer == null)) {
            xID = xIDNew;
            yID = yIDNew;
            Raster tile = im.getTile(xID, yID);

            this.dataBuffer = tile.getDataBuffer();
            dataBufferChanged();

            this.bandOffsets = dataBuffer.getOffsets();
        }
    }
View Full Code Here

        output.write(0); // TypeField
        output.write(0); // FixHeaderField
        output.write(intToMultiByte(width)); // width
        output.write(intToMultiByte(height)); // height

        Raster tile = null;

        // If the data are not formatted nominally then reformat.
        if(sm.getDataType() != DataBuffer.TYPE_BYTE ||
           !(sm instanceof MultiPixelPackedSampleModel) ||
           ((MultiPixelPackedSampleModel)sm).getDataBitOffset() != 0) {
            MultiPixelPackedSampleModel mppsm =
                new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
                                                width, height, 1,
                                                (width + 7)/8, 0);
            WritableRaster raster =
                Raster.createWritableRaster(mppsm,
                                            new Point(im.getMinX(),
                                                      im.getMinY()));
            raster.setRect(im.getData());
            tile = raster;
        } else if(im.getNumXTiles() == 1 &&
                  im.getNumYTiles() == 1) {
            tile = im.getTile(im.getMinTileX(), im.getMinTileY());
        } else {
            tile = im.getData();
        }

        // Check whether the image is white-is-zero.
        boolean isWhiteZero = false;
        if(im.getColorModel() instanceof IndexColorModel) {
            IndexColorModel icm = (IndexColorModel)im.getColorModel();
            isWhiteZero =
                (icm.getRed(0) + icm.getGreen(0) + icm.getBlue(0)) >
                (icm.getRed(1) + icm.getGreen(1) + icm.getBlue(1));
        }

        // Get the line stride, bytes per row, and data array.
        int lineStride =
            ((MultiPixelPackedSampleModel)sm).getScanlineStride();
        int bytesPerRow = (width + 7)/8;
        byte[] bdata = ((DataBufferByte)tile.getDataBuffer()).getData();

        // Write the data.
        if(!isWhiteZero && lineStride == bytesPerRow) {
            // Write the entire image.
            output.write(bdata, 0, height*bytesPerRow);
 
View Full Code Here

        prevYBoundary = Math.max(tileYStart, bounds.y);
        nextYBoundary = Math.min(tileYEnd, lastY);
    }
    
    protected void setDataBuffer() {
        Raster tile = im.getTile(tileX, tileY);
        this.dataBuffer = tile.getDataBuffer();

        int newSampleModelTranslateX = tile.getSampleModelTranslateX();
        int newSampleModelTranslateY = tile.getSampleModelTranslateY();
        localX += sampleModelTranslateX - newSampleModelTranslateX;
        localY += sampleModelTranslateY - newSampleModelTranslateY;

        this.sampleModelTranslateX = newSampleModelTranslateX;
        this.sampleModelTranslateY = newSampleModelTranslateY;
View Full Code Here

  }

  ByteArrayInputStream bais = new ByteArrayInputStream(data);
        JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(bais);

        Raster ras = decoder.decodeAsRaster()
      .createTranslatedChild(location.x, location.y);
  extractParameters(decoder.getJPEGDecodeParam(),
        ras.getSampleModel().getNumBands());

  // set the original sample model to the decoded raster
  if (sm != null) {
      int minX = ras.getMinX();
      int minY = ras.getMinY();
      int h = ras.getHeight();
      int w = ras.getWidth();
      double[] buf = ras.getPixels(minX, minY, w, h, (double[])null);
      ras = RasterFactory.createWritableRaster(sm,
                 new Point(minX, minY));
      ((WritableRaster)ras).setPixels(minX, minY, w, h, buf);
  }
  return ras;
View Full Code Here

                    row = minY + h - i -1;

                // Get the pixels
                Rectangle srcRect =
                    new Rectangle(minX, row, w, 1);
                Raster src = im.getData(srcRect);

                SampleModel sm1 = src.getSampleModel();
                int pos = 0;
                int startX = srcRect.x - src.getSampleModelTranslateX();
                int startY = srcRect.y - src.getSampleModelTranslateY();
                if (sm1 instanceof SinglePixelPackedSampleModel) {
                    SinglePixelPackedSampleModel sppsm =
                        (SinglePixelPackedSampleModel)sm1;
                    pos = sppsm.getOffset(startX, startY);
                }

                switch(dataType) {
                    case DataBuffer.TYPE_SHORT:
                    short[] sdata =
                        ((DataBufferShort)src.getDataBuffer()).getData();
        for (int m = 0; m < sdata.length; m++)
      writeWord(sdata[m]);
                    break;

                    case DataBuffer.TYPE_USHORT:
                    short[] usdata =
                        ((DataBufferUShort)src.getDataBuffer()).getData();
        for (int m = 0; m < usdata.length; m++)
      writeWord(usdata[m]);
                    break;

                    case DataBuffer.TYPE_INT:
                    int[] idata =
                        ((DataBufferInt)src.getDataBuffer()).getData();
        for (int m = 0; m < idata.length; m++)
      writeDWord(idata[m]);
                    break;
                }
      }
      return;
  }

  // palette
  if (isPalette == true) {

      // write palette
      switch(version) {

    // has 3 field entries
      case BMPEncodeParam.VERSION_2:

    for (int i=0; i<paletteEntries; i++) {
        output.write(b[i]);
        output.write(g[i]);
        output.write(r[i]);
    }
    break;

    // has 4 field entries
      default:

    for (int i=0; i<paletteEntries; i++) {
        output.write(b[i]);
        output.write(g[i]);
        output.write(r[i]);
        output.write(a[i]);
    }
    break;
      }
     
  } // else no palette
 
  // Writing of actual image data

  int scanlineBytes = w * numBands;

  // Buffer for up to 8 rows of pixels
  int[] pixels = new int[8 * scanlineBytes];

        // Also create a buffer to hold one line of the data
        // to be written to the file, so we can use array writes.
        byte[] bpixels = new byte[destScanlineBytes];

  int l;

  if (!isTopDown) {
      // Process 8 rows at a time so all but the first will have a
      // multiple of 8 rows.
      int lastRow = minY + h;

      for (int row = (lastRow-1); row >= minY; row -= 8) {
    // Number of rows being read
    int rows = Math.min(8, row - minY + 1);
 
    // Get the pixels
    Raster src = im.getData(new Rectangle(minX, row - rows + 1,
                  w, rows));

    src.getPixels(minX, row - rows + 1, w, rows, pixels);
   
    l = 0;   
   
    // Last possible position in the pixels array
    int max = scanlineBytes * rows - 1;

    for (int i=0; i<rows; i++) {

        // Beginning of each scanline in the pixels array   
        l = max - (i+1) * scanlineBytes + 1;

        writePixels(l, scanlineBytes, bitsPerPixel, pixels,
        bpixels, padding, numBands, icm);
    }
 

      }
     
  } else {
      // Process 8 rows at a time so all but the last will have a
      // multiple of 8 rows.
      int lastRow = minY + h;

      for (int row = minY; row < lastRow; row += 8) {
    int rows = Math.min(8, lastRow - row);
 
    // Get the pixels
    Raster src = im.getData(new Rectangle(minX, row,
                  w, rows));
    src.getPixels(minX, row, w, rows, pixels);

    l=0;   
    for (int i=0; i<rows; i++) {
       
        writePixels(l, scanlineBytes, bitsPerPixel, pixels,
View Full Code Here

                               WritableRaster dest,
                               Rectangle destRect) {
        // Retrieve format tags.
        RasterFormatTag[] formatTags = getFormatTags();

        Raster source = sources[0];
        Rectangle srcRect = mapDestRect(destRect, 0);

        RasterAccessor srcAccessor =
                new RasterAccessor(source, srcRect, formatTags[0],
                                   getSource(0).getColorModel());
View Full Code Here

TOP

Related Classes of java.awt.image.Raster

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.