From 49c0d825023c69e9731a76bf8b4256dc27a1301d Mon Sep 17 00:00:00 2001 From: Kushal K S V S Date: Fri, 7 Jul 2017 02:21:59 +0530 Subject: Add make_bitmap folder --- README | 18 --- bitmap.c | 269 ------------------------------------------ bitmap.h | 85 -------------- example1.c | 98 ---------------- example2.c | 93 --------------- make_bitmap/README | 18 +++ make_bitmap/bitmap.c | 269 ++++++++++++++++++++++++++++++++++++++++++ make_bitmap/bitmap.h | 85 ++++++++++++++ make_bitmap/example1.c | 98 ++++++++++++++++ make_bitmap/example2.c | 93 +++++++++++++++ make_bitmap/murmur3.c | 312 +++++++++++++++++++++++++++++++++++++++++++++++++ make_bitmap/murmur3.h | 24 ++++ make_bitmap/runme.sh | 4 + murmur3.c | 312 ------------------------------------------------- murmur3.h | 24 ---- runme.sh | 4 - 16 files changed, 903 insertions(+), 903 deletions(-) delete mode 100644 README delete mode 100644 bitmap.c delete mode 100644 bitmap.h delete mode 100644 example1.c delete mode 100644 example2.c create mode 100644 make_bitmap/README create mode 100644 make_bitmap/bitmap.c create mode 100644 make_bitmap/bitmap.h create mode 100644 make_bitmap/example1.c create mode 100644 make_bitmap/example2.c create mode 100644 make_bitmap/murmur3.c create mode 100644 make_bitmap/murmur3.h create mode 100755 make_bitmap/runme.sh delete mode 100644 murmur3.c delete mode 100644 murmur3.h delete mode 100755 runme.sh diff --git a/README b/README deleted file mode 100644 index 98208b50a..000000000 --- a/README +++ /dev/null @@ -1,18 +0,0 @@ -Use the "new" folder. - - -To compile and execute - -gcc example1.c ksvsk.c murmur3.c -Wall -I /usr/local/include/freetype2/ -lfreetype -o example1 -./example1 - -gcc example2.c ksvsk.c murmur3.c -Wall -I /usr/local/include/freetype2/ -lfreetype -o example2 -./example2 - - -NOTE - --> DONOT use Get_Padding render MONO / GRAYSCALE bitmaps. - Use FT_Bitmap_Convert to make the width of bitmap a multiple of 4 bytes and then write it to file. - - diff --git a/bitmap.c b/bitmap.c deleted file mode 100644 index 4217c3c16..000000000 --- a/bitmap.c +++ /dev/null @@ -1,269 +0,0 @@ -#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; -} - -int Get_Padding( FT_Bitmap* bitmap ){ - - int rem; - if (bitmap->pixel_mode == 6) - { - rem = ( 3 * bitmap->width ) % 4; - }else{ - rem = ( bitmap->width ) % 4; - } - - if (!rem ) - { - return rem; - } - return (4 - rem); -} - -int Get_Bits_Per_Pixel ( unsigned char PIXEL_MODE) { - if (PIXEL_MODE < 5) - { - return BITS_PER_PIXEL_GRAY; - }else{ - return BITS_PER_PIXEL_LCD; - } -} - -void Write_Bitmap_Header (FT_Bitmap * bitmap ) { - - FILE *fp = fopen("test.bmp","w"); // Bitmap File - HEADER *header = ( HEADER* ) calloc( 1 , sizeof( HEADER )); - - unsigned char pixel_mode = ( bitmap->pixel_mode ); - FT_UInt image_width; - FT_UInt image_rows; - FT_UInt color_table_size = 0; - - switch(pixel_mode){ - - case 5 : image_width = bitmap->width / 3; // LCD - image_rows = bitmap->rows; - break; - - case 6 : image_width = bitmap->width; // LCD_V - image_rows = bitmap->rows / 3; - break; - - default : image_width = bitmap->width; // MONO and GRAY - image_rows = bitmap->rows; - color_table_size = 4* 256; - break; - } - - FT_Int image_size; - image_size = (image_rows * image_width ); - - header->file_header.type = 0x4D42; - header->file_header.file_size = sizeof(HEADER) + color_table_size + image_size; - header->file_header.file_offset = sizeof(HEADER) + color_table_size; - - header->info_header.info_header_size = sizeof(BMP_INFO_HEADER); - header->info_header.width = image_width ; - header->info_header.height = - image_rows; - header->info_header.planes = PLANES; - header->info_header.bits_per_pixel = Get_Bits_Per_Pixel( bitmap->pixel_mode ); - header->info_header.compression = COMPRESSION; - header->info_header.image_size = image_size; - header->info_header.y_pixels_per_meter = Y_PIXELS_PER_METER ; - header->info_header.x_pixels_per_meter = X_PIXELS_PER_METER ; - header->info_header.used_colors = USED_COLORS; - header->info_header.important_colors = IMPORTANT_COLORS; - - fwrite (header, 1, sizeof(HEADER),fp); - free(header); - fclose(fp); -} - -void Write_Bitmap_Data_LCD_RGB( FT_Bitmap * bitmap ){ - - char value; - int i,j,k; - - FILE *fp = fopen("test.bmp","a"); - - for (i = 0; i < bitmap->rows ; ++i) - { - for ( j = 2; j < bitmap->width; j = j+3) - { - for ( k = 0; k < 3; ++k) - { - value = 0xff - bitmap->buffer[( i * bitmap->pitch) + j - k]; - fwrite (&value, 1, 1,fp); - } - } - for ( k = 0; k < Get_Padding(bitmap); ++k) - { - value = 0xff; - fwrite (&value, 1, 1,fp); - } - } - - fclose(fp); -} - -void Write_Bitmap_Data_LCD_BGR( FT_Bitmap * bitmap ){ - - char value; - int i,j,k; - - FILE *fp = fopen("test.bmp","a"); - - for ( i = 0; i < bitmap->rows ; ++i) - { - for ( j = 0; j < bitmap->width; j++) - { - value = 0xff - bitmap->buffer[( i * bitmap->pitch) + j]; - fwrite (&value, 1, 1,fp); - } - for ( k = 0; k < Get_Padding(bitmap); ++k) - { - value = 0xff; - fwrite (&value, 1, 1,fp); - } - } - - fclose(fp); -} - -void Write_Bitmap_Data_LCD_V_BGR (FT_Bitmap * bitmap) { - - FILE *fp = fopen("test.bmp","a"); - - int i,j,k,step; - char value; - step = 0; - - while ( step < bitmap->rows ){ - - for (i = 0; i < bitmap->width; i++) - { - for (j = step ; j < step + 3; ++j) - { - value = 0xff - bitmap->buffer[(j * bitmap->pitch) + i]; - fwrite (&value, 1, 1,fp); - } - } - for (k = 0; k < Get_Padding(bitmap); ++k) - { - value = 0xff; - fwrite (&value, 1, 1,fp); - } - step = step + 3; // Jumping 3 rows up - } - - fclose(fp); -} - -void Write_Bitmap_Data_LCD_V_RGB (FT_Bitmap * bitmap) { - - FILE *fp = fopen("test.bmp","a"); - - int i,j,k,step; - char value; - step = 0; - - while ( step < bitmap->rows ){ - - for (i = 0; i < bitmap->width; i++) - { - for (j = step + 2 ; j >= step; --j) - { - value = 0xff - bitmap->buffer[(j * bitmap->pitch) + i]; - fwrite (&value, 1, 1,fp); - } - } - for (k = 0; k < Get_Padding(bitmap); ++k) - { - value = 0xff; - fwrite (&value, 1, 1,fp); - } - step = step + 3; // Jumping 3 rows up - } - - fclose(fp); -} - -void Write_Bitmap_Data_MONO (FT_Bitmap * bitmap) { - - FILE *fp = fopen("test.bmp","a"); - - int i; - unsigned char value; - for ( i = 0; i < 256; ++i) - { - value = i; - fwrite (&value,1,1,fp); - fwrite (&value,1,1,fp); - fwrite (&value,1,1,fp); - value = 0; - fwrite (&value,1,1,fp); - } - - - for (int i = 0; i < bitmap->pitch * bitmap->rows; ++i) - { - if ( bitmap->buffer[i] != 0x00 ){ - value = 0x00; // remember taking reverse - fwrite (&value, 1, 1,fp); - }else{ - value = 0xff; - fwrite (&value, 1, 1,fp); - } - } - - fclose(fp); -} - -void Write_Bitmap_Data_GRAY(FT_Bitmap * bitmap) { - - FILE *fp = fopen("test.bmp","a"); - int i; - - unsigned char value; - for ( i = 0; i < 256; ++i) - { - value = i; - fwrite (&value,1,1,fp); - fwrite (&value,1,1,fp); - fwrite (&value,1,1,fp); - value = 0; - fwrite (&value,1,1,fp); - } - - for (int i = 0; i < bitmap->pitch * bitmap->rows; ++i) - { - value = 255 - bitmap->buffer[i]; - fwrite(&value,1,1,fp); - } - - fclose(fp); -} \ No newline at end of file diff --git a/bitmap.h b/bitmap.h deleted file mode 100644 index f2e309bd5..000000000 --- a/bitmap.h +++ /dev/null @@ -1,85 +0,0 @@ -#include -#include -#include "murmur3.h" // MurmurHash3_x64_128 header file - -#include FT_FREETYPE_H -#include FT_MODULE_H -#include FT_LCD_FILTER_H -#include FT_BITMAP_H - -#define BITS_PER_PIXEL_MONO 1 // Constants for the Bitmap Header -#define BITS_PER_PIXEL_GRAY 8 -#define BITS_PER_PIXEL_LCD 24 - -#define PLANES 1 // Constants for the Bitmap Header -#define COMPRESSION 0 -#define X_PIXELS_PER_METER 0 -#define Y_PIXELS_PER_METER 0 -#define USED_COLORS 0 -#define IMPORTANT_COLORS 0 -//------------------------------------------------------------------------------- -#pragma pack(push,1) - -typedef struct{ // Bitmap FILE Header - - FT_UInt16 type; - FT_UInt32 file_size; - FT_UInt32 reserved; - FT_UInt32 file_offset; - -} BMP_FILE_HEADER; - -typedef struct{ // Bitmap INFO Header - - FT_UInt32 info_header_size; - FT_UInt32 width; - FT_Int height; - FT_UInt16 planes; - FT_UInt16 bits_per_pixel; - FT_UInt32 compression; - FT_UInt32 image_size; - FT_UInt32 y_pixels_per_meter; - FT_UInt32 x_pixels_per_meter; - FT_UInt32 used_colors; - FT_UInt32 important_colors; - -} BMP_INFO_HEADER; - -typedef struct { // Bitmap Header - - BMP_FILE_HEADER file_header; - BMP_INFO_HEADER info_header; - -} HEADER; - -//------------------------------------------------------------------------------ -typedef struct { // To store 32bit Hash - FT_UInt32 hash[1]; -}HASH_32; - -typedef struct { // To store 128bit Hash - FT_UInt32 hash[4]; -}HASH_128; - -#pragma pack(pop) - -//------------------------------------------------------------------------------- - -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 Get_Padding (FT_Bitmap * bitmap); - -int Get_Bits_Per_Pixel ( unsigned char PIXEL_MODE ); - -void Write_Bitmap_Header (FT_Bitmap * bitmap ); - -void Write_Bitmap_Data_MONO (FT_Bitmap * bitmap); -void Write_Bitmap_Data_GRAY (FT_Bitmap * bitmap); -void Write_Bitmap_Data_LCD_BGR (FT_Bitmap * bitmap); -void Write_Bitmap_Data_LCD_RGB (FT_Bitmap * bitmap); -void Write_Bitmap_Data_LCD_V_RGB (FT_Bitmap * bitmap); -void Write_Bitmap_Data_LCD_V_BGR (FT_Bitmap * bitmap); diff --git a/example1.c b/example1.c deleted file mode 100644 index 9bc61216d..000000000 --- a/example1.c +++ /dev/null @@ -1,98 +0,0 @@ -// This example uses the FreeType rendering library to produce -// LCD rendered bitmap (RGB) for the glyphs of a font -// Also gives the MurmurHash3 hash value of the bitmap rendered. - -#include "bitmap.h" - -int main(int argc, char const *argv[]) -{ - FT_Library library; - FT_Face face; - FT_GlyphSlot slot; - FT_Bitmap* bitmap; - FT_Error error; - - const char* font_file; // Arguments - FT_UInt32 size; - FT_UInt glyph_index; - const char* character; - - if (argc != 4) - { - printf("\nTo render a RGB bitmap of a glyph to be displayed on an \n"); - printf("LCD surface and to generate the 128bit MurmurHash3 hash \n\n"); - - printf("Filter used is FT_LCD_FILTER_DEFAULT\n\n"); - - printf("Usage ./ \n\n"); - - exit(0); - } - - font_file = argv[1]; - size = atoi(argv[2]); - character = argv[3]; - - error = FT_Init_FreeType( &library ); - if(error){ - printf("Error while initialising library\n"); - } - - error = FT_Library_SetLcdFilter( library, - FT_LCD_FILTER_DEFAULT ); - if(error){ - printf("Error while setting LCD filter\n"); - } - - error = FT_New_Face( library, - font_file, - 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"); - } - - glyph_index = FT_Get_Char_Index( face, *character ); - - slot = face->glyph; - - error = FT_Load_Glyph( face, - glyph_index, - FT_LOAD_NO_BITMAP | FT_LOAD_TARGET_LCD ); - if(error){ - printf("Error loading glyph\n"); - } - - FT_Render_Glyph( slot, - FT_RENDER_MODE_LCD); - if(error){ - printf("Error rendering the glyph\n"); - } - - bitmap = &slot->bitmap; - - Write_Bitmap_Header(bitmap); - Write_Bitmap_Data_LCD_RGB(bitmap); - - HASH_128 * murmur = (HASH_128 *) malloc(sizeof(HASH_128)) ; - murmur = Generate_Hash_x64_128(bitmap,murmur); // using the x64_128 function of the hash - - printf("%08x %08x %08x %08x\n", murmur->hash[0], // Print hash - murmur->hash[1], - murmur->hash[2], - murmur->hash[3]); - - FT_Done_Face ( face ); - FT_Done_FreeType( library ); - - return 0; -} \ No newline at end of file diff --git a/example2.c b/example2.c deleted file mode 100644 index 4fa791075..000000000 --- a/example2.c +++ /dev/null @@ -1,93 +0,0 @@ -// 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 ./ \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; -} \ No newline at end of file diff --git a/make_bitmap/README b/make_bitmap/README new file mode 100644 index 000000000..98208b50a --- /dev/null +++ b/make_bitmap/README @@ -0,0 +1,18 @@ +Use the "new" folder. + + +To compile and execute + +gcc example1.c ksvsk.c murmur3.c -Wall -I /usr/local/include/freetype2/ -lfreetype -o example1 +./example1 + +gcc example2.c ksvsk.c murmur3.c -Wall -I /usr/local/include/freetype2/ -lfreetype -o example2 +./example2 + + +NOTE + +-> DONOT use Get_Padding render MONO / GRAYSCALE bitmaps. + Use FT_Bitmap_Convert to make the width of bitmap a multiple of 4 bytes and then write it to file. + + diff --git a/make_bitmap/bitmap.c b/make_bitmap/bitmap.c new file mode 100644 index 000000000..4217c3c16 --- /dev/null +++ b/make_bitmap/bitmap.c @@ -0,0 +1,269 @@ +#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; +} + +int Get_Padding( FT_Bitmap* bitmap ){ + + int rem; + if (bitmap->pixel_mode == 6) + { + rem = ( 3 * bitmap->width ) % 4; + }else{ + rem = ( bitmap->width ) % 4; + } + + if (!rem ) + { + return rem; + } + return (4 - rem); +} + +int Get_Bits_Per_Pixel ( unsigned char PIXEL_MODE) { + if (PIXEL_MODE < 5) + { + return BITS_PER_PIXEL_GRAY; + }else{ + return BITS_PER_PIXEL_LCD; + } +} + +void Write_Bitmap_Header (FT_Bitmap * bitmap ) { + + FILE *fp = fopen("test.bmp","w"); // Bitmap File + HEADER *header = ( HEADER* ) calloc( 1 , sizeof( HEADER )); + + unsigned char pixel_mode = ( bitmap->pixel_mode ); + FT_UInt image_width; + FT_UInt image_rows; + FT_UInt color_table_size = 0; + + switch(pixel_mode){ + + case 5 : image_width = bitmap->width / 3; // LCD + image_rows = bitmap->rows; + break; + + case 6 : image_width = bitmap->width; // LCD_V + image_rows = bitmap->rows / 3; + break; + + default : image_width = bitmap->width; // MONO and GRAY + image_rows = bitmap->rows; + color_table_size = 4* 256; + break; + } + + FT_Int image_size; + image_size = (image_rows * image_width ); + + header->file_header.type = 0x4D42; + header->file_header.file_size = sizeof(HEADER) + color_table_size + image_size; + header->file_header.file_offset = sizeof(HEADER) + color_table_size; + + header->info_header.info_header_size = sizeof(BMP_INFO_HEADER); + header->info_header.width = image_width ; + header->info_header.height = - image_rows; + header->info_header.planes = PLANES; + header->info_header.bits_per_pixel = Get_Bits_Per_Pixel( bitmap->pixel_mode ); + header->info_header.compression = COMPRESSION; + header->info_header.image_size = image_size; + header->info_header.y_pixels_per_meter = Y_PIXELS_PER_METER ; + header->info_header.x_pixels_per_meter = X_PIXELS_PER_METER ; + header->info_header.used_colors = USED_COLORS; + header->info_header.important_colors = IMPORTANT_COLORS; + + fwrite (header, 1, sizeof(HEADER),fp); + free(header); + fclose(fp); +} + +void Write_Bitmap_Data_LCD_RGB( FT_Bitmap * bitmap ){ + + char value; + int i,j,k; + + FILE *fp = fopen("test.bmp","a"); + + for (i = 0; i < bitmap->rows ; ++i) + { + for ( j = 2; j < bitmap->width; j = j+3) + { + for ( k = 0; k < 3; ++k) + { + value = 0xff - bitmap->buffer[( i * bitmap->pitch) + j - k]; + fwrite (&value, 1, 1,fp); + } + } + for ( k = 0; k < Get_Padding(bitmap); ++k) + { + value = 0xff; + fwrite (&value, 1, 1,fp); + } + } + + fclose(fp); +} + +void Write_Bitmap_Data_LCD_BGR( FT_Bitmap * bitmap ){ + + char value; + int i,j,k; + + FILE *fp = fopen("test.bmp","a"); + + for ( i = 0; i < bitmap->rows ; ++i) + { + for ( j = 0; j < bitmap->width; j++) + { + value = 0xff - bitmap->buffer[( i * bitmap->pitch) + j]; + fwrite (&value, 1, 1,fp); + } + for ( k = 0; k < Get_Padding(bitmap); ++k) + { + value = 0xff; + fwrite (&value, 1, 1,fp); + } + } + + fclose(fp); +} + +void Write_Bitmap_Data_LCD_V_BGR (FT_Bitmap * bitmap) { + + FILE *fp = fopen("test.bmp","a"); + + int i,j,k,step; + char value; + step = 0; + + while ( step < bitmap->rows ){ + + for (i = 0; i < bitmap->width; i++) + { + for (j = step ; j < step + 3; ++j) + { + value = 0xff - bitmap->buffer[(j * bitmap->pitch) + i]; + fwrite (&value, 1, 1,fp); + } + } + for (k = 0; k < Get_Padding(bitmap); ++k) + { + value = 0xff; + fwrite (&value, 1, 1,fp); + } + step = step + 3; // Jumping 3 rows up + } + + fclose(fp); +} + +void Write_Bitmap_Data_LCD_V_RGB (FT_Bitmap * bitmap) { + + FILE *fp = fopen("test.bmp","a"); + + int i,j,k,step; + char value; + step = 0; + + while ( step < bitmap->rows ){ + + for (i = 0; i < bitmap->width; i++) + { + for (j = step + 2 ; j >= step; --j) + { + value = 0xff - bitmap->buffer[(j * bitmap->pitch) + i]; + fwrite (&value, 1, 1,fp); + } + } + for (k = 0; k < Get_Padding(bitmap); ++k) + { + value = 0xff; + fwrite (&value, 1, 1,fp); + } + step = step + 3; // Jumping 3 rows up + } + + fclose(fp); +} + +void Write_Bitmap_Data_MONO (FT_Bitmap * bitmap) { + + FILE *fp = fopen("test.bmp","a"); + + int i; + unsigned char value; + for ( i = 0; i < 256; ++i) + { + value = i; + fwrite (&value,1,1,fp); + fwrite (&value,1,1,fp); + fwrite (&value,1,1,fp); + value = 0; + fwrite (&value,1,1,fp); + } + + + for (int i = 0; i < bitmap->pitch * bitmap->rows; ++i) + { + if ( bitmap->buffer[i] != 0x00 ){ + value = 0x00; // remember taking reverse + fwrite (&value, 1, 1,fp); + }else{ + value = 0xff; + fwrite (&value, 1, 1,fp); + } + } + + fclose(fp); +} + +void Write_Bitmap_Data_GRAY(FT_Bitmap * bitmap) { + + FILE *fp = fopen("test.bmp","a"); + int i; + + unsigned char value; + for ( i = 0; i < 256; ++i) + { + value = i; + fwrite (&value,1,1,fp); + fwrite (&value,1,1,fp); + fwrite (&value,1,1,fp); + value = 0; + fwrite (&value,1,1,fp); + } + + for (int i = 0; i < bitmap->pitch * bitmap->rows; ++i) + { + value = 255 - bitmap->buffer[i]; + fwrite(&value,1,1,fp); + } + + fclose(fp); +} \ No newline at end of file diff --git a/make_bitmap/bitmap.h b/make_bitmap/bitmap.h new file mode 100644 index 000000000..f2e309bd5 --- /dev/null +++ b/make_bitmap/bitmap.h @@ -0,0 +1,85 @@ +#include +#include +#include "murmur3.h" // MurmurHash3_x64_128 header file + +#include FT_FREETYPE_H +#include FT_MODULE_H +#include FT_LCD_FILTER_H +#include FT_BITMAP_H + +#define BITS_PER_PIXEL_MONO 1 // Constants for the Bitmap Header +#define BITS_PER_PIXEL_GRAY 8 +#define BITS_PER_PIXEL_LCD 24 + +#define PLANES 1 // Constants for the Bitmap Header +#define COMPRESSION 0 +#define X_PIXELS_PER_METER 0 +#define Y_PIXELS_PER_METER 0 +#define USED_COLORS 0 +#define IMPORTANT_COLORS 0 +//------------------------------------------------------------------------------- +#pragma pack(push,1) + +typedef struct{ // Bitmap FILE Header + + FT_UInt16 type; + FT_UInt32 file_size; + FT_UInt32 reserved; + FT_UInt32 file_offset; + +} BMP_FILE_HEADER; + +typedef struct{ // Bitmap INFO Header + + FT_UInt32 info_header_size; + FT_UInt32 width; + FT_Int height; + FT_UInt16 planes; + FT_UInt16 bits_per_pixel; + FT_UInt32 compression; + FT_UInt32 image_size; + FT_UInt32 y_pixels_per_meter; + FT_UInt32 x_pixels_per_meter; + FT_UInt32 used_colors; + FT_UInt32 important_colors; + +} BMP_INFO_HEADER; + +typedef struct { // Bitmap Header + + BMP_FILE_HEADER file_header; + BMP_INFO_HEADER info_header; + +} HEADER; + +//------------------------------------------------------------------------------ +typedef struct { // To store 32bit Hash + FT_UInt32 hash[1]; +}HASH_32; + +typedef struct { // To store 128bit Hash + FT_UInt32 hash[4]; +}HASH_128; + +#pragma pack(pop) + +//------------------------------------------------------------------------------- + +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 Get_Padding (FT_Bitmap * bitmap); + +int Get_Bits_Per_Pixel ( unsigned char PIXEL_MODE ); + +void Write_Bitmap_Header (FT_Bitmap * bitmap ); + +void Write_Bitmap_Data_MONO (FT_Bitmap * bitmap); +void Write_Bitmap_Data_GRAY (FT_Bitmap * bitmap); +void Write_Bitmap_Data_LCD_BGR (FT_Bitmap * bitmap); +void Write_Bitmap_Data_LCD_RGB (FT_Bitmap * bitmap); +void Write_Bitmap_Data_LCD_V_RGB (FT_Bitmap * bitmap); +void Write_Bitmap_Data_LCD_V_BGR (FT_Bitmap * bitmap); diff --git a/make_bitmap/example1.c b/make_bitmap/example1.c new file mode 100644 index 000000000..9bc61216d --- /dev/null +++ b/make_bitmap/example1.c @@ -0,0 +1,98 @@ +// This example uses the FreeType rendering library to produce +// LCD rendered bitmap (RGB) for the glyphs of a font +// Also gives the MurmurHash3 hash value of the bitmap rendered. + +#include "bitmap.h" + +int main(int argc, char const *argv[]) +{ + FT_Library library; + FT_Face face; + FT_GlyphSlot slot; + FT_Bitmap* bitmap; + FT_Error error; + + const char* font_file; // Arguments + FT_UInt32 size; + FT_UInt glyph_index; + const char* character; + + if (argc != 4) + { + printf("\nTo render a RGB bitmap of a glyph to be displayed on an \n"); + printf("LCD surface and to generate the 128bit MurmurHash3 hash \n\n"); + + printf("Filter used is FT_LCD_FILTER_DEFAULT\n\n"); + + printf("Usage ./ \n\n"); + + exit(0); + } + + font_file = argv[1]; + size = atoi(argv[2]); + character = argv[3]; + + error = FT_Init_FreeType( &library ); + if(error){ + printf("Error while initialising library\n"); + } + + error = FT_Library_SetLcdFilter( library, + FT_LCD_FILTER_DEFAULT ); + if(error){ + printf("Error while setting LCD filter\n"); + } + + error = FT_New_Face( library, + font_file, + 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"); + } + + glyph_index = FT_Get_Char_Index( face, *character ); + + slot = face->glyph; + + error = FT_Load_Glyph( face, + glyph_index, + FT_LOAD_NO_BITMAP | FT_LOAD_TARGET_LCD ); + if(error){ + printf("Error loading glyph\n"); + } + + FT_Render_Glyph( slot, + FT_RENDER_MODE_LCD); + if(error){ + printf("Error rendering the glyph\n"); + } + + bitmap = &slot->bitmap; + + Write_Bitmap_Header(bitmap); + Write_Bitmap_Data_LCD_RGB(bitmap); + + HASH_128 * murmur = (HASH_128 *) malloc(sizeof(HASH_128)) ; + murmur = Generate_Hash_x64_128(bitmap,murmur); // using the x64_128 function of the hash + + printf("%08x %08x %08x %08x\n", murmur->hash[0], // Print hash + murmur->hash[1], + murmur->hash[2], + murmur->hash[3]); + + FT_Done_Face ( face ); + FT_Done_FreeType( library ); + + return 0; +} \ No newline at end of file diff --git a/make_bitmap/example2.c b/make_bitmap/example2.c new file mode 100644 index 000000000..4fa791075 --- /dev/null +++ b/make_bitmap/example2.c @@ -0,0 +1,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 ./ \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; +} \ No newline at end of file diff --git a/make_bitmap/murmur3.c b/make_bitmap/murmur3.c new file mode 100644 index 000000000..484ebfd03 --- /dev/null +++ b/make_bitmap/murmur3.c @@ -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; +} + +//----------------------------------------------------------------------------- + diff --git a/make_bitmap/murmur3.h b/make_bitmap/murmur3.h new file mode 100644 index 000000000..90878b00d --- /dev/null +++ b/make_bitmap/murmur3.h @@ -0,0 +1,24 @@ +#ifndef _MURMURHASH3_H_ +#define _MURMURHASH3_H_ + +#include + +#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_ diff --git a/make_bitmap/runme.sh b/make_bitmap/runme.sh new file mode 100755 index 000000000..4243ea5d7 --- /dev/null +++ b/make_bitmap/runme.sh @@ -0,0 +1,4 @@ +#!/bin/bash +gcc example1.c bitmap.c murmur3.c -Wall -I /usr/local/include/freetype2/ -lfreetype -o example1 +gcc example2.c bitmap.c murmur3.c -Wall -I /usr/local/include/freetype2/ -lfreetype -o example2 + diff --git a/murmur3.c b/murmur3.c deleted file mode 100644 index 484ebfd03..000000000 --- a/murmur3.c +++ /dev/null @@ -1,312 +0,0 @@ -//----------------------------------------------------------------------------- -// 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; -} - -//----------------------------------------------------------------------------- - diff --git a/murmur3.h b/murmur3.h deleted file mode 100644 index 90878b00d..000000000 --- a/murmur3.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _MURMURHASH3_H_ -#define _MURMURHASH3_H_ - -#include - -#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_ diff --git a/runme.sh b/runme.sh deleted file mode 100755 index 4243ea5d7..000000000 --- a/runme.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -gcc example1.c bitmap.c murmur3.c -Wall -I /usr/local/include/freetype2/ -lfreetype -o example1 -gcc example2.c bitmap.c murmur3.c -Wall -I /usr/local/include/freetype2/ -lfreetype -o example2 - -- cgit v1.2.1