Prima
view release on metacpan or search on metacpan
unix/image.c view on Meta::CPAN
}
if ( i->type != imRGB ) {
if ( !dup)
if (!(dup = img-> self-> dup(( Handle) i)))
return NULL;
i = (PIcon) dup;
i-> self-> set_type(dup, imRGB);
}
if ( XT_IS_ICON(IMG) && type == CACHE_LAYERED_ALPHA && i->maskType != imbpp8 ) {
if ( !dup)
if (!(dup = i-> self-> dup((Handle) i)))
return NULL;
i = (PIcon) dup;
i-> self-> set_maskType(dup, imbpp8);
}
if ( alpha != 255 ) {
img_premultiply_alpha_constant( dup, alpha);
if ( XT_IS_ICON(IMG)) {
Image dummy;
img_fill_dummy( &dummy, img->w, img->h, imByte, PIcon(dup)->mask, std256gray_palette);
img_premultiply_alpha_constant( (Handle) &dummy, alpha);
}
}
ok = create_argb_cache(i, cache,
(XT_IS_ICON(IMG) && type == CACHE_LAYERED_ALPHA) ? CACHE_LAYERED_ALPHA : CACHE_LAYERED
);
if ( dup) Object_destroy(dup);
if ( !ok ) return NULL;
cache-> type = type;
cache->alpha = alpha;
return cache;
}
cache->alpha = alpha;
if ( type == CACHE_A8 ) {
Bool ok;
PImage i = (PImage) pass;
if ( i->type != imByte ) {
if ( !dup)
if (!(dup = img-> self-> dup(( Handle) i)))
return NULL;
i = (PImage) dup;
i-> self-> set_type(dup, imByte);
}
ok = create_argb_cache((PIcon) i, cache, CACHE_A8);
if ( dup) Object_destroy(dup);
if ( !ok ) return NULL;
cache-> type = type;
return cache;
}
/*
apply as much of system palette colors as possible to new image,
if we're working on 1-8 bit displays. CACHE_LOW_RES on displays with
dynamic colors goes only after conservative strategy, using only
immutable colors to be copied to clipboard, icon, etc.
*/
if ( target_bpp <= 8 && img-> type != imBW) {
int bpp, colors = 0;
RGBColor palbuf[256], *palptr = NULL;
if ( !dup) {
if (!(dup = img-> self-> dup(( Handle) img)))
return NULL;
}
pass = ( PImage) dup;
if ( target_bpp <= 1) bpp = imbpp1; else
if ( target_bpp <= 4) bpp = imbpp4; else bpp = imbpp8;
if ( guts. palSize > 0 && target_bpp > 1) {
int i, maxRank = RANK_FREE;
if ( type == CACHE_LOW_RES) maxRank = RANK_LOCKED;
for ( i = 0; i < guts. palSize; i++) {
if ( guts. palette[i]. rank <= maxRank) continue;
palbuf[colors]. r = guts. palette[i]. r;
palbuf[colors]. g = guts. palette[i]. g;
palbuf[colors]. b = guts. palette[i]. b;
colors++;
if ( colors > 255) break;
}
palptr = palbuf;
}
pass-> self-> reset( dup, bpp, palptr, colors);
}
/* convert image bits */
switch ( pass-> type & imBPP) {
case 1: ret = create_cache1( pass, cache, target_bpp); break;
case 4: ret = create_cache4( pass, cache, target_bpp); break;
case 8: ret = create_cache8( pass, cache, target_bpp); break;
case 24: ret = create_cache24(pass, cache, target_bpp); break;
default:
warn( "UAI_015: unsupported image type");
return NULL;
}
if ( !ret) {
if ( dup) Object_destroy(dup);
return NULL;
}
/* on paletted displays, acquire actual color indexes, and
remap pixels to match them */
if (( guts. palSize > 0) && (( pass-> type & imBPP) != 24)) {
int i, maxRank = RANK_FREE;
Byte * p = X((Handle)img)-> palette;
if ( type == CACHE_LOW_RES) /* don't use dynamic colors */
maxRank = RANK_LOCKED;
for ( i = 0; i < pass-> palSize; i++) {
int j = guts. mappingPlace[i] = prima_color_find( NULL_HANDLE,
RGB_COMPOSITE(
pass-> palette[i].r,
pass-> palette[i].g,
pass-> palette[i].b
), -1, NULL, maxRank);
( run in 2.197 seconds using v1.01-cache-2.11-cpan-2398b32b56e )