X-Git-Url: http://git.imager.perl.org/imager.git/blobdiff_plain/98747309573070774d7f2dd43f177fb0ffa39abb..9d2648493177027a5c97aa5ae7ef64bec3dceab5:/image.c diff --git a/image.c b/image.c index 03dc6e2c..cbd1b38a 100644 --- a/image.c +++ b/image.c @@ -404,6 +404,85 @@ i_img_get_height(i_img *im) { return im->ysize; } +/* +=item i_img_color_model(im) +=category Image Information +=synopsis i_color_model_t cm = i_img_color_model(im); + +Returns the color model for the image. + +A future version of Imager will allow for images with extra channels +beyond gray/rgb and alpha. + +=cut +*/ +i_color_model_t +i_img_color_model(i_img *im) { + return (i_color_model_t)im->channels; +} + +/* +=item i_img_alpha_channel(im, &channel) +=category Image Information +=synopsis int alpha_channel; +=synopsis int has_alpha = i_img_alpha_channel(im, &alpha_channel); + +Work out the alpha channel for an image. + +If the image has an alpha channel, sets C<*channel> to the alpha +channel index and returns non-zero. + +If the image has no alpha channel, returns zero and C<*channel> is not +modified. + +C may be C. + +=cut +*/ + +int +i_img_alpha_channel(i_img *im, int *channel) { + i_color_model_t model = i_img_color_model(im); + switch (model) { + case icm_gray_alpha: + case icm_rgb_alpha: + if (channel) *channel = (int)model - 1; + return 1; + + default: + return 0; + } +} + +/* +=item i_img_color_channels(im) +=category Image Information +=synopsis int color_channels = i_img_color_channels(im); + +Returns the number of color channels in the image. For now this is +always 1 (for grayscale) or 3 (for RGB) but may be 0 in some special +cases in a future release of Imager. + +=cut +*/ + +int +i_img_color_channels(i_img *im) { + i_color_model_t model = i_img_color_model(im); + switch (model) { + case icm_gray_alpha: + case icm_rgb_alpha: + return (int)model - 1; + + case icm_gray: + case icm_rgb: + return (int)model; + + default: + return 0; + } +} + /* =item i_copyto_trans(C, C, C, C, C, C, C, C, C) @@ -1131,7 +1210,8 @@ i_count_colors(i_img *im,int maxc) { for(x = 0; x < samp_cnt; ) { colorcnt += octt_add(ct, samp[x], samp[x+1], samp[x+2]); x += 3; - if (colorcnt > maxc) { + if (colorcnt > maxc) { + myfree(samp); octt_delete(ct); return -1; } @@ -1222,7 +1302,8 @@ i_get_anonymous_color_histo(i_img *im, unsigned int **col_usage, int maxc) { colorcnt += octt_add(ct, samp[x], samp[x+1], samp[x+2]); x += 3; if (colorcnt > maxc) { - octt_delete(ct); + octt_delete(ct); + myfree(samp); return -1; } }