302 else if ((*env)->IsInstanceOf(env, jraster, shortComponentRasterClass)){
303 rasterP->jdata = (*env)->GetObjectField(env, jraster, g_SCRdataID);
304 rasterP->dataType = SHORT_DATA_TYPE;
305 rasterP->dataSize = 2;
306 rasterP->dataIsShared = TRUE;
307 rasterP->rasterType = COMPONENT_RASTER_TYPE;
308 rasterP->type = (*env)->GetIntField(env, jraster, g_SCRtypeID);
309 rasterP->scanlineStride = (*env)->GetIntField(env, jraster, g_SCRscanstrID);
310 rasterP->pixelStride = (*env)->GetIntField(env, jraster, g_SCRpixstrID);
311 joffs = (*env)->GetObjectField(env, jraster, g_SCRdataOffsetsID);
312 }
313 else if ((*env)->IsInstanceOf(env, jraster, bytePackedRasterClass)){
314 rasterP->rasterType = PACKED_RASTER_TYPE;
315 rasterP->dataType = BYTE_DATA_TYPE;
316 rasterP->dataSize = 1;
317 rasterP->scanlineStride = (*env)->GetIntField(env, jraster, g_BPRscanstrID);
318 rasterP->pixelStride = (*env)->GetIntField(env, jraster, g_BPRpixstrID);
319 rasterP->jdata = (*env)->GetObjectField(env, jraster, g_BPRdataID);
320 rasterP->type = (*env)->GetIntField(env, jraster, g_BPRtypeID);
321 rasterP->chanOffsets = NULL;
322 if (SAFE_TO_ALLOC_2(rasterP->numDataElements, sizeof(jint))) {
323 rasterP->chanOffsets =
324 (jint *)malloc(rasterP->numDataElements * sizeof(jint));
325 }
326 if (rasterP->chanOffsets == NULL) {
327 /* Out of memory */
328 JNU_ThrowOutOfMemoryError(env, "Out of memory");
329 return -1;
330 }
331 rasterP->chanOffsets[0] = (*env)->GetIntField(env, jraster, g_BPRdataBitOffsetID);
332 rasterP->dataType = BYTE_DATA_TYPE;
333 }
334 else {
335 rasterP->type = sun_awt_image_IntegerComponentRaster_TYPE_CUSTOM;
336 rasterP->dataType = UNKNOWN_DATA_TYPE;
337 rasterP->rasterType = UNKNOWN_RASTER_TYPE;
338 rasterP->chanOffsets = NULL;
339 /* Custom raster */
340 return 0;
341 }
342
343 // do basic validation of the raster structure
344 if (rasterP->width <= 0 || rasterP->height <= 0 ||
345 rasterP->pixelStride <= 0 || rasterP->scanlineStride <= 0)
346 {
347 // invalid raster
348 return -1;
349 }
350
351 // channel (data) offsets
352 switch (rasterP->rasterType) {
353 case COMPONENT_RASTER_TYPE:
354 case BANDED_RASTER_TYPE: // note that this routine does not support banded rasters at the moment
355 // get channel (data) offsets
356 rasterP->chanOffsets = NULL;
357 if (SAFE_TO_ALLOC_2(rasterP->numDataElements, sizeof(jint))) {
358 rasterP->chanOffsets =
359 (jint *)malloc(rasterP->numDataElements * sizeof(jint));
360 }
361 if (rasterP->chanOffsets == NULL) {
362 /* Out of memory */
363 JNU_ThrowOutOfMemoryError(env, "Out of memory");
364 return -1;
365 }
366 (*env)->GetIntArrayRegion(env, joffs, 0, rasterP->numDataElements,
367 rasterP->chanOffsets);
368 if (rasterP->jdata == NULL) {
369 // unable to verify the raster
370 return -1;
371 }
372 // verify whether channel offsets look sane
373 if (!checkChannelOffsets(rasterP, (*env)->GetArrayLength(env, rasterP->jdata))) {
374 return -1;
375 }
376 break;
377 default:
469 cmP->supportsAlpha = (*env)->GetBooleanField(env, jcmodel,
470 g_CMsuppAlphaID);
471 cmP->isAlphaPre = (*env)->GetBooleanField(env,jcmodel,
472 g_CMisAlphaPreID);
473 cmP->transparency = (*env)->GetIntField(env, jcmodel,
474 g_CMtransparencyID);
475
476 jnBits = (*env)->GetObjectField(env, jcmodel, g_CMnBitsID);
477 if (jnBits == NULL) {
478 JNU_ThrowNullPointerException(env, "null nBits structure in CModel");
479 return -1;
480 }
481
482 nBitsLength = (*env)->GetArrayLength(env, jnBits);
483 if (nBitsLength != cmP->numComponents) {
484 // invalid number of components?
485 return -1;
486 }
487
488 cmP->nBits = NULL;
489 if (SAFE_TO_ALLOC_2(cmP->numComponents, sizeof(jint))) {
490 cmP->nBits = (jint *)malloc(cmP->numComponents * sizeof(jint));
491 }
492
493 if (cmP->nBits == NULL){
494 JNU_ThrowOutOfMemoryError(env, "Out of memory");
495 return -1;
496 }
497 (*env)->GetIntArrayRegion(env, jnBits, 0, cmP->numComponents,
498 cmP->nBits);
499 cmP->maxNbits = 0;
500 for (i=0; i < cmP->numComponents; i++) {
501 if (cmP->maxNbits < cmP->nBits[i]) {
502 cmP->maxNbits = cmP->nBits[i];
503 }
504 }
505
506 cmP->is_sRGB = (*env)->GetBooleanField(env, cmP->jcmodel, g_CMis_sRGBID);
507
508 cmP->csType = (*env)->GetIntField(env, cmP->jcmodel, g_CMcsTypeID);
509
684 break;
685 }
686 }
687
688 static int
689 setHints(JNIEnv *env, BufImageS_t *imageP) {
690 HintS_t *hintP = &imageP->hints;
691 RasterS_t *rasterP = &imageP->raster;
692 ColorModelS_t *cmodelP = &imageP->cmodel;
693 int imageType = imageP->imageType;
694
695 // check whether raster and color model are compatible
696 if (cmodelP->numComponents != rasterP->numBands) {
697 if (cmodelP->cmType != INDEX_CM_TYPE) {
698 return -1;
699 }
700 }
701
702 hintP->numChans = imageP->cmodel.numComponents;
703 hintP->colorOrder = NULL;
704 if (SAFE_TO_ALLOC_2(hintP->numChans, sizeof(int))) {
705 hintP->colorOrder = (int *)malloc(hintP->numChans * sizeof(int));
706 }
707 if (hintP->colorOrder == NULL) {
708 JNU_ThrowOutOfMemoryError(env, "Out of memory");
709 return -1;
710 }
711 if (imageType != java_awt_image_BufferedImage_TYPE_CUSTOM) {
712 awt_getBIColorOrder(imageType, hintP->colorOrder);
713 }
714 if (imageType == java_awt_image_BufferedImage_TYPE_INT_ARGB ||
715 imageType == java_awt_image_BufferedImage_TYPE_INT_ARGB_PRE ||
716 imageType == java_awt_image_BufferedImage_TYPE_INT_RGB)
717 {
718 hintP->channelOffset = rasterP->chanOffsets[0];
719 /* These hints are #bytes */
720 hintP->dataOffset = hintP->channelOffset*rasterP->dataSize;
721 hintP->sStride = rasterP->scanlineStride*rasterP->dataSize;
722 hintP->pStride = rasterP->pixelStride*rasterP->dataSize;
723 hintP->packing = BYTE_INTERLEAVED;
724 } else if (imageType ==java_awt_image_BufferedImage_TYPE_4BYTE_ABGR ||
|
302 else if ((*env)->IsInstanceOf(env, jraster, shortComponentRasterClass)){
303 rasterP->jdata = (*env)->GetObjectField(env, jraster, g_SCRdataID);
304 rasterP->dataType = SHORT_DATA_TYPE;
305 rasterP->dataSize = 2;
306 rasterP->dataIsShared = TRUE;
307 rasterP->rasterType = COMPONENT_RASTER_TYPE;
308 rasterP->type = (*env)->GetIntField(env, jraster, g_SCRtypeID);
309 rasterP->scanlineStride = (*env)->GetIntField(env, jraster, g_SCRscanstrID);
310 rasterP->pixelStride = (*env)->GetIntField(env, jraster, g_SCRpixstrID);
311 joffs = (*env)->GetObjectField(env, jraster, g_SCRdataOffsetsID);
312 }
313 else if ((*env)->IsInstanceOf(env, jraster, bytePackedRasterClass)){
314 rasterP->rasterType = PACKED_RASTER_TYPE;
315 rasterP->dataType = BYTE_DATA_TYPE;
316 rasterP->dataSize = 1;
317 rasterP->scanlineStride = (*env)->GetIntField(env, jraster, g_BPRscanstrID);
318 rasterP->pixelStride = (*env)->GetIntField(env, jraster, g_BPRpixstrID);
319 rasterP->jdata = (*env)->GetObjectField(env, jraster, g_BPRdataID);
320 rasterP->type = (*env)->GetIntField(env, jraster, g_BPRtypeID);
321 rasterP->chanOffsets = NULL;
322 if (SAFE_TO_ALLOC_2(rasterP->numDataElements, (int)sizeof(jint))) {
323 rasterP->chanOffsets =
324 (jint *)malloc(rasterP->numDataElements * sizeof(jint));
325 }
326 if (rasterP->chanOffsets == NULL) {
327 /* Out of memory */
328 JNU_ThrowOutOfMemoryError(env, "Out of memory");
329 return -1;
330 }
331 rasterP->chanOffsets[0] = (*env)->GetIntField(env, jraster, g_BPRdataBitOffsetID);
332 rasterP->dataType = BYTE_DATA_TYPE;
333 }
334 else {
335 rasterP->type = sun_awt_image_IntegerComponentRaster_TYPE_CUSTOM;
336 rasterP->dataType = UNKNOWN_DATA_TYPE;
337 rasterP->rasterType = UNKNOWN_RASTER_TYPE;
338 rasterP->chanOffsets = NULL;
339 /* Custom raster */
340 return 0;
341 }
342
343 // do basic validation of the raster structure
344 if (rasterP->width <= 0 || rasterP->height <= 0 ||
345 rasterP->pixelStride <= 0 || rasterP->scanlineStride <= 0)
346 {
347 // invalid raster
348 return -1;
349 }
350
351 // channel (data) offsets
352 switch (rasterP->rasterType) {
353 case COMPONENT_RASTER_TYPE:
354 case BANDED_RASTER_TYPE: // note that this routine does not support banded rasters at the moment
355 // get channel (data) offsets
356 rasterP->chanOffsets = NULL;
357 if (SAFE_TO_ALLOC_2(rasterP->numDataElements, (int)sizeof(jint))) {
358 rasterP->chanOffsets =
359 (jint *)malloc(rasterP->numDataElements * sizeof(jint));
360 }
361 if (rasterP->chanOffsets == NULL) {
362 /* Out of memory */
363 JNU_ThrowOutOfMemoryError(env, "Out of memory");
364 return -1;
365 }
366 (*env)->GetIntArrayRegion(env, joffs, 0, rasterP->numDataElements,
367 rasterP->chanOffsets);
368 if (rasterP->jdata == NULL) {
369 // unable to verify the raster
370 return -1;
371 }
372 // verify whether channel offsets look sane
373 if (!checkChannelOffsets(rasterP, (*env)->GetArrayLength(env, rasterP->jdata))) {
374 return -1;
375 }
376 break;
377 default:
469 cmP->supportsAlpha = (*env)->GetBooleanField(env, jcmodel,
470 g_CMsuppAlphaID);
471 cmP->isAlphaPre = (*env)->GetBooleanField(env,jcmodel,
472 g_CMisAlphaPreID);
473 cmP->transparency = (*env)->GetIntField(env, jcmodel,
474 g_CMtransparencyID);
475
476 jnBits = (*env)->GetObjectField(env, jcmodel, g_CMnBitsID);
477 if (jnBits == NULL) {
478 JNU_ThrowNullPointerException(env, "null nBits structure in CModel");
479 return -1;
480 }
481
482 nBitsLength = (*env)->GetArrayLength(env, jnBits);
483 if (nBitsLength != cmP->numComponents) {
484 // invalid number of components?
485 return -1;
486 }
487
488 cmP->nBits = NULL;
489 if (SAFE_TO_ALLOC_2(cmP->numComponents, (int)sizeof(jint))) {
490 cmP->nBits = (jint *)malloc(cmP->numComponents * sizeof(jint));
491 }
492
493 if (cmP->nBits == NULL){
494 JNU_ThrowOutOfMemoryError(env, "Out of memory");
495 return -1;
496 }
497 (*env)->GetIntArrayRegion(env, jnBits, 0, cmP->numComponents,
498 cmP->nBits);
499 cmP->maxNbits = 0;
500 for (i=0; i < cmP->numComponents; i++) {
501 if (cmP->maxNbits < cmP->nBits[i]) {
502 cmP->maxNbits = cmP->nBits[i];
503 }
504 }
505
506 cmP->is_sRGB = (*env)->GetBooleanField(env, cmP->jcmodel, g_CMis_sRGBID);
507
508 cmP->csType = (*env)->GetIntField(env, cmP->jcmodel, g_CMcsTypeID);
509
684 break;
685 }
686 }
687
688 static int
689 setHints(JNIEnv *env, BufImageS_t *imageP) {
690 HintS_t *hintP = &imageP->hints;
691 RasterS_t *rasterP = &imageP->raster;
692 ColorModelS_t *cmodelP = &imageP->cmodel;
693 int imageType = imageP->imageType;
694
695 // check whether raster and color model are compatible
696 if (cmodelP->numComponents != rasterP->numBands) {
697 if (cmodelP->cmType != INDEX_CM_TYPE) {
698 return -1;
699 }
700 }
701
702 hintP->numChans = imageP->cmodel.numComponents;
703 hintP->colorOrder = NULL;
704 if (SAFE_TO_ALLOC_2(hintP->numChans, (int)sizeof(int))) {
705 hintP->colorOrder = (int *)malloc(hintP->numChans * sizeof(int));
706 }
707 if (hintP->colorOrder == NULL) {
708 JNU_ThrowOutOfMemoryError(env, "Out of memory");
709 return -1;
710 }
711 if (imageType != java_awt_image_BufferedImage_TYPE_CUSTOM) {
712 awt_getBIColorOrder(imageType, hintP->colorOrder);
713 }
714 if (imageType == java_awt_image_BufferedImage_TYPE_INT_ARGB ||
715 imageType == java_awt_image_BufferedImage_TYPE_INT_ARGB_PRE ||
716 imageType == java_awt_image_BufferedImage_TYPE_INT_RGB)
717 {
718 hintP->channelOffset = rasterP->chanOffsets[0];
719 /* These hints are #bytes */
720 hintP->dataOffset = hintP->channelOffset*rasterP->dataSize;
721 hintP->sStride = rasterP->scanlineStride*rasterP->dataSize;
722 hintP->pStride = rasterP->pixelStride*rasterP->dataSize;
723 hintP->packing = BYTE_INTERLEAVED;
724 } else if (imageType ==java_awt_image_BufferedImage_TYPE_4BYTE_ABGR ||
|