misc/libfreetype/src/base/ftlcdfil.c
author sheepluva
Thu, 03 May 2012 14:21:53 +0200
changeset 7017 19a434fc91fc
parent 5172 88f2e05288ba
permissions -rw-r--r--
visually indicate when map preview generation is in progress.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
/*  ftlcdfil.c                                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
/*    FreeType API for color filtering of subpixel bitmap glyphs (body).   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  Copyright 2006, 2008, 2009, 2010 by                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include FT_LCD_FILTER_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include FT_IMAGE_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include FT_INTERNAL_OBJECTS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
#ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
/* define USE_LEGACY to implement the legacy filter */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
#define  USE_LEGACY
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  /* FIR filter used by the default and light filters */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  _ft_lcd_filter_fir( FT_Bitmap*      bitmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
                      FT_Render_Mode  mode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
                      FT_Library      library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
    FT_Byte*  weights = library->lcd_weights;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
    FT_UInt   width   = (FT_UInt)bitmap->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
    FT_UInt   height  = (FT_UInt)bitmap->rows;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
    /* horizontal in-place FIR filter */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
    if ( mode == FT_RENDER_MODE_LCD && width >= 4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
      FT_Byte*  line = bitmap->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
      for ( ; height > 0; height--, line += bitmap->pitch )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
        FT_UInt  fir[5];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
        FT_UInt  val1, xx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
        val1   = line[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
        fir[0] = weights[2] * val1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
        fir[1] = weights[3] * val1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
        fir[2] = weights[4] * val1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
        fir[3] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
        fir[4] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
        val1    = line[1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
        fir[0] += weights[1] * val1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
        fir[1] += weights[2] * val1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
        fir[2] += weights[3] * val1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
        fir[3] += weights[4] * val1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
        for ( xx = 2; xx < width; xx++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
          FT_UInt  val, pix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
          val    = line[xx];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
          pix    = fir[0] + weights[0] * val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
          fir[0] = fir[1] + weights[1] * val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
          fir[1] = fir[2] + weights[2] * val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
          fir[2] = fir[3] + weights[3] * val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
          fir[3] =          weights[4] * val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
          pix        >>= 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
          pix         |= -( pix >> 8 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
          line[xx - 2] = (FT_Byte)pix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
          FT_UInt  pix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
          pix          = fir[0] >> 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
          pix         |= -( pix >> 8 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
          line[xx - 2] = (FT_Byte)pix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
          pix          = fir[1] >> 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
          pix         |= -( pix >> 8 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
          line[xx - 1] = (FT_Byte)pix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
    /* vertical in-place FIR filter */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
    else if ( mode == FT_RENDER_MODE_LCD_V && height >= 4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
      FT_Byte*  column = bitmap->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
      FT_Int    pitch  = bitmap->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
      for ( ; width > 0; width--, column++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
        FT_Byte*  col = column;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
        FT_UInt   fir[5];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
        FT_UInt   val1, yy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
        val1   = col[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
        fir[0] = weights[2] * val1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
        fir[1] = weights[3] * val1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
        fir[2] = weights[4] * val1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
        fir[3] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
        fir[4] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
        col   += pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
        val1    = col[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
        fir[0] += weights[1] * val1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
        fir[1] += weights[2] * val1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
        fir[2] += weights[3] * val1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
        fir[3] += weights[4] * val1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
        col    += pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
        for ( yy = 2; yy < height; yy++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
          FT_UInt  val, pix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
          val    = col[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
          pix    = fir[0] + weights[0] * val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
          fir[0] = fir[1] + weights[1] * val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
          fir[1] = fir[2] + weights[2] * val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
          fir[2] = fir[3] + weights[3] * val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
          fir[3] =          weights[4] * val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
          pix           >>= 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
          pix            |= -( pix >> 8 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
          col[-2 * pitch] = (FT_Byte)pix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
          col            += pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
          FT_UInt  pix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
          pix             = fir[0] >> 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
          pix            |= -( pix >> 8 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
          col[-2 * pitch] = (FT_Byte)pix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
          pix         = fir[1] >> 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
          pix        |= -( pix >> 8 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
          col[-pitch] = (FT_Byte)pix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
#ifdef USE_LEGACY
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
  /* intra-pixel filter used by the legacy filter */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
  _ft_lcd_filter_legacy( FT_Bitmap*      bitmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
                         FT_Render_Mode  mode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
                         FT_Library      library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
    FT_UInt  width  = (FT_UInt)bitmap->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
    FT_UInt  height = (FT_UInt)bitmap->rows;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
    FT_Int   pitch  = bitmap->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
    static const int  filters[3][3] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
      { 65538 * 9/13, 65538 * 1/6, 65538 * 1/13 },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
      { 65538 * 3/13, 65538 * 4/6, 65538 * 3/13 },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
      { 65538 * 1/13, 65538 * 1/6, 65538 * 9/13 }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
    };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
    FT_UNUSED( library );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
    /* horizontal in-place intra-pixel filter */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
    if ( mode == FT_RENDER_MODE_LCD && width >= 3 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
      FT_Byte*  line = bitmap->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
      for ( ; height > 0; height--, line += pitch )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
        FT_UInt  xx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
        for ( xx = 0; xx < width; xx += 3 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
          FT_UInt  r = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
          FT_UInt  g = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
          FT_UInt  b = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
          FT_UInt  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
          p  = line[xx];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
          r += filters[0][0] * p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
          g += filters[0][1] * p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
          b += filters[0][2] * p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
          p  = line[xx + 1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
          r += filters[1][0] * p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
          g += filters[1][1] * p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
          b += filters[1][2] * p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
          p  = line[xx + 2];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
          r += filters[2][0] * p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
          g += filters[2][1] * p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
          b += filters[2][2] * p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
          line[xx]     = (FT_Byte)( r / 65536 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
          line[xx + 1] = (FT_Byte)( g / 65536 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
          line[xx + 2] = (FT_Byte)( b / 65536 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
    else if ( mode == FT_RENDER_MODE_LCD_V && height >= 3 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
      FT_Byte*  column = bitmap->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
      for ( ; width > 0; width--, column++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
        FT_Byte*  col     = column;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
        FT_Byte*  col_end = col + height * pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
        for ( ; col < col_end; col += 3 * pitch )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
          FT_UInt  r = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
          FT_UInt  g = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
          FT_UInt  b = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
          FT_UInt  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
          p  = col[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
          r += filters[0][0] * p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
          g += filters[0][1] * p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
          b += filters[0][2] * p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
          p  = col[pitch];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
          r += filters[1][0] * p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
          g += filters[1][1] * p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
          b += filters[1][2] * p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
          p  = col[pitch * 2];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
          r += filters[2][0] * p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
          g += filters[2][1] * p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
          b += filters[2][2] * p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
          col[0]         = (FT_Byte)( r / 65536 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
          col[pitch]     = (FT_Byte)( g / 65536 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
          col[2 * pitch] = (FT_Byte)( b / 65536 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
#endif /* USE_LEGACY */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
  FT_Library_SetLcdFilterWeights( FT_Library      library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
                                  unsigned char  *weights )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
    if ( !library || !weights )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
    ft_memcpy( library->lcd_weights, weights, 5 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
  FT_Library_SetLcdFilter( FT_Library    library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
                           FT_LcdFilter  filter )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
    static const FT_Byte  light_filter[5] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
                            { 0x00, 0x55, 0x56, 0x55, 0x00 };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
    /* the values here sum up to a value larger than 256, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
    /* providing a cheap gamma correction                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
    static const FT_Byte  default_filter[5] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
                            { 0x10, 0x40, 0x70, 0x40, 0x10 };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
    if ( !library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
    switch ( filter )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
    case FT_LCD_FILTER_NONE:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
      library->lcd_filter_func = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
      library->lcd_extra       = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
    case FT_LCD_FILTER_DEFAULT:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
#if defined( FT_FORCE_LEGACY_LCD_FILTER )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
      library->lcd_filter_func = _ft_lcd_filter_legacy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
      library->lcd_extra       = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
#elif defined( FT_FORCE_LIGHT_LCD_FILTER )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
      ft_memcpy( library->lcd_weights, light_filter, 5 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
      library->lcd_filter_func = _ft_lcd_filter_fir;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
      library->lcd_extra       = 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
      ft_memcpy( library->lcd_weights, default_filter, 5 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
      library->lcd_filter_func = _ft_lcd_filter_fir;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
      library->lcd_extra       = 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
    case FT_LCD_FILTER_LIGHT:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
      ft_memcpy( library->lcd_weights, light_filter, 5 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
      library->lcd_filter_func = _ft_lcd_filter_fir;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
      library->lcd_extra       = 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
#ifdef USE_LEGACY
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
    case FT_LCD_FILTER_LEGACY:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
      library->lcd_filter_func = _ft_lcd_filter_legacy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
      library->lcd_extra       = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
    library->lcd_filter = filter;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
#else /* !FT_CONFIG_OPTION_SUBPIXEL_RENDERING */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
  FT_Library_SetLcdFilterWeights( FT_Library      library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
                                  unsigned char  *weights )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
    FT_UNUSED( library );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
    FT_UNUSED( weights );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
    return FT_Err_Unimplemented_Feature;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
  FT_Library_SetLcdFilter( FT_Library    library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
                           FT_LcdFilter  filter )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
    FT_UNUSED( library );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
    FT_UNUSED( filter );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
    return FT_Err_Unimplemented_Feature;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
#endif /* !FT_CONFIG_OPTION_SUBPIXEL_RENDERING */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
/* END */