| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | /* | 
| 2 |  |  |  |  |  |  | =head1 NAME | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | map.c - inplace image mapping and related functionality | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | i_map(srcimage, coeffs, outchans, inchans) | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | Converts images from one format to another, typically in this case for | 
| 13 |  |  |  |  |  |  | converting from RGBA to greyscale and back. | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | =over | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | =cut | 
| 18 |  |  |  |  |  |  | */ | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | #include "imager.h" | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | /* | 
| 24 |  |  |  |  |  |  | =item i_map(im, mapcount, maps, chmasks) | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | maps im inplace into another image. | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | Each map is a unsigned char array of 256 entries, its corresponding | 
| 29 |  |  |  |  |  |  | channel mask is the same numbered entry in the chmasks array. | 
| 30 |  |  |  |  |  |  | If two maps apply to the same channel then the second one is used. | 
| 31 |  |  |  |  |  |  | If no map applies to a channel then that channel is not altered. | 
| 32 |  |  |  |  |  |  | mapcount is the number of maps. | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | =cut | 
| 35 |  |  |  |  |  |  | */ | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | void | 
| 38 | 9 |  |  |  |  |  | i_map(i_img *im, unsigned char (*maps)[256], unsigned int mask) { | 
| 39 |  |  |  |  |  |  | i_color *vals; | 
| 40 |  |  |  |  |  |  | i_img_dim x, y; | 
| 41 |  |  |  |  |  |  | int i, ch; | 
| 42 | 9 |  |  |  |  |  | int minset = -1, maxset = 0; | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 9 |  |  |  |  |  | mm_log((1,"i_map(im %p, maps %p, chmask %u)\n", im, maps, mask)); | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 9 | 100 |  |  |  |  | if (!mask) return; /* nothing to do here */ | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 32 | 100 |  |  |  |  | for(i=0; ichannels; i++) { | 
| 49 | 24 | 100 |  |  |  |  | if (mask & (1< | 
| 50 | 18 | 100 |  |  |  |  | if (minset == -1) minset = i; | 
| 51 | 18 |  |  |  |  |  | maxset = i; | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  |  | 
| 55 | 8 |  |  |  |  |  | mm_log((1, "minset=%d maxset=%d\n", minset, maxset)); | 
| 56 |  |  |  |  |  |  |  | 
| 57 | 8 | 50 |  |  |  |  | if (minset == -1) | 
| 58 | 0 |  |  |  |  |  | return; | 
| 59 |  |  |  |  |  |  |  | 
| 60 | 8 |  |  |  |  |  | vals = mymalloc(sizeof(i_color) * im->xsize); | 
| 61 |  |  |  |  |  |  |  | 
| 62 | 1538 | 100 |  |  |  |  | for (y = 0; y < im->ysize; ++y) { | 
| 63 | 1530 |  |  |  |  |  | i_glin(im, 0, im->xsize, y, vals); | 
| 64 | 284190 | 100 |  |  |  |  | for (x = 0; x < im->xsize; ++x) { | 
| 65 | 890640 | 100 |  |  |  |  | for(ch = minset; ch<=maxset; ch++) { | 
| 66 | 607980 | 100 |  |  |  |  | if (!(mask & (1 << ch))) | 
| 67 | 32530 |  |  |  |  |  | continue; | 
| 68 | 575450 |  |  |  |  |  | vals[x].channel[ch] = maps[ch][vals[x].channel[ch]]; | 
| 69 |  |  |  |  |  |  | } | 
| 70 |  |  |  |  |  |  | } | 
| 71 | 1530 |  |  |  |  |  | i_plin(im, 0, im->xsize, y, vals); | 
| 72 |  |  |  |  |  |  | } | 
| 73 | 8 |  |  |  |  |  | myfree(vals); | 
| 74 |  |  |  |  |  |  | } | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | /* | 
| 77 |  |  |  |  |  |  | =back | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | Imager(3) | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | =head1 AUTHOR | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | Arnar M. Hrafnkelsson | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | =cut | 
| 88 |  |  |  |  |  |  | */ |