316 /* out of memory exception already thrown */
317 return 0;
318 }
319
320 if ((kwidth&0x1) == 0) {
321 /* Kernel has even width */
322 w = kwidth+1;
323 }
324 else {
325 w = kwidth;
326 }
327 if ((kheight&0x1) == 0) {
328 /* Kernel has even height */
329 h = kheight+1;
330 }
331 else {
332 h = kheight;
333 }
334
335 dkern = NULL;
336 if (SAFE_TO_ALLOC_3(w, h, sizeof(mlib_d64))) {
337 dkern = (mlib_d64 *)calloc(1, w * h * sizeof(mlib_d64));
338 }
339 if (dkern == NULL) {
340 (*env)->ReleasePrimitiveArrayCritical(env, jdata, kern, JNI_ABORT);
341 return 0;
342 }
343
344 /* Need to flip and find max value of the kernel.
345 * Also, save the kernel values as mlib_d64 values.
346 * The flip is to operate correctly with medialib,
347 * which doesn't do the mathemetically correct thing,
348 * i.e. it doesn't rotate the kernel by 180 degrees.
349 * REMIND: This should perhaps be done at the Java
350 * level by ConvolveOp.
351 * REMIND: Should the max test be looking at absolute
352 * values?
353 * REMIND: What if klen != kheight * kwidth?
354 */
355 kmax = kern[klen-1];
356 i = klen-1;
399 /* Allocate the arrays */
400 if (allocateArray(env, srcImageP, &src, &sdata, TRUE,
401 hint.cvtSrcToDefault, hint.addAlpha) < 0) {
402 /* Must be some problem */
403 awt_freeParsedImage(srcImageP, TRUE);
404 awt_freeParsedImage(dstImageP, TRUE);
405 free(dkern);
406 return 0;
407 }
408 if (allocateArray(env, dstImageP, &dst, &ddata, FALSE,
409 hint.cvtToDst, FALSE) < 0) {
410 /* Must be some problem */
411 freeArray(env, srcImageP, src, sdata, NULL, NULL, NULL);
412 awt_freeParsedImage(srcImageP, TRUE);
413 awt_freeParsedImage(dstImageP, TRUE);
414 free(dkern);
415 return 0;
416 }
417
418 kdata = NULL;
419 if (SAFE_TO_ALLOC_3(w, h, sizeof(mlib_s32))) {
420 kdata = (mlib_s32 *)malloc(w * h * sizeof(mlib_s32));
421 }
422 if (kdata == NULL) {
423 freeArray(env, srcImageP, src, sdata, dstImageP, dst, ddata);
424 awt_freeParsedImage(srcImageP, TRUE);
425 awt_freeParsedImage(dstImageP, TRUE);
426 free(dkern);
427 return 0;
428 }
429
430 if ((*sMlibFns[MLIB_CONVKERNCVT].fptr)(kdata, &scale, dkern, w, h,
431 mlib_ImageGetType(src)) != MLIB_SUCCESS) {
432 freeArray(env, srcImageP, src, sdata, dstImageP, dst, ddata);
433 awt_freeParsedImage(srcImageP, TRUE);
434 awt_freeParsedImage(dstImageP, TRUE);
435 free(dkern);
436 free(kdata);
437 return 0;
438 }
439
557 /* out of memory exception already thrown */
558 return 0;
559 }
560
561 if ((kwidth&0x1) == 0) {
562 /* Kernel has even width */
563 w = kwidth+1;
564 }
565 else {
566 w = kwidth;
567 }
568 if ((kheight&0x1) == 0) {
569 /* Kernel has even height */
570 h = kheight+1;
571 }
572 else {
573 h = kheight;
574 }
575
576 dkern = NULL;
577 if (SAFE_TO_ALLOC_3(w, h, sizeof(mlib_d64))) {
578 dkern = (mlib_d64 *)calloc(1, w * h * sizeof(mlib_d64));
579 }
580 if (dkern == NULL) {
581 (*env)->ReleasePrimitiveArrayCritical(env, jdata, kern, JNI_ABORT);
582 return 0;
583 }
584
585 /* Need to flip and find max value of the kernel.
586 * Also, save the kernel values as mlib_d64 values.
587 * The flip is to operate correctly with medialib,
588 * which doesn't do the mathemetically correct thing,
589 * i.e. it doesn't rotate the kernel by 180 degrees.
590 * REMIND: This should perhaps be done at the Java
591 * level by ConvolveOp.
592 * REMIND: Should the max test be looking at absolute
593 * values?
594 * REMIND: What if klen != kheight * kwidth?
595 */
596 kmax = kern[klen-1];
597 i = klen-1;
645 }
646
647 /* Allocate the arrays */
648 if (allocateRasterArray(env, srcRasterP, &src, &sdata, TRUE) < 0) {
649 /* Must be some problem */
650 awt_freeParsedRaster(srcRasterP, TRUE);
651 awt_freeParsedRaster(dstRasterP, TRUE);
652 free(dkern);
653 return 0;
654 }
655 if (allocateRasterArray(env, dstRasterP, &dst, &ddata, FALSE) < 0) {
656 /* Must be some problem */
657 freeDataArray(env, srcRasterP->jdata, src, sdata, NULL, NULL, NULL);
658 awt_freeParsedRaster(srcRasterP, TRUE);
659 awt_freeParsedRaster(dstRasterP, TRUE);
660 free(dkern);
661 return 0;
662 }
663
664 kdata = NULL;
665 if (SAFE_TO_ALLOC_3(w, h, sizeof(mlib_s32))) {
666 kdata = (mlib_s32 *)malloc(w * h * sizeof(mlib_s32));
667 }
668 if (kdata == NULL) {
669 freeDataArray(env, srcRasterP->jdata, src, sdata,
670 dstRasterP->jdata, dst, ddata);
671 awt_freeParsedRaster(srcRasterP, TRUE);
672 awt_freeParsedRaster(dstRasterP, TRUE);
673 free(dkern);
674 return 0;
675 }
676
677 if ((*sMlibFns[MLIB_CONVKERNCVT].fptr)(kdata, &scale, dkern, w, h,
678 mlib_ImageGetType(src)) != MLIB_SUCCESS) {
679 freeDataArray(env, srcRasterP->jdata, src, sdata,
680 dstRasterP->jdata, dst, ddata);
681 awt_freeParsedRaster(srcRasterP, TRUE);
682 awt_freeParsedRaster(dstRasterP, TRUE);
683 free(dkern);
684 free(kdata);
685 return 0;
1358 /* Make sure that color order can be used for
1359 * re-ordering of lookup arrays.
1360 */
1361 for (i = 0; i < nbands; i++) {
1362 int idx = srcImageP->hints.colorOrder[i];
1363
1364 if (idx < 0 || idx >= ncomponents) {
1365 awt_freeParsedImage(srcImageP, TRUE);
1366 awt_freeParsedImage(dstImageP, TRUE);
1367 return 0;
1368 }
1369 }
1370
1371 lut_nbands = (*env)->GetArrayLength(env, jtableArrays);
1372
1373 if (lut_nbands > ncomponents) {
1374 lut_nbands = ncomponents;
1375 }
1376
1377 tbl = NULL;
1378 if (SAFE_TO_ALLOC_2(ncomponents, sizeof(unsigned char *))) {
1379 tbl = (unsigned char **)
1380 calloc(1, ncomponents * sizeof(unsigned char *));
1381 }
1382
1383 jtable = NULL;
1384 if (SAFE_TO_ALLOC_2(lut_nbands, sizeof(LookupArrayInfo))) {
1385 jtable = (LookupArrayInfo *)malloc(lut_nbands * sizeof (LookupArrayInfo));
1386 }
1387
1388 if (tbl == NULL || jtable == NULL) {
1389 if (tbl != NULL) free(tbl);
1390 if (jtable != NULL) free(jtable);
1391 awt_freeParsedImage(srcImageP, TRUE);
1392 awt_freeParsedImage(dstImageP, TRUE);
1393 JNU_ThrowNullPointerException(env, "NULL LUT");
1394 return 0;
1395 }
1396 /* Need to grab these pointers before we lock down arrays */
1397 for (i=0; i < lut_nbands; i++) {
1398 jtable[i].jArray = (*env)->GetObjectArrayElement(env, jtableArrays, i);
1399
1400 if (jtable[i].jArray != NULL) {
1401 jtable[i].length = (*env)->GetArrayLength(env, jtable[i].jArray);
1402 jtable[i].table = NULL;
1403
1404 if (jtable[i].length < 256) {
|
316 /* out of memory exception already thrown */
317 return 0;
318 }
319
320 if ((kwidth&0x1) == 0) {
321 /* Kernel has even width */
322 w = kwidth+1;
323 }
324 else {
325 w = kwidth;
326 }
327 if ((kheight&0x1) == 0) {
328 /* Kernel has even height */
329 h = kheight+1;
330 }
331 else {
332 h = kheight;
333 }
334
335 dkern = NULL;
336 if (SAFE_TO_ALLOC_3(w, h, (int)sizeof(mlib_d64))) {
337 dkern = (mlib_d64 *)calloc(1, w * h * sizeof(mlib_d64));
338 }
339 if (dkern == NULL) {
340 (*env)->ReleasePrimitiveArrayCritical(env, jdata, kern, JNI_ABORT);
341 return 0;
342 }
343
344 /* Need to flip and find max value of the kernel.
345 * Also, save the kernel values as mlib_d64 values.
346 * The flip is to operate correctly with medialib,
347 * which doesn't do the mathemetically correct thing,
348 * i.e. it doesn't rotate the kernel by 180 degrees.
349 * REMIND: This should perhaps be done at the Java
350 * level by ConvolveOp.
351 * REMIND: Should the max test be looking at absolute
352 * values?
353 * REMIND: What if klen != kheight * kwidth?
354 */
355 kmax = kern[klen-1];
356 i = klen-1;
399 /* Allocate the arrays */
400 if (allocateArray(env, srcImageP, &src, &sdata, TRUE,
401 hint.cvtSrcToDefault, hint.addAlpha) < 0) {
402 /* Must be some problem */
403 awt_freeParsedImage(srcImageP, TRUE);
404 awt_freeParsedImage(dstImageP, TRUE);
405 free(dkern);
406 return 0;
407 }
408 if (allocateArray(env, dstImageP, &dst, &ddata, FALSE,
409 hint.cvtToDst, FALSE) < 0) {
410 /* Must be some problem */
411 freeArray(env, srcImageP, src, sdata, NULL, NULL, NULL);
412 awt_freeParsedImage(srcImageP, TRUE);
413 awt_freeParsedImage(dstImageP, TRUE);
414 free(dkern);
415 return 0;
416 }
417
418 kdata = NULL;
419 if (SAFE_TO_ALLOC_3(w, h, (int)sizeof(mlib_s32))) {
420 kdata = (mlib_s32 *)malloc(w * h * sizeof(mlib_s32));
421 }
422 if (kdata == NULL) {
423 freeArray(env, srcImageP, src, sdata, dstImageP, dst, ddata);
424 awt_freeParsedImage(srcImageP, TRUE);
425 awt_freeParsedImage(dstImageP, TRUE);
426 free(dkern);
427 return 0;
428 }
429
430 if ((*sMlibFns[MLIB_CONVKERNCVT].fptr)(kdata, &scale, dkern, w, h,
431 mlib_ImageGetType(src)) != MLIB_SUCCESS) {
432 freeArray(env, srcImageP, src, sdata, dstImageP, dst, ddata);
433 awt_freeParsedImage(srcImageP, TRUE);
434 awt_freeParsedImage(dstImageP, TRUE);
435 free(dkern);
436 free(kdata);
437 return 0;
438 }
439
557 /* out of memory exception already thrown */
558 return 0;
559 }
560
561 if ((kwidth&0x1) == 0) {
562 /* Kernel has even width */
563 w = kwidth+1;
564 }
565 else {
566 w = kwidth;
567 }
568 if ((kheight&0x1) == 0) {
569 /* Kernel has even height */
570 h = kheight+1;
571 }
572 else {
573 h = kheight;
574 }
575
576 dkern = NULL;
577 if (SAFE_TO_ALLOC_3(w, h, (int)sizeof(mlib_d64))) {
578 dkern = (mlib_d64 *)calloc(1, w * h * sizeof(mlib_d64));
579 }
580 if (dkern == NULL) {
581 (*env)->ReleasePrimitiveArrayCritical(env, jdata, kern, JNI_ABORT);
582 return 0;
583 }
584
585 /* Need to flip and find max value of the kernel.
586 * Also, save the kernel values as mlib_d64 values.
587 * The flip is to operate correctly with medialib,
588 * which doesn't do the mathemetically correct thing,
589 * i.e. it doesn't rotate the kernel by 180 degrees.
590 * REMIND: This should perhaps be done at the Java
591 * level by ConvolveOp.
592 * REMIND: Should the max test be looking at absolute
593 * values?
594 * REMIND: What if klen != kheight * kwidth?
595 */
596 kmax = kern[klen-1];
597 i = klen-1;
645 }
646
647 /* Allocate the arrays */
648 if (allocateRasterArray(env, srcRasterP, &src, &sdata, TRUE) < 0) {
649 /* Must be some problem */
650 awt_freeParsedRaster(srcRasterP, TRUE);
651 awt_freeParsedRaster(dstRasterP, TRUE);
652 free(dkern);
653 return 0;
654 }
655 if (allocateRasterArray(env, dstRasterP, &dst, &ddata, FALSE) < 0) {
656 /* Must be some problem */
657 freeDataArray(env, srcRasterP->jdata, src, sdata, NULL, NULL, NULL);
658 awt_freeParsedRaster(srcRasterP, TRUE);
659 awt_freeParsedRaster(dstRasterP, TRUE);
660 free(dkern);
661 return 0;
662 }
663
664 kdata = NULL;
665 if (SAFE_TO_ALLOC_3(w, h, (int)sizeof(mlib_s32))) {
666 kdata = (mlib_s32 *)malloc(w * h * sizeof(mlib_s32));
667 }
668 if (kdata == NULL) {
669 freeDataArray(env, srcRasterP->jdata, src, sdata,
670 dstRasterP->jdata, dst, ddata);
671 awt_freeParsedRaster(srcRasterP, TRUE);
672 awt_freeParsedRaster(dstRasterP, TRUE);
673 free(dkern);
674 return 0;
675 }
676
677 if ((*sMlibFns[MLIB_CONVKERNCVT].fptr)(kdata, &scale, dkern, w, h,
678 mlib_ImageGetType(src)) != MLIB_SUCCESS) {
679 freeDataArray(env, srcRasterP->jdata, src, sdata,
680 dstRasterP->jdata, dst, ddata);
681 awt_freeParsedRaster(srcRasterP, TRUE);
682 awt_freeParsedRaster(dstRasterP, TRUE);
683 free(dkern);
684 free(kdata);
685 return 0;
1358 /* Make sure that color order can be used for
1359 * re-ordering of lookup arrays.
1360 */
1361 for (i = 0; i < nbands; i++) {
1362 int idx = srcImageP->hints.colorOrder[i];
1363
1364 if (idx < 0 || idx >= ncomponents) {
1365 awt_freeParsedImage(srcImageP, TRUE);
1366 awt_freeParsedImage(dstImageP, TRUE);
1367 return 0;
1368 }
1369 }
1370
1371 lut_nbands = (*env)->GetArrayLength(env, jtableArrays);
1372
1373 if (lut_nbands > ncomponents) {
1374 lut_nbands = ncomponents;
1375 }
1376
1377 tbl = NULL;
1378 if (SAFE_TO_ALLOC_2(ncomponents, (int)sizeof(unsigned char *))) {
1379 tbl = (unsigned char **)
1380 calloc(1, ncomponents * sizeof(unsigned char *));
1381 }
1382
1383 jtable = NULL;
1384 if (SAFE_TO_ALLOC_2(lut_nbands, (int)sizeof(LookupArrayInfo))) {
1385 jtable = (LookupArrayInfo *)malloc(lut_nbands * sizeof (LookupArrayInfo));
1386 }
1387
1388 if (tbl == NULL || jtable == NULL) {
1389 if (tbl != NULL) free(tbl);
1390 if (jtable != NULL) free(jtable);
1391 awt_freeParsedImage(srcImageP, TRUE);
1392 awt_freeParsedImage(dstImageP, TRUE);
1393 JNU_ThrowNullPointerException(env, "NULL LUT");
1394 return 0;
1395 }
1396 /* Need to grab these pointers before we lock down arrays */
1397 for (i=0; i < lut_nbands; i++) {
1398 jtable[i].jArray = (*env)->GetObjectArrayElement(env, jtableArrays, i);
1399
1400 if (jtable[i].jArray != NULL) {
1401 jtable[i].length = (*env)->GetArrayLength(env, jtable[i].jArray);
1402 jtable[i].table = NULL;
1403
1404 if (jtable[i].length < 256) {
|