src/share/native/sun/awt/image/awt_parseImage.c

Print this page




 472     }
 473 }
 474 
 475 void awt_freeParsedImage(BufImageS_t *imageP, int freeImageP) {
 476     if (imageP->hints.colorOrder) {
 477         free ((void *) imageP->hints.colorOrder);
 478     }
 479 
 480     if (imageP->cmodel.nBits) {
 481         free ((void *) imageP->cmodel.nBits);
 482     }
 483 
 484     /* Free the raster */
 485     awt_freeParsedRaster(&imageP->raster, FALSE);
 486 
 487     if (freeImageP) {
 488         free((void *) imageP);
 489     }
 490 }
 491 

































































 492 
 493 static int
 494 setHints(JNIEnv *env, BufImageS_t *imageP) {
 495     HintS_t *hintP = &imageP->hints;
 496     RasterS_t *rasterP = &imageP->raster;
 497     ColorModelS_t *cmodelP = &imageP->cmodel;
 498     int imageType = imageP->imageType;
 499 
 500     hintP->numChans = imageP->cmodel.numComponents;
 501     hintP->colorOrder = NULL;
 502     if (SAFE_TO_ALLOC_2(hintP->numChans, sizeof(int))) {
 503         hintP->colorOrder = (int *)malloc(hintP->numChans * sizeof(int));
 504     }
 505     if (hintP->colorOrder == NULL) {
 506         JNU_ThrowOutOfMemoryError(env, "Out of memory");
 507         return -1;
 508     }
 509     if (imageType != java_awt_image_BufferedImage_TYPE_CUSTOM) {
 510         awt_getBIColorOrder(imageType, hintP->colorOrder);
 511     }




 472     }
 473 }
 474 
 475 void awt_freeParsedImage(BufImageS_t *imageP, int freeImageP) {
 476     if (imageP->hints.colorOrder) {
 477         free ((void *) imageP->hints.colorOrder);
 478     }
 479 
 480     if (imageP->cmodel.nBits) {
 481         free ((void *) imageP->cmodel.nBits);
 482     }
 483 
 484     /* Free the raster */
 485     awt_freeParsedRaster(&imageP->raster, FALSE);
 486 
 487     if (freeImageP) {
 488         free((void *) imageP);
 489     }
 490 }
 491 
 492 static void
 493 awt_getBIColorOrder(int type, int *colorOrder) {
 494     switch(type) {
 495         case java_awt_image_BufferedImage_TYPE_INT_ARGB:
 496         case java_awt_image_BufferedImage_TYPE_INT_ARGB_PRE:
 497 #ifdef _LITTLE_ENDIAN
 498             colorOrder[0] = 2;
 499             colorOrder[1] = 1;
 500             colorOrder[2] = 0;
 501             colorOrder[3] = 3;
 502 #else
 503             colorOrder[0] = 1;
 504             colorOrder[1] = 2;
 505             colorOrder[2] = 3;
 506             colorOrder[3] = 0;
 507 #endif
 508             break;
 509         case java_awt_image_BufferedImage_TYPE_INT_BGR:
 510 #ifdef _LITTLE_ENDIAN
 511             colorOrder[0] = 0;
 512             colorOrder[1] = 1;
 513             colorOrder[2] = 2;
 514 #else
 515             colorOrder[0] = 3;
 516             colorOrder[1] = 2;
 517             colorOrder[2] = 1;
 518 #endif
 519             break;
 520         case java_awt_image_BufferedImage_TYPE_INT_RGB:
 521 #ifdef _LITTLE_ENDIAN
 522             colorOrder[0] = 2;
 523             colorOrder[1] = 1;
 524             colorOrder[2] = 0;
 525 #else
 526             colorOrder[0] = 1;
 527             colorOrder[1] = 2;
 528             colorOrder[2] = 3;
 529 #endif
 530             break;
 531         case java_awt_image_BufferedImage_TYPE_4BYTE_ABGR:
 532         case java_awt_image_BufferedImage_TYPE_4BYTE_ABGR_PRE:
 533             colorOrder[0] = 3;
 534             colorOrder[1] = 2;
 535             colorOrder[2] = 1;
 536             colorOrder[3] = 0;
 537             break;
 538         case java_awt_image_BufferedImage_TYPE_3BYTE_BGR:
 539             colorOrder[0] = 2;
 540             colorOrder[1] = 1;
 541             colorOrder[2] = 0;
 542             break;
 543         case java_awt_image_BufferedImage_TYPE_USHORT_565_RGB:
 544         case java_awt_image_BufferedImage_TYPE_USHORT_555_RGB:
 545             colorOrder[0] = 0;
 546             colorOrder[1] = 1;
 547             colorOrder[2] = 2;
 548             break;
 549         case java_awt_image_BufferedImage_TYPE_BYTE_GRAY:
 550         case java_awt_image_BufferedImage_TYPE_USHORT_GRAY:
 551         case java_awt_image_BufferedImage_TYPE_BYTE_BINARY:
 552         case java_awt_image_BufferedImage_TYPE_BYTE_INDEXED:
 553             colorOrder[0] = 0;
 554             break;
 555     }
 556 }
 557 
 558 static int
 559 setHints(JNIEnv *env, BufImageS_t *imageP) {
 560     HintS_t *hintP = &imageP->hints;
 561     RasterS_t *rasterP = &imageP->raster;
 562     ColorModelS_t *cmodelP = &imageP->cmodel;
 563     int imageType = imageP->imageType;
 564 
 565     hintP->numChans = imageP->cmodel.numComponents;
 566     hintP->colorOrder = NULL;
 567     if (SAFE_TO_ALLOC_2(hintP->numChans, sizeof(int))) {
 568         hintP->colorOrder = (int *)malloc(hintP->numChans * sizeof(int));
 569     }
 570     if (hintP->colorOrder == NULL) {
 571         JNU_ThrowOutOfMemoryError(env, "Out of memory");
 572         return -1;
 573     }
 574     if (imageType != java_awt_image_BufferedImage_TYPE_CUSTOM) {
 575         awt_getBIColorOrder(imageType, hintP->colorOrder);
 576     }