Java 类java.awt.image.ComponentSampleModel 实例源码

项目:OpenJSharp    文件:ImageUtil.java   
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();

}
项目:OpenJSharp    文件:ImageUtil.java   
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);
}
项目:jdk8u-jdk    文件:ImageUtil.java   
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();

}
项目:jdk8u-jdk    文件:ImageUtil.java   
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);
}
项目:jdk8u-jdk    文件:GetDataElementsTest.java   
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.");
    }
}
项目:openjdk-jdk10    文件:ImageUtil.java   
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();

}
项目:openjdk-jdk10    文件:ImageUtil.java   
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);
}
项目:openjdk-jdk10    文件:GetDataElementsTest.java   
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.");
    }
}
项目:openjdk9    文件:ImageUtil.java   
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();

}
项目:openjdk9    文件:ImageUtil.java   
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);
}
项目:openjdk9    文件:GetDataElementsTest.java   
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.");
    }
}
项目:jdk8u_jdk    文件:ImageUtil.java   
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();

}
项目:jdk8u_jdk    文件:ImageUtil.java   
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);
}
项目:jdk8u_jdk    文件:GetDataElementsTest.java   
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.");
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:ImageUtil.java   
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();

}
项目:lookaside_java-1.8.0-openjdk    文件:ImageUtil.java   
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);
}
项目:lookaside_java-1.8.0-openjdk    文件:GetDataElementsTest.java   
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.");
    }
}
项目:javify    文件:PixmapVolatileImage.java   
@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);
}
项目:jvm-stm    文件:PixmapVolatileImage.java   
@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);
}
项目:infobip-open-jdk-8    文件:ImageUtil.java   
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();

}
项目:infobip-open-jdk-8    文件:ImageUtil.java   
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);
}
项目:infobip-open-jdk-8    文件:GetDataElementsTest.java   
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.");
    }
}
项目:jdk8u-dev-jdk    文件:ImageUtil.java   
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();

}
项目:jdk8u-dev-jdk    文件:ImageUtil.java   
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);
}
项目:jdk8u-dev-jdk    文件:GetDataElementsTest.java   
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.");
    }
}
项目:grib2geotiff    文件:GeoTiffExporter.java   
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;
}
项目:jdk7-jdk    文件:ImageUtil.java   
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();

}
项目:jdk7-jdk    文件:ImageUtil.java   
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);
}
项目:jdk7-jdk    文件:GetDataElementsTest.java   
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.");
    }
}
项目:rastertheque    文件:RectIterCSM.java   
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];
}
项目:rastertheque    文件:RecyclingTileFactory.java   
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;
}
项目:openjdk-source-code-learn    文件:ImageUtil.java   
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();

}
项目:openjdk-source-code-learn    文件:ImageUtil.java   
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);
}
项目:openjdk-source-code-learn    文件:GetDataElementsTest.java   
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.");
    }
}
项目:OLD-OpenJDK8    文件:ImageUtil.java   
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();

}
项目:OLD-OpenJDK8    文件:ImageUtil.java   
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);
}
项目:OLD-OpenJDK8    文件:GetDataElementsTest.java   
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.");
    }
}
项目:jLibuvc    文件:Utils.java   
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;
}
项目:visual-scripting    文件:FT2Helper.java   
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;
}
项目:cn1    文件:JavaBlitterTest.java   
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));
        }
    }
}