Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 83 lines (57 sloc) 1.612 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
/*
=head1 NAME

map.c - inplace image mapping and related functionality

=head1 SYNOPSIS

i_map(srcimage, coeffs, outchans, inchans)

=head1 DESCRIPTION

Converts images from one format to another, typically in this case for
converting from RGBA to greyscale and back.

=over

=cut
*/

#include "imager.h"


/*
=item i_map(im, mapcount, maps, chmasks)

maps im inplace into another image.

Each map is a unsigned char array of 256 entries, its corresponding
channel mask is the same numbered entry in the chmasks array.
If two maps apply to the same channel then the second one is used.
If no map applies to a channel then that channel is not altered.
mapcount is the number of maps.

=cut
*/

void
i_map(i_img *im, unsigned char (*maps)[256], unsigned int mask) {
  i_color *vals;
  i_img_dim x, y;
  int i, ch;
  int minset = -1, maxset = 0;

  mm_log((1,"i_map(im %p, maps %p, chmask %u)\n", im, maps, mask));

  if (!mask) return; /* nothing to do here */

  for(i=0; i<im->channels; i++)
    if (mask & (1<<i)) {
      if (minset == -1) minset = i;
      maxset = i;
    }

  mm_log((1, "minset=%d maxset=%d\n", minset, maxset));

  vals = mymalloc(sizeof(i_color) * im->xsize);

  for (y = 0; y < im->ysize; ++y) {
    i_glin(im, 0, im->xsize, y, vals);
    for (x = 0; x < im->xsize; ++x) {
      for(ch = minset; ch<=maxset; ch++) {
if (!maps[ch]) continue;
vals[x].channel[ch] = maps[ch][vals[x].channel[ch]];
      }
    }
    i_plin(im, 0, im->xsize, y, vals);
  }
  myfree(vals);
}

/*
=back

=head1 SEE ALSO

Imager(3)

=head1 AUTHOR

Arnar M. Hrafnkelsson <addi@umich.edu>

=cut
*/
Something went wrong with that request. Please try again.