final int h, final SampleModel sampleModel) {
int size = 0;
if (sampleModel instanceof ComponentSampleModel) {
ComponentSampleModel csm = (ComponentSampleModel) sampleModel;
int offsets[] = csm.getBandOffsets();
int maxOffset = offsets[0];
for (int i = 1; i < offsets.length; i++) {
if (offsets[i] > maxOffset) {
maxOffset = offsets[i];
}
}
int scanlineStride = csm.getScanlineStride();
int pixelStride = csm.getPixelStride();
size = (h - 1) * scanlineStride +
(w - 1) * pixelStride + maxOffset + 1;
} else if (sampleModel instanceof MultiPixelPackedSampleModel) {