Mercurial > projects > dwt-linux
diff dwt/graphics/ImageData.d @ 240:ce446666f5a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 12 May 2008 19:13:01 +0200 |
parents | 380bad9f6852 |
children | 5a30aa9820f3 |
line wrap: on
line diff
--- a/dwt/graphics/ImageData.d Mon May 12 15:36:37 2008 +0200 +++ b/dwt/graphics/ImageData.d Mon May 12 19:13:01 2008 +0200 @@ -289,7 +289,7 @@ * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT - if the width or height is negative, or if the depth is not - * one of 1, 2, 4, 8, 16, 24 or 32</li> + * one of 1, 2, 4, 8, 16, 24 or 32, or the data array is too small to contain the image data</li> * <li>ERROR_NULL_ARGUMENT - if the palette or data is null</li> * <li>ERROR_CANNOT_BE_ZERO - if the scanlinePad is zero</li> * </ul> @@ -444,6 +444,17 @@ int bytesPerLine = (((width * depth + 7) / 8) + (scanlinePad - 1)) / scanlinePad * scanlinePad; + + /* + * When the image is being loaded from a PNG, we need to use the theoretical minimum + * number of bytes per line to check whether there is enough data, because the actual + * number of bytes per line is calculated based on the given depth, which may be larger + * than the actual depth of the PNG. + */ + int minBytesPerLine = type is DWT.IMAGE_PNG ? ((((width + 7) / 8) + 3) / 4) * 4 : bytesPerLine; + if (data !is null && data.length < minBytesPerLine * height) { + DWT.error(DWT.ERROR_INVALID_ARGUMENT); + } setAllFields( width, height,