This commit is contained in:
prrace 2026-01-27 14:48:34 -08:00
parent eb6e74b1fa
commit 621433818a
4 changed files with 106 additions and 6 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -503,7 +503,11 @@ public class ComponentSampleModel extends SampleModel
}
/** Returns the number of bits per sample for the specified band.
* @param band the specified band
* <p>
* Since all bands of a {@code ComponentSampleModel} are the same
* size, this method ignores the {@code band} parameter and returns
* the size of the first (0th) band.
* @param band the specified band (ignored)
* @return the number of bits per sample for the specified band.
*/
public final int getSampleSize(int band) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -235,7 +235,11 @@ public class MultiPixelPackedSampleModel extends SampleModel
/**
* Returns the number of bits per sample for the specified band.
* @param band the specified band
* <p>
* Since {@code MultiPixelPackedSampleModel} has only one band,
* this method ignores the {@code band} parameter and returns
* the sample size of the single band.
* @param band the specified band (ignored).
* @return the number of bits per sample for the specified band.
*/
public int getSampleSize(int band) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -250,7 +250,12 @@ public class SinglePixelPackedSampleModel extends SampleModel
return bitSizes.clone();
}
/** Returns the number of bits per sample for the specified band. */
/** Returns the number of bits per sample for the specified band.
* @param band the specified band
* @return the size of the samples of the specified band.
* @throws ArrayIndexOutOfBoundsException if the {@code band} index
* is less than zero or greater than or equal to {@code getNumBands()}
*/
public int getSampleSize(int band) {
return bitSizes[band];
}

View File

@ -0,0 +1,87 @@
/*
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.awt.image.ComponentSampleModel;
import java.awt.image.DataBuffer;
import java.awt.image.MultiPixelPackedSampleModel;
import java.awt.image.SinglePixelPackedSampleModel;
/*
* @test
* @bug 8376297
* @summary Test SampleModel.getSampleSize(int)
*/
public class GetSampleSizeTest {
public static void main(String[] args) {
final int width = 10;
final int height = 10;
int[] bandOffsets = {0, 0};
int[] bitMask = {0x00ff0000, 0x0000ff00, 0xff, 0x0};
{
ComponentSampleModel csm =
new ComponentSampleModel(DataBuffer.TYPE_BYTE,
width, height, 1, width, bandOffsets);
int numBands = csm.getNumBands();
System.out.println("CSM numBands = " + numBands);
if (numBands != 2) {
throw new RuntimeException("Unexpected numBands");
}
System.out.println("CSM sample size = " + csm.getSampleSize(numBands));
}
{
MultiPixelPackedSampleModel mppsm =
new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
width, height, 4);
int numBands = mppsm.getNumBands();
System.out.println("MPPSM numBands = " + numBands);
if (numBands != 1) {
throw new RuntimeException("Unexpected numBands");
}
System.out.println("MPPSM sample size = " + mppsm.getSampleSize(numBands));
}
{
SinglePixelPackedSampleModel sppsm =
new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE,
width, height, bitMask);
int numBands = sppsm.getNumBands();
System.out.println("SPPSM numBands = " + numBands);
if (numBands != 4) {
throw new RuntimeException("Unexpected numBands");
}
try {
System.out.println("SPPSM sample size = " + sppsm.getSampleSize(numBands));
throw new RuntimeException("No expected AIOBE");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Got expected AIOBE for SPPSM");
}
}
}
}