Mercurial > hg > release > icedtea7-forest-2.4 > jdk
changeset 7245:87bce4c4d211
8027841: Enhance pixel manipulations
Reviewed-by: prr, vadim
author | bae |
---|---|
date | Wed, 27 Nov 2013 12:08:21 +0400 |
parents | e33366af7724 |
children | a41e6d94840b |
files | src/share/native/sun/awt/medialib/awt_ImagingLib.c |
diffstat | 1 files changed, 65 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/native/sun/awt/medialib/awt_ImagingLib.c Sun Nov 24 13:08:16 2013 +0000 +++ b/src/share/native/sun/awt/medialib/awt_ImagingLib.c Wed Nov 27 12:08:21 2013 +0400 @@ -228,6 +228,49 @@ } } +/* + * We have to make sure that awt_setPixels can be safely applied to the given pair of + * raster and mlib image. + * + * In particular, make sure that + * - dimension is the same + * - number of channels in mlib image corresponds to the number of bands in the raster + * - sample size in image and raster are the same. + * + * Returns: + * -1 to indicate failure, + * 1 to indicate success + */ +static int setPixelsFormMlibImage(JNIEnv *env, RasterS_t *rasterP, mlib_image* img) { + if (rasterP->width != img->width || rasterP->height != img->height) { + /* dimension does not match */ + return -1; + } + + if (rasterP->numBands != img->channels) { + /* number of bands does not match */ + return -1; + } + + switch (rasterP->dataType) { + case BYTE_DATA_TYPE: + if (img->type != MLIB_BYTE) { + return -1; + } + break; + case SHORT_DATA_TYPE: + if (img->type != MLIB_SHORT && img->type != MLIB_USHORT) { + return -1; + } + break; + default: + /* awt_setPixels does not support such rasters */ + return -1; + } + + return awt_setPixels(env, rasterP, mlib_ImageGetData(img)); +} + /*************************************************************************** * External Functions * ***************************************************************************/ @@ -700,7 +743,9 @@ /* Means that we couldn't write directly into the destination buffer */ if (ddata == NULL) { - retStatus = awt_setPixels(env, dstRasterP, mlib_ImageGetData(dst)); + if (storeRasterArray(env, srcRasterP, dstRasterP, dst) < 0) { + retStatus = setPixelsFormMlibImage(env, dstRasterP, dst); + } } /* Release the pinned memory */ @@ -1106,7 +1151,7 @@ if (ddata == NULL) { /* Need to store it back into the array */ if (storeRasterArray(env, srcRasterP, dstRasterP, dst) < 0) { - retStatus = awt_setPixels(env, dstRasterP, mlib_ImageGetData(dst)); + retStatus = setPixelsFormMlibImage(env, dstRasterP, dst); } } @@ -1432,6 +1477,14 @@ retStatus = 0; } + /* Release the LUT */ + for (i=0; i < lut_nbands; i++) { + (*env)->ReleasePrimitiveArrayCritical(env, jtable[i].jArray, + (jbyte *) jtable[i].table, JNI_ABORT); + } + free ((void *) jtable); + free ((void *) tbl); + /* * Means that we couldn't write directly into * the destination buffer @@ -1445,13 +1498,6 @@ } } - /* Release the LUT */ - for (i=0; i < lut_nbands; i++) { - (*env)->ReleasePrimitiveArrayCritical(env, jtable[i].jArray, - (jbyte *) jtable[i].table, JNI_ABORT); - } - free ((void *) jtable); - free ((void *) tbl); /* Release the pinned memory */ freeArray(env, srcImageP, src, sdata, dstImageP, dst, ddata); @@ -1669,18 +1715,20 @@ retStatus = 0; } + /* Release the LUT */ + for (i=0; i < lut_nbands; i++) { + (*env)->ReleasePrimitiveArrayCritical(env, jtable[i].jArray, + (jbyte *) jtable[i].table, JNI_ABORT); + } + /* * Means that we couldn't write directly into * the destination buffer */ if (ddata == NULL) { - retStatus = awt_setPixels(env, dstRasterP, mlib_ImageGetData(dst)); - } - - /* Release the LUT */ - for (i=0; i < lut_nbands; i++) { - (*env)->ReleasePrimitiveArrayCritical(env, jtable[i].jArray, - (jbyte *) jtable[i].table, JNI_ABORT); + if (storeRasterArray(env, srcRasterP, dstRasterP, dst) < 0) { + retStatus = setPixelsFormMlibImage(env, dstRasterP, dst); + } } /* Release the pinned memory */ @@ -2640,7 +2688,7 @@ } } else if (mlibImP->type == MLIB_SHORT) { - return awt_setPixels(env, rasterP, mlibImP->data); + return setPixelsFormMlibImage(env, rasterP, mlibImP); } } else {