summaryrefslogtreecommitdiff
path: root/make_bitmap/example2.c
blob: 4fa791075edae1b7998dcc5e266af76dc717c771 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// This example uses the FreeType rendering library to print 
// the MurmurHash3 hash value of the 8-bit anti-aliased
// bitmaps of all the glyphs in the font.

#include "bitmap.h" // The header file

int main(int argc, char const *argv[])
{
    FT_Library      library;
    FT_Face         face;
    FT_GlyphSlot    slot;
    FT_Bitmap*      bitmap;

    FT_Error        error;

    const char*     filename;
    FT_UInt32       size; 

    if (argc != 3)
    {
    	printf("This program prints the hashes of 8-bit grayscale\n"); 
    	printf("anti-aliased bitmaps of all the glyphs in a font\n\n");

    	printf("Usage ./<exe> <font_file> <pt_size>\n\n");
    	exit(0);
    }


    filename = argv[1];
    size =  atoi(argv[2]); 

    error = FT_Init_FreeType( &library );
    if(error){
        printf("Error while initialising library\n");
    }

    error = FT_New_Face( library, 
                         filename, 
                         0, 
                         &face );
    if(error){
        printf("Error loading new face\n");
    }

    error = FT_Set_Char_Size( face,
                              size * 64,
                              0, 
                              100, 
                              0 );
    if(error){
        printf("Error setting character size\n");
    }

    slot = face->glyph;

    for (int i = 0; i < face->num_glyphs; ++i)      // Loop
    {
	    error = FT_Load_Glyph( face,
	                            i, 
	                            FT_LOAD_DEFAULT);
	    if(error){
	        printf("Error loading glyph\n");
	    }

	    FT_Render_Glyph( slot, 
	                     FT_RENDER_MODE_NORMAL);
	    if(error){
	        printf("Error rendering the glyph\n");
	    }
	    	
		bitmap = &slot->bitmap;

		if (bitmap->width == 0|| bitmap->rows == 0)
		{
			printf("%d - Empty Glyph\n",i);
			continue;
		}

	    HASH_128 *  murmur = (HASH_128 *) malloc(sizeof(HASH_128)) ;
	    murmur = Generate_Hash_x64_128(bitmap,murmur);

	    printf("%d - %08x %08x %08x %08x\n",i,
                                            murmur->hash[0], 
	                                        murmur->hash[1],
	                                   	    murmur->hash[2], 
	                                        murmur->hash[3]); 
    }

    FT_Done_Face    ( face );
    FT_Done_FreeType( library );

    return 0;
}