summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArvinder Bhathal <arvinder.bhathal@gmail.com>2017-07-28 09:27:06 -0400
committerArvinder Bhathal <arvinder.bhathal@gmail.com>2017-07-28 09:27:06 -0400
commitd8dc158939a3f17050b5dcdab920356e14e8e007 (patch)
tree58d6c9a08679312058875ce2d77171b609acef73
parent2572b1bea7cc22ea3c1cd26e27a5bc7e997dfefb (diff)
downloadfreetype2-arv-testing.tar.gz
Update to latest bitmap codearv-testing
-rw-r--r--tests/web_interface/bitmap.c405
-rw-r--r--tests/web_interface/bitmap.h33
-rw-r--r--tests/web_interface/main.c2
3 files changed, 397 insertions, 43 deletions
diff --git a/tests/web_interface/bitmap.c b/tests/web_interface/bitmap.c
index d542155ab..6f7cbb9ef 100644
--- a/tests/web_interface/bitmap.c
+++ b/tests/web_interface/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++) {
@@ -140,6 +140,8 @@ int Generate_PNG (IMAGE *bitmap,
}
png_free (png_ptr, row_pointers);
+ free (bitmap->pixels);
+
png_failure:
png_create_info_struct_failed:
png_destroy_write_struct (&png_ptr, &info_ptr);
@@ -149,9 +151,8 @@ int Generate_PNG (IMAGE *bitmap,
return status;
}
-void Make_PNG(FT_Bitmap* bitmap,char* name,int i,int render_mode){
+void Make_PNG(FT_Bitmap* bitmap,IMAGE* fruit,int i,int render_mode){
- IMAGE fruit;
int x;
int y;
@@ -160,16 +161,16 @@ void Make_PNG(FT_Bitmap* bitmap,char* name,int i,int render_mode){
switch(render_mode){
- case 0 : fruit.width = bitmap->width; // MONO and GRAY
- fruit.height = bitmap->rows;
+ case 0 : fruit->width = bitmap->width; // MONO and GRAY
+ fruit->height = bitmap->rows;
- fruit.pixels = calloc ( fruit.width * fruit.height,
+ fruit->pixels = calloc ( fruit->width * fruit->height,
sizeof (PIXEL));
- for (y = 0; y < fruit.height; y++) {
- for (x = 0; x < fruit.width; x++) {
+ for (y = 0; y < fruit->height; y++) {
+ for (x = 0; x < fruit->width; x++) {
- PIXEL * pixel = Pixel_At (& fruit, x, y);
+ PIXEL * pixel = Pixel_At ( fruit, x, y);
p = (y * bitmap->pitch ) + x;
value = bitmap->buffer[p];
@@ -187,16 +188,16 @@ void Make_PNG(FT_Bitmap* bitmap,char* name,int i,int render_mode){
}
}
break;
- case 1 : fruit.width = bitmap->width; // MONO and GRAY
- fruit.height = bitmap->rows;
+ case 1 : fruit->width = bitmap->width; // MONO and GRAY
+ fruit->height = bitmap->rows;
- fruit.pixels = calloc ( fruit.width * fruit.height,
+ fruit->pixels = calloc ( fruit->width * fruit->height,
sizeof (PIXEL));
- for (y = 0; y < fruit.height; y++) {
- for (x = 0; x < fruit.width; x++) {
+ for (y = 0; y < fruit->height; y++) {
+ for (x = 0; x < fruit->width; x++) {
- PIXEL * pixel = Pixel_At (& fruit, x, y);
+ PIXEL * pixel = Pixel_At ( fruit, x, y);
p = (y * bitmap->pitch ) + x;
value = bitmap->buffer[p];
@@ -210,16 +211,16 @@ void Make_PNG(FT_Bitmap* bitmap,char* name,int i,int render_mode){
break;
case 2 :
- case 3 : fruit.width = bitmap->width / 3; // LCD
- fruit.height = bitmap->rows;
+ case 3 : fruit->width = bitmap->width / 3; // LCD
+ fruit->height = bitmap->rows;
- fruit.pixels = calloc ( fruit.width * fruit.height,
+ fruit->pixels = calloc ( fruit->width * fruit->height,
sizeof (PIXEL));
- for (y = 0; y < fruit.height; y++) {
- for (x = 0; x < fruit.width; x++) {
+ for (y = 0; y < fruit->height; y++) {
+ for (x = 0; x < fruit->width; x++) {
- PIXEL * pixel = Pixel_At (& fruit, x, y);
+ PIXEL * pixel = Pixel_At ( fruit, x, y);
p = (y * bitmap->pitch ) + (x)*3;
value = bitmap->buffer[p];
@@ -239,16 +240,16 @@ void Make_PNG(FT_Bitmap* bitmap,char* name,int i,int render_mode){
break;
case 4 :
- case 5 : fruit.width = bitmap->width; // LCD_V
- fruit.height = bitmap->rows / 3;
+ case 5 : fruit->width = bitmap->width; // LCD_V
+ fruit->height = bitmap->rows / 3;
- fruit.pixels = calloc ( fruit.width * fruit.height,
+ fruit->pixels = calloc ( fruit->width * fruit->height,
sizeof (PIXEL));
- for (y = 0; y < fruit.height; y++) {
- for (x = 0; x < fruit.width; x++) {
+ for (y = 0; y < fruit->height; y++) {
+ for (x = 0; x < fruit->width; x++) {
- PIXEL * pixel = Pixel_At (& fruit, x, y);
+ PIXEL * pixel = Pixel_At ( fruit, x, y);
p = ((y*3) * bitmap->pitch ) + x;
value = bitmap->buffer[p];
@@ -267,16 +268,348 @@ void Make_PNG(FT_Bitmap* bitmap,char* name,int i,int render_mode){
}
break;
- default : fruit.width = bitmap->width;
- fruit.height = bitmap->rows;
+ 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;
+ }
+ }
- char * file_name = ( char * )calloc(150,sizeof(char));
+ 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;
+}
- sprintf(file_name, "%s_%d.png", name, i);
+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));
- Generate_PNG (& fruit, file_name, render_mode);
+ int first_col = First_Column(big);
- free (fruit.pixels);
-} \ No newline at end of file
+ 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;
+}
diff --git a/tests/web_interface/bitmap.h b/tests/web_interface/bitmap.h
index 426d62218..ef0da295b 100644
--- a/tests/web_interface/bitmap.h
+++ b/tests/web_interface/bitmap.h
@@ -11,7 +11,8 @@
#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
@@ -19,9 +20,10 @@
#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[1];
+ FT_UInt32 hash;
}HASH_32;
typedef struct { // To store 128bit Hash
@@ -56,12 +58,33 @@ 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,char* name,int i,int render_mode);
+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);
-
+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);
diff --git a/tests/web_interface/main.c b/tests/web_interface/main.c
index 95fbcf17a..499a83eef 100644
--- a/tests/web_interface/main.c
+++ b/tests/web_interface/main.c
@@ -1,6 +1,4 @@
#include "bitmap.h"
-#include <dlfcn.h>
-#include <math.h>
struct entry
{