misc/libfreetype/src/tools/test_bbox.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
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
#include FT_FREETYPE_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
#include FT_BBOX_H
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
#include <time.h>    /* for clock() */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/* SunOS 4.1.* does not define CLOCKS_PER_SEC, so include <sys/param.h> */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/* to get the HZ macro which is the equivalent.                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
#if defined(__sun__) && !defined(SVR4) && !defined(__SVR4)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
#include <sys/param.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
#define CLOCKS_PER_SEC HZ
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
  static long
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
  get_time( void )
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
    return clock() * 10000L / CLOCKS_PER_SEC;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
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
  /* test bbox computations */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
#define  XSCALE    65536
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
#define  XX(x)     ((FT_Pos)(x*XSCALE))
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
#define  XVEC(x,y)  { XX(x), XX(y) }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
#define  XVAL(x)   ((x)/(1.0*XSCALE))
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
  /* dummy outline #1 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  static FT_Vector  dummy_vec_1[4] =
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
#if 1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
    XVEC( 408.9111, 535.3164 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
    XVEC( 455.8887, 634.396  ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
    XVEC( -37.8765, 786.2207 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
    XVEC( 164.6074, 535.3164 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
    { (FT_Int32)0x0198E93DL , (FT_Int32)0x021750FFL },  /* 408.9111, 535.3164 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
    { (FT_Int32)0x01C7E312L , (FT_Int32)0x027A6560L },  /* 455.8887, 634.3960 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
    { (FT_Int32)0xFFDA1F9EL , (FT_Int32)0x0312387FL },  /* -37.8765, 786.2207 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
    { (FT_Int32)0x00A49B7EL , (FT_Int32)0x021750FFL }   /* 164.6074, 535.3164 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
   };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
  static char  dummy_tag_1[4] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
    FT_CURVE_TAG_ON,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
    FT_CURVE_TAG_CUBIC,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
    FT_CURVE_TAG_CUBIC,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
    FT_CURVE_TAG_ON
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
  static short  dummy_contour_1[1] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
    3
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
  };
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
  static FT_Outline  dummy_outline_1 =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
    1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
    4,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
    dummy_vec_1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
    dummy_tag_1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
    dummy_contour_1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
    0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
  };
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
  /* dummy outline #2 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
  static FT_Vector  dummy_vec_2[4] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
    XVEC( 100.0, 100.0 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
    XVEC( 100.0, 200.0 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
    XVEC( 200.0, 200.0 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
    XVEC( 200.0, 133.0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
  static FT_Outline  dummy_outline_2 =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
    1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
    4,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
    dummy_vec_2,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
    dummy_tag_1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
    dummy_contour_1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
    0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
  };
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
  dump_outline( FT_Outline*  outline )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
    FT_BBox  bbox;
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
    /* compute and display cbox */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
    FT_Outline_Get_CBox( outline, &bbox );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
    printf( "cbox = [%.2f %.2f %.2f %.2f]\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
             XVAL( bbox.xMin ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
             XVAL( bbox.yMin ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
             XVAL( bbox.xMax ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
             XVAL( bbox.yMax ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
    /* compute and display bbox */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
    FT_Outline_Get_BBox( outline, &bbox );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
    printf( "bbox = [%.2f %.2f %.2f %.2f]\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
             XVAL( bbox.xMin ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
             XVAL( bbox.yMin ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
             XVAL( bbox.xMax ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
             XVAL( bbox.yMax ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
  profile_outline( FT_Outline*   outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
                   long          repeat )
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
    FT_BBox  bbox;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
    long     count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
    long     time0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
    time0 = get_time();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
    for ( count = repeat; count > 0; count-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
      FT_Outline_Get_CBox( outline, &bbox );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
    time0 = get_time() - time0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
    printf( "time = %5.2f cbox = [%.2f %.2f %.2f %.2f]\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
             ((double)time0/10000.0),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
             XVAL( bbox.xMin ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
             XVAL( bbox.yMin ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
             XVAL( bbox.xMax ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
             XVAL( bbox.yMax ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
    time0 = get_time();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
    for ( count = repeat; count > 0; count-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
      FT_Outline_Get_BBox( outline, &bbox );
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
    time0 = get_time() - time0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
    printf( "time = %5.2f bbox = [%.2f %.2f %.2f %.2f]\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
             ((double)time0/10000.0),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
             XVAL( bbox.xMin ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
             XVAL( bbox.yMin ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
             XVAL( bbox.xMax ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
             XVAL( bbox.yMax ) );
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
#define REPEAT  100000L
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
  int  main( int  argc, char**  argv )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
    printf( "outline #1\n" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
    profile_outline( &dummy_outline_1, REPEAT );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
    printf( "outline #2\n" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
    profile_outline( &dummy_outline_2, REPEAT );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
    return 0;
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