java.awt.image.SinglePixelPackedSampleModel Java Examples

The following examples show how to use java.awt.image.SinglePixelPackedSampleModel. 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: BMPImageWriterSpi.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public boolean canEncodeImage(ImageTypeSpecifier type) {
    int dataType= type.getSampleModel().getDataType();
    if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT)
        return false;

    SampleModel sm = type.getSampleModel();
    int numBands = sm.getNumBands();
    if (!(numBands == 1 || numBands == 3))
        return false;

    if (numBands == 1 && dataType != DataBuffer.TYPE_BYTE)
        return false;

    if (dataType > DataBuffer.TYPE_BYTE &&
          !(sm instanceof SinglePixelPackedSampleModel))
        return false;

    return true;
}
 
Example #2
Source File: ImageUtil.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static int getElementSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof MultiPixelPackedSampleModel) {
        MultiPixelPackedSampleModel mppsm =
            (MultiPixelPackedSampleModel)sm;
        return mppsm.getSampleSize(0) * mppsm.getNumBands();
    } else if (sm instanceof ComponentSampleModel) {
        return sm.getNumBands() * elementSize;
    } else if (sm instanceof SinglePixelPackedSampleModel) {
        return elementSize;
    }

    return elementSize * sm.getNumBands();

}
 
Example #3
Source File: ImageUtil.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static int getElementSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof MultiPixelPackedSampleModel) {
        MultiPixelPackedSampleModel mppsm =
            (MultiPixelPackedSampleModel)sm;
        return mppsm.getSampleSize(0) * mppsm.getNumBands();
    } else if (sm instanceof ComponentSampleModel) {
        return sm.getNumBands() * elementSize;
    } else if (sm instanceof SinglePixelPackedSampleModel) {
        return elementSize;
    }

    return elementSize * sm.getNumBands();

}
 
Example #4
Source File: BMPImageWriterSpi.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public boolean canEncodeImage(ImageTypeSpecifier type) {
    int dataType= type.getSampleModel().getDataType();
    if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT)
        return false;

    SampleModel sm = type.getSampleModel();
    int numBands = sm.getNumBands();
    if (!(numBands == 1 || numBands == 3))
        return false;

    if (numBands == 1 && dataType != DataBuffer.TYPE_BYTE)
        return false;

    if (dataType > DataBuffer.TYPE_BYTE &&
          !(sm instanceof SinglePixelPackedSampleModel))
        return false;

    return true;
}
 
Example #5
Source File: BMPImageWriterSpi.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public boolean canEncodeImage(ImageTypeSpecifier type) {
    int dataType= type.getSampleModel().getDataType();
    if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT)
        return false;

    SampleModel sm = type.getSampleModel();
    int numBands = sm.getNumBands();
    if (!(numBands == 1 || numBands == 3))
        return false;

    if (numBands == 1 && dataType != DataBuffer.TYPE_BYTE)
        return false;

    if (dataType > DataBuffer.TYPE_BYTE &&
          !(sm instanceof SinglePixelPackedSampleModel))
        return false;

    return true;
}
 
Example #6
Source File: BMPImageWriterSpi.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public boolean canEncodeImage(ImageTypeSpecifier type) {
    int dataType= type.getSampleModel().getDataType();
    if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT)
        return false;

    SampleModel sm = type.getSampleModel();
    int numBands = sm.getNumBands();
    if (!(numBands == 1 || numBands == 3))
        return false;

    if (numBands == 1 && dataType != DataBuffer.TYPE_BYTE)
        return false;

    if (dataType > DataBuffer.TYPE_BYTE &&
          !(sm instanceof SinglePixelPackedSampleModel))
        return false;

    return true;
}
 
Example #7
Source File: ImageUtil.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static int getElementSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof MultiPixelPackedSampleModel) {
        MultiPixelPackedSampleModel mppsm =
            (MultiPixelPackedSampleModel)sm;
        return mppsm.getSampleSize(0) * mppsm.getNumBands();
    } else if (sm instanceof ComponentSampleModel) {
        return sm.getNumBands() * elementSize;
    } else if (sm instanceof SinglePixelPackedSampleModel) {
        return elementSize;
    }

    return elementSize * sm.getNumBands();

}
 
Example #8
Source File: ImageUtil.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static int getElementSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof MultiPixelPackedSampleModel) {
        MultiPixelPackedSampleModel mppsm =
            (MultiPixelPackedSampleModel)sm;
        return mppsm.getSampleSize(0) * mppsm.getNumBands();
    } else if (sm instanceof ComponentSampleModel) {
        return sm.getNumBands() * elementSize;
    } else if (sm instanceof SinglePixelPackedSampleModel) {
        return elementSize;
    }

    return elementSize * sm.getNumBands();

}
 
Example #9
Source File: WebP.java    From webp-imageio with Apache License 2.0 6 votes vote down vote up
private static byte[] extractDirectRGBInt( int aWidth, int aHeight, DirectColorModel aColorModel, SinglePixelPackedSampleModel aSampleModel, DataBufferInt aDataBuffer ) {
  byte[] out = new byte[ aWidth * aHeight * 3 ];

  int rMask = aColorModel.getRedMask();
  int gMask = aColorModel.getGreenMask();
  int bMask = aColorModel.getBlueMask();
  int rShift = getShift( rMask );
  int gShift = getShift( gMask );
  int bShift = getShift( bMask );
  int[] bank = aDataBuffer.getBankData()[ 0 ];
  int scanlineStride = aSampleModel.getScanlineStride();
  int scanIx = 0;
  for ( int b = 0, y = 0; y < aHeight; y++ ) {
    int pixIx = scanIx;
    for ( int x = 0; x < aWidth; x++, b += 3 ) {
      int pixel = bank[ pixIx++ ];
      out[ b ] = ( byte ) ( ( pixel & rMask ) >>> rShift );
      out[ b + 1 ] = ( byte ) ( ( pixel & gMask ) >>> gShift );
      out[ b + 2 ] = ( byte ) ( ( pixel & bMask ) >>> bShift );
    }
    scanIx += scanlineStride;
  }
  return out;
}
 
Example #10
Source File: BMPImageWriterSpi.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public boolean canEncodeImage(ImageTypeSpecifier type) {
    int dataType= type.getSampleModel().getDataType();
    if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT)
        return false;

    SampleModel sm = type.getSampleModel();
    int numBands = sm.getNumBands();
    if (!(numBands == 1 || numBands == 3))
        return false;

    if (numBands == 1 && dataType != DataBuffer.TYPE_BYTE)
        return false;

    if (dataType > DataBuffer.TYPE_BYTE &&
          !(sm instanceof SinglePixelPackedSampleModel))
        return false;

    return true;
}
 
Example #11
Source File: BMPImageWriterSpi.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public boolean canEncodeImage(ImageTypeSpecifier type) {
    int dataType= type.getSampleModel().getDataType();
    if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT)
        return false;

    SampleModel sm = type.getSampleModel();
    int numBands = sm.getNumBands();
    if (!(numBands == 1 || numBands == 3))
        return false;

    if (numBands == 1 && dataType != DataBuffer.TYPE_BYTE)
        return false;

    if (dataType > DataBuffer.TYPE_BYTE &&
          !(sm instanceof SinglePixelPackedSampleModel))
        return false;

    return true;
}
 
Example #12
Source File: ImageUtil.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static int getElementSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof MultiPixelPackedSampleModel) {
        MultiPixelPackedSampleModel mppsm =
            (MultiPixelPackedSampleModel)sm;
        return mppsm.getSampleSize(0) * mppsm.getNumBands();
    } else if (sm instanceof ComponentSampleModel) {
        return sm.getNumBands() * elementSize;
    } else if (sm instanceof SinglePixelPackedSampleModel) {
        return elementSize;
    }

    return elementSize * sm.getNumBands();

}
 
Example #13
Source File: ImageUtil.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static int getElementSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof MultiPixelPackedSampleModel) {
        MultiPixelPackedSampleModel mppsm =
            (MultiPixelPackedSampleModel)sm;
        return mppsm.getSampleSize(0) * mppsm.getNumBands();
    } else if (sm instanceof ComponentSampleModel) {
        return sm.getNumBands() * elementSize;
    } else if (sm instanceof SinglePixelPackedSampleModel) {
        return elementSize;
    }

    return elementSize * sm.getNumBands();

}
 
Example #14
Source File: ImageUtil.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public static int getElementSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof MultiPixelPackedSampleModel) {
        MultiPixelPackedSampleModel mppsm =
            (MultiPixelPackedSampleModel)sm;
        return mppsm.getSampleSize(0) * mppsm.getNumBands();
    } else if (sm instanceof ComponentSampleModel) {
        return sm.getNumBands() * elementSize;
    } else if (sm instanceof SinglePixelPackedSampleModel) {
        return elementSize;
    }

    return elementSize * sm.getNumBands();

}
 
Example #15
Source File: ImageUtil.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static int getElementSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof MultiPixelPackedSampleModel) {
        MultiPixelPackedSampleModel mppsm =
            (MultiPixelPackedSampleModel)sm;
        return mppsm.getSampleSize(0) * mppsm.getNumBands();
    } else if (sm instanceof ComponentSampleModel) {
        return sm.getNumBands() * elementSize;
    } else if (sm instanceof SinglePixelPackedSampleModel) {
        return elementSize;
    }

    return elementSize * sm.getNumBands();

}
 
Example #16
Source File: BiomeExporter.java    From amidst with GNU General Public License v3.0 6 votes vote down vote up
public CustomRenderedImage(
		int worldX,
		int worldY,
		int width,
		int height,
		BiomeProfileSelection biomeProfileSelection,
		BiomeDataOracle biomeDataOracle,
		boolean useQuarterResolution,
		ProgressReporter<Entry<ProgressEntryType, Integer>> progressReporter) {
	this.useQuarterResolution = useQuarterResolution;
	this.resolutionFactor = useQuarterResolution ? 4 : 1;
	this.worldX = worldX;
	this.worldY = worldY;
	this.width = width;
	this.height = height;
	this.colorModel = new DirectColorModel(24, BITMASKS[0], BITMASKS[1], BITMASKS[2]);
	this.sampleModel = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, width, height, BITMASKS);
	this.biomeProfileSelection = biomeProfileSelection;
	this.biomeDataOracle = biomeDataOracle;
	this.progressReporter = progressReporter;
}
 
Example #17
Source File: BMPImageWriterSpi.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
public boolean canEncodeImage(ImageTypeSpecifier type) {
    int dataType= type.getSampleModel().getDataType();
    if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT)
        return false;

    SampleModel sm = type.getSampleModel();
    int numBands = sm.getNumBands();
    if (!(numBands == 1 || numBands == 3))
        return false;

    if (numBands == 1 && dataType != DataBuffer.TYPE_BYTE)
        return false;

    if (dataType > DataBuffer.TYPE_BYTE &&
          !(sm instanceof SinglePixelPackedSampleModel))
        return false;

    return true;
}
 
Example #18
Source File: GetSamplesTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Vector<Class<? extends SampleModel>> classes = new Vector<Class<? extends SampleModel>>();

    classes.add(ComponentSampleModel.class);
    classes.add(MultiPixelPackedSampleModel.class);
    classes.add(SinglePixelPackedSampleModel.class);
    classes.add(BandedSampleModel.class);
    classes.add(PixelInterleavedSampleModel.class);

    for (Class<? extends SampleModel> c : classes) {
        doTest(c);
    }
}
 
Example #19
Source File: IntegerInterleavedRaster.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a IntegerInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferInt and
 * SampleModel must be of type SinglePixelPackedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coodinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferInt that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public IntegerInterleavedRaster(SampleModel sampleModel,
                                DataBufferInt dataBuffer,
                                Rectangle aRegion,
                                Point origin,
                                IntegerInterleavedRaster parent)
{
    super(sampleModel,dataBuffer,aRegion,origin,parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    this.data = stealData(dataBuffer, 0);

    if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride    = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dataBuffer.getOffset();
        this.bandOffset = this.dataOffsets[0];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        dataOffsets[0] += xOffset+yOffset*scanlineStride;
        this.numDataElems = sppsm.getNumDataElements();
    } else {
        throw new RasterFormatException("IntegerInterleavedRasters must have"+
                                        " SinglePixelPackedSampleModel");
    }
    verify();
}
 
Example #20
Source File: MultipleGradientPaintContext.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public final Raster getRaster(int x, int y, int w, int h) {
    // If working raster is big enough, reuse it. Otherwise,
    // build a large enough new one.
    Raster raster = saved;
    if (raster == null ||
        raster.getWidth() < w || raster.getHeight() < h)
    {
        raster = getCachedRaster(model, w, h);
        saved = raster;
    }

    // Access raster internal int array. Because we use a DirectColorModel,
    // we know the DataBuffer is of type DataBufferInt and the SampleModel
    // is SinglePixelPackedSampleModel.
    // Adjust for initial offset in DataBuffer and also for the scanline
    // stride.
    // These calls make the DataBuffer non-acceleratable, but the
    // Raster is never Stable long enough to accelerate anyway...
    DataBufferInt rasterDB = (DataBufferInt)raster.getDataBuffer();
    int[] pixels = rasterDB.getData(0);
    int off = rasterDB.getOffset();
    int scanlineStride = ((SinglePixelPackedSampleModel)
                          raster.getSampleModel()).getScanlineStride();
    int adjust = scanlineStride - w;

    fillRaster(pixels, off, adjust, x, y, w, h); // delegate to subclass

    return raster;
}
 
Example #21
Source File: IntegerInterleavedRaster.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a IntegerInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferInt and
 * SampleModel must be of type SinglePixelPackedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coodinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferInt that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public IntegerInterleavedRaster(SampleModel sampleModel,
                                 DataBuffer dataBuffer,
                                 Rectangle aRegion,
                                 Point origin,
                                 IntegerInterleavedRaster parent){
    super(sampleModel,dataBuffer,aRegion,origin,parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferInt)) {
       throw new RasterFormatException("IntegerInterleavedRasters must have" +
            "integer DataBuffers");
    }
    DataBufferInt dbi = (DataBufferInt)dataBuffer;
    this.data = stealData(dbi, 0);

    if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride    = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbi.getOffset();
        this.bandOffset = this.dataOffsets[0];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        dataOffsets[0] += xOffset+yOffset*scanlineStride;
        this.numDataElems = sppsm.getNumDataElements();
    } else {
        throw new RasterFormatException("IntegerInterleavedRasters must have"+
                                        " SinglePixelPackedSampleModel");
    }
    verify();
}
 
Example #22
Source File: IntegerInterleavedRaster.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a IntegerInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferInt and
 * SampleModel must be of type SinglePixelPackedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coodinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferInt that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public IntegerInterleavedRaster(SampleModel sampleModel,
                                 DataBuffer dataBuffer,
                                 Rectangle aRegion,
                                 Point origin,
                                 IntegerInterleavedRaster parent){
    super(sampleModel,dataBuffer,aRegion,origin,parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferInt)) {
       throw new RasterFormatException("IntegerInterleavedRasters must have" +
            "integer DataBuffers");
    }
    DataBufferInt dbi = (DataBufferInt)dataBuffer;
    this.data = stealData(dbi, 0);

    if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride    = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbi.getOffset();
        this.bandOffset = this.dataOffsets[0];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        dataOffsets[0] += xOffset+yOffset*scanlineStride;
        this.numDataElems = sppsm.getNumDataElements();
    } else {
        throw new RasterFormatException("IntegerInterleavedRasters must have"+
                                        " SinglePixelPackedSampleModel");
    }
    verify();
}
 
Example #23
Source File: IncorrectSampleMaskTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void doTest(int dataType) {
    int maxSize = DataBuffer.getDataTypeSize(dataType);
    System.out.println("Type size: " + maxSize);

    int theMask = (int)(1L << (maxSize + 2)) - 1;
    System.out.printf("theMask=%x\n", theMask);

    SinglePixelPackedSampleModel sm =
        new SinglePixelPackedSampleModel(dataType, w, h,
                                         new int[] { theMask });


    int[] sampleSize = sm.getSampleSize();
    for (int s : sampleSize) {
        if (s > maxSize) {
            throw new RuntimeException("Test failed: sample size is too big:" + s);
        }
    }

    System.out.println("Test medialib...");
    DataBuffer buf = createDataBuffer(dataType);

    WritableRaster wr = Raster.createWritableRaster(sm, buf, null);

    op.filter(wr, null);
    System.out.println("Test PASSED.");
}
 
Example #24
Source File: IntegerInterleavedRaster.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a IntegerInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferInt and
 * SampleModel must be of type SinglePixelPackedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coodinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferInt that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public IntegerInterleavedRaster(SampleModel sampleModel,
                                DataBufferInt dataBuffer,
                                Rectangle aRegion,
                                Point origin,
                                IntegerInterleavedRaster parent)
{
    super(sampleModel,dataBuffer,aRegion,origin,parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    this.data = stealData(dataBuffer, 0);

    if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride    = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dataBuffer.getOffset();
        this.bandOffset = this.dataOffsets[0];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        dataOffsets[0] += xOffset+yOffset*scanlineStride;
        this.numDataElems = sppsm.getNumDataElements();
    } else {
        throw new RasterFormatException("IntegerInterleavedRasters must have"+
                                        " SinglePixelPackedSampleModel");
    }
    verify();
}
 
Example #25
Source File: MultipleGradientPaintContext.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public final Raster getRaster(int x, int y, int w, int h) {
    // If working raster is big enough, reuse it. Otherwise,
    // build a large enough new one.
    Raster raster = saved;
    if (raster == null ||
        raster.getWidth() < w || raster.getHeight() < h)
    {
        raster = getCachedRaster(model, w, h);
        saved = raster;
    }

    // Access raster internal int array. Because we use a DirectColorModel,
    // we know the DataBuffer is of type DataBufferInt and the SampleModel
    // is SinglePixelPackedSampleModel.
    // Adjust for initial offset in DataBuffer and also for the scanline
    // stride.
    // These calls make the DataBuffer non-acceleratable, but the
    // Raster is never Stable long enough to accelerate anyway...
    DataBufferInt rasterDB = (DataBufferInt)raster.getDataBuffer();
    int[] pixels = rasterDB.getData(0);
    int off = rasterDB.getOffset();
    int scanlineStride = ((SinglePixelPackedSampleModel)
                          raster.getSampleModel()).getScanlineStride();
    int adjust = scanlineStride - w;

    fillRaster(pixels, off, adjust, x, y, w, h); // delegate to subclass

    return raster;
}
 
Example #26
Source File: IncorrectSampleMaskTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void doTest(int dataType) {
    int maxSize = DataBuffer.getDataTypeSize(dataType);
    System.out.println("Type size: " + maxSize);

    int theMask = (int)(1L << (maxSize + 2)) - 1;
    System.out.printf("theMask=%x\n", theMask);

    SinglePixelPackedSampleModel sm =
        new SinglePixelPackedSampleModel(dataType, w, h,
                                         new int[] { theMask });


    int[] sampleSize = sm.getSampleSize();
    for (int s : sampleSize) {
        if (s > maxSize) {
            throw new RuntimeException("Test failed: sample size is too big:" + s);
        }
    }

    System.out.println("Test medialib...");
    DataBuffer buf = createDataBuffer(dataType);

    WritableRaster wr = Raster.createWritableRaster(sm, buf, null);

    op.filter(wr, null);
    System.out.println("Test PASSED.");
}
 
Example #27
Source File: CustomCompositeTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void compose(Raster src, Raster dstIn, WritableRaster dstOut) {
    int w = src.getWidth();
    int h = src.getHeight();

    DataBufferInt srcDB = (DataBufferInt) src.getDataBuffer();
    DataBufferInt dstOutDB = (DataBufferInt) dstOut.getDataBuffer();
    int srcRGB[] = srcDB.getBankData()[0];
    int dstOutRGB[] = dstOutDB.getBankData()[0];
    int srcOffset = srcDB.getOffset();
    int dstOutOffset = dstOutDB.getOffset();
    int srcScanStride = ((SinglePixelPackedSampleModel) src.getSampleModel()).getScanlineStride();
    int dstOutScanStride = ((SinglePixelPackedSampleModel) dstOut.getSampleModel()).getScanlineStride();
    int srcAdjust = srcScanStride - w;
    int dstOutAdjust = dstOutScanStride - w;

    int si = srcOffset;
    int doi = dstOutOffset;

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            dstOutRGB[doi] = srcRGB[si] ^ 0x00ffffff;
            si++;
            doi++;
        }

        si += srcAdjust;
        doi += dstOutAdjust;
    }
}
 
Example #28
Source File: MultipleGradientPaintContext.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public final Raster getRaster(int x, int y, int w, int h) {
    // If working raster is big enough, reuse it. Otherwise,
    // build a large enough new one.
    Raster raster = saved;
    if (raster == null ||
        raster.getWidth() < w || raster.getHeight() < h)
    {
        raster = getCachedRaster(model, w, h);
        saved = raster;
    }

    // Access raster internal int array. Because we use a DirectColorModel,
    // we know the DataBuffer is of type DataBufferInt and the SampleModel
    // is SinglePixelPackedSampleModel.
    // Adjust for initial offset in DataBuffer and also for the scanline
    // stride.
    // These calls make the DataBuffer non-acceleratable, but the
    // Raster is never Stable long enough to accelerate anyway...
    DataBufferInt rasterDB = (DataBufferInt)raster.getDataBuffer();
    int[] pixels = rasterDB.getData(0);
    int off = rasterDB.getOffset();
    int scanlineStride = ((SinglePixelPackedSampleModel)
                          raster.getSampleModel()).getScanlineStride();
    int adjust = scanlineStride - w;

    fillRaster(pixels, off, adjust, x, y, w, h); // delegate to subclass

    return raster;
}
 
Example #29
Source File: IncorrectSampleMaskTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void doTest(int dataType) {
    int maxSize = DataBuffer.getDataTypeSize(dataType);
    System.out.println("Type size: " + maxSize);

    int theMask = (int)(1L << (maxSize + 2)) - 1;
    System.out.printf("theMask=%x\n", theMask);

    SinglePixelPackedSampleModel sm =
        new SinglePixelPackedSampleModel(dataType, w, h,
                                         new int[] { theMask });


    int[] sampleSize = sm.getSampleSize();
    for (int s : sampleSize) {
        if (s > maxSize) {
            throw new RuntimeException("Test failed: sample size is too big:" + s);
        }
    }

    System.out.println("Test medialib...");
    DataBuffer buf = createDataBuffer(dataType);

    WritableRaster wr = Raster.createWritableRaster(sm, buf, null);

    op.filter(wr, null);
    System.out.println("Test PASSED.");
}
 
Example #30
Source File: IncorrectSampleMaskTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void doTest(int dataType) {
    int maxSize = DataBuffer.getDataTypeSize(dataType);
    System.out.println("Type size: " + maxSize);

    int theMask = (int)(1L << (maxSize + 2)) - 1;
    System.out.printf("theMask=%x\n", theMask);

    SinglePixelPackedSampleModel sm =
        new SinglePixelPackedSampleModel(dataType, w, h,
                                         new int[] { theMask });


    int[] sampleSize = sm.getSampleSize();
    for (int s : sampleSize) {
        if (s > maxSize) {
            throw new RuntimeException("Test failed: sample size is too big:" + s);
        }
    }

    System.out.println("Test medialib...");
    DataBuffer buf = createDataBuffer(dataType);

    WritableRaster wr = Raster.createWritableRaster(sm, buf, null);

    op.filter(wr, null);
    System.out.println("Test PASSED.");
}