|
| 1 | +#include "test_common.h" |
| 2 | + |
| 3 | +UTEST( backend_diagnostics, bbox_profiles_and_centroid ) |
| 4 | +{ |
| 5 | + std::vector< uint8_t > pixels = ve_fontcache_backend_test_make_image( 8, 8, 0 ); |
| 6 | + ve_fontcache_backend_test_fill_rect( pixels, 8, 8, 2, 1, 3, 4, 20 ); |
| 7 | + |
| 8 | + ve_fontcache_backend_test_bbox bbox = ve_fontcache_backend_test_thresholded_bbox( pixels, 8, 8, 1 ); |
| 9 | + std::vector< uint32_t > rows = ve_fontcache_backend_test_row_sum_profile( pixels, 8, 8 ); |
| 10 | + std::vector< uint32_t > cols = ve_fontcache_backend_test_column_sum_profile( pixels, 8, 8 ); |
| 11 | + ve_fontcache_backend_test_center_of_mass center = ve_fontcache_backend_test_center_of_mass_grayscale( pixels, 8, 8 ); |
| 12 | + |
| 13 | + EXPECT_TRUE( bbox.valid ); |
| 14 | + EXPECT_EQ( 2, bbox.x ); |
| 15 | + EXPECT_EQ( 1, bbox.y ); |
| 16 | + EXPECT_EQ( 3, bbox.w ); |
| 17 | + EXPECT_EQ( 4, bbox.h ); |
| 18 | + EXPECT_EQ( 12, bbox.area ); |
| 19 | + EXPECT_EQ( 60u, rows[ 1 ] ); |
| 20 | + EXPECT_EQ( 60u, rows[ 4 ] ); |
| 21 | + EXPECT_EQ( 80u, cols[ 2 ] ); |
| 22 | + EXPECT_EQ( 80u, cols[ 4 ] ); |
| 23 | + EXPECT_TRUE( std::fabs( center.x - 3.5 ) <= 0.01 ); |
| 24 | + EXPECT_TRUE( std::fabs( center.y - 3.0 ) <= 0.01 ); |
| 25 | +} |
| 26 | + |
| 27 | +UTEST( backend_diagnostics, components_and_border_leakage ) |
| 28 | +{ |
| 29 | + std::vector< uint8_t > pixels = ve_fontcache_backend_test_make_image( 6, 6, 0 ); |
| 30 | + ve_fontcache_backend_test_fill_rect( pixels, 6, 6, 1, 1, 2, 2, 255 ); |
| 31 | + ve_fontcache_backend_test_fill_rect( pixels, 6, 6, 0, 5, 1, 1, 255 ); |
| 32 | + |
| 33 | + EXPECT_EQ( 2, ve_fontcache_backend_test_connected_component_count( pixels, 6, 6, 1 ) ); |
| 34 | + EXPECT_EQ( 1, ve_fontcache_backend_test_border_leakage_count( pixels, 6, 6, 1, 1 ) ); |
| 35 | + EXPECT_EQ( 1, ve_fontcache_backend_test_outside_rect_count( pixels, 6, 6, { 1, 1, 2, 2 }, 1 ) ); |
| 36 | +} |
| 37 | + |
| 38 | +UTEST( backend_diagnostics, diff_stats_and_peak_location ) |
| 39 | +{ |
| 40 | + std::vector< uint8_t > expected = ve_fontcache_backend_test_make_image( 4, 4, 0 ); |
| 41 | + std::vector< uint8_t > actual = expected; |
| 42 | + actual[ 1 ] = 20; |
| 43 | + actual[ 14 ] = 120; |
| 44 | + |
| 45 | + ve_fontcache_backend_test_diff_stats diff = ve_fontcache_backend_test_expected_vs_actual_diff( expected, actual, 4, 4 ); |
| 46 | + |
| 47 | + EXPECT_EQ( 140ull, diff.total_abs_error ); |
| 48 | + EXPECT_TRUE( std::fabs( diff.mean_abs_error - 8.75 ) <= 0.01 ); |
| 49 | + EXPECT_EQ( 120, diff.max_abs_error ); |
| 50 | + EXPECT_EQ( 2, diff.peak_x ); |
| 51 | + EXPECT_EQ( 3, diff.peak_y ); |
| 52 | + EXPECT_EQ( 2, diff.differing_pixels ); |
| 53 | +} |
| 54 | + |
| 55 | +UTEST( backend_diagnostics, mirror_scores_detect_flips ) |
| 56 | +{ |
| 57 | + std::vector< uint8_t > expected = ve_fontcache_backend_test_make_image( 6, 6, 0 ); |
| 58 | + ve_fontcache_backend_test_fill_l_shape( expected, 6, 6, 1, 1, 4, 4, 2, 255 ); |
| 59 | + |
| 60 | + std::vector< uint8_t > vertical = ve_fontcache_backend_test_flip_vertical( expected, 6, 6 ); |
| 61 | + std::vector< uint8_t > horizontal = ve_fontcache_backend_test_flip_horizontal( expected, 6, 6 ); |
| 62 | + |
| 63 | + ve_fontcache_backend_test_mirror_scores vertical_scores = |
| 64 | + ve_fontcache_backend_test_mirror_scores_for_expected( expected, vertical, 6, 6 ); |
| 65 | + ve_fontcache_backend_test_mirror_scores horizontal_scores = |
| 66 | + ve_fontcache_backend_test_mirror_scores_for_expected( expected, horizontal, 6, 6 ); |
| 67 | + |
| 68 | + EXPECT_TRUE( ve_fontcache_backend_test_is_vertical_flip( vertical_scores ) ); |
| 69 | + EXPECT_FALSE( ve_fontcache_backend_test_is_horizontal_flip( vertical_scores ) ); |
| 70 | + EXPECT_TRUE( ve_fontcache_backend_test_is_horizontal_flip( horizontal_scores ) ); |
| 71 | + EXPECT_FALSE( ve_fontcache_backend_test_is_vertical_flip( horizontal_scores ) ); |
| 72 | +} |
| 73 | + |
| 74 | +UTEST( backend_diagnostics, classifier_helpers_flag_scale_aspect_and_source_binding ) |
| 75 | +{ |
| 76 | + ve_fontcache_backend_test_bbox expected_bbox { true, 10, 20, 40, 40, 1600 }; |
| 77 | + ve_fontcache_backend_test_bbox uniform_scaled { true, 12, 22, 48, 48, 2304 }; |
| 78 | + ve_fontcache_backend_test_bbox aspect_scaled { true, 12, 22, 56, 40, 2240 }; |
| 79 | + |
| 80 | + EXPECT_TRUE( ve_fontcache_backend_test_is_uniform_scale_error( expected_bbox, uniform_scaled ) ); |
| 81 | + EXPECT_FALSE( ve_fontcache_backend_test_is_aspect_ratio_deformation( expected_bbox, uniform_scaled ) ); |
| 82 | + EXPECT_TRUE( ve_fontcache_backend_test_is_aspect_ratio_deformation( expected_bbox, aspect_scaled ) ); |
| 83 | + |
| 84 | + std::vector< uint8_t > pattern = ve_fontcache_backend_test_make_image( 4, 4, 0 ); |
| 85 | + ve_fontcache_backend_test_fill_rect( pattern, 4, 4, 0, 0, 2, 4, 255 ); |
| 86 | + std::vector< uint8_t > zero = ve_fontcache_backend_test_make_image( 4, 4, 0 ); |
| 87 | + |
| 88 | + ve_fontcache_backend_test_diff_stats expected_diff = |
| 89 | + ve_fontcache_backend_test_expected_vs_actual_diff( pattern, zero, 4, 4 ); |
| 90 | + ve_fontcache_backend_test_diff_stats alternate_diff = |
| 91 | + ve_fontcache_backend_test_expected_vs_actual_diff( zero, zero, 4, 4 ); |
| 92 | + |
| 93 | + EXPECT_TRUE( ve_fontcache_backend_test_is_wrong_source_texture_bound( expected_diff, alternate_diff ) ); |
| 94 | +} |
0 commit comments