uint32 req_w=0, req_h=0;
il_size(il_container *ic){    float aspect;    int status;    uint8 img_depth;    uint32 src_width, src_height;    int32 image_bytes, old_image_bytes;    IL_GroupContext *img_cx = ic->img_cx;    NI_PixmapHeader *src_header = ic->src_header; /* Source image header. */    NI_PixmapHeader *img_header = &ic->image->header; /* Destination image                                                         header. */        /* Get the dimensions of the source image. */    src_width = src_header->width;    src_height = src_header->height;	/* Ensure that the source image has a sane area. */	if (!src_width || !src_height            ||        (src_width > MAX_IMAGE_WIDTH)        ||        (src_height > MAX_IMAGE_HEIGHT)) {            		ILTRACE(1,("il: bad image size: %dx%d", src_width, src_height));		return MK_IMAGE_LOSSAGE;	}	ic->state = IC_SIZED;	if (ic->state == IC_MULTI)		return 0;    /* For now, we don't allow an image to change output size on the     * fly, but we do allow the source image size to change, and thus     * we may need to change the scaling factor to fit it into the     * same size container on the display.     */    if (ic->sized) {        status = il_init_scaling(ic);        return status;    }    /* This must appear before il_init_img_header. */    old_image_bytes = (int32)img_header->widthBytes * img_header->height;        /* Initialize the dimensions of the destination image header structure       to be the dimensions of the source image.  The Display Front End will       reset these dimensions to be the target dimensions of the image if       it does not handle scaling. */    img_header->width = src_width;    img_header->height = src_height;    /* Determine the target dimensions of the image.  */    aspect = (float)src_width/(float)src_height;    if (!ic->dest_width && !ic->dest_height) {        /* Both target dimensions were unspecified, so use the dimensions of           the source image. */        ic->dest_width  = src_width;        ic->dest_height = src_height;    }    else if (ic->dest_width && ic->dest_height) {        /* Both target dimensions were specified; determine if this causes           aspect ratio distortion. */        if (ic->dest_width * src_height != ic->dest_height * src_width)            ic->aspect_distorted = PR_TRUE;    }    else if (ic->dest_width) {        /* Only the target width was specified.  Determine the target height           which preserves aspect ratio. */        ic->dest_height = (int)((float)ic->dest_width / aspect + 0.5);    }    else {        /* Only the target height was specified.  Determine the target width           which preserves aspect ratio. */        ic->dest_width  = (int)(aspect * (float)ic->dest_height + 0.5);    }    if (ic->dest_width == 0) ic->dest_width = 1;    if (ic->dest_height == 0) ic->dest_height = 1;    /* Determine if the image will be displayed at its natural size. */    if (ic->dest_width == src_width && ic->dest_height == src_height)        ic->natural_size = PR_TRUE;    /* Check that the target image dimensions are reasonable. */    if ((ic->dest_width > MAX_IMAGE_WIDTH)     ||        (ic->dest_height > MAX_IMAGE_HEIGHT)) {        return MK_IMAGE_LOSSAGE;    }	ILTRACE(2,("il: size %dx%d, scaled from %dx%d, ic = 0x%08x\n",               ic->dest_width, ic->dest_height, src_width, src_height, ic));    /* Determine the number of bytes per scan-line.  Image data must be       quadlet aligned for optimizations. */    img_depth = img_header->color_space->pixmap_depth;    img_header->widthBytes = (img_header->width * img_depth + 7) / 8;    img_header->widthBytes = ROUNDUP(img_header->widthBytes, 4);    /* Create and initialize the mask pixmap structure, if required.  A mask       is allocated only if the image is transparent and no background color       was specified for this image request. */    if (src_header->transparent_pixel && !ic->background_color) {        if (!ic->mask) {            NI_PixmapHeader *mask_header;                if (!(ic->mask = XP_NEW_ZAP(IL_Pixmap))) {                return MK_OUT_OF_MEMORY;            }            mask_header = &ic->mask->header;            mask_header->color_space = IL_CreateGreyScaleColorSpace(1, 1);            if (!mask_header->color_space)                return MK_OUT_OF_MEMORY;            mask_header->width = img_header->width;            mask_header->height = img_header->height;            mask_header->widthBytes = (mask_header->width + 7) / 8;            /* Mask data must be quadlet aligned for optimizations */            mask_header->widthBytes = ROUNDUP(mask_header->widthBytes, 4);        }        /* Notify observers that the image is transparent and has a mask. */        il_transparent_notify(ic);    }    else {                      /* Mask not required. */        /*  for png alpha*/        if (ic->mask) {                il_transparent_notify(ic);                if(ic->background_color){/*                    src_header->transparent_pixel = ic->background_color;                    img_header->transparent_pixel = ic->background_color;                                   XP_MEMCPY(img_trans_pixel, ic->background_color, sizeof(IL_IRGB)); */        }/*            il_destroy_pixmap(ic->img_cb, ic->mask);            ic->mask = NULL;*/        }            }    ic->sized = 1;    /* Notify observers of the target dimensions of the image. */    il_dimensions_notify(ic, ic->dest_width, ic->dest_height);    /* Fabricate a title for the image and notify observers.  Image Plugins       will need to supply information on the image type. */    il_description_notify(ic);    /* If the display front-end doesn't support scaling, IMGCBIF_NewPixmap will       set the image and mask dimensions to scaled_width and scaled_height. */    IMGCBIF_NewPixmap(img_cx->img_cb, img_cx->dpy_cx, ic->dest_width,                      ic->dest_height, ic->image, ic->mask);    	if (!ic->image->bits)		return MK_OUT_OF_MEMORY;	if (ic->mask && !ic->mask->bits)		return MK_OUT_OF_MEMORY;	/* Adjust the total cache byte count to reflect any departure from the       original predicted byte count for this image. */    image_bytes = (int32)img_header->widthBytes * img_header->height;    if (image_bytes - old_image_bytes)        il_adjust_cache_fullness(image_bytes - old_image_bytes);    /* If we have a mask, initialize its bits. */    if (ic->mask) {        NI_PixmapHeader *mask_header = &ic->mask->header;        uint32 mask_size = mask_header->widthBytes * mask_header->height;        IMGCBIF_ControlPixmapBits(img_cx->img_cb, img_cx->dpy_cx, ic->mask,                                  IL_LOCK_BITS);                                        memset (ic->mask->bits, ~0, mask_size);                IMGCBIF_ControlPixmapBits(img_cx->img_cb, img_cx->dpy_cx, ic->mask,                                  IL_UNLOCK_BITS);    }        if ((status = il_init_scaling(ic)) < 0)        return status;    /* XXXM12N Clean this up */	/* Get memory for quantizing.  (required amount depends on image width) */	if (img_header->color_space->type == NI_PseudoColor) {		if (!il_init_quantize(ic)) {			ILTRACE(0,("il: MEM il_init_quantize"));			return MK_OUT_OF_MEMORY;		}	}	return 0;}