From fe67a5ac72d12dd8faf471d1c612492fed829a4b Mon Sep 17 00:00:00 2001 From: Andrew John Hughes Date: Fri, 14 Apr 2006 06:50:23 +0000 Subject: 2006-04-13 Andrew John Hughes * Merge of HEAD --> generics-branch from 2006/03/26 to 2006/04/13. --- java/awt/image/SampleModel.java | 412 ++++++++++++++++++++++------------------ 1 file changed, 226 insertions(+), 186 deletions(-) (limited to 'java/awt/image/SampleModel.java') diff --git a/java/awt/image/SampleModel.java b/java/awt/image/SampleModel.java index 115966222..6e3fd4069 100644 --- a/java/awt/image/SampleModel.java +++ b/java/awt/image/SampleModel.java @@ -1,4 +1,4 @@ -/* Copyright (C) 2000, 2001, 2002, 2005 Free Software Foundation +/* Copyright (C) 2000, 2001, 2002, 2005, 2006, Free Software Foundation This file is part of GNU Classpath. @@ -57,15 +57,43 @@ public abstract class SampleModel */ protected int dataType; + /** + * Creates a new sample model with the specified attributes. + * + * @param dataType the data type (one of {@link DataBuffer#TYPE_BYTE}, + * {@link DataBuffer#TYPE_USHORT}, {@link DataBuffer#TYPE_SHORT}, + * {@link DataBuffer#TYPE_INT}, {@link DataBuffer#TYPE_FLOAT}, + * {@link DataBuffer#TYPE_DOUBLE} or {@link DataBuffer#TYPE_UNDEFINED}). + * @param w the width in pixels (must be greater than zero). + * @param h the height in pixels (must be greater than zero). + * @param numBands the number of bands (must be greater than zero). + * + * @throws IllegalArgumentException if dataType is not one of + * the listed values. + * @throws IllegalArgumentException if w is less than or equal + * to zero. + * @throws IllegalArgumentException if h is less than or equal + * to zero. + * @throws IllegalArgumentException if w * h is greater than + * {@link Integer#MAX_VALUE}. + */ public SampleModel(int dataType, int w, int h, int numBands) { + if (dataType != DataBuffer.TYPE_UNDEFINED) + if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_DOUBLE) + throw new IllegalArgumentException("Unrecognised 'dataType' argument."); + if ((w <= 0) || (h <= 0)) throw new IllegalArgumentException((w <= 0 ? " width<=0" : " width is ok") - +(h <= 0 ? " height<=0" : " height is ok")); - - // FIXME: How can an int be greater than Integer.MAX_VALUE? - // FIXME: How do we identify an unsupported data type? - + + (h <= 0 ? " height<=0" : " height is ok")); + + long area = (long) w * (long) h; + if (area > Integer.MAX_VALUE) + throw new IllegalArgumentException("w * h exceeds Integer.MAX_VALUE."); + + if (numBands <= 0) + throw new IllegalArgumentException("Requires numBands > 0."); + this.dataType = dataType; this.width = w; this.height = h; @@ -102,8 +130,10 @@ public abstract class SampleModel public int[] getPixel(int x, int y, int[] iArray, DataBuffer data) { - if (iArray == null) iArray = new int[numBands]; - for (int b=0; b