1 #include <freetype/freetype.h> 2 #include <freetype/ftbbox.h> 3 4 5 #include <time.h> /* for clock() */ 6 7 /* SunOS 4.1.* does not define CLOCKS_PER_SEC, so include <sys/param.h> */ 8 /* to get the HZ macro which is the equivalent. */ 9 #if defined(__sun__) && !defined(SVR4) && !defined(__SVR4) 10 #include <sys/param.h> 11 #define CLOCKS_PER_SEC HZ 12 #endif 13 14 static long get_time(void)15 get_time( void ) 16 { 17 return clock() * 10000L / CLOCKS_PER_SEC; 18 } 19 20 21 22 23 /* test bbox computations */ 24 25 #define XSCALE 65536 26 #define XX(x) ((FT_Pos)(x*XSCALE)) 27 #define XVEC(x,y) { XX(x), XX(y) } 28 #define XVAL(x) ((x)/(1.0*XSCALE)) 29 30 /* dummy outline #1 */ 31 static FT_Vector dummy_vec_1[4] = 32 { 33 #if 1 34 XVEC( 408.9111, 535.3164 ), 35 XVEC( 455.8887, 634.396 ), 36 XVEC( -37.8765, 786.2207 ), 37 XVEC( 164.6074, 535.3164 ) 38 #else 39 { (FT_Int32)0x0198E93DL , (FT_Int32)0x021750FFL }, /* 408.9111, 535.3164 */ 40 { (FT_Int32)0x01C7E312L , (FT_Int32)0x027A6560L }, /* 455.8887, 634.3960 */ 41 { (FT_Int32)0xFFDA1F9EL , (FT_Int32)0x0312387FL }, /* -37.8765, 786.2207 */ 42 { (FT_Int32)0x00A49B7EL , (FT_Int32)0x021750FFL } /* 164.6074, 535.3164 */ 43 #endif 44 }; 45 46 static char dummy_tag_1[4] = 47 { 48 FT_CURVE_TAG_ON, 49 FT_CURVE_TAG_CUBIC, 50 FT_CURVE_TAG_CUBIC, 51 FT_CURVE_TAG_ON 52 }; 53 54 static short dummy_contour_1[1] = 55 { 56 3 57 }; 58 59 static FT_Outline dummy_outline_1 = 60 { 61 1, 62 4, 63 dummy_vec_1, 64 dummy_tag_1, 65 dummy_contour_1, 66 0 67 }; 68 69 70 /* dummy outline #2 */ 71 static FT_Vector dummy_vec_2[4] = 72 { 73 XVEC( 100.0, 100.0 ), 74 XVEC( 100.0, 200.0 ), 75 XVEC( 200.0, 200.0 ), 76 XVEC( 200.0, 133.0 ) 77 }; 78 79 static FT_Outline dummy_outline_2 = 80 { 81 1, 82 4, 83 dummy_vec_2, 84 dummy_tag_1, 85 dummy_contour_1, 86 0 87 }; 88 89 90 /* dummy outline #3 with bbox of [0 100 128 128] precisely */ 91 static FT_Vector dummy_vec_3[4] = 92 { 93 XVEC( 100.0, 127.0 ), 94 XVEC( 200.0, 127.0 ), 95 XVEC( 0.0, 136.0 ), 96 XVEC( 0.0, 100.0 ) 97 }; 98 99 static FT_Outline dummy_outline_3 = 100 { 101 1, 102 4, 103 dummy_vec_3, 104 dummy_tag_1, 105 dummy_contour_1, 106 0 107 }; 108 109 110 static void dump_outline(FT_Outline * outline)111 dump_outline( FT_Outline* outline ) 112 { 113 FT_BBox bbox; 114 115 /* compute and display cbox */ 116 FT_Outline_Get_CBox( outline, &bbox ); 117 printf( "cbox = [%.2f %.2f %.2f %.2f]\n", 118 XVAL( bbox.xMin ), 119 XVAL( bbox.yMin ), 120 XVAL( bbox.xMax ), 121 XVAL( bbox.yMax ) ); 122 123 /* compute and display bbox */ 124 FT_Outline_Get_BBox( outline, &bbox ); 125 printf( "bbox = [%.2f %.2f %.2f %.2f]\n", 126 XVAL( bbox.xMin ), 127 XVAL( bbox.yMin ), 128 XVAL( bbox.xMax ), 129 XVAL( bbox.yMax ) ); 130 } 131 132 133 134 static void profile_outline(FT_Outline * outline,long repeat)135 profile_outline( FT_Outline* outline, 136 long repeat ) 137 { 138 FT_BBox bbox; 139 long count; 140 long time0; 141 142 time0 = get_time(); 143 for ( count = repeat; count > 0; count-- ) 144 FT_Outline_Get_CBox( outline, &bbox ); 145 146 time0 = get_time() - time0; 147 printf( "time = %6.3f cbox = [%8.4f %8.4f %8.4f %8.4f]\n", 148 ((double)time0/10000.0), 149 XVAL( bbox.xMin ), 150 XVAL( bbox.yMin ), 151 XVAL( bbox.xMax ), 152 XVAL( bbox.yMax ) ); 153 printf( "cbox_hex = [%08X %08X %08X %08X]\n", 154 bbox.xMin, bbox.yMin, bbox.xMax, bbox.yMax ); 155 156 157 time0 = get_time(); 158 for ( count = repeat; count > 0; count-- ) 159 FT_Outline_Get_BBox( outline, &bbox ); 160 161 time0 = get_time() - time0; 162 printf( "time = %6.3f bbox = [%8.4f %8.4f %8.4f %8.4f]\n", 163 ((double)time0/10000.0), 164 XVAL( bbox.xMin ), 165 XVAL( bbox.yMin ), 166 XVAL( bbox.xMax ), 167 XVAL( bbox.yMax ) ); 168 printf( "bbox_hex = [%08X %08X %08X %08X]\n", 169 bbox.xMin, bbox.yMin, bbox.xMax, bbox.yMax ); 170 } 171 172 #define REPEAT 1000000L 173 main(int argc,char ** argv)174 int main( int argc, char** argv ) 175 { 176 printf( "outline #1\n" ); 177 profile_outline( &dummy_outline_1, REPEAT ); 178 179 printf( "outline #2\n" ); 180 profile_outline( &dummy_outline_2, REPEAT ); 181 182 printf( "outline #3\n" ); 183 profile_outline( &dummy_outline_3, REPEAT ); 184 185 return 0; 186 } 187 188