Package java.awt.image

Examples of java.awt.image.SampleModel


      return true;

  RenderedImage src = args.getRenderedSource(0);

        double[][] matrix = (double[][])args.getObjectParameter(0);
        SampleModel sm = src.getSampleModel();
        int rowLength = sm.getNumBands() + 1;

        if (matrix.length < 1) {
            message.append(getName() + ": " +
                           "bad matrix dimensions");
            return false;
View Full Code Here


     * <code>false</code> with the <code>SampleModel</code> of the
     * supplied <code>Raster</code> as argument.
     */
    public static byte[] getPackedBinaryData(Raster raster,
                                             Rectangle rect) {
        SampleModel sm = raster.getSampleModel();
        if(!isBinary(sm)) {
            throw new IllegalArgumentException(JaiI18N.getString("ImageUtil0"));
        }

        int rectX = rect.x;
View Full Code Here

     * <code>false</code> with the <code>SampleModel</code> of the
     * supplied <code>Raster</code> as argument.
     */
    public static byte[] getUnpackedBinaryData(Raster raster,
                                               Rectangle rect) {
        SampleModel sm = raster.getSampleModel();
        if(!isBinary(sm)) {
            throw new IllegalArgumentException(JaiI18N.getString("ImageUtil0"));
        }

        int rectX = rect.x;
View Full Code Here

     * supplied <code>Raster</code> as argument.
     */
    public static void setPackedBinaryData(byte[] binaryDataArray,
                                           WritableRaster raster,
                                           Rectangle rect) {
        SampleModel sm = raster.getSampleModel();
        if(!isBinary(sm)) {
            throw new IllegalArgumentException(JaiI18N.getString("ImageUtil0"));
        }

        int rectX = rect.x;
View Full Code Here

     * supplied <code>Raster</code> as argument.
     */
    public static void setUnpackedBinaryData(byte[] bdata,
                                             WritableRaster raster,
                                             Rectangle rect) {
        SampleModel sm = raster.getSampleModel();
        if(!isBinary(sm)) {
            throw new IllegalArgumentException(JaiI18N.getString("ImageUtil0"));
        }

        int rectX = rect.x;
View Full Code Here

    public static void fillBackground(WritableRaster raster,
              Rectangle rect,
              double[] backgroundValues) {
  rect = rect.intersection(raster.getBounds());
  int numBands = raster.getSampleModel().getNumBands();
        SampleModel sm = raster.getSampleModel();
        PixelAccessor accessor = new PixelAccessor(sm, null);

        if (isBinary(sm)) {
            //fill binary data
            byte value = (byte)(((int)backgroundValues[0]) & 1);
            if (value == 0)
                return;
            int rectX = rect.x;
            int rectY = rect.y;
            int rectWidth = rect.width;
            int rectHeight = rect.height;

            int dx = rectX - raster.getSampleModelTranslateX();
            int dy = rectY - raster.getSampleModelTranslateY();

            DataBuffer dataBuffer = raster.getDataBuffer();
            MultiPixelPackedSampleModel mpp = (MultiPixelPackedSampleModel)sm;
            int lineStride = mpp.getScanlineStride();
            int eltOffset = dataBuffer.getOffset() + mpp.getOffset(dx, dy);
            int bitOffset = mpp.getBitOffset(dx);

            switch(sm.getDataType()) {
            case DataBuffer.TYPE_BYTE:
                {
                    byte[] data = ((DataBufferByte)dataBuffer).getData();
                    int bits = bitOffset & 7;
                    int otherBits = (bits == 0) ? 0: 8 - bits;
View Full Code Here

  int bitsPerPixel = 24;
  boolean isPalette = false;
  int paletteEntries = 0;
  IndexColorModel icm = null;
  SampleModel sm = im.getSampleModel();
  int numBands = sm.getNumBands();

  ColorModel cm = im.getColorModel();

  if (numBands != 1 && numBands != 3) {
      throw new
    IllegalArgumentException(JaiI18N.getString("BMPImageEncoder1"));
  }
 
  int sampleSize[] = sm.getSampleSize();
  if (sampleSize[0] > 8) {
      throw new RuntimeException(JaiI18N.getString("BMPImageEncoder2"));
  }

  for (int i=1; i<sampleSize.length; i++) {
      if (sampleSize[i] != sampleSize[0]) {
    throw
        new RuntimeException(JaiI18N.getString("BMPImageEncoder3"));
      }
  }

  // Float and Double data cannot be written in a BMP format.
  int dataType = sm.getTransferType();
        if (dataType != DataBuffer.TYPE_BYTE &&
            !CodecUtils.isPackedByteImage(im)) {
            throw new RuntimeException(JaiI18N.getString("BMPImageEncoder0"));
        }

  // Number of bytes that a scanline for the image written out will have.
  int destScanlineBytes = w * numBands;
  int compression = 0;


  byte r[] = null, g[] = null, b[] = null, a[] = null;

  if (cm instanceof IndexColorModel) {

      isPalette = true;
      icm = (IndexColorModel)cm;
      paletteEntries = icm.getMapSize();

      if (paletteEntries <= 2) {

    bitsPerPixel = 1;
    destScanlineBytes = (int)Math.ceil((double)w/8.0);

      } else if (paletteEntries <= 16) {

    bitsPerPixel = 4;
    destScanlineBytes = (int)Math.ceil((double)w/2.0);

      } else if (paletteEntries <= 256) {

    bitsPerPixel = 8;

      } else {

    // Cannot be written as a Palette image. So write out as
    // 24 bit image.
    bitsPerPixel = 24;
    isPalette = false;
    paletteEntries = 0;
    destScanlineBytes = w * 3;
      }

      if (isPalette == true) {

    r = new byte[paletteEntries];
    g = new byte[paletteEntries];
    b = new byte[paletteEntries];
    a = new byte[paletteEntries];
   
    icm.getAlphas(a);
    icm.getReds(r);
    icm.getGreens(g);
    icm.getBlues(b);
      }

  } else {
     
      // Grey scale images
      if (numBands == 1) {
   
    isPalette = true;
    paletteEntries = 256;
    //    int sampleSize[] = sm.getSampleSize();
    bitsPerPixel = sampleSize[0];
   
    destScanlineBytes = (int)Math.ceil((double)(w * bitsPerPixel) /
               8.0);

    r = new byte[256];
    g = new byte[256];
    b = new byte[256];
    a = new byte[256];
   
    for (int i = 0; i < 256; i++) {
        r[i] = (byte)i;
        g[i] = (byte)i;
        b[i] = (byte)i;
        //Fix 4672486: BMPEncoder writes wrong alpha lut into
        // stream for gray-scale image
        a[i] = (byte)255;
    }
      } else if (sm instanceof SinglePixelPackedSampleModel) {
    bitsPerPixel = DataBuffer.getDataTypeSize(sm.getDataType());
    destScanlineBytes = w * bitsPerPixel + 7 >> 3;
      }
  }

  // actual writing of image data
  int fileSize = 0;
  int offset = 0;
  int headerSize = 0;
  int imageSize = 0;
  int xPelsPerMeter = 0;
  int yPelsPerMeter = 0;
  int colorsUsed = 0;
  int colorsImportant = paletteEntries;
  int padding = 0;

  // Calculate padding for each scanline
  int remainder = destScanlineBytes % 4;
  if (remainder != 0) {
      padding = 4 - remainder;
  }
 
  switch (version) {     
  case BMPEncodeParam.VERSION_2:
      offset = 26 + paletteEntries * 3;
      headerSize = 12;
      imageSize = (destScanlineBytes + padding) * h;
      fileSize = imageSize + offset;
      throw new
    RuntimeException(JaiI18N.getString("BMPImageEncoder5"));
      //break;
     
  case BMPEncodeParam.VERSION_3:
      // FileHeader is 14 bytes, BitmapHeader is 40 bytes,
      // add palette size and that is where the data will begin
      if (isCompressed &&  bitsPerPixel == 8) {
    compression = 1;
      } else if (isCompressed && bitsPerPixel == 4) {
    compression = 2;
      }
      offset = 54 + paletteEntries * 4;

      imageSize = (destScanlineBytes + padding) * h;
      fileSize = imageSize + offset;
      headerSize = 40;
      break;
   
  case BMPEncodeParam.VERSION_4:
      headerSize = 108;
      throw new
    RuntimeException(JaiI18N.getString("BMPImageEncoder5"));
      // break;
  }

  int redMask = 0, blueMask = 0, greenMask = 0;
  if (cm instanceof DirectColorModel) {
      redMask = ((DirectColorModel)cm).getRedMask();
      greenMask = ((DirectColorModel)cm).getGreenMask();
      blueMask = ((DirectColorModel)cm).getBlueMask();
      destScanlineBytes = w;
      compression = 3;
      fileSize += 12;
      offset += 12;
  }

  writeFileHeader(fileSize, offset);
 
  writeInfoHeader(headerSize, bitsPerPixel);

  // compression
  writeDWord(compression);
 
  // imageSize
  writeDWord(imageSize);

  // xPelsPerMeter
  writeDWord(xPelsPerMeter);
 
  // yPelsPerMeter
  writeDWord(yPelsPerMeter);
 
  // Colors Used
  writeDWord(colorsUsed);
 
  // Colors Important
  writeDWord(colorsImportant);

  if (compression == 3) {
      writeDWord(redMask);
      writeDWord(greenMask);
      writeDWord(blueMask);
  }

  if (compression == 3) {
            for (int i = 0; i < h; i++) {
                int row = minY + i;

                if (!isTopDown)
                    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 =
View Full Code Here

        return Object.class;
    }

    public boolean canEncodeImage(RenderedImage im,
                                  ImageEncodeParam param) {
        SampleModel sampleModel = im.getSampleModel();

        int dataType = sampleModel.getTransferType();
        if ((dataType == DataBuffer.TYPE_FLOAT) ||
            (dataType == DataBuffer.TYPE_DOUBLE)) {
            return false;
        }

        int numBands = sampleModel.getNumBands();
        if (numBands != 1 && numBands != 3) {
            return false;
        }

        return true;
View Full Code Here

        int minY = im.getMinY();
        int width = im.getWidth();
        int height = im.getHeight();

        // Get SampleModel.
        SampleModel sampleModel = im.getSampleModel();

        // Retrieve and verify sample size.
  int sampleSize[] = sampleModel.getSampleSize();
        for(int i = 1; i < sampleSize.length; i++) {
            if(sampleSize[i] != sampleSize[0]) {
                throw new RuntimeException(JaiI18N.getString("TIFFImageEncoder0"));
            }
        }

        // Check low bit limits.
  int numBands = sampleModel.getNumBands();
        if((sampleSize[0] == 1 || sampleSize[0] == 4) && numBands != 1) {
            throw new RuntimeException(JaiI18N.getString("TIFFImageEncoder1"));
        }

        // Retrieve and verify data type.
  int dataType = sampleModel.getDataType();
        switch(dataType) {
        case DataBuffer.TYPE_BYTE:
            if(sampleSize[0] != 1 && sampleSize[0] != 4 &&
               sampleSize[0] != 8) {
                throw new RuntimeException(JaiI18N.getString("TIFFImageEncoder2"));
View Full Code Here

                endX = XToTileX(xsect.x + xsect.width - 1);
                endY = YToTileY(xsect.y + xsect.height - 1);
            }

            // Create a WritableRaster of the desired size
            SampleModel sm =
                sampleModel.createCompatibleSampleModel(bounds.width,
                                                        bounds.height);

            // Translate it
            WritableRaster dest =
View Full Code Here

TOP

Related Classes of java.awt.image.SampleModel

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.