示例#1
0
  private static ByteInterleavedRaster normalizeRaster(ByteInterleavedRaster raster) {
    boolean reallocBuffer = false;
    int scanLineStride = raster.getScanlineStride();
    int dataOffsets[] = raster.getDataOffsets();
    for (int i = 0; i < dataOffsets.length; i++)
      if (dataOffsets[i] != i) {
        reallocBuffer = true;
        break;
      }
    int bands = raster.getNumBands();
    if (!reallocBuffer
        && (raster.getPixelStride() != bands || scanLineStride != raster.getWidth() * bands))
      reallocBuffer = true;
    if (reallocBuffer) {
      PixelInterleavedSampleModel sm = (PixelInterleavedSampleModel) raster.getSampleModel();

      PixelInterleavedSampleModel newSM =
          new PixelInterleavedSampleModel(
              sm.getDataType(),
              raster.getWidth(),
              raster.getHeight(),
              bands,
              bands * raster.getWidth(),
              bands == 1 ? new int[] {0} : new int[] {0, 1, 2});

      ByteInterleavedRaster newRaster =
          new ByteInterleavedRaster(newSM, new Point(raster.getMinX(), raster.getMinY()));
      Functions.copyData(newRaster, raster);
      raster = newRaster;
    }
    return raster;
  }
示例#2
0
 public void doTransform(ShortInterleavedRaster input, ShortInterleavedRaster output) {
   if (cmsTransform != null) {
     ShortInterleavedRaster ri = normalizeRaster(input);
     ShortInterleavedRaster ro;
     int outBands = output.getNumBands();
     if (!input.getBounds().equals(output.getBounds())) {
       int[] offsets = outBands == 1 ? new int[] {0} : new int[] {0, 1, 2};
       SampleModel sm =
           new PixelInterleavedSampleModel(
               DataBuffer.TYPE_USHORT,
               ri.getWidth(),
               ri.getHeight(),
               outBands,
               outBands * ri.getWidth(),
               offsets);
       ro = new ShortInterleavedRaster(sm, new Point(ri.getMinX(), ri.getMinY()));
     } else ro = normalizeRaster(output);
     int pixels =
         outBands == 1 ? ro.getDataStorage().length : ro.getDataStorage().length / outBands;
     cmsDoTransform(cmsTransform.handle, ri.getDataStorage(), ro.getDataStorage(), pixels);
     if (ro != output) Functions.copyData(output, ro);
   }
 }