MAking code compatible with C89

This commit is contained in:
Kushal K S V S 2017-07-31 23:59:43 -07:00
parent a5755f0842
commit 6277cc4600
5 changed files with 121 additions and 114 deletions

View File

@ -3,7 +3,7 @@
HASH_128 * Generate_Hash_x64_128( FT_Bitmap * bitmap,
HASH_128 * murmur)
{
int seed = 99; // Dont change
int seed = 99; /* Dont change */
MurmurHash3_x64_128(bitmap->buffer,
(bitmap->pitch * bitmap->rows),
@ -16,7 +16,7 @@ HASH_128 * Generate_Hash_x64_128( FT_Bitmap * bitmap,
HASH_128 * Generate_Hash_x86_128( FT_Bitmap * bitmap,
HASH_128 * murmur)
{
int seed = 99; // Dont change
int seed = 99; /* Dont change */
MurmurHash3_x86_128(bitmap->buffer,
(bitmap->pitch * bitmap->rows),
@ -29,7 +29,7 @@ HASH_128 * Generate_Hash_x86_128( FT_Bitmap * bitmap,
HASH_32 * Generate_Hash_x86_32( FT_Bitmap * bitmap,
HASH_32 * murmur)
{
int seed = 99; // Dont change
int seed = 99; /* Dont change */
MurmurHash3_x86_32( bitmap->buffer,
(bitmap->pitch * bitmap->rows),
@ -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,
@ -188,7 +188,7 @@ void Make_PNG(FT_Bitmap* bitmap,IMAGE* fruit,int i,int render_mode){
}
}
break;
case 1 : fruit->width = bitmap->width; // MONO and GRAY
case 1 : fruit->width = bitmap->width; /* MONO and GRAY */
fruit->height = bitmap->rows;
fruit->pixels = calloc ( fruit->width * fruit->height,
@ -211,7 +211,7 @@ void Make_PNG(FT_Bitmap* bitmap,IMAGE* fruit,int i,int render_mode){
break;
case 2 :
case 3 : fruit->width = bitmap->width / 3; // LCD
case 3 : fruit->width = bitmap->width / 3; /* LCD */
fruit->height = bitmap->rows;
fruit->pixels = calloc ( fruit->width * fruit->height,
@ -240,7 +240,7 @@ void Make_PNG(FT_Bitmap* bitmap,IMAGE* fruit,int i,int render_mode){
break;
case 4 :
case 5 : fruit->width = bitmap->width; // LCD_V
case 5 : fruit->width = bitmap->width; /* LCD_V */
fruit->height = bitmap->rows / 3;
fruit->pixels = calloc ( fruit->width * fruit->height,
@ -276,7 +276,7 @@ void Make_PNG(FT_Bitmap* bitmap,IMAGE* fruit,int i,int render_mode){
void Read_PNG(char *filename, IMAGE * after_effect) {
int width, height;
int width, height, x, y;
png_bytep *row_pointers;
FILE *fp = fopen(filename, "rb");
@ -305,7 +305,7 @@ void Read_PNG(char *filename, IMAGE * after_effect) {
after_effect->height = height;
row_pointers = (png_bytep*)malloc(sizeof(png_bytep) * height);
for(int y = 0; y < height; y++) {
for( y = 0; y < height; y++) {
row_pointers[y] = (png_byte*)malloc(png_get_rowbytes(png,info));
}
@ -314,11 +314,11 @@ void Read_PNG(char *filename, IMAGE * after_effect) {
after_effect->pixels =
(PIXEL*) malloc( width * height * sizeof(PIXEL));
for(int y = 0; y < height; y++) {
for( y = 0; y < height; y++) {
png_bytep row = row_pointers[y];
for(int x = 0; x < width; x++ ) {
for( x = 0; x < width; x++ ) {
png_bytep px = &(row[x * 4]);
@ -337,14 +337,15 @@ void Read_PNG(char *filename, IMAGE * after_effect) {
int Add_effect(IMAGE* base, IMAGE* test, IMAGE* out, int Effect_ID)
{
int pixel_diff = 0;
int x,y;
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++ ) {
for( y = 0; y < base->height; y++) {
for( x = 0; x < base->width; x++ ) {
PIXEL * pixel_base = Pixel_At ( base, x, y);
PIXEL * pixel_test = Pixel_At ( test, x, y);
@ -397,15 +398,17 @@ int Add_effect(IMAGE* base, IMAGE* test, IMAGE* out, int Effect_ID)
void Stitch(IMAGE* left, IMAGE* right, IMAGE* result){
int x, y;
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 ( y = 0; y < left->height; ++y)
{
for (int x = 0; x < left->width; ++x)
for ( x = 0; x < left->width; ++x)
{
PIXEL * pixel_left = Pixel_At ( left, x, y);
PIXEL * pixel_result = Pixel_At ( result, x, y);
@ -417,9 +420,9 @@ void Stitch(IMAGE* left, IMAGE* right, IMAGE* result){
}
}
for (int y = 0; y < right->height; ++y)
for ( y = 0; y < right->height; ++y)
{
for (int x = left->width; x < result->width; ++x)
for ( 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);
@ -464,9 +467,11 @@ void Print_Row( FILE* fp, int index, char* name, int diff,
int First_Column(IMAGE* input){
for (int x = 0; x < input->width; ++x)
int x, y;
for ( x = 0; x < input->width; ++x)
{
for (int y = 0; y < input->height; ++y)
for ( y = 0; y < input->height; ++y)
{
PIXEL * pixel_result = Pixel_At ( input, x, y);
@ -486,9 +491,11 @@ int First_Column(IMAGE* input){
int First_Row(IMAGE* input){
for (int y = 0; y < input->height; ++y)
int x, y;
for ( y = 0; y < input->height; ++y)
{
for (int x = 0; x < input->width; ++x)
for ( x = 0; x < input->width; ++x)
{
PIXEL * pixel_result = Pixel_At ( input, x, y);
@ -508,6 +515,8 @@ int First_Row(IMAGE* input){
IMAGE* Append_Columns(IMAGE* small, IMAGE* big){
int x, y;
IMAGE* result = (IMAGE*)malloc(sizeof(IMAGE));
result->height = small->height;
@ -517,9 +526,9 @@ IMAGE* Append_Columns(IMAGE* small, IMAGE* big){
int first_col = First_Column(big);
for (int x = 0; x < first_col; ++x)
for ( x = 0; x < first_col; ++x)
{
for (int y = 0; y < result->height; ++y)
for ( y = 0; y < result->height; ++y)
{
PIXEL * pixel_result = Pixel_At ( result, x, y);
@ -530,9 +539,9 @@ IMAGE* Append_Columns(IMAGE* small, IMAGE* big){
}
}
for (int y = 0; y < result->height; ++y)
for ( y = 0; y < result->height; ++y)
{
for (int x = first_col; x < first_col + small->width; ++x)
for ( 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);
@ -544,9 +553,9 @@ IMAGE* Append_Columns(IMAGE* small, IMAGE* big){
}
}
for (int x = first_col + small->width; x < result->width; ++x)
for ( x = first_col + small->width; x < result->width; ++x)
{
for (int y = 0; y < result->height; ++y)
for ( y = 0; y < result->height; ++y)
{
PIXEL * pixel_result = Pixel_At ( result, x, y);
@ -562,6 +571,8 @@ IMAGE* Append_Columns(IMAGE* small, IMAGE* big){
IMAGE* Append_Rows(IMAGE* small, IMAGE* big){
int x, y;
IMAGE* result = (IMAGE*)malloc(sizeof(IMAGE));
result->height = big->height;
@ -571,9 +582,9 @@ IMAGE* Append_Rows(IMAGE* small, IMAGE* big){
int first_row = First_Row(big);
for (int y = 0; y < first_row; ++y)
for ( y = 0; y < first_row; ++y)
{
for (int x = 0; x < result->width; ++x)
for ( x = 0; x < result->width; ++x)
{
PIXEL * pixel_result = Pixel_At ( result, x, y);
@ -584,9 +595,9 @@ IMAGE* Append_Rows(IMAGE* small, IMAGE* big){
}
}
for (int y = first_row; y < first_row + small->height; ++y)
for ( y = first_row; y < first_row + small->height; ++y)
{
for (int x = 0; x < result->width; ++x)
for ( x = 0; x < result->width; ++x)
{
PIXEL * pixel_small = Pixel_At ( small, x, y - first_row);
PIXEL * pixel_result = Pixel_At ( result, x, y);
@ -598,9 +609,9 @@ IMAGE* Append_Rows(IMAGE* small, IMAGE* big){
}
}
for (int y = first_row + small->height; y < result->height; ++y)
for ( y = first_row + small->height; y < result->height; ++y)
{
for (int x = 0; x < result->width; ++x)
for ( x = 0; x < result->width; ++x)
{
PIXEL * pixel_result = Pixel_At ( result, x, y);

View File

@ -8,7 +8,7 @@
#include <ft2build.h>
#include "murmur3.h" // MurmurHash3_x64_128 header file
#include "murmur3.h" /* MurmurHash3_x64_128 header file */
#include <png.h>
#include <dlfcn.h>
@ -22,11 +22,11 @@
#define BITS_PER_PIXEL_RGBA 32
#define MAX(a, b) ((a) > (b) ? (a) : (b))
typedef struct { // To store 32bit Hash
typedef struct { /* To store 32bit Hash */
FT_UInt32 hash;
}HASH_32;
typedef struct { // To store 128bit Hash
typedef struct { /* To store 128bit Hash */
FT_UInt32 hash[4];
}HASH_128;
@ -52,7 +52,7 @@ typedef struct {
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);
@ -60,31 +60,32 @@ 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
/* Returns a pointer to pixel */
/* at (x,y) co-ordinate */
PIXEL* Pixel_At (IMAGE * bitmap, int x, int y);
/* buffer to image */
void Make_PNG (FT_Bitmap* bitmap,IMAGE* fruit, int i,int render_mode);
// Image to file
/* Image to file */
int Generate_PNG (IMAGE *bitmap, const char *path,int render_mode);
// Read PNG
/* 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}
/* 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
/* 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
/* Print the row in list-view webpage */
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
/* Finding the first non-empty (non-white) column */
int First_Column(IMAGE* input);
// Finding the first non-empty (non-white) row
/* Finding the first non-empty (non-white) row */
int First_Row(IMAGE* input);
// Appening white columns with image alignment
/* Appening white columns with image alignment */
IMAGE* Append_Columns(IMAGE* small, IMAGE* big);
// Appening white columns with image alignment
/* Appening white columns with image alignment */
IMAGE* Append_Rows(IMAGE* small, IMAGE* big);

View File

@ -8,9 +8,9 @@ int main(int argc, char const *argv[])
int size;
int render_mode;
int load_flag; // FT_LOAD_XXX
int render_flag; // FT_RENDER_MODE_XXX
int target_flag; // FT_LOAD_TARGET_XXX
int load_flag; /* FT_LOAD_XXX */
int render_flag; /* FT_RENDER_MODE_XXX */
int target_flag; /* FT_LOAD_TARGET_XXX */
if(argc != 6)
{
@ -63,7 +63,7 @@ int main(int argc, char const *argv[])
HASH_128 * test_murmur = (HASH_128 *) malloc(sizeof(HASH_128)) ;
int Is_Different;
int pixel_diff;
int pixel_diff, i;
char glyph_name[50] = ".not-def";
/*******************************************************************/
@ -351,8 +351,8 @@ int main(int argc, char const *argv[])
size,
DPI);
// Need to write code to check the values in FT_Face and compare
for (int i = 0; i < base_face->num_glyphs; ++i)
/* Need to write code to check the values in FT_Face and compare */
for ( i = 0; i < base_face->num_glyphs; ++i)
{
error = Base_Load_Glyph( base_face,
i,
@ -384,7 +384,7 @@ int main(int argc, char const *argv[])
base_bitmap = &base_slot->bitmap;
test_bitmap = &test_slot->bitmap;
// Need to write code to check the values in FT_Bitmap and compare
/* Need to write code to check the values in FT_Bitmap and compare */
if (base_bitmap->width == 0 || base_bitmap->rows == 0)
{
printf("Empty Glyph in glyph-index %d\n", i);

View File

@ -1,26 +1,21 @@
//-----------------------------------------------------------------------------
// 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.
/*------------------------------------------------------------------*/
/* 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
/*------------------------------------------------------------------*/
/* 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 )
static 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 )
static uint64_t rotl64 ( uint64_t x, int8_t r )
{
return (x << r) | (x >> (64 - r));
}
@ -30,16 +25,16 @@ static FORCE_INLINE uint64_t rotl64 ( uint64_t x, int8_t r )
#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
/*------------------------------------------------------------------*/
/* 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
/*------------------------------------------------------------------*/
/* Finalization mix - force all bits of a hash block to avalanche */
static FORCE_INLINE uint32_t fmix32 ( uint32_t h )
static uint32_t fmix32 ( uint32_t h )
{
h ^= h >> 16;
h *= 0x85ebca6b;
@ -50,9 +45,9 @@ static FORCE_INLINE uint32_t fmix32 ( uint32_t h )
return h;
}
//----------
/*----------*/
static FORCE_INLINE uint64_t fmix64 ( uint64_t k )
static uint64_t fmix64 ( uint64_t k )
{
k ^= k >> 33;
k *= BIG_CONSTANT(0xff51afd7ed558ccd);
@ -63,7 +58,7 @@ static FORCE_INLINE uint64_t fmix64 ( uint64_t k )
return k;
}
//-----------------------------------------------------------------------------
/*------------------------------------------------------------------*/
void MurmurHash3_x86_32 ( const void * key, int len,
uint32_t seed, void * out )
@ -77,8 +72,8 @@ void MurmurHash3_x86_32 ( const void * key, int len,
uint32_t c1 = 0xcc9e2d51;
uint32_t c2 = 0x1b873593;
//----------
// body
/*----------*/
/* body */
const uint32_t * blocks = (const uint32_t *)(data + nblocks*4);
@ -95,8 +90,8 @@ void MurmurHash3_x86_32 ( const void * key, int len,
h1 = h1*5+0xe6546b64;
}
//----------
// tail
/*----------*/
/* tail */
const uint8_t * tail = (const uint8_t*)(data + nblocks*4);
@ -110,8 +105,8 @@ void MurmurHash3_x86_32 ( const void * key, int len,
k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
};
//----------
// finalization
/*----------*/
/* finalization */
h1 ^= len;
@ -120,7 +115,7 @@ void MurmurHash3_x86_32 ( const void * key, int len,
*(uint32_t*)out = h1;
}
//-----------------------------------------------------------------------------
/*------------------------------------------------------------------*/
void MurmurHash3_x86_128 ( const void * key, const int len,
uint32_t seed, void * out )
@ -139,8 +134,8 @@ void MurmurHash3_x86_128 ( const void * key, const int len,
uint32_t c3 = 0x38b34ae5;
uint32_t c4 = 0xa1e38b93;
//----------
// body
/*----------*/
/* body */
const uint32_t * blocks = (const uint32_t *)(data + nblocks*16);
@ -168,8 +163,8 @@ void MurmurHash3_x86_128 ( const void * key, const int len,
h4 = ROTL32(h4,13); h4 += h1; h4 = h4*5+0x32ac3b17;
}
//----------
// tail
/*----------*/
/* tail */
const uint8_t * tail = (const uint8_t*)(data + nblocks*16);
@ -204,8 +199,8 @@ void MurmurHash3_x86_128 ( const void * key, const int len,
k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
};
//----------
// finalization
/*----------*/
/* finalization */
h1 ^= len; h2 ^= len; h3 ^= len; h4 ^= len;
@ -226,7 +221,7 @@ void MurmurHash3_x86_128 ( const void * key, const int len,
((uint32_t*)out)[3] = h4;
}
//-----------------------------------------------------------------------------
/*------------------------------------------------------------------*/
void MurmurHash3_x64_128 ( const void * key, const int len,
const uint32_t seed, void * out )
@ -241,8 +236,8 @@ void MurmurHash3_x64_128 ( const void * key, const int len,
uint64_t c1 = BIG_CONSTANT(0x87c37b91114253d5);
uint64_t c2 = BIG_CONSTANT(0x4cf5ad432745937f);
//----------
// body
/*----------*/
/* body */
const uint64_t * blocks = (const uint64_t *)(data);
@ -260,8 +255,8 @@ void MurmurHash3_x64_128 ( const void * key, const int len,
h2 = ROTL64(h2,31); h2 += h1; h2 = h2*5+0x38495ab5;
}
//----------
// tail
/*----------*/
/* tail */
const uint8_t * tail = (const uint8_t*)(data + nblocks*16);
@ -290,8 +285,8 @@ void MurmurHash3_x64_128 ( const void * key, const int len,
k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1;
};
//----------
// finalization
/*----------*/
/* finalization*/
h1 ^= len; h2 ^= len;
@ -308,5 +303,5 @@ void MurmurHash3_x64_128 ( const void * key, const int len,
((uint64_t*)out)[1] = h2;
}
//-----------------------------------------------------------------------------
/*------------------------------------------------------------------*/

View File

@ -7,7 +7,7 @@
extern "C" {
#endif
//-----------------------------------------------------------------------------
/*-----------------------------------------------------------------*/
void MurmurHash3_x86_32 (const void *key, int len, uint32_t seed, void *out);
@ -15,10 +15,10 @@ 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_
#endif /* _MURMURHASH3_H_ */