From aa15682fd811bb4620f8079d65e646e22461f53f Mon Sep 17 00:00:00 2001 From: Kushal K S V S Date: Mon, 17 Jul 2017 22:53:10 +0530 Subject: [PATCH] To display Hashes --- tests/make_png/README | 2 +- tests/make_png/bitmap.c | 56 ++++++++++++++++++++++++++---------- tests/make_png/bitmap.h | 9 ++++-- tests/make_png/make_sprite.c | 11 ++++--- tests/make_png/style.css | 3 ++ 5 files changed, 56 insertions(+), 25 deletions(-) diff --git a/tests/make_png/README b/tests/make_png/README index 15dae26d9..d2acfb764 100644 --- a/tests/make_png/README +++ b/tests/make_png/README @@ -5,7 +5,7 @@ NOTE: First make freetype library (in the ../../ directory) TODO: Generate HTML page (testing going on) /*******************************************************************/ - +(DEPRECATED) To generate hashes and store it in the ./hashes folder, 1) make hash diff --git a/tests/make_png/bitmap.c b/tests/make_png/bitmap.c index 7cf5eb4ac..8284eba8c 100644 --- a/tests/make_png/bitmap.c +++ b/tests/make_png/bitmap.c @@ -34,7 +34,7 @@ HASH_32 * Generate_Hash_x86_32( FT_Bitmap * bitmap, MurmurHash3_x86_32( bitmap->buffer, (bitmap->pitch * bitmap->rows), seed, - murmur->hash); + &murmur->hash); return murmur; } @@ -97,8 +97,8 @@ int Generate_PNG (IMAGE *bitmap, for (y = 0; y < bitmap->height; y++) { - png_byte *row = png_malloc (png_ptr, - sizeof (uint8_t) * bitmap->width * pixel_size); + 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++) { @@ -161,7 +161,7 @@ void Make_PNG(FT_Bitmap* bitmap,IMAGE* fruit,int i,int render_mode){ switch(render_mode){ - case 0 : fruit->width = bitmap->width; // MONO and GRAY + case 0 : fruit->width = bitmap->width; // MONO and GRAY fruit->height = bitmap->rows; fruit->pixels = calloc ( fruit->width * fruit->height, @@ -281,7 +281,10 @@ void Read_PNG(char *filename, IMAGE * after_effect) { FILE *fp = fopen(filename, "rb"); - png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + 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); @@ -308,7 +311,8 @@ void Read_PNG(char *filename, IMAGE * after_effect) { png_read_image(png, row_pointers); - after_effect->pixels = (PIXEL*)malloc(width * height * sizeof(PIXEL)); + after_effect->pixels = + (PIXEL*) malloc( width * height * sizeof(PIXEL)); for(int y = 0; y < height; y++) { @@ -337,7 +341,8 @@ IMAGE* Adjust_Height(IMAGE* small, IMAGE* big){ result->height = big->height; result->width = small->width; - result->pixels = (PIXEL*)malloc(result->width * result->height * sizeof(PIXEL)); + result->pixels = + (PIXEL*) malloc(result->width * result->height * sizeof(PIXEL)); h_delta = big->height - small->height; @@ -376,7 +381,8 @@ IMAGE* Adjust_Width(IMAGE* small, IMAGE* big){ result->height = small->height; result->width = big->width; - result->pixels = (PIXEL*)malloc(result->width * result->height * sizeof(PIXEL)); + result->pixels = + (PIXEL*) malloc(result->width * result->height * sizeof(PIXEL)); for (int x = small->width; x < big->width; ++x) { @@ -413,7 +419,8 @@ int Add_effect(IMAGE* base, IMAGE* test, IMAGE* out, int Effect_ID) out->width = base->width; out->height = base->height; - out->pixels = (PIXEL*)malloc(base->width * base->height * sizeof(PIXEL)); + 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++ ) { @@ -470,9 +477,10 @@ int Add_effect(IMAGE* base, IMAGE* test, IMAGE* out, int Effect_ID) void Stitch(IMAGE* left, IMAGE* right, IMAGE* result){ result->width = left->width + right->width; - result->height = MAX(left->height, right->height); // Horizontal clipping + result->height = MAX(left->height, right->height); - result->pixels = (PIXEL*)calloc(result->width * result->height, sizeof(PIXEL)); + result->pixels = + (PIXEL*)calloc(result->width * result->height, sizeof(PIXEL)); for (int y = 0; y < left->height; ++y) { @@ -503,14 +511,32 @@ void Stitch(IMAGE* left, IMAGE* right, IMAGE* result){ } } -void Print_Row( FILE* fp, int index, char* name, int diff){ - fprintf(fp, +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, "\n\ %04d\n\ %s\n\ %04d\n\ + %08x%08x%08x%08x
%08x%08x%08x%08x\n\ \n\ - To-be-displayed\n\ - \n", index, name, diff, index); + \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); } diff --git a/tests/make_png/bitmap.h b/tests/make_png/bitmap.h index 2f2fcb585..d009a689e 100644 --- a/tests/make_png/bitmap.h +++ b/tests/make_png/bitmap.h @@ -23,11 +23,11 @@ #define MAX(a, b) ((a) > (b) ? (a) : (b)) typedef struct { // To store 32bit Hash - char hash[4]; + FT_UInt32 hash; }HASH_32; typedef struct { // To store 128bit Hash - char hash[16]; + FT_UInt32 hash[4]; }HASH_128; typedef struct { @@ -58,6 +58,8 @@ 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 @@ -80,4 +82,5 @@ IMAGE* Adjust_Height(IMAGE* small, IMAGE* big ); // Make the Width of both the PNG(s) same by filling with white pixels IMAGE* Adjust_Width(IMAGE* small, IMAGE* big ); // Print Row in a HTML file -void Print_Row( FILE* fp, int index, char* name, int diff); +void Print_Row( FILE* fp, int index, char* name, int diff, + HASH_128* hash_b, HASH_128* hash_t); diff --git a/tests/make_png/make_sprite.c b/tests/make_png/make_sprite.c index 141dec0e0..5a9a27b82 100644 --- a/tests/make_png/make_sprite.c +++ b/tests/make_png/make_sprite.c @@ -339,10 +339,10 @@ int main(int argc, char const *argv[]) Difference\n\ \n\ \n\ - Images\n\ + 128-bit Hash-values\n\ \n\ \n\ - Hash-Values\n\ + Images\n\ \n\ \n\ \n\ @@ -391,12 +391,10 @@ int main(int argc, char const *argv[]) continue; } - Is_Different = 0; - base_murmur = Generate_Hash_x64_128(base_bitmap,base_murmur); test_murmur = Generate_Hash_x64_128(test_bitmap,test_murmur); - Is_Different = strcmp(base_murmur->hash, test_murmur->hash); + Is_Different = Compare_Hash(base_murmur, test_murmur); Base_Bitmap_Init( &base_target ); Test_Bitmap_Init( &test_target ); @@ -468,7 +466,8 @@ int main(int argc, char const *argv[]) 50 ); } - Print_Row(fp,i,glyph_name,pixel_diff); + Print_Row(fp,i,glyph_name,pixel_diff, base_murmur, + test_murmur ); } } diff --git a/tests/make_png/style.css b/tests/make_png/style.css index 64a3e4a00..25cecbe20 100644 --- a/tests/make_png/style.css +++ b/tests/make_png/style.css @@ -31,4 +31,7 @@ td { th { background-color: #C8C8C8; cursor: pointer; +} +#hash{ + font-size: 12px; } \ No newline at end of file