Compare commits

...

4 Commits

Author SHA1 Message Date
Arvinder Bhathal d8dc158939 Update to latest bitmap code 2017-07-28 09:27:06 -04:00
Arvinder Bhathal 2572b1bea7 Merge branch 'master' of git.sv.gnu.org:/srv/git/freetype/freetype2 into arv-testing 2017-07-03 15:53:35 -04:00
Arvinder Bhathal 9cac265289 Add html generating code 2017-06-30 03:55:47 -04:00
Arvinder Bhathal 9f04eab17e Add tests folder 2017-06-29 13:18:50 -04:00
7 changed files with 1274 additions and 0 deletions

View File

View File

@ -0,0 +1,5 @@
Compile with current ft folder:
gcc main.c bitmap.c murmur3.c -Wall -I /usr/local/include/freetype2/ -lfreetype -ldl -lpng -lm -o main
Run
./main <base libfreetype.so> <test libfreetype.so> <size> <font file>

View File

@ -0,0 +1,615 @@
#include "bitmap.h"
HASH_128 * Generate_Hash_x64_128( FT_Bitmap * bitmap,
HASH_128 * murmur)
{
int seed = 99; // Dont change
MurmurHash3_x64_128(bitmap->buffer,
(bitmap->pitch * bitmap->rows),
seed,
murmur->hash);
return murmur;
}
HASH_128 * Generate_Hash_x86_128( FT_Bitmap * bitmap,
HASH_128 * murmur)
{
int seed = 99; // Dont change
MurmurHash3_x86_128(bitmap->buffer,
(bitmap->pitch * bitmap->rows),
seed,
murmur->hash);
return murmur;
}
HASH_32 * Generate_Hash_x86_32( FT_Bitmap * bitmap,
HASH_32 * murmur)
{
int seed = 99; // Dont change
MurmurHash3_x86_32( bitmap->buffer,
(bitmap->pitch * bitmap->rows),
seed,
&murmur->hash);
return murmur;
}
PIXEL * Pixel_At (IMAGE * bitmap, int x, int y)
{
return bitmap->pixels + bitmap->width * y + x;
}
int Generate_PNG (IMAGE *bitmap,
const char *path,
int render_mode)
{
FILE * fp;
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
size_t x, y;
png_byte ** row_pointers = NULL;
int status = -1;
int pixel_size = 4;
int depth = 8;
fp = fopen (path, "wb");
if (! fp) {
goto fopen_failed;
}
png_ptr = png_create_write_struct ( PNG_LIBPNG_VER_STRING,
NULL,
NULL,
NULL);
if (png_ptr == NULL) {
goto png_create_write_struct_failed;
}
info_ptr = png_create_info_struct (png_ptr);
if (info_ptr == NULL) {
goto png_create_info_struct_failed;
}
if (setjmp (png_jmpbuf (png_ptr))) {
goto png_failure;
}
png_set_IHDR (png_ptr,
info_ptr,
bitmap->width,
bitmap->height,
depth,
PNG_COLOR_TYPE_RGBA,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
row_pointers = png_malloc ( png_ptr,
bitmap->height * sizeof (png_byte *));
for (y = 0; y < bitmap->height; y++) {
png_byte *row =
png_malloc(png_ptr, sizeof(uint8_t) * bitmap->width * pixel_size);
row_pointers[y] = row;
for (x = 0; x < bitmap->width; x++) {
PIXEL * pixel = Pixel_At (bitmap, x, y);
if (render_mode == 3 || render_mode == 5)
{
*row++ = pixel->blue;
*row++ = pixel->green;
*row++ = pixel->red;
*row++ = pixel->alpha;
continue;
}
*row++ = pixel->red;
*row++ = pixel->green;
*row++ = pixel->blue;
*row++ = pixel->alpha;
}
}
png_init_io ( png_ptr,
fp);
png_set_rows (png_ptr,
info_ptr,
row_pointers);
png_write_png ( png_ptr,
info_ptr,
PNG_TRANSFORM_IDENTITY,
NULL);
status = 0;
for (y = 0; y < bitmap->height; y++) {
png_free (png_ptr, row_pointers[y]);
}
png_free (png_ptr, row_pointers);
free (bitmap->pixels);
png_failure:
png_create_info_struct_failed:
png_destroy_write_struct (&png_ptr, &info_ptr);
png_create_write_struct_failed:
fclose (fp);
fopen_failed:
return status;
}
void Make_PNG(FT_Bitmap* bitmap,IMAGE* fruit,int i,int render_mode){
int x;
int y;
unsigned char value;
int p;
switch(render_mode){
case 0 : fruit->width = bitmap->width; // MONO and GRAY
fruit->height = bitmap->rows;
fruit->pixels = calloc ( fruit->width * fruit->height,
sizeof (PIXEL));
for (y = 0; y < fruit->height; y++) {
for (x = 0; x < fruit->width; x++) {
PIXEL * pixel = Pixel_At ( fruit, x, y);
p = (y * bitmap->pitch ) + x;
value = bitmap->buffer[p];
if ( value != 0x00 ){
value = 0xff;
}else{
value = 0x00;
}
pixel->red = 255- value;
pixel->green = 255- value;
pixel->blue = 255- value;
pixel->alpha = 255;
}
}
break;
case 1 : fruit->width = bitmap->width; // MONO and GRAY
fruit->height = bitmap->rows;
fruit->pixels = calloc ( fruit->width * fruit->height,
sizeof (PIXEL));
for (y = 0; y < fruit->height; y++) {
for (x = 0; x < fruit->width; x++) {
PIXEL * pixel = Pixel_At ( fruit, x, y);
p = (y * bitmap->pitch ) + x;
value = bitmap->buffer[p];
pixel->red = 255- value;
pixel->green = 255- value;
pixel->blue = 255- value;
pixel->alpha = 255;
}
}
break;
case 2 :
case 3 : fruit->width = bitmap->width / 3; // LCD
fruit->height = bitmap->rows;
fruit->pixels = calloc ( fruit->width * fruit->height,
sizeof (PIXEL));
for (y = 0; y < fruit->height; y++) {
for (x = 0; x < fruit->width; x++) {
PIXEL * pixel = Pixel_At ( fruit, x, y);
p = (y * bitmap->pitch ) + (x)*3;
value = bitmap->buffer[p];
pixel->red = 255- value;
p++;
value = bitmap->buffer[p];
pixel->green = 255- value;
p++;
value = bitmap->buffer[p];
pixel->blue = 255- value;
pixel->alpha = 255;
}
}
break;
case 4 :
case 5 : fruit->width = bitmap->width; // LCD_V
fruit->height = bitmap->rows / 3;
fruit->pixels = calloc ( fruit->width * fruit->height,
sizeof (PIXEL));
for (y = 0; y < fruit->height; y++) {
for (x = 0; x < fruit->width; x++) {
PIXEL * pixel = Pixel_At ( fruit, x, y);
p = ((y*3) * bitmap->pitch ) + x;
value = bitmap->buffer[p];
pixel->red = 255- value;
p += bitmap->pitch;
value = bitmap->buffer[p];
pixel->green = 255- value;
p += bitmap->pitch;
value = bitmap->buffer[p];
pixel->blue = 255- value;
pixel->alpha = 255;
}
}
break;
default : fruit->width = bitmap->width;
fruit->height = bitmap->rows;
break;
}
}
void Read_PNG(char *filename, IMAGE * after_effect) {
int width, height;
png_bytep *row_pointers;
FILE *fp = fopen(filename, "rb");
png_structp png = png_create_read_struct( PNG_LIBPNG_VER_STRING,
NULL,
NULL,
NULL);
if(!png) abort();
png_infop info = png_create_info_struct(png);
if(!info) abort();
if(setjmp(png_jmpbuf(png))) abort();
png_init_io(png, fp);
png_set_user_limits(png, 0x7fffffffL, 0x7fffffffL);
png_read_info(png, info);
width = png_get_image_width(png, info);
height = png_get_image_height(png, info);
after_effect->width = width;
after_effect->height = height;
row_pointers = (png_bytep*)malloc(sizeof(png_bytep) * height);
for(int y = 0; y < height; y++) {
row_pointers[y] = (png_byte*)malloc(png_get_rowbytes(png,info));
}
png_read_image(png, row_pointers);
after_effect->pixels =
(PIXEL*) malloc( width * height * sizeof(PIXEL));
for(int y = 0; y < height; y++) {
png_bytep row = row_pointers[y];
for(int x = 0; x < width; x++ ) {
png_bytep px = &(row[x * 4]);
PIXEL * pixel = Pixel_At ( after_effect, x, y);
pixel->red = px[0];
pixel->green = px[1];
pixel->blue = px[2];
pixel->alpha = px[3];
}
}
fclose(fp);
}
int Add_effect(IMAGE* base, IMAGE* test, IMAGE* out, int Effect_ID)
{
int pixel_diff = 0;
out->width = base->width;
out->height = base->height;
out->pixels =
(PIXEL*)malloc(base->width * base->height * sizeof(PIXEL));
for(int y = 0; y < base->height; y++) {
for(int x = 0; x < base->width; x++ ) {
PIXEL * pixel_base = Pixel_At ( base, x, y);
PIXEL * pixel_test = Pixel_At ( test, x, y);
PIXEL * pixel_out = Pixel_At ( out, x, y);
if (Effect_ID == 1)
{
if (pixel_base->red == 255 &&
pixel_base->green == 255 &&
pixel_base->blue == 255 &&
pixel_base->alpha == 255 )
{
pixel_out->red = 255;
pixel_out->green = 255;
pixel_out->blue = 255;
pixel_out->alpha = 255;
}else{
pixel_out->red = 127;
pixel_out->green = 127;
pixel_out->blue = 127;
pixel_out->alpha = 255;
}
}
if (pixel_base->red != pixel_test->red ||
pixel_base->green != pixel_test->green ||
pixel_base->blue != pixel_test->blue ||
pixel_base->alpha != pixel_test->alpha )
{
pixel_out->red = 255;
pixel_out->green = 0;
pixel_out->blue = 0;
pixel_out->alpha = 255;
pixel_diff++;
}else{
if (Effect_ID == 2)
{
pixel_out->red = pixel_base->red;
pixel_out->green = pixel_base->green;
pixel_out->blue = pixel_base->blue;
pixel_out->alpha = pixel_base->alpha;
}
}
}
}
return pixel_diff;
}
void Stitch(IMAGE* left, IMAGE* right, IMAGE* result){
result->width = left->width + right->width;
result->height = MAX(left->height, right->height);
result->pixels =
(PIXEL*)calloc(result->width * result->height, sizeof(PIXEL));
for (int y = 0; y < left->height; ++y)
{
for (int x = 0; x < left->width; ++x)
{
PIXEL * pixel_left = Pixel_At ( left, x, y);
PIXEL * pixel_result = Pixel_At ( result, x, y);
pixel_result->red = pixel_left->red;
pixel_result->green = pixel_left->green;
pixel_result->blue = pixel_left->blue;
pixel_result->alpha = pixel_left->alpha;
}
}
for (int y = 0; y < right->height; ++y)
{
for (int x = left->width; x < result->width; ++x)
{
PIXEL * pixel_right = Pixel_At ( right, x - left->width, y);
PIXEL * pixel_result = Pixel_At ( result, x, y);
pixel_result->red = pixel_right->red;
pixel_result->green = pixel_right->green;
pixel_result->blue = pixel_right->blue;
pixel_result->alpha = pixel_right->alpha;
}
}
}
int Compare_Hash(HASH_128* hash_b, HASH_128* hash_t){
if (hash_b->hash[0] != hash_t->hash[0] ||
hash_b->hash[1] != hash_t->hash[1] ||
hash_b->hash[2] != hash_t->hash[2] ||
hash_b->hash[3] != hash_t->hash[3] )
{
return 1;
}
return 0;
}
void Print_Row( FILE* fp, int index, char* name, int diff,
HASH_128* hash_b, HASH_128* hash_t){
fprintf(fp,
"<tr>\n\
<td>%04d</td>\n\
<td>%s</td>\n\
<td>%04d</td>\n\
<td id=\"hash\">%08x%08x%08x%08x<br>%08x%08x%08x%08x</td>\n\
<td><img id=\"sprite\" src=\"images/sprite_%04d.png\"></td>\n\
</tr>\n", index, name, diff,hash_b->hash[0],
hash_b->hash[1],
hash_b->hash[2],
hash_b->hash[3],
hash_t->hash[0],
hash_t->hash[1],
hash_t->hash[2],
hash_t->hash[3], index);
}
int First_Column(IMAGE* input){
for (int x = 0; x < input->width; ++x)
{
for (int y = 0; y < input->height; ++y)
{
PIXEL * pixel_result = Pixel_At ( input, x, y);
if ( pixel_result->red == 255 &&
pixel_result->green == 255 &&
pixel_result->blue == 255 &&
pixel_result->alpha == 255 )
{
continue;
}else{
return x;
}
}
}
return input->width;
}
int First_Row(IMAGE* input){
for (int y = 0; y < input->height; ++y)
{
for (int x = 0; x < input->width; ++x)
{
PIXEL * pixel_result = Pixel_At ( input, x, y);
if ( pixel_result->red == 255 &&
pixel_result->green == 255 &&
pixel_result->blue == 255 &&
pixel_result->alpha == 255 )
{
continue;
}else{
return y;
}
}
}
return input->height;
}
IMAGE* Append_Columns(IMAGE* small, IMAGE* big){
IMAGE* result = (IMAGE*)malloc(sizeof(IMAGE));
result->height = small->height;
result->width = big->width;
result->pixels =
(PIXEL*) malloc(result->width * result->height * sizeof(PIXEL));
int first_col = First_Column(big);
for (int x = 0; x < first_col; ++x)
{
for (int y = 0; y < result->height; ++y)
{
PIXEL * pixel_result = Pixel_At ( result, x, y);
pixel_result->red = 255;
pixel_result->green = 255;
pixel_result->blue = 255;
pixel_result->alpha = 255;
}
}
for (int y = 0; y < result->height; ++y)
{
for (int x = first_col; x < first_col + small->width; ++x)
{
PIXEL * pixel_small = Pixel_At ( small, (x - first_col), y);
PIXEL * pixel_result = Pixel_At ( result, x, y);
pixel_result->red = pixel_small->red;
pixel_result->green = pixel_small->green;
pixel_result->blue = pixel_small->blue;
pixel_result->alpha = pixel_small->alpha;
}
}
for (int x = first_col + small->width; x < result->width; ++x)
{
for (int y = 0; y < result->height; ++y)
{
PIXEL * pixel_result = Pixel_At ( result, x, y);
pixel_result->red = 255;
pixel_result->green = 255;
pixel_result->blue = 255;
pixel_result->alpha = 255;
}
}
return result;
}
IMAGE* Append_Rows(IMAGE* small, IMAGE* big){
IMAGE* result = (IMAGE*)malloc(sizeof(IMAGE));
result->height = big->height;
result->width = small->width;
result->pixels =
(PIXEL*) malloc(result->width * result->height * sizeof(PIXEL));
int first_row = First_Row(big);
for (int y = 0; y < first_row; ++y)
{
for (int x = 0; x < result->width; ++x)
{
PIXEL * pixel_result = Pixel_At ( result, x, y);
pixel_result->red = 255;
pixel_result->green = 255;
pixel_result->blue = 255;
pixel_result->alpha = 255;
}
}
for (int y = first_row; y < first_row + small->height; ++y)
{
for (int x = 0; x < result->width; ++x)
{
PIXEL * pixel_small = Pixel_At ( small, x, y - first_row);
PIXEL * pixel_result = Pixel_At ( result, x, y);
pixel_result->red = pixel_small->red;
pixel_result->green = pixel_small->green;
pixel_result->blue = pixel_small->blue;
pixel_result->alpha = pixel_small->alpha;
}
}
for (int y = first_row + small->height; y < result->height; ++y)
{
for (int x = 0; x < result->width; ++x)
{
PIXEL * pixel_result = Pixel_At ( result, x, y);
pixel_result->red = 255;
pixel_result->green = 255;
pixel_result->blue = 255;
pixel_result->alpha = 255;
}
}
return result;
}

View File

@ -0,0 +1,90 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ft2build.h>
#include "murmur3.h" // MurmurHash3_x64_128 header file
#include <png.h>
#include <dlfcn.h>
#include <math.h>
#include FT_FREETYPE_H
#include FT_MODULE_H
#include FT_LCD_FILTER_H
#include FT_BITMAP_H
#define BITS_PER_PIXEL_RGBA 32
#define MAX(a, b) ((a) > (b) ? (a) : (b))
typedef struct { // To store 32bit Hash
FT_UInt32 hash;
}HASH_32;
typedef struct { // To store 128bit Hash
FT_UInt32 hash[4];
}HASH_128;
typedef struct {
unsigned char red;
unsigned char green;
unsigned char blue;
unsigned char alpha;
} PIXEL;
typedef struct {
unsigned char red;
unsigned char green;
unsigned char blue;
unsigned char alpha;
} PIXEL_BGRA;
/* A picture. */
typedef struct {
PIXEL *pixels;
size_t width;
size_t height;
} IMAGE;
//------------------------------------------------------------------------------
HASH_32 * Generate_Hash_x86_32(FT_Bitmap * bitmap, HASH_32 * murmur);
HASH_128 * Generate_Hash_x86_128(FT_Bitmap * bitmap, HASH_128 * murmur);
HASH_128 * Generate_Hash_x64_128(FT_Bitmap * bitmap, HASH_128 * murmur);
int Compare_Hash(HASH_128* hash_b, HASH_128* hash_t);
//------------------------------------------------------------------------------
PIXEL * Pixel_At (IMAGE * bitmap, int x, int y); // Returns a pointer to pixel
// at (x,y) co-ordinate
// buffer to image
void Make_PNG (FT_Bitmap* bitmap,IMAGE* fruit, int i,int render_mode);
// Image to file
int Generate_PNG (IMAGE *bitmap, const char *path,int render_mode);
// Read PNG
void Read_PNG(char *filename, IMAGE * after_effect);
// Add an effect using two PNG images
// Base Glyph = Gray {127,0,0,255} OR as it is
// Differences = Red {255,0,0,255}
// Effect_ID = {1 or 2}
int Add_effect(IMAGE* base, IMAGE* test, IMAGE* out, int Effect_ID);
// Stitch 2 PNG files
void Stitch(IMAGE* left, IMAGE* right, IMAGE* result);
// Make the Height of both the PNG(s) same by filling with white pixels
void Print_Row( FILE* fp, int index, char* name, int diff,
HASH_128* hash_b, HASH_128* hash_t);
// Finding the first non-empty (non-white) column
int First_Column(IMAGE* input);
// Finding the first non-empty (non-white) row
int First_Row(IMAGE* input);
// Appening white columns with image alignment
IMAGE* Append_Columns(IMAGE* small, IMAGE* big);
// Appening white columns with image alignment
IMAGE* Append_Rows(IMAGE* small, IMAGE* big);

228
tests/web_interface/main.c Normal file
View File

@ -0,0 +1,228 @@
#include "bitmap.h"
struct entry
{
int code;
char base_img[256];
char test_img[256];
char base_hash[33];
char test_hash[33];
double base_value;
double test_value;
double difference;
};
void render(const char*, const char*, FT_UInt32, int, struct entry (*entries)[], int*, int*);
int compare(const void* e1, const void* e2);
void make_html(struct entry (*entries)[], int* num, const char*);
int main(int argc, char const *argv[])
{
const char* base_ft;
const char* test_ft;
FT_UInt32 size;
const char* font;
int num = 0;
int max = 0;
int mode;
struct entry entries[2000];
for (int i = 0; i < 2000; ++i)
{
entries[i].difference = 0.0;
}
if(argc != 5)
{
printf("Usage: %s <base ft.so> <test ft.so> <char size> <font>\n", argv[0]);
return 0;
}
base_ft = argv[1];
test_ft = argv[2];
size = atoi(argv[3]);
font = argv[4];
mode = 0; // base hashes
render(base_ft, font, size, mode, &entries, &num, &max);
mode = 1; // test hashes
render(test_ft, font, size, mode, &entries, &num, &max);
mode = 2; // base images for differing glyphs
render(test_ft, font, size, mode, &entries, &num, &max);
mode = 3; // test images for differing glyphs
render(test_ft, font, size, mode, &entries, &num, &max);
qsort(entries, 2000, sizeof(struct entry), compare);
make_html(&entries, &num, font);
}
void make_html(struct entry (*entries)[], int* num, const char* font)
{
FILE *fp = fopen("index.html", "w");
if (fp == NULL)
{
printf("Error opening file.\n");
exit(1);
}
fprintf(fp, "<!DOCTYPE html>\n<html>\n<head>\n<style>\nimg{image-rendering: optimizeSpeed;image-rendering: -moz-crisp-edges;image-rendering: -o-crisp-edges;image-rendering: -webkit-optimize-contrast;image-rendering: pixelated;image-rendering: optimize-contrast;-ms-interpolation-mode: nearest-neighbor;min-width:10%%}\ntable, th, td{\nborder: 1px solid black;\n}\n</style>\n</head>\n\n<body>\n");
fprintf(fp, "<p>%s</p>\n<table style=\"width:100%%\">", font);
fprintf(fp, "<tr><th>ID</th><th>Difference</th><th>Base glyph | Test glyph</th></tr>\n");
for (int i = 0; i < *num; ++i)
{
fprintf(fp, "<tr><td>%d</td><td>%.2f</td><td><img src=\"%s\"</img> <img src=\"%s\"</img></td></tr>\n", (*entries)[i].code, (*entries)[i].difference, (*entries)[i].base_img, (*entries)[i].test_img);
}
fprintf(fp, "</table>\n</body>\n</html>");
fclose(fp);
}
int compare (const void* e1, const void* e2)
{
struct entry *s1 = (struct entry *)e1;
struct entry *s2 = (struct entry *)e2;
int comp = (int)(s1->difference) - (int)(s2->difference);
return -comp;
}
// mode 0: hash base
// mode 1: hash test
// mode 2: image base
// mode 3: image test
void render(const char* ft_dir, const char* font, FT_UInt32 size, int mode, struct entry (*entries)[], int* num, int* max)
{
FT_Library library;
FT_Face face;
FT_GlyphSlot slot;
FT_Bitmap *bitmap;
FT_Error error;
int i;
FT_Error (*ft_init_fun)(FT_Library*);
FT_Error (*ft_newface_fun)(FT_Library, const char*, FT_Long, FT_Face*);
FT_Error (*ft_setcharsize_fun)(FT_Face, FT_F26Dot6, FT_F26Dot6, FT_UInt,
FT_UInt);
FT_Error (*ft_loadglyph_fun)(FT_Face, FT_UInt, FT_Int32);
FT_Error (*ft_renderglyph_fun)(FT_GlyphSlot, FT_Render_Mode);
FT_Error (*ft_doneface_fun)(FT_Face);
FT_Error (*ft_donefreetype_fun)(FT_Library);
void (*ft_bitmapinit_fun)(FT_Bitmap*);
FT_Error (*ft_bitmapconvert_fun)(FT_Library, const FT_Bitmap*, FT_Bitmap,
FT_Int);
void* handle = dlopen(ft_dir, RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND);
if (!handle) {
fputs(dlerror(), stderr);
exit(1);
}
dlerror();
*(void**)(&ft_init_fun) = dlsym(handle,"FT_Init_FreeType");
*(void**)(&ft_newface_fun) = dlsym(handle,"FT_New_Face");
*(void**)(&ft_setcharsize_fun) = dlsym(handle,"FT_Set_Char_Size");
*(void**)(&ft_loadglyph_fun) = dlsym(handle,"FT_Load_Glyph");
*(void**)(&ft_renderglyph_fun) = dlsym(handle,"FT_Render_Glyph");
*(void**)(&ft_doneface_fun) = dlsym(handle,"FT_Done_Face");
*(void**)(&ft_donefreetype_fun) = dlsym(handle,"FT_Done_FreeType");
*(void**)(&ft_bitmapinit_fun) = dlsym(handle,"FT_Bitmap_Init");
*(void**)(&ft_bitmapconvert_fun) = dlsym(handle,"FT_Bitmap_Convert");
dlerror();
error = ft_init_fun(&library);
if (error)
{
printf("Error: library init");
}
error = ft_newface_fun(library, font, 0, &face);
if (error)
{
printf("Error: loading face");
}
error = ft_setcharsize_fun(face, size * 64, 0, 96, 0);
if (error)
{
printf("Error: setting char size");
}
slot = face->glyph;
for (i = 0; i < face->num_glyphs; ++i)
{
(*entries)[i].code = i;
if (((mode == 2) || (mode == 3)) &&
(strcmp((*entries)[i].base_hash, (*entries)[i].test_hash) == 0))
{
continue;
}
error = ft_loadglyph_fun(face, i, FT_LOAD_DEFAULT);
if (error)
{
printf("Error: loading glyph");
}
error = ft_renderglyph_fun(slot, FT_RENDER_MODE_NORMAL);
if (error)
{
printf("Error: rendering glyph");
}
bitmap = &slot->bitmap;
if ((mode == 0) || (mode == 1))
{
HASH_128 * murmur = (HASH_128 *)malloc(sizeof(HASH_128));
murmur = Generate_Hash_x64_128(bitmap, murmur);
if (mode == 0)
{
sprintf((*entries)[i].base_hash, "%08x%08x%08x%08x", murmur->hash[0], murmur->hash[1],
murmur->hash[2], murmur->hash[3]);
}
else
{
sprintf((*entries)[i].test_hash, "%08x%08x%08x%08x", murmur->hash[0], murmur->hash[1],
murmur->hash[2], murmur->hash[3]);
}
} else {
*max = i;
if (bitmap->width == 0 || bitmap->rows == 0)
{
continue;
}
if (mode == 2)
{
*num = *num + 1;
Make_PNG(bitmap, "base", i, 1);
sprintf((*entries)[i].base_img, "base_%d.png", i);
(*entries)[i].base_value = (double)(rand() % 1000);
} else if (mode == 3){
Make_PNG(bitmap, "test", i, 1);
sprintf((*entries)[i].test_img, "test_%d.png", i);
(*entries)[i].test_value = (double)(rand() % 1000);
(*entries)[i].difference = fabs((*entries)[i].base_value- (*entries)[i].test_value);
}
}
}
error = ft_doneface_fun(face);
if (error)
{
printf("Error: freeing face");
}
error = ft_donefreetype_fun(library);
if (error)
{
printf("Error: freeing library");
}
dlclose(handle);
}

View File

@ -0,0 +1,312 @@
//-----------------------------------------------------------------------------
// Note - The x86 and x64 versions do _not_ produce the same results, as the
// algorithms are optimized for their respective platforms. You can still
// compile and run any of them on any platform, but your performance with the
// non-native version will be less than optimal.
#include "murmur3.h"
//-----------------------------------------------------------------------------
// Platform-specific functions and macros
#ifdef __GNUC__
#define FORCE_INLINE __attribute__((always_inline)) inline
#else
#define FORCE_INLINE inline
#endif
static FORCE_INLINE uint32_t rotl32 ( uint32_t x, int8_t r )
{
return (x << r) | (x >> (32 - r));
}
static FORCE_INLINE uint64_t rotl64 ( uint64_t x, int8_t r )
{
return (x << r) | (x >> (64 - r));
}
#define ROTL32(x,y) rotl32(x,y)
#define ROTL64(x,y) rotl64(x,y)
#define BIG_CONSTANT(x) (x##LLU)
//-----------------------------------------------------------------------------
// Block read - if your platform needs to do endian-swapping or can only
// handle aligned reads, do the conversion here
#define getblock(p, i) (p[i])
//-----------------------------------------------------------------------------
// Finalization mix - force all bits of a hash block to avalanche
static FORCE_INLINE uint32_t fmix32 ( uint32_t h )
{
h ^= h >> 16;
h *= 0x85ebca6b;
h ^= h >> 13;
h *= 0xc2b2ae35;
h ^= h >> 16;
return h;
}
//----------
static FORCE_INLINE uint64_t fmix64 ( uint64_t k )
{
k ^= k >> 33;
k *= BIG_CONSTANT(0xff51afd7ed558ccd);
k ^= k >> 33;
k *= BIG_CONSTANT(0xc4ceb9fe1a85ec53);
k ^= k >> 33;
return k;
}
//-----------------------------------------------------------------------------
void MurmurHash3_x86_32 ( const void * key, int len,
uint32_t seed, void * out )
{
const uint8_t * data = (const uint8_t*)key;
const int nblocks = len / 4;
int i;
uint32_t h1 = seed;
uint32_t c1 = 0xcc9e2d51;
uint32_t c2 = 0x1b873593;
//----------
// body
const uint32_t * blocks = (const uint32_t *)(data + nblocks*4);
for(i = -nblocks; i; i++)
{
uint32_t k1 = getblock(blocks,i);
k1 *= c1;
k1 = ROTL32(k1,15);
k1 *= c2;
h1 ^= k1;
h1 = ROTL32(h1,13);
h1 = h1*5+0xe6546b64;
}
//----------
// tail
const uint8_t * tail = (const uint8_t*)(data + nblocks*4);
uint32_t k1 = 0;
switch(len & 3)
{
case 3: k1 ^= tail[2] << 16;
case 2: k1 ^= tail[1] << 8;
case 1: k1 ^= tail[0];
k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
};
//----------
// finalization
h1 ^= len;
h1 = fmix32(h1);
*(uint32_t*)out = h1;
}
//-----------------------------------------------------------------------------
void MurmurHash3_x86_128 ( const void * key, const int len,
uint32_t seed, void * out )
{
const uint8_t * data = (const uint8_t*)key;
const int nblocks = len / 16;
int i;
uint32_t h1 = seed;
uint32_t h2 = seed;
uint32_t h3 = seed;
uint32_t h4 = seed;
uint32_t c1 = 0x239b961b;
uint32_t c2 = 0xab0e9789;
uint32_t c3 = 0x38b34ae5;
uint32_t c4 = 0xa1e38b93;
//----------
// body
const uint32_t * blocks = (const uint32_t *)(data + nblocks*16);
for(i = -nblocks; i; i++)
{
uint32_t k1 = getblock(blocks,i*4+0);
uint32_t k2 = getblock(blocks,i*4+1);
uint32_t k3 = getblock(blocks,i*4+2);
uint32_t k4 = getblock(blocks,i*4+3);
k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
h1 = ROTL32(h1,19); h1 += h2; h1 = h1*5+0x561ccd1b;
k2 *= c2; k2 = ROTL32(k2,16); k2 *= c3; h2 ^= k2;
h2 = ROTL32(h2,17); h2 += h3; h2 = h2*5+0x0bcaa747;
k3 *= c3; k3 = ROTL32(k3,17); k3 *= c4; h3 ^= k3;
h3 = ROTL32(h3,15); h3 += h4; h3 = h3*5+0x96cd1c35;
k4 *= c4; k4 = ROTL32(k4,18); k4 *= c1; h4 ^= k4;
h4 = ROTL32(h4,13); h4 += h1; h4 = h4*5+0x32ac3b17;
}
//----------
// tail
const uint8_t * tail = (const uint8_t*)(data + nblocks*16);
uint32_t k1 = 0;
uint32_t k2 = 0;
uint32_t k3 = 0;
uint32_t k4 = 0;
switch(len & 15)
{
case 15: k4 ^= tail[14] << 16;
case 14: k4 ^= tail[13] << 8;
case 13: k4 ^= tail[12] << 0;
k4 *= c4; k4 = ROTL32(k4,18); k4 *= c1; h4 ^= k4;
case 12: k3 ^= tail[11] << 24;
case 11: k3 ^= tail[10] << 16;
case 10: k3 ^= tail[ 9] << 8;
case 9: k3 ^= tail[ 8] << 0;
k3 *= c3; k3 = ROTL32(k3,17); k3 *= c4; h3 ^= k3;
case 8: k2 ^= tail[ 7] << 24;
case 7: k2 ^= tail[ 6] << 16;
case 6: k2 ^= tail[ 5] << 8;
case 5: k2 ^= tail[ 4] << 0;
k2 *= c2; k2 = ROTL32(k2,16); k2 *= c3; h2 ^= k2;
case 4: k1 ^= tail[ 3] << 24;
case 3: k1 ^= tail[ 2] << 16;
case 2: k1 ^= tail[ 1] << 8;
case 1: k1 ^= tail[ 0] << 0;
k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
};
//----------
// finalization
h1 ^= len; h2 ^= len; h3 ^= len; h4 ^= len;
h1 += h2; h1 += h3; h1 += h4;
h2 += h1; h3 += h1; h4 += h1;
h1 = fmix32(h1);
h2 = fmix32(h2);
h3 = fmix32(h3);
h4 = fmix32(h4);
h1 += h2; h1 += h3; h1 += h4;
h2 += h1; h3 += h1; h4 += h1;
((uint32_t*)out)[0] = h1;
((uint32_t*)out)[1] = h2;
((uint32_t*)out)[2] = h3;
((uint32_t*)out)[3] = h4;
}
//-----------------------------------------------------------------------------
void MurmurHash3_x64_128 ( const void * key, const int len,
const uint32_t seed, void * out )
{
const uint8_t * data = (const uint8_t*)key;
const int nblocks = len / 16;
int i;
uint64_t h1 = seed;
uint64_t h2 = seed;
uint64_t c1 = BIG_CONSTANT(0x87c37b91114253d5);
uint64_t c2 = BIG_CONSTANT(0x4cf5ad432745937f);
//----------
// body
const uint64_t * blocks = (const uint64_t *)(data);
for(i = 0; i < nblocks; i++)
{
uint64_t k1 = getblock(blocks,i*2+0);
uint64_t k2 = getblock(blocks,i*2+1);
k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1;
h1 = ROTL64(h1,27); h1 += h2; h1 = h1*5+0x52dce729;
k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2;
h2 = ROTL64(h2,31); h2 += h1; h2 = h2*5+0x38495ab5;
}
//----------
// tail
const uint8_t * tail = (const uint8_t*)(data + nblocks*16);
uint64_t k1 = 0;
uint64_t k2 = 0;
switch(len & 15)
{
case 15: k2 ^= (uint64_t)(tail[14]) << 48;
case 14: k2 ^= (uint64_t)(tail[13]) << 40;
case 13: k2 ^= (uint64_t)(tail[12]) << 32;
case 12: k2 ^= (uint64_t)(tail[11]) << 24;
case 11: k2 ^= (uint64_t)(tail[10]) << 16;
case 10: k2 ^= (uint64_t)(tail[ 9]) << 8;
case 9: k2 ^= (uint64_t)(tail[ 8]) << 0;
k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2;
case 8: k1 ^= (uint64_t)(tail[ 7]) << 56;
case 7: k1 ^= (uint64_t)(tail[ 6]) << 48;
case 6: k1 ^= (uint64_t)(tail[ 5]) << 40;
case 5: k1 ^= (uint64_t)(tail[ 4]) << 32;
case 4: k1 ^= (uint64_t)(tail[ 3]) << 24;
case 3: k1 ^= (uint64_t)(tail[ 2]) << 16;
case 2: k1 ^= (uint64_t)(tail[ 1]) << 8;
case 1: k1 ^= (uint64_t)(tail[ 0]) << 0;
k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1;
};
//----------
// finalization
h1 ^= len; h2 ^= len;
h1 += h2;
h2 += h1;
h1 = fmix64(h1);
h2 = fmix64(h2);
h1 += h2;
h2 += h1;
((uint64_t*)out)[0] = h1;
((uint64_t*)out)[1] = h2;
}
//-----------------------------------------------------------------------------

View File

@ -0,0 +1,24 @@
#ifndef _MURMURHASH3_H_
#define _MURMURHASH3_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
//-----------------------------------------------------------------------------
void MurmurHash3_x86_32 (const void *key, int len, uint32_t seed, void *out);
void MurmurHash3_x86_128(const void *key, int len, uint32_t seed, void *out);
void MurmurHash3_x64_128(const void *key, int len, uint32_t seed, void *out);
//-----------------------------------------------------------------------------
#ifdef __cplusplus
}
#endif
#endif // _MURMURHASH3_H_