freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Git][freetype/freetype-demos][master] [graph] Complete removal of legac


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype-demos][master] [graph] Complete removal of legacy blitter.
Date: Wed, 17 Nov 2021 03:10:48 +0000

Alexei Podtelezhnikov pushed to branch master at FreeType / FreeType Demo Programs

Commits:

9 changed files:

Changes:

  • builds/windows/msvc/migs.vcxproj
    ... ... @@ -142,7 +142,6 @@
    142 142
       <ItemGroup>
    
    143 143
         <ClCompile Include="..\..\..\graph\gblblit.c" />
    
    144 144
         <ClCompile Include="..\..\..\graph\gblender.c" />
    
    145
    -    <ClCompile Include="..\..\..\graph\grblit.c" />
    
    146 145
         <ClCompile Include="..\..\..\graph\grdevice.c" />
    
    147 146
         <ClCompile Include="..\..\..\graph\grfill.c" />
    
    148 147
         <ClCompile Include="..\..\..\graph\grfont.c" />
    
    ... ... @@ -166,7 +165,6 @@
    166 165
         <ClInclude Include="..\..\..\graph\gblvbgr.h" />
    
    167 166
         <ClInclude Include="..\..\..\graph\gblvrgb.h" />
    
    168 167
         <ClInclude Include="..\..\..\graph\graph.h" />
    
    169
    -    <ClInclude Include="..\..\..\graph\grblit.h" />
    
    170 168
         <ClInclude Include="..\..\..\graph\grconfig.h" />
    
    171 169
         <ClInclude Include="..\..\..\graph\grdevice.h" />
    
    172 170
         <ClInclude Include="..\..\..\graph\grevents.h" />
    

  • graph/graph.h
    ... ... @@ -194,47 +194,6 @@
    194 194
                                 grBitmap    *bit );
    
    195 195
     
    
    196 196
     
    
    197
    - /**********************************************************************
    
    198
    -  *
    
    199
    -  * <Function>
    
    200
    -  *    grBlitGlyphToBitmap
    
    201
    -  *
    
    202
    -  * <Description>
    
    203
    -  *    writes a given glyph bitmap to a target surface.
    
    204
    -  *
    
    205
    -  * <Input>
    
    206
    -  *    target  :: handle to target bitmap that belongs to surface
    
    207
    -  *    glyph   :: handle to source glyph bitmap
    
    208
    -  *    x       :: position of left-most pixel of glyph image in target surface
    
    209
    -  *    y       :: position of top-most pixel of glyph image in target surface
    
    210
    -  *    color   :: color to be used to draw a monochrome glyph
    
    211
    -  *
    
    212
    -  * <Return>
    
    213
    -  *   Error code. 0 means success
    
    214
    -  *
    
    215
    -  * <Note>
    
    216
    -  *   There are only two supported source pixel modes : monochrome
    
    217
    -  *   and gray. The 8-bit images can have any number of grays between
    
    218
    -  *   2 and 128, and conversions to the target surface is handled
    
    219
    -  *   _automatically_.
    
    220
    -  *
    
    221
    -  *   Note however that you should avoid blitting a gray glyph to a gray
    
    222
    -  *   bitmap with fewer levels of grays, as this would much probably
    
    223
    -  *   give unpleasant results..
    
    224
    -  *
    
    225
    -  *   This function performs clipping.  This function does not implement
    
    226
    -  *   gamma correction.
    
    227
    -  *
    
    228
    -  **********************************************************************/
    
    229
    -
    
    230
    -  extern int
    
    231
    -  grBlitGlyphToBitmap( grBitmap*  target,
    
    232
    -                       grBitmap*  glyph,
    
    233
    -                       grPos      x,
    
    234
    -                       grPos      y,
    
    235
    -                       grColor    color );
    
    236
    -
    
    237
    -
    
    238 197
      /**********************************************************************
    
    239 198
       *
    
    240 199
       * <Function>
    

  • graph/grblit.c deleted
    1
    -/****************************************************************************/
    
    2
    -/*                                                                          */
    
    3
    -/*  The FreeType project -- a free and portable quality TrueType renderer.  */
    
    4
    -/*                                                                          */
    
    5
    -/*  Copyright (C) 1996-2021 by                                              */
    
    6
    -/*  D. Turner, R.Wilhelm, and W. Lemberg                                    */
    
    7
    -/*                                                                          */
    
    8
    -/*  grblit.c: Support for blitting of bitmaps with various depth.           */
    
    9
    -/*                                                                          */
    
    10
    -/****************************************************************************/
    
    11
    -
    
    12
    -#include "grblit.h"
    
    13
    -#include <string.h>
    
    14
    -
    
    15
    -#define  GRAY8
    
    16
    -
    
    17
    -  static
    
    18
    -  int  compute_clips( grBlitter*  blit,
    
    19
    -                      int         x_offset,
    
    20
    -                      int         y_offset )
    
    21
    -  {
    
    22
    -    int  xmin, ymin, xmax, ymax, width, height, target_width;
    
    23
    -
    
    24
    -    /* perform clipping and setup variables */
    
    25
    -    width  = blit->source.width;
    
    26
    -    height = blit->source.rows;
    
    27
    -
    
    28
    -    switch ( blit->source.mode )
    
    29
    -    {
    
    30
    -    case gr_pixel_mode_mono:
    
    31
    -      width = (width + 7) & -8;
    
    32
    -      break;
    
    33
    -
    
    34
    -    case gr_pixel_mode_pal4:
    
    35
    -      width = (width + 1) & -2;
    
    36
    -      break;
    
    37
    -
    
    38
    -    case gr_pixel_mode_lcd:
    
    39
    -    case gr_pixel_mode_lcd2:
    
    40
    -      width /= 3;
    
    41
    -      break;
    
    42
    -
    
    43
    -    case gr_pixel_mode_lcdv:
    
    44
    -    case gr_pixel_mode_lcdv2:
    
    45
    -      height /= 3;
    
    46
    -      break;
    
    47
    -
    
    48
    -    default:
    
    49
    -      ;
    
    50
    -    }
    
    51
    -
    
    52
    -    xmin = x_offset;
    
    53
    -    ymin = y_offset;
    
    54
    -    xmax = xmin + width-1;
    
    55
    -    ymax = ymin + height-1;
    
    56
    -
    
    57
    -    /* clip if necessary */
    
    58
    -    if ( width == 0 || height == 0                ||
    
    59
    -         xmax < 0   || xmin >= blit->target.width ||
    
    60
    -         ymax < 0   || ymin >= blit->target.rows  )
    
    61
    -      return 1;
    
    62
    -
    
    63
    -    /* set up clipping and cursors */
    
    64
    -    blit->yread = 0;
    
    65
    -    if ( ymin < 0 )
    
    66
    -    {
    
    67
    -      blit->yread  -= ymin;
    
    68
    -      height       += ymin;
    
    69
    -      blit->ywrite  = 0;
    
    70
    -    }
    
    71
    -    else
    
    72
    -      blit->ywrite  = ymin;
    
    73
    -
    
    74
    -    if ( ymax >= blit->target.rows )
    
    75
    -      height -= ymax - blit->target.rows + 1;
    
    76
    -
    
    77
    -    blit->xread = 0;
    
    78
    -    if ( xmin < 0 )
    
    79
    -    {
    
    80
    -      blit->xread  -= xmin;
    
    81
    -      width        += xmin;
    
    82
    -      blit->xwrite  = 0;
    
    83
    -    }
    
    84
    -    else
    
    85
    -      blit->xwrite  = xmin;
    
    86
    -
    
    87
    -    target_width = blit->target.width;
    
    88
    -
    
    89
    -    switch ( blit->target.mode )
    
    90
    -    {
    
    91
    -    case gr_pixel_mode_mono:
    
    92
    -      target_width = (target_width + 7) & -8;
    
    93
    -      break;
    
    94
    -    case gr_pixel_mode_pal4:
    
    95
    -      target_width = (target_width + 1) & -2;
    
    96
    -      break;
    
    97
    -
    
    98
    -    default:
    
    99
    -      ;
    
    100
    -    }
    
    101
    -
    
    102
    -    blit->right_clip = xmax - target_width + 1;
    
    103
    -    if ( blit->right_clip > 0 )
    
    104
    -      width -= blit->right_clip;
    
    105
    -    else
    
    106
    -      blit->right_clip = 0;
    
    107
    -
    
    108
    -    blit->width  = width;
    
    109
    -    blit->height = height;
    
    110
    -
    
    111
    -    /* set read and write to the top-left corner of the read */
    
    112
    -    /* and write areas before clipping.                      */
    
    113
    -
    
    114
    -    blit->read  = blit->source.buffer;
    
    115
    -    blit->write = blit->target.buffer;
    
    116
    -
    
    117
    -    blit->read_line  = blit->source.pitch;
    
    118
    -    blit->write_line = blit->target.pitch;
    
    119
    -
    
    120
    -    if ( blit->read_line < 0 )
    
    121
    -      blit->read -= (blit->source.rows-1) * blit->read_line;
    
    122
    -
    
    123
    -    if ( blit->write_line < 0 )
    
    124
    -      blit->write -= (blit->target.rows-1) * blit->write_line;
    
    125
    -
    
    126
    -    /* now go to the start line. Note that we do not move the   */
    
    127
    -    /* x position yet, as this is dependent on the pixel format */
    
    128
    -    blit->read  += blit->yread * blit->read_line;
    
    129
    -    blit->write += blit->ywrite * blit->write_line;
    
    130
    -
    
    131
    -    return 0;
    
    132
    -  }
    
    133
    -
    
    134
    -
    
    135
    -/**************************************************************************/
    
    136
    -/*                                                                        */
    
    137
    -/* <Function> blit_mono_to_mono                                           */
    
    138
    -/*                                                                        */
    
    139
    -/**************************************************************************/
    
    140
    -
    
    141
    -  static
    
    142
    -  void  blit_mono_to_mono( grBlitter*  blit,
    
    143
    -                           grColor     color )
    
    144
    -  {
    
    145
    -    unsigned int  shift;
    
    146
    -    int           left_clip, x, y;
    
    147
    -
    
    148
    -    byte*  read;
    
    149
    -    byte*  write;
    
    150
    -
    
    151
    -    (void)color;   /* unused argument */
    
    152
    -
    
    153
    -    left_clip = ( blit->xread > 0 );
    
    154
    -    shift     = (unsigned int)( blit->xwrite - blit->xread ) & 7;
    
    155
    -
    
    156
    -    read  = blit->read  + (blit->xread >> 3);
    
    157
    -    write = blit->write + (blit->xwrite >> 3);
    
    158
    -
    
    159
    -    if ( shift == 0 )
    
    160
    -    {
    
    161
    -      y = blit->height;
    
    162
    -      do
    
    163
    -      {
    
    164
    -        byte*  _read  = read;
    
    165
    -        byte*  _write = write;
    
    166
    -
    
    167
    -        x = blit->width;
    
    168
    -
    
    169
    -        do
    
    170
    -        {
    
    171
    -          *_write++ |= *_read++;
    
    172
    -          x -= 8;
    
    173
    -        } while ( x > 0 );
    
    174
    -
    
    175
    -        read  += blit->read_line;
    
    176
    -        write += blit->write_line;
    
    177
    -        y--;
    
    178
    -      } while ( y > 0 );
    
    179
    -    }
    
    180
    -    else
    
    181
    -    {
    
    182
    -      int  first, last, count;
    
    183
    -
    
    184
    -
    
    185
    -      first = blit->xwrite >> 3;
    
    186
    -      last  = (blit->xwrite + blit->width-1) >> 3;
    
    187
    -
    
    188
    -      count = last - first;
    
    189
    -
    
    190
    -      if ( blit->right_clip )
    
    191
    -        count++;
    
    192
    -
    
    193
    -      y = blit->height;
    
    194
    -
    
    195
    -      do
    
    196
    -      {
    
    197
    -        unsigned char*  _read  = read;
    
    198
    -        unsigned char*  _write = write;
    
    199
    -        unsigned int    old;
    
    200
    -        unsigned int    shift2 = (8-shift);
    
    201
    -
    
    202
    -        if ( left_clip )
    
    203
    -          old = (unsigned int)(*_read++) << shift2;
    
    204
    -        else
    
    205
    -          old = 0;
    
    206
    -
    
    207
    -        x = count;
    
    208
    -        while ( x > 0 )
    
    209
    -        {
    
    210
    -          unsigned int  val = *_read++;
    
    211
    -
    
    212
    -          *_write++ |= (unsigned char)( (val >> shift) | old );
    
    213
    -          old = val << shift2;
    
    214
    -          x--;
    
    215
    -        }
    
    216
    -
    
    217
    -        if ( !blit->right_clip )
    
    218
    -          *_write |= (unsigned char)old;
    
    219
    -
    
    220
    -        read  += blit->read_line;
    
    221
    -        write += blit->write_line;
    
    222
    -        y--;
    
    223
    -
    
    224
    -      } while ( y > 0 );
    
    225
    -    }
    
    226
    -  }
    
    227
    -
    
    228
    -
    
    229
    -/**************************************************************************/
    
    230
    -/*                                                                        */
    
    231
    -/* <Function> blit_mono_to_pal8                                           */
    
    232
    -/*                                                                        */
    
    233
    -/**************************************************************************/
    
    234
    -
    
    235
    -  static
    
    236
    -  void  blit_mono_to_pal8( grBlitter*  blit,
    
    237
    -                           grColor     color )
    
    238
    -  {
    
    239
    -    int             x, y;
    
    240
    -    unsigned char*  write = blit->write + blit->xwrite;
    
    241
    -    unsigned char*  read  = blit->read  + ( blit->xread >> 3 );
    
    242
    -    unsigned int    mask  = 0x80 >> ( blit->xread & 7 );
    
    243
    -
    
    244
    -    y = blit->height;
    
    245
    -    do
    
    246
    -    {
    
    247
    -      unsigned char*  _write = write;
    
    248
    -      unsigned char*  _read  = read;
    
    249
    -      unsigned int    _mask  = mask;
    
    250
    -      unsigned int     val   = *_read;
    
    251
    -
    
    252
    -      x = blit->width;
    
    253
    -      do
    
    254
    -      {
    
    255
    -        if ( !_mask )
    
    256
    -        {
    
    257
    -          val   = *++_read;
    
    258
    -          _mask = 0x80;
    
    259
    -        }
    
    260
    -
    
    261
    -        if ( val & _mask )
    
    262
    -          *_write = (unsigned char)color.value;
    
    263
    -
    
    264
    -        _mask >>= 1;
    
    265
    -        _write++;
    
    266
    -
    
    267
    -      } while ( --x > 0 );
    
    268
    -
    
    269
    -      read  += blit->read_line;
    
    270
    -      write += blit->write_line;
    
    271
    -      y--;
    
    272
    -    } while ( y > 0 );
    
    273
    -  }
    
    274
    -
    
    275
    -
    
    276
    -/**************************************************************************/
    
    277
    -/*                                                                        */
    
    278
    -/* <Function> blit_mono_to_pal4                                           */
    
    279
    -/*                                                                        */
    
    280
    -/**************************************************************************/
    
    281
    -
    
    282
    -  static
    
    283
    -  void  blit_mono_to_pal4( grBlitter*  blit,
    
    284
    -                           grColor     color )
    
    285
    -  {
    
    286
    -    int             x, y;
    
    287
    -    unsigned char*  write = blit->write + ( blit->xwrite >> 1 );
    
    288
    -    unsigned int    phase = blit->xwrite & 1 ? 0x0F : 0xF0;
    
    289
    -    unsigned char*  read  = blit->read  + ( blit->xread >> 3 );
    
    290
    -    unsigned int    mask  = 0x80 >> ( blit->xread & 7 );
    
    291
    -    unsigned int    col = color.value | ( color.value << 4 );
    
    292
    -
    
    293
    -    y = blit->height;
    
    294
    -    do
    
    295
    -    {
    
    296
    -      unsigned char*  _write = write;
    
    297
    -      unsigned int    _phase = phase;
    
    298
    -      unsigned char*  _read  = read;
    
    299
    -      unsigned int    _mask  = mask;
    
    300
    -      unsigned int     val   = *_read;
    
    301
    -
    
    302
    -      x = blit->width;
    
    303
    -      do
    
    304
    -      {
    
    305
    -        if ( !_mask )
    
    306
    -        {
    
    307
    -          val   = *++_read;
    
    308
    -          _mask = 0x80;
    
    309
    -        }
    
    310
    -
    
    311
    -        if ( val & _mask )
    
    312
    -          *_write = (unsigned char)( (col & _phase) | (*_write & ~_phase) );
    
    313
    -
    
    314
    -        _mask >>= 1;
    
    315
    -        _write += _phase & 1;
    
    316
    -        _phase  = ~_phase;
    
    317
    -        x--;
    
    318
    -      } while ( x > 0 );
    
    319
    -
    
    320
    -      read  += blit->read_line;
    
    321
    -      write += blit->write_line;
    
    322
    -      y--;
    
    323
    -    } while ( y > 0 );
    
    324
    -  }
    
    325
    -
    
    326
    -
    
    327
    -/**************************************************************************/
    
    328
    -/*                                                                        */
    
    329
    -/* <Function> blit_mono_to_rgb16                                          */
    
    330
    -/*                                                                        */
    
    331
    -/**************************************************************************/
    
    332
    -
    
    333
    -  static
    
    334
    -  void  blit_mono_to_rgb16( grBlitter*  blit,
    
    335
    -                            grColor     color )
    
    336
    -  {
    
    337
    -    int              x, y;
    
    338
    -    unsigned char*   write = blit->write + blit->xwrite * 2;
    
    339
    -    unsigned char*   read  = blit->read  + ( blit->xread >> 3 );
    
    340
    -    unsigned int     mask  = 0x80 >> ( blit->xread & 7 );
    
    341
    -
    
    342
    -    y = blit->height;
    
    343
    -    do
    
    344
    -    {
    
    345
    -      unsigned short* _write = (unsigned short*)write;
    
    346
    -      unsigned char*  _read  = read;
    
    347
    -      unsigned int    _mask  = mask;
    
    348
    -      unsigned int     val   = *_read;
    
    349
    -
    
    350
    -      x = blit->width;
    
    351
    -      do
    
    352
    -      {
    
    353
    -        if ( !_mask )
    
    354
    -        {
    
    355
    -          val   = *++_read;
    
    356
    -          _mask = 0x80;
    
    357
    -        }
    
    358
    -
    
    359
    -        if ( val & _mask )
    
    360
    -          *_write = (unsigned short)color.value;
    
    361
    -
    
    362
    -        _mask >>= 1;
    
    363
    -        _write++;
    
    364
    -        x--;
    
    365
    -      } while ( x > 0 );
    
    366
    -
    
    367
    -      read  += blit->read_line;
    
    368
    -      write += blit->write_line;
    
    369
    -      y--;
    
    370
    -    } while ( y > 0 );
    
    371
    -  }
    
    372
    -
    
    373
    -
    
    374
    -/**************************************************************************/
    
    375
    -/*                                                                        */
    
    376
    -/* <Function> blit_mono_to_rgb24                                          */
    
    377
    -/*                                                                        */
    
    378
    -/**************************************************************************/
    
    379
    -
    
    380
    -  static
    
    381
    -  void  blit_mono_to_rgb24( grBlitter*  blit,
    
    382
    -                            grColor     color )
    
    383
    -  {
    
    384
    -    int             x, y;
    
    385
    -    unsigned char*  write = blit->write + blit->xwrite * 3;
    
    386
    -    unsigned char*  read  = blit->read  + ( blit->xread >> 3 );
    
    387
    -    unsigned int    mask  = 0x80 >> ( blit->xread & 7 );
    
    388
    -
    
    389
    -    y = blit->height;
    
    390
    -    do
    
    391
    -    {
    
    392
    -      unsigned char*  _write = write;
    
    393
    -      unsigned char*  _read  = read;
    
    394
    -      unsigned int    _mask  = mask;
    
    395
    -      unsigned int     val   = *_read;
    
    396
    -
    
    397
    -      x = blit->width;
    
    398
    -      do
    
    399
    -      {
    
    400
    -        if ( !_mask )
    
    401
    -        {
    
    402
    -          val   = *++_read;
    
    403
    -          _mask = 0x80;
    
    404
    -        }
    
    405
    -
    
    406
    -        if ( val & _mask )
    
    407
    -        {
    
    408
    -          _write[0] = color.chroma[0];
    
    409
    -          _write[1] = color.chroma[1];
    
    410
    -          _write[2] = color.chroma[2];
    
    411
    -        }
    
    412
    -
    
    413
    -        _mask >>= 1;
    
    414
    -        _write += 3;
    
    415
    -        x--;
    
    416
    -      } while ( x > 0 );
    
    417
    -
    
    418
    -      read  += blit->read_line;
    
    419
    -      write += blit->write_line;
    
    420
    -      y--;
    
    421
    -    } while ( y > 0 );
    
    422
    -  }
    
    423
    -
    
    424
    -
    
    425
    -/**************************************************************************/
    
    426
    -/*                                                                        */
    
    427
    -/* <Function> blit_mono_to_rgb32                                          */
    
    428
    -/*                                                                        */
    
    429
    -/**************************************************************************/
    
    430
    -
    
    431
    -  static
    
    432
    -  void  blit_mono_to_rgb32( grBlitter*  blit,
    
    433
    -                            grColor     color )
    
    434
    -  {
    
    435
    -    int             x, y;
    
    436
    -    unsigned char*  write = blit->write + blit->xwrite * 4;
    
    437
    -    unsigned char*  read  = blit->read  + ( blit->xread >> 3 );
    
    438
    -    unsigned int    mask  = 0x80 >> ( blit->xread & 7 );
    
    439
    -
    
    440
    -    y = blit->height;
    
    441
    -    do
    
    442
    -    {
    
    443
    -      uint32_t*       _write = (uint32_t*)write;
    
    444
    -      unsigned char*  _read  = read;
    
    445
    -      unsigned int    _mask  = mask;
    
    446
    -      unsigned int     val   = *_read;
    
    447
    -
    
    448
    -      x = blit->width;
    
    449
    -      do
    
    450
    -      {
    
    451
    -        if ( !_mask )
    
    452
    -        {
    
    453
    -          val   = *++_read;
    
    454
    -          _mask = 0x80;
    
    455
    -        }
    
    456
    -
    
    457
    -        if ( val & _mask )
    
    458
    -          *_write = color.value;
    
    459
    -
    
    460
    -        _mask >>= 1;
    
    461
    -        _write++;
    
    462
    -        x--;
    
    463
    -
    
    464
    -      } while ( x > 0 );
    
    465
    -
    
    466
    -      read  += blit->read_line;
    
    467
    -      write += blit->write_line;
    
    468
    -      y--;
    
    469
    -
    
    470
    -    } while ( y > 0 );
    
    471
    -  }
    
    472
    -
    
    473
    -
    
    474
    -  static
    
    475
    -  const grBlitterFunc  gr_mono_blitters[gr_pixel_mode_max] =
    
    476
    -  {
    
    477
    -    0,
    
    478
    -    blit_mono_to_mono,
    
    479
    -    blit_mono_to_pal4,
    
    480
    -    blit_mono_to_pal8,
    
    481
    -    blit_mono_to_pal8,
    
    482
    -    blit_mono_to_rgb16,
    
    483
    -    blit_mono_to_rgb16,
    
    484
    -    blit_mono_to_rgb24,
    
    485
    -    blit_mono_to_rgb32
    
    486
    -  };
    
    487
    -
    
    488
    -
    
    489
    -  /*******************************************************************/
    
    490
    -  /*                                                                 */
    
    491
    -  /*                    Saturation tables                            */
    
    492
    -  /*                                                                 */
    
    493
    -  /*******************************************************************/
    
    494
    -
    
    495
    -  typedef struct grSaturation_
    
    496
    -  {
    
    497
    -    int          count;
    
    498
    -    const byte*  table;
    
    499
    -
    
    500
    -  } grSaturation;
    
    501
    -
    
    502
    -
    
    503
    -  static
    
    504
    -  const byte  gr_saturation_5[8] = { 0, 1, 2, 3, 4, 4, 4, 4 };
    
    505
    -
    
    506
    -
    
    507
    -  static
    
    508
    -  const byte  gr_saturation_17[32] =
    
    509
    -  {
    
    510
    -     0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
    
    511
    -    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    
    512
    -  };
    
    513
    -
    
    514
    -
    
    515
    -  static
    
    516
    -  grSaturation  gr_saturations[ GR_MAX_SATURATIONS ] =
    
    517
    -  {
    
    518
    -    {  5, gr_saturation_5  },
    
    519
    -    { 17, gr_saturation_17 }
    
    520
    -  };
    
    521
    -
    
    522
    -  static
    
    523
    -  int  gr_num_saturations = 2;
    
    524
    -
    
    525
    -  static
    
    526
    -  grSaturation*  gr_last_saturation = gr_saturations;
    
    527
    -
    
    528
    -
    
    529
    -  static const byte*
    
    530
    -  grGetSaturation( int  num_grays )
    
    531
    -  {
    
    532
    -    /* first of all, scan the current saturations table */
    
    533
    -    grSaturation*  sat   = gr_saturations;
    
    534
    -    grSaturation*  limit = sat + gr_num_saturations;
    
    535
    -
    
    536
    -    if ( num_grays < 2 )
    
    537
    -    {
    
    538
    -      grError = gr_err_bad_argument;
    
    539
    -      return NULL;
    
    540
    -    }
    
    541
    -
    
    542
    -    for ( ; sat < limit; sat++ )
    
    543
    -    {
    
    544
    -      if ( sat->count == num_grays )
    
    545
    -      {
    
    546
    -        gr_last_saturation = sat;
    
    547
    -        return sat->table;
    
    548
    -      }
    
    549
    -    }
    
    550
    -
    
    551
    -    /* not found, simply create a new entry if there is room */
    
    552
    -    if (gr_num_saturations < GR_MAX_SATURATIONS)
    
    553
    -    {
    
    554
    -      int    i;
    
    555
    -      byte*  table;
    
    556
    -
    
    557
    -      table = (byte*)malloc( (size_t)( 3 * num_grays - 1 ) * sizeof ( byte ) );
    
    558
    -      if (!table)
    
    559
    -        return NULL;
    
    560
    -
    
    561
    -      sat->count = num_grays;
    
    562
    -      sat->table = table;
    
    563
    -
    
    564
    -      for ( i = 0; i < num_grays; i++ )
    
    565
    -        table[i] = (byte)i;
    
    566
    -
    
    567
    -      memset( table+num_grays, num_grays-1, 2*num_grays-1 );
    
    568
    -
    
    569
    -      gr_num_saturations++;
    
    570
    -      gr_last_saturation = sat;
    
    571
    -      return table;
    
    572
    -    }
    
    573
    -    grError = gr_err_saturation_overflow;
    
    574
    -    return NULL;
    
    575
    -  }
    
    576
    -
    
    577
    -
    
    578
    -
    
    579
    -  /*******************************************************************/
    
    580
    -  /*                                                                 */
    
    581
    -  /*                    conversion tables                            */
    
    582
    -  /*                                                                 */
    
    583
    -  /*******************************************************************/
    
    584
    -
    
    585
    -  typedef struct grConversion_
    
    586
    -  {
    
    587
    -    int          target_grays;
    
    588
    -    int          source_grays;
    
    589
    -    const byte*  table;
    
    590
    -
    
    591
    -  } grConversion;
    
    592
    -
    
    593
    -
    
    594
    -
    
    595
    -  static
    
    596
    -  const byte  gr_gray5_to_gray17[5] = { 0, 4, 8, 12, 16 };
    
    597
    -
    
    598
    -
    
    599
    -  static
    
    600
    -  const byte  gr_gray5_to_gray128[5] = { 0, 32, 64, 96, 127 };
    
    601
    -
    
    602
    -
    
    603
    -  static
    
    604
    -  const byte  gr_gray17_to_gray128[17] =
    
    605
    -  {
    
    606
    -    0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 127
    
    607
    -  };
    
    608
    -
    
    609
    -  static
    
    610
    -  grConversion  gr_conversions[ GR_MAX_CONVERSIONS ] =
    
    611
    -  {
    
    612
    -    {  17,  5, gr_gray5_to_gray17   },
    
    613
    -    { 128,  5, gr_gray5_to_gray128  },
    
    614
    -    { 128, 17, gr_gray17_to_gray128 }
    
    615
    -  };
    
    616
    -
    
    617
    -  static
    
    618
    -  int  gr_num_conversions = 3;
    
    619
    -
    
    620
    -  static
    
    621
    -  grConversion*  gr_last_conversion = gr_conversions;
    
    622
    -
    
    623
    -
    
    624
    -  static const byte*
    
    625
    -  grGetConversion( int  target_grays,
    
    626
    -                   int  source_grays )
    
    627
    -  {
    
    628
    -    grConversion*  conv  = gr_conversions;
    
    629
    -    grConversion*  limit = conv + gr_num_conversions;
    
    630
    -
    
    631
    -    if ( target_grays < 2 || source_grays < 2 )
    
    632
    -    {
    
    633
    -      grError = gr_err_bad_argument;
    
    634
    -      return NULL;
    
    635
    -    }
    
    636
    -
    
    637
    -    /* otherwise, scan table */
    
    638
    -    for ( ; conv < limit; conv++ )
    
    639
    -    {
    
    640
    -      if ( conv->target_grays == target_grays &&
    
    641
    -           conv->source_grays == source_grays )
    
    642
    -      {
    
    643
    -        gr_last_conversion = conv;
    
    644
    -        return conv->table;
    
    645
    -      }
    
    646
    -    }
    
    647
    -
    
    648
    -    /* not found, add a new conversion to the table */
    
    649
    -    if (gr_num_conversions < GR_MAX_CONVERSIONS)
    
    650
    -    {
    
    651
    -      byte*  table;
    
    652
    -      int    n;
    
    653
    -
    
    654
    -      table = (byte*)malloc( (size_t)source_grays * sizeof ( byte ) );
    
    655
    -      if (!table)
    
    656
    -        return NULL;
    
    657
    -
    
    658
    -      conv->target_grays = target_grays;
    
    659
    -      conv->source_grays = source_grays;
    
    660
    -      conv->table        = table;
    
    661
    -
    
    662
    -      for ( n = 0; n < source_grays; n++ )
    
    663
    -        table[n] = (byte)(n*(target_grays-1) / (source_grays-1));
    
    664
    -
    
    665
    -      gr_num_conversions++;
    
    666
    -      gr_last_conversion = conv;
    
    667
    -      return table;
    
    668
    -    }
    
    669
    -    grError = gr_err_conversion_overflow;
    
    670
    -    return NULL;
    
    671
    -  }
    
    672
    -
    
    673
    -
    
    674
    -
    
    675
    -
    
    676
    -/**************************************************************************/
    
    677
    -/*                                                                        */
    
    678
    -/* <Function> blit_gray_to_gray                                           */
    
    679
    -/*                                                                        */
    
    680
    -/**************************************************************************/
    
    681
    -
    
    682
    -  static
    
    683
    -  void  blit_gray_to_gray( grBlitter*   blit,
    
    684
    -                           const byte*  saturation,
    
    685
    -                           const byte*  conversion )
    
    686
    -  {
    
    687
    -    int             y;
    
    688
    -    unsigned char*  read;
    
    689
    -    unsigned char*  write;
    
    690
    -#ifdef GR_CONFIG_GRAY_SKIP_WHITE
    
    691
    -    int  max = blit->source.grays - 1;
    
    692
    -    int  max2 = blit-target.grays - 1;
    
    693
    -#endif
    
    694
    -
    
    695
    -    read  = blit->read  + blit->xread;
    
    696
    -    write = blit->write + blit->xwrite;
    
    697
    -
    
    698
    -    y = blit->height;
    
    699
    -    do
    
    700
    -    {
    
    701
    -      unsigned char*  _read  = read;
    
    702
    -      unsigned char*  _write = write;
    
    703
    -      int             x      = blit->width;
    
    704
    -
    
    705
    -      while (x > 0)
    
    706
    -      {
    
    707
    -#ifdef GR_CONFIG_GRAY_SKIP_WHITE
    
    708
    -        int  val = *_read;
    
    709
    -
    
    710
    -        if (val)
    
    711
    -        {
    
    712
    -          if (val == max)
    
    713
    -            *_write = (byte)max2;
    
    714
    -          else
    
    715
    -            *_write = saturation[ (int)*_write + conversion[ *_read ] ];
    
    716
    -        }
    
    717
    -#else
    
    718
    -        *_write = saturation[ (int)*_write + conversion[ *_read ] ];
    
    719
    -#endif
    
    720
    -        _write++;
    
    721
    -        _read++;
    
    722
    -        x--;
    
    723
    -      }
    
    724
    -
    
    725
    -      read  += blit->read_line;
    
    726
    -      write += blit->write_line;
    
    727
    -      y--;
    
    728
    -    }
    
    729
    -    while (y > 0);
    
    730
    -  }
    
    731
    -
    
    732
    -
    
    733
    -/**************************************************************************/
    
    734
    -/*                                                                        */
    
    735
    -/* <Function> blit_gray_to_gray_simple                                    */
    
    736
    -/*                                                                        */
    
    737
    -/**************************************************************************/
    
    738
    -
    
    739
    -  static
    
    740
    -  void  blit_gray_to_gray_simple( grBlitter*   blit,
    
    741
    -                                  const byte*  saturation )
    
    742
    -  {
    
    743
    -    int             y;
    
    744
    -    unsigned char*  read;
    
    745
    -    unsigned char*  write;
    
    746
    -#ifdef GR_CONFIG_GRAY_SKIP_WHITE
    
    747
    -    int  max = blit->source.grays - 1;
    
    748
    -#endif
    
    749
    -
    
    750
    -    read  = blit->read  + blit->xread;
    
    751
    -    write = blit->write + blit->xwrite;
    
    752
    -
    
    753
    -    y = blit->height;
    
    754
    -    do
    
    755
    -    {
    
    756
    -      unsigned char*  _read  = read;
    
    757
    -      unsigned char*  _write = write;
    
    758
    -      int             x      = blit->width;
    
    759
    -
    
    760
    -      while (x > 0)
    
    761
    -      {
    
    762
    -#ifdef GR_CONFIG_GRAY_SKIP_WHITE
    
    763
    -        int  val = *_read;
    
    764
    -
    
    765
    -        if (val)
    
    766
    -        {
    
    767
    -          if (val == max)
    
    768
    -            *_write = val;
    
    769
    -          else
    
    770
    -            *_write = saturation[ (int)*_write + *_read ];
    
    771
    -        }
    
    772
    -#else
    
    773
    -        *_write = saturation[ (int)*_write + *_read ];
    
    774
    -#endif
    
    775
    -        _write++;
    
    776
    -        _read++;
    
    777
    -        x--;
    
    778
    -      }
    
    779
    -
    
    780
    -      read  += blit->read_line;
    
    781
    -      write += blit->write_line;
    
    782
    -      y--;
    
    783
    -    }
    
    784
    -    while (y > 0);
    
    785
    -  }
    
    786
    -
    
    787
    -
    
    788
    -
    
    789
    -#define compose_pixel_full( a, b, n0, n1, n2, max )    \
    
    790
    -  do                                                   \
    
    791
    -  {                                                    \
    
    792
    -    int  d, half = max >> 1;                           \
    
    793
    -                                                       \
    
    794
    -                                                       \
    
    795
    -    d = (int)b.chroma[0] - a.chroma[0];                \
    
    796
    -    a.chroma[0] += (unsigned char)((n0*d + half)/max); \
    
    797
    -                                                       \
    
    798
    -    d = (int)b.chroma[1] - a.chroma[1];                \
    
    799
    -    a.chroma[1] += (unsigned char)((n1*d + half)/max); \
    
    800
    -                                                       \
    
    801
    -    d = (int)b.chroma[2] - a.chroma[2];                \
    
    802
    -    a.chroma[2] += (unsigned char)((n2*d + half)/max); \
    
    803
    -  } while ( 0 )
    
    804
    -
    
    805
    -#define compose_pixel( a, b, n, max )  \
    
    806
    -    compose_pixel_full( a, b, n, n, n, max )
    
    807
    -
    
    808
    -
    
    809
    -#define extract555( pixel, color )                           \
    
    810
    -   color.chroma[0] = (unsigned char)((pixel >> 10) & 0x1F);  \
    
    811
    -   color.chroma[1] = (unsigned char)((pixel >>  5) & 0x1F);  \
    
    812
    -   color.chroma[2] = (unsigned char)((pixel      ) & 0x1F)
    
    813
    -
    
    814
    -
    
    815
    -#define extract565( pixel, color )                           \
    
    816
    -   color.chroma[0] = (unsigned char)((pixel >> 11) & 0x1F);  \
    
    817
    -   color.chroma[1] = (unsigned char)((pixel >>  5) & 0x3F);  \
    
    818
    -   color.chroma[2] = (unsigned char)((pixel      ) & 0x1F)
    
    819
    -
    
    820
    -
    
    821
    -#define inject555( color )                          \
    
    822
    -   (unsigned short)( ( color.chroma[0] << 10 ) |    \
    
    823
    -                     ( color.chroma[1] <<  5 ) |    \
    
    824
    -                       color.chroma[2]           )
    
    825
    -
    
    826
    -
    
    827
    -#define inject565( color )                          \
    
    828
    -   (unsigned short)( ( color.chroma[0] << 11 ) |    \
    
    829
    -                     ( color.chroma[1] <<  5 ) |    \
    
    830
    -                       color.chroma[2]           )
    
    831
    -
    
    832
    -
    
    833
    -/**************************************************************************/
    
    834
    -/*                                                                        */
    
    835
    -/* <Function> blit_gray_to_555                                            */
    
    836
    -/*                                                                        */
    
    837
    -/**************************************************************************/
    
    838
    -
    
    839
    -#ifdef GRAY8
    
    840
    -  static
    
    841
    -  void  blit_gray8_to_555( grBlitter*  blit,
    
    842
    -                           grColor     color )
    
    843
    -  {
    
    844
    -    int             y;
    
    845
    -    int             sr = color.value & 0x7C00;
    
    846
    -    int             sg = color.value & 0x03E0;
    
    847
    -    int             sb = color.value & 0x001F;
    
    848
    -    unsigned char*  read;
    
    849
    -    unsigned char*  write;
    
    850
    -
    
    851
    -    read   = blit->read  + blit->xread;
    
    852
    -    write  = blit->write + 2*blit->xwrite;
    
    853
    -
    
    854
    -    y = blit->height;
    
    855
    -    do
    
    856
    -    {
    
    857
    -      unsigned char*   _read  = read;
    
    858
    -      unsigned short*  _write = (unsigned short*)write;
    
    859
    -      int              x      = blit->width;
    
    860
    -
    
    861
    -      while (x > 0)
    
    862
    -      {
    
    863
    -        unsigned char  val = *_read;
    
    864
    -
    
    865
    -        if (val)
    
    866
    -        {
    
    867
    -          if (val >= 254 )
    
    868
    -            *_write = (unsigned short)( sr | sg | sb );
    
    869
    -          else if ( val >= 2 )
    
    870
    -          {
    
    871
    -            /* compose gray value */
    
    872
    -            int   pix = (int)*_write;
    
    873
    -            int   dr  = pix & 0x7C00;
    
    874
    -            int   dg  = pix & 0x03E0;
    
    875
    -            int   db  = pix & 0x001F;
    
    876
    -
    
    877
    -            dr += ((sr-dr)*val) >> 8;
    
    878
    -            dr &= 0x7C00;
    
    879
    -
    
    880
    -            dg += ((sg-dg)*val) >> 8;
    
    881
    -            dg &= 0x03E0;
    
    882
    -
    
    883
    -            db += ((sb-db)*val) >> 8;
    
    884
    -            db &= 0x001F;
    
    885
    -
    
    886
    -            *_write = (unsigned short)( dr | dg | db );
    
    887
    -          }
    
    888
    -        }
    
    889
    -        _write ++;
    
    890
    -        _read  ++;
    
    891
    -        x--;
    
    892
    -      }
    
    893
    -
    
    894
    -      read  += blit->read_line;
    
    895
    -      write += blit->write_line;
    
    896
    -      y--;
    
    897
    -    }
    
    898
    -    while (y > 0);
    
    899
    -
    
    900
    -  }
    
    901
    -#endif /* GRAY8 */
    
    902
    -
    
    903
    -  static
    
    904
    -  void  blit_gray_to_555( grBlitter*  blit,
    
    905
    -                          grColor     color,
    
    906
    -                          int         max )
    
    907
    -  {
    
    908
    -    int             y;
    
    909
    -    unsigned char*  read;
    
    910
    -    unsigned char*  write;
    
    911
    -
    
    912
    -    read   = blit->read  + blit->xread;
    
    913
    -    write  = blit->write + 2*blit->xwrite;
    
    914
    -
    
    915
    -    /* scale down R:G:B triplet */
    
    916
    -    color.chroma[0] >>= 3;
    
    917
    -    color.chroma[1] >>= 3;
    
    918
    -    color.chroma[2] >>= 3;
    
    919
    -
    
    920
    -    y = blit->height;
    
    921
    -    do
    
    922
    -    {
    
    923
    -      unsigned char*   _read  = read;
    
    924
    -      unsigned short*  _write = (unsigned short*)write;
    
    925
    -      int              x      = blit->width;
    
    926
    -
    
    927
    -      while (x > 0)
    
    928
    -      {
    
    929
    -        int  val = *_read;
    
    930
    -
    
    931
    -        if (val)
    
    932
    -        {
    
    933
    -          if (val == max)
    
    934
    -            *_write = inject555( color );
    
    935
    -          else
    
    936
    -          {
    
    937
    -            /* compose gray value */
    
    938
    -            unsigned short  pix16 = *_write;
    
    939
    -            grColor         pix;
    
    940
    -
    
    941
    -            extract555( pix16, pix );
    
    942
    -
    
    943
    -            compose_pixel( pix, color, val, max );
    
    944
    -            *_write = inject555( pix );
    
    945
    -          }
    
    946
    -        }
    
    947
    -        _write ++;
    
    948
    -        _read  ++;
    
    949
    -        x--;
    
    950
    -      }
    
    951
    -
    
    952
    -      read  += blit->read_line;
    
    953
    -      write += blit->write_line;
    
    954
    -      y--;
    
    955
    -    }
    
    956
    -    while (y > 0);
    
    957
    -  }
    
    958
    -
    
    959
    -
    
    960
    -/**************************************************************************/
    
    961
    -/*                                                                        */
    
    962
    -/* <Function> blit_gray_to_565                                            */
    
    963
    -/*                                                                        */
    
    964
    -/**************************************************************************/
    
    965
    -
    
    966
    -#ifdef GRAY8
    
    967
    -  static
    
    968
    -  void  blit_gray8_to_565( grBlitter*  blit,
    
    969
    -                           grColor     color )
    
    970
    -  {
    
    971
    -    int             y;
    
    972
    -    int             sr = color.value & 0xF800;
    
    973
    -    int             sg = color.value & 0x07E0;
    
    974
    -    int             sb = color.value & 0x001F;
    
    975
    -    unsigned char*  read;
    
    976
    -    unsigned char*  write;
    
    977
    -
    
    978
    -    read   = blit->read  + blit->xread;
    
    979
    -    write  = blit->write + 2*blit->xwrite;
    
    980
    -
    
    981
    -    y = blit->height;
    
    982
    -    do
    
    983
    -    {
    
    984
    -      unsigned char*   _read  = read;
    
    985
    -      unsigned short*  _write = (unsigned short*)write;
    
    986
    -      int              x      = blit->width;
    
    987
    -
    
    988
    -      while (x > 0)
    
    989
    -      {
    
    990
    -        unsigned char  val = *_read;
    
    991
    -
    
    992
    -        if (val)
    
    993
    -        {
    
    994
    -          if (val >= 254 )
    
    995
    -            *_write = (unsigned short)( sr | sg | sb );
    
    996
    -          else if ( val >= 2 )
    
    997
    -          {
    
    998
    -            /* compose gray value */
    
    999
    -            int   pix = (int)*_write;
    
    1000
    -            int   dr  = pix & 0xF800;
    
    1001
    -            int   dg  = pix & 0x07E0;
    
    1002
    -            int   db  = pix & 0x001F;
    
    1003
    -
    
    1004
    -            dr += ((sr-dr)*val) >> 8;
    
    1005
    -            dr &= 0xF800;
    
    1006
    -
    
    1007
    -            dg += ((sg-dg)*val) >> 8;
    
    1008
    -            dg &= 0x07E0;
    
    1009
    -
    
    1010
    -            db += ((sb-db)*val) >> 8;
    
    1011
    -            db &= 0x001F;
    
    1012
    -
    
    1013
    -            *_write = (unsigned short)( dr | dg | db );
    
    1014
    -          }
    
    1015
    -        }
    
    1016
    -        _write ++;
    
    1017
    -        _read  ++;
    
    1018
    -        x--;
    
    1019
    -      }
    
    1020
    -
    
    1021
    -      read  += blit->read_line;
    
    1022
    -      write += blit->write_line;
    
    1023
    -      y--;
    
    1024
    -    }
    
    1025
    -    while (y > 0);
    
    1026
    -  }
    
    1027
    -#endif
    
    1028
    -
    
    1029
    -  static
    
    1030
    -  void  blit_gray_to_565( grBlitter*  blit,
    
    1031
    -                          grColor     color,
    
    1032
    -                          int         max )
    
    1033
    -  {
    
    1034
    -    int             y;
    
    1035
    -    unsigned char*  read;
    
    1036
    -    unsigned char*  write;
    
    1037
    -
    
    1038
    -    read   = blit->read  + blit->xread;
    
    1039
    -    write  = blit->write + 2*blit->xwrite;
    
    1040
    -
    
    1041
    -    /* scale down R:G:B triplet */
    
    1042
    -    color.chroma[0] >>= 3;
    
    1043
    -    color.chroma[1] >>= 2;
    
    1044
    -    color.chroma[2] >>= 3;
    
    1045
    -
    
    1046
    -    y = blit->height;
    
    1047
    -    do
    
    1048
    -    {
    
    1049
    -      unsigned char*   _read  = read;
    
    1050
    -      unsigned short*  _write = (unsigned short*)write;
    
    1051
    -      int              x      = blit->width;
    
    1052
    -
    
    1053
    -      while (x > 0)
    
    1054
    -      {
    
    1055
    -        int  val = *_read;
    
    1056
    -
    
    1057
    -        if (val)
    
    1058
    -        {
    
    1059
    -          if (val == max)
    
    1060
    -            *_write = inject565( color );
    
    1061
    -          else
    
    1062
    -          {
    
    1063
    -            /* compose gray value */
    
    1064
    -            unsigned short  pix16 = *_write;
    
    1065
    -            grColor         pix;
    
    1066
    -
    
    1067
    -            extract565( pix16, pix );
    
    1068
    -
    
    1069
    -            compose_pixel( pix, color, val, max );
    
    1070
    -            *_write = inject565( pix );
    
    1071
    -          }
    
    1072
    -        }
    
    1073
    -        _write ++;
    
    1074
    -        _read  ++;
    
    1075