summaryrefslogtreecommitdiff
path: root/src/rgbfilt/ftrgbgen.h
blob: da7cf15c0bc32cf4977c8afbc6427adfec7f5c2f (plain)
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
/* this file contains a template for the RGB color filter algorithm
 * it is included several times by "ftrgb.c"
 */
#ifndef OFF_R
#error "OFF_R must be defined as the offset of the red channel"
#endif

#ifndef OFF_G
#error "OFF_G must be defiend as the offset of the green channel"
#endif

#ifndef OFF_B
#error "OFF_B must be defined as the offset of the blue channel"
#endif

#ifndef HMUL
#error "HMUL must be defined as the horizontal multiplier, either 1 or 3"
#endif

#ifndef VMUL
#error "VMUL must be defined as the vertical multipler, either 1 or 3"
#endif


  int        hh        = oper->height;
  FT_Byte*   in_line   = oper->in_line;
  FT_Long    in_pitch  = oper->in_pitch;
  FT_Byte*   out_line  = oper->out_line;
  FT_Long    out_pitch = oper->out_pitch;
  FT_Fixed*  mults     = oper->factors;

  for ( ; hh > 0; hh--, in_line += in_pitch*VMUL, out_line += out_pitch )
  {
    int         ww    = oper->width;
    FT_Byte*    read  = in_line;
    FT_UInt32*  write = (FT_UInt32*)out_line;

    for ( ; ww > 0; ww--, read += HMUL, write += 1 )
    {
      FT_UInt    rr, gg, bb;
      FT_UInt    val;

      val = read[OFF_R];
      rr  = mults[0]*val;
      gg  = mults[3]*val;
      bb  = mults[6]*val;

      val = read[OFF_G];
      rr += mults[1]*val;
      gg += mults[4]*val;
      bb += mults[7]*val;

      val = read[OFF_B];
      rr += mults[2]*val;
      gg += mults[5]*val;
      bb += mults[8]*val;

      rr = (rr >> 16) & 255;
      gg = (gg >> 16) & 255;
      bb = (bb >> 16) & 255;

      write[0] = (FT_UInt)( (gg << 24) | (rr << 16) | (gg << 8) | bb );
    }
  }

#undef  OFF_R
#undef  OFF_G
#undef  OFF_B
#undef  HMUL
#undef  VMUL