Java Code Examples for java.awt.image.ComponentSampleModel

The following are top voted examples for showing how to use java.awt.image.ComponentSampleModel. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: OpenJSharp   File: ImageUtil.java   View source code 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 2
Project: OpenJSharp   File: ImageUtil.java   View source code 6 votes vote down vote up
public static long getBandSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof ComponentSampleModel) {
        ComponentSampleModel csm = (ComponentSampleModel)sm;
        int pixelStride = csm.getPixelStride();
        int scanlineStride = csm.getScanlineStride();
        long size = Math.min(pixelStride, scanlineStride);

        if (pixelStride > 0)
            size += pixelStride * (sm.getWidth() - 1);
        if (scanlineStride > 0)
            size += scanlineStride * (sm.getHeight() - 1);
        return size * ((elementSize + 7) / 8);
    } else
        return getTileSize(sm);
}
 
Example 3
Project: jdk8u-jdk   File: ImageUtil.java   View source code 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
Project: jdk8u-jdk   File: ImageUtil.java   View source code 6 votes vote down vote up
public static long getBandSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof ComponentSampleModel) {
        ComponentSampleModel csm = (ComponentSampleModel)sm;
        int pixelStride = csm.getPixelStride();
        int scanlineStride = csm.getScanlineStride();
        long size = Math.min(pixelStride, scanlineStride);

        if (pixelStride > 0)
            size += pixelStride * (sm.getWidth() - 1);
        if (scanlineStride > 0)
            size += scanlineStride * (sm.getHeight() - 1);
        return size * ((elementSize + 7) / 8);
    } else
        return getTileSize(sm);
}
 
Example 5
Project: jdk8u-jdk   File: GetDataElementsTest.java   View source code 6 votes vote down vote up
public static void main(String[] args) {
    SampleModel sm = new ComponentSampleModel(dataType, width, height, 4, width * 4, new int[] { 0, 1, 2, 3 } );

    DataBuffer db = sm.createDataBuffer();
    Object o = null;

    boolean testPassed = false;
    try {
        o = sm.getDataElements(Integer.MAX_VALUE, 0, 1, 1, o, db);
    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println(e.getMessage());
        testPassed = true;
    }

    if (!testPassed) {
        throw new RuntimeException("Excpected excprion was not thrown.");
    }
}
 
Example 6
Project: openjdk-jdk10   File: ImageUtil.java   View source code 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 7
Project: openjdk-jdk10   File: ImageUtil.java   View source code 6 votes vote down vote up
public static long getBandSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof ComponentSampleModel) {
        ComponentSampleModel csm = (ComponentSampleModel)sm;
        int pixelStride = csm.getPixelStride();
        int scanlineStride = csm.getScanlineStride();
        long size = Math.min(pixelStride, scanlineStride);

        if (pixelStride > 0)
            size += pixelStride * (sm.getWidth() - 1);
        if (scanlineStride > 0)
            size += scanlineStride * (sm.getHeight() - 1);
        return size * ((elementSize + 7) / 8);
    } else
        return getTileSize(sm);
}
 
Example 8
Project: openjdk-jdk10   File: GetDataElementsTest.java   View source code 6 votes vote down vote up
public static void main(String[] args) {
    SampleModel sm = new ComponentSampleModel(dataType, width, height, 4, width * 4, new int[] { 0, 1, 2, 3 } );

    DataBuffer db = sm.createDataBuffer();
    Object o = null;

    boolean testPassed = false;
    try {
        o = sm.getDataElements(Integer.MAX_VALUE, 0, 1, 1, o, db);
    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println(e.getMessage());
        testPassed = true;
    }

    if (!testPassed) {
        throw new RuntimeException("Excpected excprion was not thrown.");
    }
}
 
Example 9
Project: openjdk9   File: ImageUtil.java   View source code 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 10
Project: openjdk9   File: ImageUtil.java   View source code 6 votes vote down vote up
public static long getBandSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof ComponentSampleModel) {
        ComponentSampleModel csm = (ComponentSampleModel)sm;
        int pixelStride = csm.getPixelStride();
        int scanlineStride = csm.getScanlineStride();
        long size = Math.min(pixelStride, scanlineStride);

        if (pixelStride > 0)
            size += pixelStride * (sm.getWidth() - 1);
        if (scanlineStride > 0)
            size += scanlineStride * (sm.getHeight() - 1);
        return size * ((elementSize + 7) / 8);
    } else
        return getTileSize(sm);
}
 
Example 11
Project: openjdk9   File: GetDataElementsTest.java   View source code 6 votes vote down vote up
public static void main(String[] args) {
    SampleModel sm = new ComponentSampleModel(dataType, width, height, 4, width * 4, new int[] { 0, 1, 2, 3 } );

    DataBuffer db = sm.createDataBuffer();
    Object o = null;

    boolean testPassed = false;
    try {
        o = sm.getDataElements(Integer.MAX_VALUE, 0, 1, 1, o, db);
    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println(e.getMessage());
        testPassed = true;
    }

    if (!testPassed) {
        throw new RuntimeException("Excpected excprion was not thrown.");
    }
}
 
Example 12
Project: jdk8u_jdk   File: ImageUtil.java   View source code 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
Project: jdk8u_jdk   File: ImageUtil.java   View source code 6 votes vote down vote up
public static long getBandSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof ComponentSampleModel) {
        ComponentSampleModel csm = (ComponentSampleModel)sm;
        int pixelStride = csm.getPixelStride();
        int scanlineStride = csm.getScanlineStride();
        long size = Math.min(pixelStride, scanlineStride);

        if (pixelStride > 0)
            size += pixelStride * (sm.getWidth() - 1);
        if (scanlineStride > 0)
            size += scanlineStride * (sm.getHeight() - 1);
        return size * ((elementSize + 7) / 8);
    } else
        return getTileSize(sm);
}
 
Example 14
Project: jdk8u_jdk   File: GetDataElementsTest.java   View source code 6 votes vote down vote up
public static void main(String[] args) {
    SampleModel sm = new ComponentSampleModel(dataType, width, height, 4, width * 4, new int[] { 0, 1, 2, 3 } );

    DataBuffer db = sm.createDataBuffer();
    Object o = null;

    boolean testPassed = false;
    try {
        o = sm.getDataElements(Integer.MAX_VALUE, 0, 1, 1, o, db);
    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println(e.getMessage());
        testPassed = true;
    }

    if (!testPassed) {
        throw new RuntimeException("Excpected excprion was not thrown.");
    }
}
 
Example 15
Project: lookaside_java-1.8.0-openjdk   File: ImageUtil.java   View source code 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
Project: lookaside_java-1.8.0-openjdk   File: ImageUtil.java   View source code 6 votes vote down vote up
public static long getBandSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof ComponentSampleModel) {
        ComponentSampleModel csm = (ComponentSampleModel)sm;
        int pixelStride = csm.getPixelStride();
        int scanlineStride = csm.getScanlineStride();
        long size = Math.min(pixelStride, scanlineStride);

        if (pixelStride > 0)
            size += pixelStride * (sm.getWidth() - 1);
        if (scanlineStride > 0)
            size += scanlineStride * (sm.getHeight() - 1);
        return size * ((elementSize + 7) / 8);
    } else
        return getTileSize(sm);
}
 
Example 17
Project: lookaside_java-1.8.0-openjdk   File: GetDataElementsTest.java   View source code 6 votes vote down vote up
public static void main(String[] args) {
    SampleModel sm = new ComponentSampleModel(dataType, width, height, 4, width * 4, new int[] { 0, 1, 2, 3 } );

    DataBuffer db = sm.createDataBuffer();
    Object o = null;

    boolean testPassed = false;
    try {
        o = sm.getDataElements(Integer.MAX_VALUE, 0, 1, 1, o, db);
    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println(e.getMessage());
        testPassed = true;
    }

    if (!testPassed) {
        throw new RuntimeException("Excpected excprion was not thrown.");
    }
}
 
Example 18
Project: javify   File: PixmapVolatileImage.java   View source code 6 votes vote down vote up
@Override
public BufferedImage getSnapshot()
{
  // TODO: Support non-24-bit resolutions.
  int w = pixmap.width;
  int h = pixmap.height;
  ZPixmap zpixmap = (ZPixmap) pixmap.image(0, 0, w, h, 0xffffffff,
                                           Image.Format.ZPIXMAP);
  DataBuffer buffer = new ZPixmapDataBuffer(zpixmap);
  SampleModel sm = new ComponentSampleModel(DataBuffer.TYPE_BYTE, w, h, 4,
                                            w * 4,
                                            new int[]{0, 1, 2, 3 });
  ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
  ColorModel cm = new ComponentColorModel(cs, true, false,
                                          Transparency.OPAQUE,
                                          DataBuffer.TYPE_BYTE);
  WritableRaster raster = Raster.createWritableRaster(sm, buffer,
                                                      new Point(0, 0));
  return new BufferedImage(cm, raster, false, null);
}
 
Example 19
Project: jvm-stm   File: PixmapVolatileImage.java   View source code 6 votes vote down vote up
@Override
public BufferedImage getSnapshot()
{
  // TODO: Support non-24-bit resolutions.
  int w = pixmap.width;
  int h = pixmap.height;
  ZPixmap zpixmap = (ZPixmap) pixmap.image(0, 0, w, h, 0xffffffff,
                                           Image.Format.ZPIXMAP);
  DataBuffer buffer = new ZPixmapDataBuffer(zpixmap);
  SampleModel sm = new ComponentSampleModel(DataBuffer.TYPE_BYTE, w, h, 4,
                                            w * 4,
                                            new int[]{0, 1, 2, 3 });
  ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
  ColorModel cm = new ComponentColorModel(cs, true, false,
                                          Transparency.OPAQUE,
                                          DataBuffer.TYPE_BYTE);
  WritableRaster raster = Raster.createWritableRaster(sm, buffer,
                                                      new Point(0, 0));
  return new BufferedImage(cm, raster, false, null);
}
 
Example 20
Project: infobip-open-jdk-8   File: ImageUtil.java   View source code 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 21
Project: infobip-open-jdk-8   File: ImageUtil.java   View source code 6 votes vote down vote up
public static long getBandSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof ComponentSampleModel) {
        ComponentSampleModel csm = (ComponentSampleModel)sm;
        int pixelStride = csm.getPixelStride();
        int scanlineStride = csm.getScanlineStride();
        long size = Math.min(pixelStride, scanlineStride);

        if (pixelStride > 0)
            size += pixelStride * (sm.getWidth() - 1);
        if (scanlineStride > 0)
            size += scanlineStride * (sm.getHeight() - 1);
        return size * ((elementSize + 7) / 8);
    } else
        return getTileSize(sm);
}
 
Example 22
Project: infobip-open-jdk-8   File: GetDataElementsTest.java   View source code 6 votes vote down vote up
public static void main(String[] args) {
    SampleModel sm = new ComponentSampleModel(dataType, width, height, 4, width * 4, new int[] { 0, 1, 2, 3 } );

    DataBuffer db = sm.createDataBuffer();
    Object o = null;

    boolean testPassed = false;
    try {
        o = sm.getDataElements(Integer.MAX_VALUE, 0, 1, 1, o, db);
    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println(e.getMessage());
        testPassed = true;
    }

    if (!testPassed) {
        throw new RuntimeException("Excpected excprion was not thrown.");
    }
}
 
Example 23
Project: jdk8u-dev-jdk   File: ImageUtil.java   View source code 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 24
Project: jdk8u-dev-jdk   File: ImageUtil.java   View source code 6 votes vote down vote up
public static long getBandSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof ComponentSampleModel) {
        ComponentSampleModel csm = (ComponentSampleModel)sm;
        int pixelStride = csm.getPixelStride();
        int scanlineStride = csm.getScanlineStride();
        long size = Math.min(pixelStride, scanlineStride);

        if (pixelStride > 0)
            size += pixelStride * (sm.getWidth() - 1);
        if (scanlineStride > 0)
            size += scanlineStride * (sm.getHeight() - 1);
        return size * ((elementSize + 7) / 8);
    } else
        return getTileSize(sm);
}
 
Example 25
Project: jdk8u-dev-jdk   File: GetDataElementsTest.java   View source code 6 votes vote down vote up
public static void main(String[] args) {
    SampleModel sm = new ComponentSampleModel(dataType, width, height, 4, width * 4, new int[] { 0, 1, 2, 3 } );

    DataBuffer db = sm.createDataBuffer();
    Object o = null;

    boolean testPassed = false;
    try {
        o = sm.getDataElements(Integer.MAX_VALUE, 0, 1, 1, o, db);
    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println(e.getMessage());
        testPassed = true;
    }

    if (!testPassed) {
        throw new RuntimeException("Excpected excprion was not thrown.");
    }
}
 
Example 26
Project: grib2geotiff   File: GeoTiffExporter.java   View source code 6 votes vote down vote up
private TiledImage ceateImageContent(float[] data, int columns, int rows) {
  SampleModel sm = new ComponentSampleModel(DataBuffer.TYPE_DOUBLE,
      TILE_SIZE, TILE_SIZE, 1, TILE_SIZE, new int[]{0});

  ColorModel cm = TiledImage.createColorModel(sm);

  TiledImage img = new TiledImage(0, 0, columns, rows, 0, 0, sm, cm);

  int i = 0;
  int halfColumns = (int) ((double) columns / 2.0);
  for (int y = 0; y < rows; y++) {
    for (int x = 0; x < columns; x++) {
      if (x >= halfColumns) {
        img.setSample(x - halfColumns, y, 0, data[i]);
      } else {
        img.setSample(x + halfColumns, y, 0, data[i]);
      }
      i++;
    }
  }
  return img;
}
 
Example 27
Project: jdk7-jdk   File: ImageUtil.java   View source code 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 28
Project: jdk7-jdk   File: ImageUtil.java   View source code 6 votes vote down vote up
public static long getBandSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof ComponentSampleModel) {
        ComponentSampleModel csm = (ComponentSampleModel)sm;
        int pixelStride = csm.getPixelStride();
        int scanlineStride = csm.getScanlineStride();
        long size = Math.min(pixelStride, scanlineStride);

        if (pixelStride > 0)
            size += pixelStride * (sm.getWidth() - 1);
        if (scanlineStride > 0)
            size += scanlineStride * (sm.getHeight() - 1);
        return size * ((elementSize + 7) / 8);
    } else
        return getTileSize(sm);
}
 
Example 29
Project: jdk7-jdk   File: GetDataElementsTest.java   View source code 6 votes vote down vote up
public static void main(String[] args) {
    SampleModel sm = new ComponentSampleModel(dataType, width, height, 4, width * 4, new int[] { 0, 1, 2, 3 } );

    DataBuffer db = sm.createDataBuffer();
    Object o = null;

    boolean testPassed = false;
    try {
        o = sm.getDataElements(Integer.MAX_VALUE, 0, 1, 1, o, db);
    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println(e.getMessage());
        testPassed = true;
    }

    if (!testPassed) {
        throw new RuntimeException("Excpected excprion was not thrown.");
    }
}
 
Example 30
Project: rastertheque   File: RectIterCSM.java   View source code 6 votes vote down vote up
public RectIterCSM(RenderedImage im, Rectangle bounds) {
    super(im, bounds);

    ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
    
    this.scanlineStride = csm.getScanlineStride();
    this.pixelStride = csm.getPixelStride();
    this.bankIndices = csm.getBankIndices();
    int[] bo = csm.getBandOffsets();

    this.bandOffsets = new int[numBands + 1];
    for (int i = 0; i < numBands; i++) {
        bandOffsets[i] = bo[i];
    }
    bandOffsets[numBands] = 0;

    this.DBOffsets = new int[numBands];

    this.offset = (y - sampleModelTranslateY)*scanlineStride +
        (x - sampleModelTranslateX)*pixelStride;
    this.bandOffset = bandOffsets[0];
}
 
Example 31
Project: rastertheque   File: RecyclingTileFactory.java   View source code 6 votes vote down vote up
private static long getBufferSizeCSM(ComponentSampleModel csm) {
    int[] bandOffsets = csm.getBandOffsets();
    int maxBandOff=bandOffsets[0];
    for (int i=1; i<bandOffsets.length; i++)
        maxBandOff = Math.max(maxBandOff,bandOffsets[i]);

    long size = 0;
    if (maxBandOff >= 0)
        size += maxBandOff+1;
    int pixelStride = csm.getPixelStride();
    if (pixelStride > 0)
        size += pixelStride * (csm.getWidth()-1);
    int scanlineStride = csm.getScanlineStride();
    if (scanlineStride > 0)
        size += scanlineStride*(csm.getHeight()-1);
    return size;
}
 
Example 32
Project: openjdk-source-code-learn   File: ImageUtil.java   View source code 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 33
Project: openjdk-source-code-learn   File: ImageUtil.java   View source code 6 votes vote down vote up
public static long getBandSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof ComponentSampleModel) {
        ComponentSampleModel csm = (ComponentSampleModel)sm;
        int pixelStride = csm.getPixelStride();
        int scanlineStride = csm.getScanlineStride();
        long size = Math.min(pixelStride, scanlineStride);

        if (pixelStride > 0)
            size += pixelStride * (sm.getWidth() - 1);
        if (scanlineStride > 0)
            size += scanlineStride * (sm.getHeight() - 1);
        return size * ((elementSize + 7) / 8);
    } else
        return getTileSize(sm);
}
 
Example 34
Project: openjdk-source-code-learn   File: GetDataElementsTest.java   View source code 6 votes vote down vote up
public static void main(String[] args) {
    SampleModel sm = new ComponentSampleModel(dataType, width, height, 4, width * 4, new int[] { 0, 1, 2, 3 } );

    DataBuffer db = sm.createDataBuffer();
    Object o = null;

    boolean testPassed = false;
    try {
        o = sm.getDataElements(Integer.MAX_VALUE, 0, 1, 1, o, db);
    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println(e.getMessage());
        testPassed = true;
    }

    if (!testPassed) {
        throw new RuntimeException("Excpected excprion was not thrown.");
    }
}
 
Example 35
Project: OLD-OpenJDK8   File: ImageUtil.java   View source code 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 36
Project: OLD-OpenJDK8   File: ImageUtil.java   View source code 6 votes vote down vote up
public static long getBandSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof ComponentSampleModel) {
        ComponentSampleModel csm = (ComponentSampleModel)sm;
        int pixelStride = csm.getPixelStride();
        int scanlineStride = csm.getScanlineStride();
        long size = Math.min(pixelStride, scanlineStride);

        if (pixelStride > 0)
            size += pixelStride * (sm.getWidth() - 1);
        if (scanlineStride > 0)
            size += scanlineStride * (sm.getHeight() - 1);
        return size * ((elementSize + 7) / 8);
    } else
        return getTileSize(sm);
}
 
Example 37
Project: OLD-OpenJDK8   File: GetDataElementsTest.java   View source code 6 votes vote down vote up
public static void main(String[] args) {
    SampleModel sm = new ComponentSampleModel(dataType, width, height, 4, width * 4, new int[] { 0, 1, 2, 3 } );

    DataBuffer db = sm.createDataBuffer();
    Object o = null;

    boolean testPassed = false;
    try {
        o = sm.getDataElements(Integer.MAX_VALUE, 0, 1, 1, o, db);
    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println(e.getMessage());
        testPassed = true;
    }

    if (!testPassed) {
        throw new RuntimeException("Excpected excprion was not thrown.");
    }
}
 
Example 38
Project: jLibuvc   File: Utils.java   View source code 6 votes vote down vote up
public static BufferedImage getImage(UVCController.UVCFrame frame) {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);

    // raster in "BGR" order like OpenCV..
    int[] offsets = new int[]{2, 1, 0};

    ColorModel cm = new ComponentColorModel(cs, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
    ComponentSampleModel csm = new ComponentSampleModel(DataBuffer.TYPE_BYTE, frame.width(), frame.height(), 3, frame.width() * 3, offsets);
    WritableRaster wr = Raster.createWritableRaster(csm, null);

    BufferedImage bImage = new BufferedImage(cm, wr, false, null);
    DataBufferByte out = (DataBufferByte) bImage.getRaster().getDataBuffer();
    ByteBuffer buff = frame.data().capacity(frame.data_bytes()).asByteBuffer();

    copyByteBuffer(buff, frame.width() * 3, ByteBuffer.wrap(out.getData()), frame.width() * 3);
    return bImage;
}
 
Example 39
Project: visual-scripting   File: FT2Helper.java   View source code 6 votes vote down vote up
static boolean copyGlyphToBufferedImageGray(FT2Library.FT_Bitmap bitmap, BufferedImage img, int x, int y) {
	if (x + bitmap.width > img.getWidth()) {
		return false;
	}
	if (y + bitmap.rows > img.getHeight()) {
		return false;
	}

	final DataBufferByte dataBuffer = (DataBufferByte) img.getRaster().getDataBuffer();
	final byte[] data = dataBuffer.getData();
	final int stride = ((ComponentSampleModel) img.getSampleModel()).getScanlineStride();

	ByteBuffer bb = bitmap.buffer.getByteBuffer(0, Math.abs(bitmap.pitch) * bitmap.rows);
	int bbOff = (bitmap.pitch < 0) ? (-bitmap.pitch * (bitmap.rows - 1)) : 0;
	int dataOff = dataBuffer.getOffset() + y * stride + x;

	for (int r = 0; r < bitmap.rows; r++, bbOff += bitmap.pitch, dataOff += stride) {
		for (int c = 0; c < bitmap.width; c++) {
			data[dataOff + c] = (byte) (bb.get(bbOff + c) ^ 0xff);
		}
	}

	return true;
}
 
Example 40
Project: cn1   File: JavaBlitterTest.java   View source code 6 votes vote down vote up
public final void test_from_BuffImg_to_FloatDataBuffer(){
    src = createImage(BufferedImage.TYPE_INT_RGB);

    DataBufferFloat dbf = new DataBufferFloat(w * h * 3);
    int offsets[] = new int[]{0,1,2};
    ComponentSampleModel csm = new ComponentSampleModel(DataBuffer.TYPE_FLOAT,
            w, h, 3, 3 * w, offsets);
    WritableRaster wr = new OrdinaryWritableRaster(csm, dbf, new Point(0, 0));
    ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false, Transparency.OPAQUE, DataBuffer.TYPE_FLOAT);
    BufferedImage dst = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
    Graphics2D g2d = dst.createGraphics();
    g2d.drawImage(src, 0, 0, null);

    for(int y = 0; y < h; y++){
        for(int x = 0; x < w; x++){
            assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
        }
    }
}