java.awt.image.PixelInterleavedSampleModel Java Examples

The following examples show how to use java.awt.image.PixelInterleavedSampleModel. 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: RasterOpNullDestinationRasterTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {

        byte[][] data = new byte[1][10];
        ByteLookupTable lut = new ByteLookupTable(0, data);
        RasterOp op = new LookupOp(lut, null);

        int[] bandOffsets = {0};
        Point location = new Point(0, 0);
        DataBuffer db = new DataBufferByte(10 * 10);
        SampleModel sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
                                                         10, 10, 1, 10,
                                                         bandOffsets);

        Raster src = Raster.createRaster(sm, db, location);

        op.filter(src, null); // this used to result in NullPointerException
    }
 
Example #2
Source File: ColCvtAlpha.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    BufferedImage src
        = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB);

    // Set src pixel values
    Color pelColor = new Color(100, 100, 100, 128);
    for (int i = 0; i < 10; i++) {
        src.setRGB(0, i, pelColor.getRGB());
    }

    ColorModel cm = new ComponentColorModel
        (ColorSpace.getInstance(ColorSpace.CS_GRAY),
         new int [] {8,8}, true,
         src.getColorModel().isAlphaPremultiplied(),
         Transparency.TRANSLUCENT,
         DataBuffer.TYPE_BYTE);

    SampleModel sm = new PixelInterleavedSampleModel
        (DataBuffer.TYPE_BYTE, 100, 100, 2, 200,
         new int [] { 0, 1 });

    WritableRaster wr = Raster.createWritableRaster(sm, new Point(0,0));

    BufferedImage dst =
        new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
    dst = dst.getSubimage(0, 0, 1, 10);

    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    for (int i = 0; i < 10; i++) {
        if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) {
            throw new RuntimeException(
                "Incorrect destination alpha value.");
        }
    }

}
 
Example #3
Source File: ColCvtAlpha.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    BufferedImage src
        = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB);

    // Set src pixel values
    Color pelColor = new Color(100, 100, 100, 128);
    for (int i = 0; i < 10; i++) {
        src.setRGB(0, i, pelColor.getRGB());
    }

    ColorModel cm = new ComponentColorModel
        (ColorSpace.getInstance(ColorSpace.CS_GRAY),
         new int [] {8,8}, true,
         src.getColorModel().isAlphaPremultiplied(),
         Transparency.TRANSLUCENT,
         DataBuffer.TYPE_BYTE);

    SampleModel sm = new PixelInterleavedSampleModel
        (DataBuffer.TYPE_BYTE, 100, 100, 2, 200,
         new int [] { 0, 1 });

    WritableRaster wr = Raster.createWritableRaster(sm, new Point(0,0));

    BufferedImage dst =
        new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
    dst = dst.getSubimage(0, 0, 1, 10);

    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    for (int i = 0; i < 10; i++) {
        if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) {
            throw new RuntimeException(
                "Incorrect destination alpha value.");
        }
    }

}
 
Example #4
Source File: GetSamplesTest.java    From TencentKona-8 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 #5
Source File: ColCvtAlpha.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    BufferedImage src
        = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB);

    // Set src pixel values
    Color pelColor = new Color(100, 100, 100, 128);
    for (int i = 0; i < 10; i++) {
        src.setRGB(0, i, pelColor.getRGB());
    }

    ColorModel cm = new ComponentColorModel
        (ColorSpace.getInstance(ColorSpace.CS_GRAY),
         new int [] {8,8}, true,
         src.getColorModel().isAlphaPremultiplied(),
         Transparency.TRANSLUCENT,
         DataBuffer.TYPE_BYTE);

    SampleModel sm = new PixelInterleavedSampleModel
        (DataBuffer.TYPE_BYTE, 100, 100, 2, 200,
         new int [] { 0, 1 });

    WritableRaster wr = Raster.createWritableRaster(sm, new Point(0,0));

    BufferedImage dst =
        new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
    dst = dst.getSubimage(0, 0, 1, 10);

    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    for (int i = 0; i < 10; i++) {
        if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) {
            throw new RuntimeException(
                "Incorrect destination alpha value.");
        }
    }

}
 
Example #6
Source File: GetSamplesTest.java    From dragonwell8_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 #7
Source File: GetSamplesTest.java    From jdk8u60 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 #8
Source File: ColCvtAlpha.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    BufferedImage src
        = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB);

    // Set src pixel values
    Color pelColor = new Color(100, 100, 100, 128);
    for (int i = 0; i < 10; i++) {
        src.setRGB(0, i, pelColor.getRGB());
    }

    ColorModel cm = new ComponentColorModel
        (ColorSpace.getInstance(ColorSpace.CS_GRAY),
         new int [] {8,8}, true,
         src.getColorModel().isAlphaPremultiplied(),
         Transparency.TRANSLUCENT,
         DataBuffer.TYPE_BYTE);

    SampleModel sm = new PixelInterleavedSampleModel
        (DataBuffer.TYPE_BYTE, 100, 100, 2, 200,
         new int [] { 0, 1 });

    WritableRaster wr = Raster.createWritableRaster(sm, new Point(0,0));

    BufferedImage dst =
        new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
    dst = dst.getSubimage(0, 0, 1, 10);

    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    for (int i = 0; i < 10; i++) {
        if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) {
            throw new RuntimeException(
                "Incorrect destination alpha value.");
        }
    }

}
 
Example #9
Source File: ColCvtAlpha.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    BufferedImage src
        = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB);

    // Set src pixel values
    Color pelColor = new Color(100, 100, 100, 128);
    for (int i = 0; i < 10; i++) {
        src.setRGB(0, i, pelColor.getRGB());
    }

    ColorModel cm = new ComponentColorModel
        (ColorSpace.getInstance(ColorSpace.CS_GRAY),
         new int [] {8,8}, true,
         src.getColorModel().isAlphaPremultiplied(),
         Transparency.TRANSLUCENT,
         DataBuffer.TYPE_BYTE);

    SampleModel sm = new PixelInterleavedSampleModel
        (DataBuffer.TYPE_BYTE, 100, 100, 2, 200,
         new int [] { 0, 1 });

    WritableRaster wr = Raster.createWritableRaster(sm, new Point(0,0));

    BufferedImage dst =
        new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
    dst = dst.getSubimage(0, 0, 1, 10);

    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    for (int i = 0; i < 10; i++) {
        if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) {
            throw new RuntimeException(
                "Incorrect destination alpha value.");
        }
    }

}
 
Example #10
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 #11
Source File: GetSamplesTest.java    From openjdk-jdk8u 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 #12
Source File: ColCvtAlpha.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    BufferedImage src
        = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB);

    // Set src pixel values
    Color pelColor = new Color(100, 100, 100, 128);
    for (int i = 0; i < 10; i++) {
        src.setRGB(0, i, pelColor.getRGB());
    }

    ColorModel cm = new ComponentColorModel
        (ColorSpace.getInstance(ColorSpace.CS_GRAY),
         new int [] {8,8}, true,
         src.getColorModel().isAlphaPremultiplied(),
         Transparency.TRANSLUCENT,
         DataBuffer.TYPE_BYTE);

    SampleModel sm = new PixelInterleavedSampleModel
        (DataBuffer.TYPE_BYTE, 100, 100, 2, 200,
         new int [] { 0, 1 });

    WritableRaster wr = Raster.createWritableRaster(sm, new Point(0,0));

    BufferedImage dst =
        new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
    dst = dst.getSubimage(0, 0, 1, 10);

    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    for (int i = 0; i < 10; i++) {
        if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) {
            throw new RuntimeException(
                "Incorrect destination alpha value.");
        }
    }

}
 
Example #13
Source File: ColCvtAlpha.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    BufferedImage src
        = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB);

    // Set src pixel values
    Color pelColor = new Color(100, 100, 100, 128);
    for (int i = 0; i < 10; i++) {
        src.setRGB(0, i, pelColor.getRGB());
    }

    ColorModel cm = new ComponentColorModel
        (ColorSpace.getInstance(ColorSpace.CS_GRAY),
         new int [] {8,8}, true,
         src.getColorModel().isAlphaPremultiplied(),
         Transparency.TRANSLUCENT,
         DataBuffer.TYPE_BYTE);

    SampleModel sm = new PixelInterleavedSampleModel
        (DataBuffer.TYPE_BYTE, 100, 100, 2, 200,
         new int [] { 0, 1 });

    WritableRaster wr = Raster.createWritableRaster(sm, new Point(0,0));

    BufferedImage dst =
        new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
    dst = dst.getSubimage(0, 0, 1, 10);

    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    for (int i = 0; i < 10; i++) {
        if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) {
            throw new RuntimeException(
                "Incorrect destination alpha value.");
        }
    }

}
 
Example #14
Source File: GetSamplesTest.java    From openjdk-jdk8u-backup 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 #15
Source File: GetSamplesTest.java    From openjdk-8 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 #16
Source File: ColCvtAlpha.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    BufferedImage src
        = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB);

    // Set src pixel values
    Color pelColor = new Color(100, 100, 100, 128);
    for (int i = 0; i < 10; i++) {
        src.setRGB(0, i, pelColor.getRGB());
    }

    ColorModel cm = new ComponentColorModel
        (ColorSpace.getInstance(ColorSpace.CS_GRAY),
         new int [] {8,8}, true,
         src.getColorModel().isAlphaPremultiplied(),
         Transparency.TRANSLUCENT,
         DataBuffer.TYPE_BYTE);

    SampleModel sm = new PixelInterleavedSampleModel
        (DataBuffer.TYPE_BYTE, 100, 100, 2, 200,
         new int [] { 0, 1 });

    WritableRaster wr = Raster.createWritableRaster(sm, new Point(0,0));

    BufferedImage dst =
        new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
    dst = dst.getSubimage(0, 0, 1, 10);

    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    for (int i = 0; i < 10; i++) {
        if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) {
            throw new RuntimeException(
                "Incorrect destination alpha value.");
        }
    }

}
 
Example #17
Source File: GetSamplesTest.java    From hottub 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 #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: ColCvtAlpha.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    BufferedImage src
        = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB);

    // Set src pixel values
    Color pelColor = new Color(100, 100, 100, 128);
    for (int i = 0; i < 10; i++) {
        src.setRGB(0, i, pelColor.getRGB());
    }

    ColorModel cm = new ComponentColorModel
        (ColorSpace.getInstance(ColorSpace.CS_GRAY),
         new int [] {8,8}, true,
         src.getColorModel().isAlphaPremultiplied(),
         Transparency.TRANSLUCENT,
         DataBuffer.TYPE_BYTE);

    SampleModel sm = new PixelInterleavedSampleModel
        (DataBuffer.TYPE_BYTE, 100, 100, 2, 200,
         new int [] { 0, 1 });

    WritableRaster wr = Raster.createWritableRaster(sm, new Point(0,0));

    BufferedImage dst =
        new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
    dst = dst.getSubimage(0, 0, 1, 10);

    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    for (int i = 0; i < 10; i++) {
        if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) {
            throw new RuntimeException(
                "Incorrect destination alpha value.");
        }
    }

}
 
Example #20
Source File: GetSamplesTest.java    From openjdk-jdk9 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 #21
Source File: TIFFDecompressor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a {@code PixelInterleavedSampleModel} for use in creating
 * an {@code ImageTypeSpecifier}.  Its dimensions will be 1x1 and
 * it will have ascending band offsets as {0, 1, 2, ..., numBands}.
 *
 * @param dataType The data type (DataBuffer.TYPE_*).
 * @param numBands The number of bands.
 * @return A {@code PixelInterleavedSampleModel}.
 */
static SampleModel createInterleavedSM(int dataType,
                                       int numBands) {
    int[] bandOffsets = new int[numBands];
    for(int i = 0; i < numBands; i++) {
        bandOffsets[i] = i;
    }
    return new PixelInterleavedSampleModel(dataType,
                                           1, // width
                                           1, // height
                                           numBands, // pixelStride,
                                           numBands, // scanlineStride
                                           bandOffsets);
}
 
Example #22
Source File: TIFFDecompressor.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Create a {@code PixelInterleavedSampleModel} for use in creating
 * an {@code ImageTypeSpecifier}.  Its dimensions will be 1x1 and
 * it will have ascending band offsets as {0, 1, 2, ..., numBands}.
 *
 * @param dataType The data type (DataBuffer.TYPE_*).
 * @param numBands The number of bands.
 * @return A {@code PixelInterleavedSampleModel}.
 */
static SampleModel createInterleavedSM(int dataType,
                                       int numBands) {
    int[] bandOffsets = new int[numBands];
    for(int i = 0; i < numBands; i++) {
        bandOffsets[i] = i;
    }
    return new PixelInterleavedSampleModel(dataType,
                                           1, // width
                                           1, // height
                                           numBands, // pixelStride,
                                           numBands, // scanlineStride
                                           bandOffsets);
}
 
Example #23
Source File: ImageBuilder.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public SampleModel convert(FieldAccessor fa, Instance instance) throws FieldAccessor.InvalidFieldException {
    int width = fa.getInt(instance, "width");          // NOI18N
    int height = fa.getInt(instance, "height");  // NOI18N
    int dataType = fa.getInt(instance, "dataType");   // NOI18N
    int pixelStride = fa.getInt(instance, "pixelStride");  // NOI18N
    int scanlineStride = fa.getInt(instance, "scanlineStride");  // NOI18N
    int[] bandOffsets = fa.getIntArray(instance, "bandOffsets", false);  // NOI18N
    return new PixelInterleavedSampleModel(dataType, width, height, pixelStride, scanlineStride, bandOffsets);
}
 
Example #24
Source File: ByteInterleavedRaster.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferByte and
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or InterleavedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coordinate 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 DataBufferShort 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 ByteInterleavedRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Rectangle aRegion,
                              Point origin,
                              ByteInterleavedRaster parent) {
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    if (!(dataBuffer instanceof DataBufferByte)) {
        throw new RasterFormatException("ByteInterleavedRasters must have " +
                                        "byte DataBuffers");
    }

    DataBufferByte dbb = (DataBufferByte)dataBuffer;
    this.data = stealData(dbb, 0);

    int xOffset = aRegion.x - origin.x;
    int yOffset = aRegion.y - origin.y;
    if (sampleModel instanceof PixelInterleavedSampleModel ||
        (sampleModel instanceof ComponentSampleModel &&
         isInterleaved((ComponentSampleModel)sampleModel))) {
        ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
        this.scanlineStride = csm.getScanlineStride();
        this.pixelStride = csm.getPixelStride();
        this.dataOffsets = csm.getBandOffsets();
        for (int i = 0; i < getNumDataElements(); i++) {
            dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
        }
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.packed = true;
        this.bitMasks = sppsm.getBitMasks();
        this.bitOffsets = sppsm.getBitOffsets();
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbb.getOffset();
        dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
    } else {
        throw new RasterFormatException("ByteInterleavedRasters must " +
          "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
          " or interleaved ComponentSampleModel.  Sample model is " +
          sampleModel);
    }
    this.bandOffset = this.dataOffsets[0];

    this.dbOffsetPacked = dataBuffer.getOffset() -
        sampleModelTranslateY*scanlineStride -
        sampleModelTranslateX*pixelStride;
    this.dbOffset = dbOffsetPacked -
        (xOffset*pixelStride+yOffset*scanlineStride);

    // Set inOrder to true if the data elements are in order and
    // have no gaps between them
    this.inOrder = false;
    if (numDataElements == pixelStride) {
        inOrder = true;
        for (int i = 1; i < numDataElements; i++) {
            if (dataOffsets[i] - dataOffsets[0] != i) {
                inOrder = false;
                break;
            }
        }
    }

    verify();
}
 
Example #25
Source File: ImageTypeSpecifier.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public Indexed(byte[] redLUT,
               byte[] greenLUT,
               byte[] blueLUT,
               byte[] alphaLUT,
               int bits,
               int dataType) {
    if (redLUT == null || greenLUT == null || blueLUT == null) {
        throw new IllegalArgumentException("LUT is null!");
    }
    if (bits != 1 && bits != 2 && bits != 4 &&
        bits != 8 && bits != 16) {
        throw new IllegalArgumentException("Bad value for bits!");
    }
    if (dataType != DataBuffer.TYPE_BYTE &&
        dataType != DataBuffer.TYPE_SHORT &&
        dataType != DataBuffer.TYPE_USHORT &&
        dataType != DataBuffer.TYPE_INT) {
        throw new IllegalArgumentException
            ("Bad value for dataType!");
    }
    if ((bits > 8 && dataType == DataBuffer.TYPE_BYTE) ||
        (bits > 16 && dataType != DataBuffer.TYPE_INT)) {
        throw new IllegalArgumentException
            ("Too many bits for dataType!");
    }

    int len = 1 << bits;
    if (redLUT.length != len ||
        greenLUT.length != len ||
        blueLUT.length != len ||
        (alphaLUT != null && alphaLUT.length != len)) {
        throw new IllegalArgumentException("LUT has improper length!");
    }
    this.redLUT = (byte[])redLUT.clone();
    this.greenLUT = (byte[])greenLUT.clone();
    this.blueLUT = (byte[])blueLUT.clone();
    if (alphaLUT != null) {
        this.alphaLUT = (byte[])alphaLUT.clone();
    }
    this.bits = bits;
    this.dataType = dataType;

    if (alphaLUT == null) {
        this.colorModel = new IndexColorModel(bits,
                                              redLUT.length,
                                              redLUT,
                                              greenLUT,
                                              blueLUT);
    } else {
        this.colorModel = new IndexColorModel(bits,
                                              redLUT.length,
                                              redLUT,
                                              greenLUT,
                                              blueLUT,
                                              alphaLUT);
    }

    if ((bits == 8 && dataType == DataBuffer.TYPE_BYTE) ||
        (bits == 16 &&
         (dataType == DataBuffer.TYPE_SHORT ||
          dataType == DataBuffer.TYPE_USHORT))) {
        int[] bandOffsets = { 0 };
        this.sampleModel =
            new PixelInterleavedSampleModel(dataType,
                                            1, 1, 1, 1,
                                            bandOffsets);
    } else {
        this.sampleModel =
            new MultiPixelPackedSampleModel(dataType, 1, 1, bits);
    }
}
 
Example #26
Source File: Win32ColorModel24.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a SampleModel with the specified width and height, that
 * has a data layout compatible with this ColorModel.
 * @see SampleModel
 */
public SampleModel createCompatibleSampleModel(int w, int h) {
    int[] bOffs = {2, 1, 0};
    return new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
                                           w, h, 3, w*3, bOffs);
}
 
Example #27
Source File: ImageTypeSpecifier.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
public Interleaved(ColorSpace colorSpace,
                   int[] bandOffsets,
                   int dataType,
                   boolean hasAlpha,
                   boolean isAlphaPremultiplied) {
    if (colorSpace == null) {
        throw new IllegalArgumentException("colorSpace == null!");
    }
    if (bandOffsets == null) {
        throw new IllegalArgumentException("bandOffsets == null!");
    }
    int numBands = colorSpace.getNumComponents() +
        (hasAlpha ? 1 : 0);
    if (bandOffsets.length != numBands) {
        throw new IllegalArgumentException
            ("bandOffsets.length is wrong!");
    }
    if (dataType != DataBuffer.TYPE_BYTE &&
        dataType != DataBuffer.TYPE_SHORT &&
        dataType != DataBuffer.TYPE_USHORT &&
        dataType != DataBuffer.TYPE_INT &&
        dataType != DataBuffer.TYPE_FLOAT &&
        dataType != DataBuffer.TYPE_DOUBLE) {
        throw new IllegalArgumentException
            ("Bad value for dataType!");
    }
    this.colorSpace = colorSpace;
    this.bandOffsets = (int[])bandOffsets.clone();
    this.dataType = dataType;
    this.hasAlpha = hasAlpha;
    this.isAlphaPremultiplied = isAlphaPremultiplied;

    this.colorModel =
        ImageTypeSpecifier.createComponentCM(colorSpace,
                                             bandOffsets.length,
                                             dataType,
                                             hasAlpha,
                                             isAlphaPremultiplied);

    int minBandOffset = bandOffsets[0];
    int maxBandOffset = minBandOffset;
    for (int i = 0; i < bandOffsets.length; i++) {
        int offset = bandOffsets[i];
        minBandOffset = Math.min(offset, minBandOffset);
        maxBandOffset = Math.max(offset, maxBandOffset);
    }
    int pixelStride = maxBandOffset - minBandOffset + 1;

    int w = 1;
    int h = 1;
    this.sampleModel =
        new PixelInterleavedSampleModel(dataType,
                                        w, h,
                                        pixelStride,
                                        w*pixelStride,
                                        bandOffsets);
}
 
Example #28
Source File: ByteInterleavedRaster.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferByte and
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or InterleavedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coordinate 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 DataBufferShort 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 ByteInterleavedRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Rectangle aRegion,
                              Point origin,
                              ByteInterleavedRaster parent) {
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    if (!(dataBuffer instanceof DataBufferByte)) {
        throw new RasterFormatException("ByteInterleavedRasters must have " +
                                        "byte DataBuffers");
    }

    DataBufferByte dbb = (DataBufferByte)dataBuffer;
    this.data = stealData(dbb, 0);

    int xOffset = aRegion.x - origin.x;
    int yOffset = aRegion.y - origin.y;
    if (sampleModel instanceof PixelInterleavedSampleModel ||
        (sampleModel instanceof ComponentSampleModel &&
         isInterleaved((ComponentSampleModel)sampleModel))) {
        ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
        this.scanlineStride = csm.getScanlineStride();
        this.pixelStride = csm.getPixelStride();
        this.dataOffsets = csm.getBandOffsets();
        for (int i = 0; i < getNumDataElements(); i++) {
            dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
        }
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.packed = true;
        this.bitMasks = sppsm.getBitMasks();
        this.bitOffsets = sppsm.getBitOffsets();
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbb.getOffset();
        dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
    } else {
        throw new RasterFormatException("ByteInterleavedRasters must " +
          "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
          " or interleaved ComponentSampleModel.  Sample model is " +
          sampleModel);
    }
    this.bandOffset = this.dataOffsets[0];

    this.dbOffsetPacked = dataBuffer.getOffset() -
        sampleModelTranslateY*scanlineStride -
        sampleModelTranslateX*pixelStride;
    this.dbOffset = dbOffsetPacked -
        (xOffset*pixelStride+yOffset*scanlineStride);

    // Set inOrder to true if the data elements are in order and
    // have no gaps between them
    this.inOrder = false;
    if (numDataElements == pixelStride) {
        inOrder = true;
        for (int i = 1; i < numDataElements; i++) {
            if (dataOffsets[i] - dataOffsets[0] != i) {
                inOrder = false;
                break;
            }
        }
    }

    verify();
}
 
Example #29
Source File: ImageTypeSpecifier.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public Grayscale(int bits,
                 int dataType,
                 boolean isSigned,
                 boolean hasAlpha,
                 boolean isAlphaPremultiplied)
{
    if (bits != 1 && bits != 2 && bits != 4 &&
        bits != 8 && bits != 16)
    {
        throw new IllegalArgumentException("Bad value for bits!");
    }
    if (dataType != DataBuffer.TYPE_BYTE &&
        dataType != DataBuffer.TYPE_SHORT &&
        dataType != DataBuffer.TYPE_USHORT)
    {
        throw new IllegalArgumentException
            ("Bad value for dataType!");
    }
    if (bits > 8 && dataType == DataBuffer.TYPE_BYTE) {
        throw new IllegalArgumentException
            ("Too many bits for dataType!");
    }

    this.bits = bits;
    this.dataType = dataType;
    this.isSigned = isSigned;
    this.hasAlpha = hasAlpha;
    this.isAlphaPremultiplied = isAlphaPremultiplied;

    ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY);

    if ((bits == 8 && dataType == DataBuffer.TYPE_BYTE) ||
        (bits == 16 &&
         (dataType == DataBuffer.TYPE_SHORT ||
          dataType == DataBuffer.TYPE_USHORT))) {
        // Use component color model & sample model

        int numBands = hasAlpha ? 2 : 1;
        int transparency =
            hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;


        int[] nBits = new int[numBands];
        nBits[0] = bits;
        if (numBands == 2) {
            nBits[1] = bits;
        }
        this.colorModel =
            new ComponentColorModel(colorSpace,
                                    nBits,
                                    hasAlpha,
                                    isAlphaPremultiplied,
                                    transparency,
                                    dataType);

        int[] bandOffsets = new int[numBands];
        bandOffsets[0] = 0;
        if (numBands == 2) {
            bandOffsets[1] = 1;
        }

        int w = 1;
        int h = 1;
        this.sampleModel =
            new PixelInterleavedSampleModel(dataType,
                                            w, h,
                                            numBands, w*numBands,
                                            bandOffsets);
    } else {
        int numEntries = 1 << bits;
        byte[] arr = new byte[numEntries];
        for (int i = 0; i < numEntries; i++) {
            arr[i] = (byte)(i*255/(numEntries - 1));
        }
        this.colorModel =
            new IndexColorModel(bits, numEntries, arr, arr, arr);

        this.sampleModel =
            new MultiPixelPackedSampleModel(dataType, 1, 1, bits);
    }
}
 
Example #30
Source File: ImageTypeSpecifier.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
public Grayscale(int bits,
                 int dataType,
                 boolean isSigned,
                 boolean hasAlpha,
                 boolean isAlphaPremultiplied)
{
    if (bits != 1 && bits != 2 && bits != 4 &&
        bits != 8 && bits != 16)
    {
        throw new IllegalArgumentException("Bad value for bits!");
    }
    if (dataType != DataBuffer.TYPE_BYTE &&
        dataType != DataBuffer.TYPE_SHORT &&
        dataType != DataBuffer.TYPE_USHORT)
    {
        throw new IllegalArgumentException
            ("Bad value for dataType!");
    }
    if (bits > 8 && dataType == DataBuffer.TYPE_BYTE) {
        throw new IllegalArgumentException
            ("Too many bits for dataType!");
    }

    this.bits = bits;
    this.dataType = dataType;
    this.isSigned = isSigned;
    this.hasAlpha = hasAlpha;
    this.isAlphaPremultiplied = isAlphaPremultiplied;

    ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY);

    if ((bits == 8 && dataType == DataBuffer.TYPE_BYTE) ||
        (bits == 16 &&
         (dataType == DataBuffer.TYPE_SHORT ||
          dataType == DataBuffer.TYPE_USHORT))) {
        // Use component color model & sample model

        int numBands = hasAlpha ? 2 : 1;
        int transparency =
            hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;


        int[] nBits = new int[numBands];
        nBits[0] = bits;
        if (numBands == 2) {
            nBits[1] = bits;
        }
        this.colorModel =
            new ComponentColorModel(colorSpace,
                                    nBits,
                                    hasAlpha,
                                    isAlphaPremultiplied,
                                    transparency,
                                    dataType);

        int[] bandOffsets = new int[numBands];
        bandOffsets[0] = 0;
        if (numBands == 2) {
            bandOffsets[1] = 1;
        }

        int w = 1;
        int h = 1;
        this.sampleModel =
            new PixelInterleavedSampleModel(dataType,
                                            w, h,
                                            numBands, w*numBands,
                                            bandOffsets);
    } else {
        int numEntries = 1 << bits;
        byte[] arr = new byte[numEntries];
        for (int i = 0; i < numEntries; i++) {
            arr[i] = (byte)(i*255/(numEntries - 1));
        }
        this.colorModel =
            new IndexColorModel(bits, numEntries, arr, arr, arr);

        this.sampleModel =
            new MultiPixelPackedSampleModel(dataType, 1, 1, bits);
    }
}