154 |
return createWritableRaster(sm, location); |
return createWritableRaster(sm, location); |
155 |
} |
} |
156 |
|
|
157 |
|
public static WritableRaster createPackedRaster(int dataType, |
158 |
|
int w, int h, |
159 |
|
int bands, int bitsPerBand, |
160 |
|
Point location) |
161 |
|
{ |
162 |
|
if (bands <= 0 || (bands * bitsPerBand > getTypeBits(dataType))) |
163 |
|
throw new IllegalArgumentException(); |
164 |
|
|
165 |
|
SampleModel sm; |
166 |
|
|
167 |
|
if (bands == 1) |
168 |
|
sm = new MultiPixelPackedSampleModel(dataType, w, h, bitsPerBand); |
169 |
|
else |
170 |
|
{ |
171 |
|
int[] bandMasks = new int[bands]; |
172 |
|
int mask = 0x1; |
173 |
|
for (int bits = bitsPerBand; --bits != 0;) |
174 |
|
mask = (mask << 1) | 0x1; |
175 |
|
for (int i = 0; i < bands; i++) |
176 |
|
{ |
177 |
|
bandMasks[i] = mask; |
178 |
|
mask <<= bitsPerBand; |
179 |
|
} |
180 |
|
|
181 |
|
sm = new SinglePixelPackedSampleModel(dataType, w, h, bandMasks); |
182 |
|
} |
183 |
|
return createWritableRaster(sm, location); |
184 |
|
} |
185 |
|
|
186 |
public static WritableRaster |
public static WritableRaster |
187 |
createInterleavedRaster(DataBuffer dataBuffer, int w, int h, |
createInterleavedRaster(DataBuffer dataBuffer, int w, int h, |
188 |
int scanlineStride, int pixelStride, |
int scanlineStride, int pixelStride, |
358 |
return height; |
return height; |
359 |
} |
} |
360 |
|
|
361 |
|
public final int getNumBands() |
362 |
|
{ |
363 |
|
return numBands; |
364 |
|
} |
365 |
|
|
366 |
public final int getNumDataElements() |
public final int getNumDataElements() |
367 |
{ |
{ |
368 |
return numDataElements; |
return numDataElements; |
506 |
|
|
507 |
return result.toString(); |
return result.toString(); |
508 |
} |
} |
509 |
|
|
510 |
|
// Map from datatype to bits |
511 |
|
private static int getTypeBits(int dataType) |
512 |
|
{ |
513 |
|
switch (dataType) |
514 |
|
{ |
515 |
|
case DataBuffer.TYPE_BYTE: |
516 |
|
return 8; |
517 |
|
case DataBuffer.TYPE_USHORT: |
518 |
|
case DataBuffer.TYPE_SHORT: |
519 |
|
return 16; |
520 |
|
case DataBuffer.TYPE_INT: |
521 |
|
case DataBuffer.TYPE_FLOAT: |
522 |
|
return 32; |
523 |
|
case DataBuffer.TYPE_DOUBLE: |
524 |
|
return 64; |
525 |
|
default: |
526 |
|
return 0; |
527 |
|
} |
528 |
|
} |
529 |
} |
} |