4 convert.c - image conversions
8 i_convert(outimage, srcimage, coeff, outchans, inchans)
12 Converts images from one format to another, typically in this case for
13 converting from RGBA to greyscale and back.
24 =item i_convert(im, src, coeff, outchan, inchan)
26 Converts the image src into another image.
28 coeff contains the co-efficients of an outchan x inchan matrix, for
31 coeff[0], coeff[1] ...
32 im[x,y] = [ coeff[inchan], coeff[inchan+1]... ] * [ src[x,y], 1]
33 ... coeff[inchan*outchan-1]
35 If im has the wrong number of channels or is the wrong size then
36 i_convert() will re-create it.
42 i_convert(i_img *im, i_img *src, float *coeff, int outchan, int inchan)
48 double work[MAXCHANNELS];
50 mm_log((1,"i_convert(im* 0x%x, src, 0x%x, coeff 0x%x,outchan %d, inchan %d)\n",im,src, coeff,outchan, inchan));
55 if (ilimit > src->channels)
56 ilimit = src->channels;
57 if (outchan > MAXCHANNELS) {
58 i_push_error(0, "cannot have outchan > MAXCHANNELS");
62 /* first check the output image */
63 if (im->channels != outchan || im->xsize != src->xsize
64 || im->ysize != src->ysize) {
65 i_img_empty_ch(im, src->xsize, src->ysize, outchan);
67 vals = mymalloc(sizeof(i_color) * src->xsize);
68 for (y = 0; y < src->ysize; ++y) {
69 i_glin(src, 0, src->xsize, y, vals);
70 for (x = 0; x < src->xsize; ++x) {
71 for (j = 0; j < outchan; ++j) {
73 for (i = 0; i < ilimit; ++i) {
74 work[j] += coeff[i+inchan*j] * vals[x].channel[i];
77 work[j] += coeff[i+inchan*j] * 255.9;
80 for (j = 0; j < outchan; ++j) {
82 vals[x].channel[j] = 0;
83 else if (work[j] >= 256)
84 vals[x].channel[j] = 255;
86 vals[x].channel[j] = work[j];
89 i_plin(im, 0, src->xsize, y, vals);
104 Tony Cook <tony@develop-help.com>