misc/libfreetype/src/base/ftbitmap.c
author koda
Mon, 25 Apr 2011 01:46:54 +0200
changeset 5172 88f2e05288ba
permissions -rw-r--r--
aaand let's add freetype as well while we are at it other smaller changes
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
/*  ftbitmap.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 utility functions for bitmaps (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 2004, 2005, 2006, 2007, 2008, 2009 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_BITMAP_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
  static
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
  const FT_Bitmap  null_bitmap = { 0, 0, 0, 0, 0, 0, 0, 0 };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
  /* documentation is in ftbitmap.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  FT_Bitmap_New( FT_Bitmap  *abitmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
    *abitmap = null_bitmap;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
  /* documentation is in ftbitmap.h */
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
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  FT_Bitmap_Copy( FT_Library        library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
                  const FT_Bitmap  *source,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
                  FT_Bitmap        *target)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
    FT_Memory  memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
    FT_Error   error  = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
    FT_Int     pitch  = source->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
    FT_ULong   size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
    if ( source == target )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
      return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
    if ( source->buffer == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
      *target = *source;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
      return FT_Err_Ok;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
    if ( pitch < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
      pitch = -pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
    size = (FT_ULong)( pitch * source->rows );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
    if ( target->buffer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
      FT_Int    target_pitch = target->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
      FT_ULong  target_size;
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
      if ( target_pitch < 0  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
        target_pitch = -target_pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
      target_size = (FT_ULong)( target_pitch * target->rows );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
      if ( target_size != size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
        (void)FT_QREALLOC( target->buffer, target_size, size );
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
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
      (void)FT_QALLOC( target->buffer, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
    if ( !error )
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
      unsigned char *p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
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
      p = target->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
      *target = *source;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
      target->buffer = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
      FT_MEM_COPY( target->buffer, source->buffer, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
    return error;
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
  ft_bitmap_assure_buffer( FT_Memory   memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
                           FT_Bitmap*  bitmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
                           FT_UInt     xpixels,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
                           FT_UInt     ypixels )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
    FT_Error        error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
    int             pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
    int             new_pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
    FT_UInt         bpp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
    FT_Int          i, width, height;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
    unsigned char*  buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
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
    width  = bitmap->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
    height = bitmap->rows;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
    pitch  = bitmap->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
    if ( pitch < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
      pitch = -pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
    switch ( bitmap->pixel_mode )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
    case FT_PIXEL_MODE_MONO:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
      bpp       = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
      new_pitch = ( width + xpixels + 7 ) >> 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
    case FT_PIXEL_MODE_GRAY2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
      bpp       = 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
      new_pitch = ( width + xpixels + 3 ) >> 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
    case FT_PIXEL_MODE_GRAY4:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
      bpp       = 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
      new_pitch = ( width + xpixels + 1 ) >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
    case FT_PIXEL_MODE_GRAY:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
    case FT_PIXEL_MODE_LCD:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
    case FT_PIXEL_MODE_LCD_V:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
      bpp       = 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
      new_pitch = ( width + xpixels );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
      return FT_Err_Invalid_Glyph_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
    /* if no need to allocate memory */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
    if ( ypixels == 0 && new_pitch <= 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
      /* zero the padding */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
      FT_Int  bit_width = pitch * 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
      FT_Int  bit_last  = ( width + xpixels ) * bpp;
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
      if ( bit_last < bit_width )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
        FT_Byte*  line  = bitmap->buffer + ( bit_last >> 3 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
        FT_Byte*  end   = bitmap->buffer + pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
        FT_Int    shift = bit_last & 7;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
        FT_UInt   mask  = 0xFF00U >> shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
        FT_Int    count = height;
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
        for ( ; count > 0; count--, line += pitch, end += pitch )
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
          FT_Byte*  write = line;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
          if ( shift > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
            write[0] = (FT_Byte)( write[0] & mask );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
            write++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
          if ( write < end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
            FT_MEM_ZERO( write, end-write );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
      return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
    }
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
    if ( FT_QALLOC_MULT( buffer, new_pitch, bitmap->rows + ypixels ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
    if ( bitmap->pitch > 0 )
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_Int  len = ( width * bpp + 7 ) >> 3;
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
      for ( i = 0; i < bitmap->rows; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
        FT_MEM_COPY( buffer + new_pitch * ( ypixels + i ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
                     bitmap->buffer + pitch * i, len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
    else
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
      FT_Int  len = ( width * bpp + 7 ) >> 3;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
      for ( i = 0; i < bitmap->rows; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
        FT_MEM_COPY( buffer + new_pitch * i,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
                     bitmap->buffer + pitch * i, len );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
    FT_FREE( bitmap->buffer );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
    bitmap->buffer = buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
    if ( bitmap->pitch < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
      new_pitch = -new_pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
    /* set pitch only, width and height are left untouched */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
    bitmap->pitch = new_pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
  /* documentation is in ftbitmap.h */
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
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
  FT_Bitmap_Embolden( FT_Library  library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
                      FT_Bitmap*  bitmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
                      FT_Pos      xStrength,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
                      FT_Pos      yStrength )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
    FT_Error        error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
    unsigned char*  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
    FT_Int          i, x, y, pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
    FT_Int          xstr, ystr;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
    if ( !library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
      return FT_Err_Invalid_Library_Handle;
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
    if ( !bitmap || !bitmap->buffer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
      return FT_Err_Invalid_Argument;
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
    if ( ( ( FT_PIX_ROUND( xStrength ) >> 6 ) > FT_INT_MAX ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
         ( ( FT_PIX_ROUND( yStrength ) >> 6 ) > FT_INT_MAX ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
      return FT_Err_Invalid_Argument;
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
    xstr = (FT_Int)FT_PIX_ROUND( xStrength ) >> 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
    ystr = (FT_Int)FT_PIX_ROUND( yStrength ) >> 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
    if ( xstr == 0 && ystr == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
      return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
    else if ( xstr < 0 || ystr < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
      return FT_Err_Invalid_Argument;
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
    switch ( bitmap->pixel_mode )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
    case FT_PIXEL_MODE_GRAY2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
    case FT_PIXEL_MODE_GRAY4:
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
        FT_Bitmap  tmp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
        FT_Int     align;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
        if ( bitmap->pixel_mode == FT_PIXEL_MODE_GRAY2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
          align = ( bitmap->width + xstr + 3 ) / 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
          align = ( bitmap->width + xstr + 1 ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
        FT_Bitmap_New( &tmp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
        error = FT_Bitmap_Convert( library, bitmap, &tmp, align );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
          return error;
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
        FT_Bitmap_Done( library, bitmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
        *bitmap = tmp;
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
      break;
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
    case FT_PIXEL_MODE_MONO:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
      if ( xstr > 8 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
        xstr = 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
      break;
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
    case FT_PIXEL_MODE_LCD:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
      xstr *= 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
    case FT_PIXEL_MODE_LCD_V:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
      ystr *= 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
      break;
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
    error = ft_bitmap_assure_buffer( library->memory, bitmap, xstr, ystr );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
      return error;
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
    pitch = bitmap->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
    if ( pitch > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
      p = bitmap->buffer + pitch * ystr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
      pitch = -pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
      p = bitmap->buffer + pitch * ( bitmap->rows - 1 );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
    /* for each row */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
    for ( y = 0; y < bitmap->rows ; y++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
    {
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
       * Horizontally:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
       *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
       * From the last pixel on, make each pixel or'ed with the
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
       * `xstr' pixels before it.
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
      for ( x = pitch - 1; x >= 0; x-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
        unsigned char tmp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
        tmp = p[x];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
        for ( i = 1; i <= xstr; i++ )
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
          if ( bitmap->pixel_mode == FT_PIXEL_MODE_MONO )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
            p[x] |= tmp >> i;
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
            /* the maximum value of 8 for `xstr' comes from here */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
            if ( x > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
              p[x] |= p[x - 1] << ( 8 - i );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
            if ( p[x] == 0xff )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
              break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
            if ( x - i >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
              if ( p[x] + p[x - i] > bitmap->num_grays - 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
              {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
                p[x] = (unsigned char)(bitmap->num_grays - 1);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
                break;
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
              else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
              {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
                p[x] = (unsigned char)(p[x] + p[x-i]);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
                if ( p[x] == bitmap->num_grays - 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
                  break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
              }
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
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
              break;
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
      }
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
      /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
       * Vertically:
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
       * Make the above `ystr' rows or'ed with it.
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
      for ( x = 1; x <= ystr; x++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
        unsigned char*  q;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
        q = p - bitmap->pitch * x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
        for ( i = 0; i < pitch; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
          q[i] |= p[i];
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
      p += bitmap->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
    bitmap->width += xstr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
    bitmap->rows += ystr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
    return FT_Err_Ok;
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
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
  /* documentation is in ftbitmap.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
  FT_Bitmap_Convert( FT_Library        library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
                     const FT_Bitmap  *source,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
                     FT_Bitmap        *target,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
                     FT_Int            alignment )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
    FT_Error   error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
    FT_Memory  memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
    if ( !library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
      return FT_Err_Invalid_Library_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
    memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
    switch ( source->pixel_mode )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
    case FT_PIXEL_MODE_MONO:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
    case FT_PIXEL_MODE_GRAY:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
    case FT_PIXEL_MODE_GRAY2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
    case FT_PIXEL_MODE_GRAY4:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
    case FT_PIXEL_MODE_LCD:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
    case FT_PIXEL_MODE_LCD_V:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
        FT_Int   pad;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
        FT_Long  old_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
        old_size = target->rows * target->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
        if ( old_size < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
          old_size = -old_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
        target->pixel_mode = FT_PIXEL_MODE_GRAY;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
        target->rows       = source->rows;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
        target->width      = source->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
        pad = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
        if ( alignment > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
          pad = source->width % alignment;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
          if ( pad != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
            pad = alignment - pad;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
        target->pitch = source->width + pad;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
        if ( target->rows * target->pitch > old_size             &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
             FT_QREALLOC( target->buffer,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
                          old_size, target->rows * target->pitch ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
          return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
      error = FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
    switch ( source->pixel_mode )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
    case FT_PIXEL_MODE_MONO:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
        FT_Byte*  s = source->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
        FT_Byte*  t = target->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
        FT_Int    i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
        target->num_grays = 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
        for ( i = source->rows; i > 0; i-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
          FT_Byte*  ss = s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
          FT_Byte*  tt = t;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
          FT_Int    j;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
          /* get the full bytes */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
          for ( j = source->width >> 3; j > 0; j-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
            FT_Int  val = ss[0]; /* avoid a byte->int cast on each line */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
            tt[0] = (FT_Byte)( ( val & 0x80 ) >> 7 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
            tt[1] = (FT_Byte)( ( val & 0x40 ) >> 6 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
            tt[2] = (FT_Byte)( ( val & 0x20 ) >> 5 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
            tt[3] = (FT_Byte)( ( val & 0x10 ) >> 4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
            tt[4] = (FT_Byte)( ( val & 0x08 ) >> 3 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
            tt[5] = (FT_Byte)( ( val & 0x04 ) >> 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
            tt[6] = (FT_Byte)( ( val & 0x02 ) >> 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
            tt[7] = (FT_Byte)(   val & 0x01 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
            tt += 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
            ss += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
          /* get remaining pixels (if any) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
          j = source->width & 7;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
          if ( j > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
            FT_Int  val = *ss;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
            for ( ; j > 0; j-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
              tt[0] = (FT_Byte)( ( val & 0x80 ) >> 7);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
              val <<= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
              tt   += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
          s += source->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
          t += target->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
    case FT_PIXEL_MODE_GRAY:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
    case FT_PIXEL_MODE_LCD:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
    case FT_PIXEL_MODE_LCD_V:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
        FT_Int    width   = source->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
        FT_Byte*  s       = source->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
        FT_Byte*  t       = target->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
        FT_Int    s_pitch = source->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
        FT_Int    t_pitch = target->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
        FT_Int    i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
        target->num_grays = 256;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
        for ( i = source->rows; i > 0; i-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
          FT_ARRAY_COPY( t, s, width );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
          s += s_pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
          t += t_pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
    case FT_PIXEL_MODE_GRAY2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
        FT_Byte*  s = source->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
        FT_Byte*  t = target->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
        FT_Int    i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
        target->num_grays = 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
        for ( i = source->rows; i > 0; i-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
          FT_Byte*  ss = s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
          FT_Byte*  tt = t;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
          FT_Int    j;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
          /* get the full bytes */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
          for ( j = source->width >> 2; j > 0; j-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
            FT_Int  val = ss[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
            tt[0] = (FT_Byte)( ( val & 0xC0 ) >> 6 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
            tt[1] = (FT_Byte)( ( val & 0x30 ) >> 4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
            tt[2] = (FT_Byte)( ( val & 0x0C ) >> 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
            tt[3] = (FT_Byte)( ( val & 0x03 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
            ss += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
            tt += 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
          j = source->width & 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
          if ( j > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
            FT_Int  val = ss[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
            for ( ; j > 0; j-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
              tt[0]  = (FT_Byte)( ( val & 0xC0 ) >> 6 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
              val  <<= 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
              tt    += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
          s += source->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
          t += target->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
    case FT_PIXEL_MODE_GRAY4:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
        FT_Byte*  s = source->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
        FT_Byte*  t = target->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
        FT_Int    i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
        target->num_grays = 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
        for ( i = source->rows; i > 0; i-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
          FT_Byte*  ss = s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
          FT_Byte*  tt = t;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
          FT_Int    j;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
          /* get the full bytes */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
          for ( j = source->width >> 1; j > 0; j-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
            FT_Int  val = ss[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
            tt[0] = (FT_Byte)( ( val & 0xF0 ) >> 4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
            tt[1] = (FT_Byte)( ( val & 0x0F ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
            ss += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
            tt += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
          if ( source->width & 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
            tt[0] = (FT_Byte)( ( ss[0] & 0xF0 ) >> 4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
          s += source->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
          t += target->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
      ;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
  /* documentation is in ftbitmap.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
  FT_GlyphSlot_Own_Bitmap( FT_GlyphSlot  slot )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
    if ( slot && slot->format == FT_GLYPH_FORMAT_BITMAP   &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
         !( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
      FT_Bitmap  bitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
      FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
      FT_Bitmap_New( &bitmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
      error = FT_Bitmap_Copy( slot->library, &slot->bitmap, &bitmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
        return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
      slot->bitmap = bitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
      slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
  /* documentation is in ftbitmap.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
  FT_Bitmap_Done( FT_Library  library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
                  FT_Bitmap  *bitmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
    FT_Memory  memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
    if ( !library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
      return FT_Err_Invalid_Library_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
    if ( !bitmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
    memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
    FT_FREE( bitmap->buffer );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
    *bitmap = null_bitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
/* END */