CUBE_SCALE(r, dmax_val, crm1, dcrm1);
(uint8) (CUBE_SCALE(r, dmax_val, crm1, dcrm1));
il_NewColorCube(uint32 red_size, uint32 green_size, uint32 blue_size,                uint32 base_offset){    uint8 r, g, b, map_index;    uint32 i, j, k, size, red_offset, green_offset, dmax_val;    uint32 trm1, tgm1, tbm1, dtrm1, dtgm1, dtbm1;    uint32 crm1, cgm1, cbm1, dcrm1, dcgm1, dcbm1;    uint8 *lookup_table, *ptr, *done;    IL_RGB *map;    IL_ColorMap *cmap;    /* Colormap size and offsets for computing the colormap indices. */    size = base_offset + red_size * green_size * blue_size;    if (size > CUBE_MAX_SIZE)        return PR_FALSE;    red_offset = green_size * blue_size;    green_offset = blue_size;     /* Operation on lookup table dimensions. */    trm1 = LOOKUP_TABLE_RED - 1;    dtrm1 = trm1 << 1;    tgm1 = LOOKUP_TABLE_GREEN - 1;  dtgm1 = tgm1 << 1;    tbm1 = LOOKUP_TABLE_BLUE - 1;   dtbm1 = tbm1 << 1;     /* Operations on color cube dimensions. */    crm1 = red_size - 1;    dcrm1 = crm1 << 1;    cgm1 = green_size - 1;  dcgm1 = cgm1 << 1;    cbm1 = blue_size - 1;   dcbm1 = cbm1 << 1;     /* Operation on target RGB color space dimensions. */    dmax_val = 255 << 1;    /* We may want to add entries to the map array subsequently, so always       allocate space for a full palette. */    map = (IL_RGB *)PR_Calloc(256, sizeof(IL_RGB));    if (!map)        return PR_FALSE;    lookup_table = (uint8 *)PR_Calloc(LOOKUP_TABLE_SIZE, 1);    if (!lookup_table)        return PR_FALSE;    done = (uint8 *)PR_Calloc(size, 1);    if (!done)        return PR_FALSE;        ptr = lookup_table;    for (i = 0; i < LOOKUP_TABLE_RED; i++)        for (j = 0; j < LOOKUP_TABLE_GREEN; j++)            for (k = 0; k < LOOKUP_TABLE_BLUE; k++) {                /* Scale indices down to cube coordinates. */                r = CUBE_SCALE(i, dcrm1, trm1, dtrm1);                g = CUBE_SCALE(j, dcgm1, tgm1, dtgm1);                b = CUBE_SCALE(k, dcbm1, tbm1, dtbm1);                /* Compute the colormap index. */                map_index = r * red_offset + g * green_offset + b +                    base_offset;                /* Fill out the colormap entry for this index if we haven't                   already done so. */                if (!done[map_index]) {                    /* Scale from cube coordinates up to 8-bit RGB values. */                    map[map_index].red =                        CUBE_SCALE(r, dmax_val, crm1, dcrm1);                    map[map_index].green =                         CUBE_SCALE(g, dmax_val, cgm1, dcgm1);                    map[map_index].blue =                        CUBE_SCALE(b, dmax_val, cbm1, dcbm1);                    /* Mark as done. */                    done[map_index] = 1;                }                /* Fill in the lookup table entry with the colormap index. */                *ptr++ = map_index;            }    PR_FREEIF(done);    cmap = PR_NEWZAP(IL_ColorMap);    if (!cmap) {        PR_FREEIF(map);        PR_FREEIF(lookup_table);        return NULL;    }    cmap->num_colors = size;    cmap->map = map;    cmap->index = NULL;    cmap->table = (void *)lookup_table;    return cmap;}