-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
8, 25
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
When the BandedSampleModel is configured to utilize multiple banks for its DataBuffer, the createDataBuffer() method determines the size of each bank's underlying data array according to the global maximum offset identified across all the provided bandOffsets. This calculation occurs regardless of the specific bank to which a particular band (and its corresponding offset) pertains. The consequence is that banks which only necessitate a smaller internal offset are nonetheless allocated memory based on this global maximum value, resulting in unnecessary memory utilization.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
java -ea BandedSampleModelSizeTest
---------- BEGIN SOURCE ----------
import java.awt.image.BandedSampleModel;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
public class BandedSampleModelSizeTest {
public static void main(String[] args) {
// Initialize multi-bank model
int[] bandOffsets = {0, 20, 40}; // Band 0 offset=0, Band 1 offset=20, Band 2 offset=40
int[] bankIndices = {0, 1, 2}; // Band 0 -> Bank 0; Band 1 -> Bank 1; Band 2 -> Bank 2
int width = 10;
int height = 10;
int scanlineStride = 10; // Assuming tightly packed data within a band scanline
BandedSampleModel model = new BandedSampleModel(
DataBuffer.TYPE_BYTE, width, height, scanlineStride,
bankIndices, bandOffsets
);
// Create DataBuffer
DataBufferByte buffer = (DataBufferByte) model.createDataBuffer();
// Verification
// Base data size per band = scanlineStride * height = 10 * 10 = 100
// Bank 0: Expected size = 100 (data) + 0 (offset) = 100
// Bank 1: Expected size = 100 (data) + 20 (offset) = 120
// Bank 2: Expected size = 100 (data) + 40 (offset) = 140
System.out.println("Bank 0 - Expected: 100, Actual: " + buffer.getData(0).length);
System.out.println("Bank 1 - Expected: 120, Actual: " + buffer.getData(1).length);
System.out.println("Bank 2 - Expected: 140, Actual: " + buffer.getData(2).length);
// Assertion based on the bug report's finding for bank 0:
// assert buffer.getData(0).length == 100; // This would fail, actual is 140
}
}
---------- END SOURCE ----------
When the BandedSampleModel is configured to utilize multiple banks for its DataBuffer, the createDataBuffer() method determines the size of each bank's underlying data array according to the global maximum offset identified across all the provided bandOffsets. This calculation occurs regardless of the specific bank to which a particular band (and its corresponding offset) pertains. The consequence is that banks which only necessitate a smaller internal offset are nonetheless allocated memory based on this global maximum value, resulting in unnecessary memory utilization.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
java -ea BandedSampleModelSizeTest
---------- BEGIN SOURCE ----------
import java.awt.image.BandedSampleModel;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
public class BandedSampleModelSizeTest {
public static void main(String[] args) {
// Initialize multi-bank model
int[] bandOffsets = {0, 20, 40}; // Band 0 offset=0, Band 1 offset=20, Band 2 offset=40
int[] bankIndices = {0, 1, 2}; // Band 0 -> Bank 0; Band 1 -> Bank 1; Band 2 -> Bank 2
int width = 10;
int height = 10;
int scanlineStride = 10; // Assuming tightly packed data within a band scanline
BandedSampleModel model = new BandedSampleModel(
DataBuffer.TYPE_BYTE, width, height, scanlineStride,
bankIndices, bandOffsets
);
// Create DataBuffer
DataBufferByte buffer = (DataBufferByte) model.createDataBuffer();
// Verification
// Base data size per band = scanlineStride * height = 10 * 10 = 100
// Bank 0: Expected size = 100 (data) + 0 (offset) = 100
// Bank 1: Expected size = 100 (data) + 20 (offset) = 120
// Bank 2: Expected size = 100 (data) + 40 (offset) = 140
System.out.println("Bank 0 - Expected: 100, Actual: " + buffer.getData(0).length);
System.out.println("Bank 1 - Expected: 120, Actual: " + buffer.getData(1).length);
System.out.println("Bank 2 - Expected: 140, Actual: " + buffer.getData(2).length);
// Assertion based on the bug report's finding for bank 0:
// assert buffer.getData(0).length == 100; // This would fail, actual is 140
}
}
---------- END SOURCE ----------