Aligning glyphs and adding white rows/columns

This commit is contained in:
Kushal K S V S 2017-07-27 13:36:10 +05:30
parent 2241dc7b81
commit 785ce40aa6
4 changed files with 206 additions and 127 deletions

View File

@ -2,13 +2,47 @@ NOTE: First make freetype library (in the ../../ directory)
make devel
make
TODO: Generate HTML page (testing going on)
TODO: Generate HTML page for detailed comparison
/*******************************************************************/
To generate sprite sheets in the /images folder and to generate the
"index.html" (List-View) of the glyphs.
By clicking on the Headers of the respective columns,they can be
arranged (in increasing/decreasing order) based on
-> Glyph-Index
-> Name
-> Difference Metric (right now it is the number of pixels that are
different between the base and the test glyph)
It displays the whole sprite sheet right now (will be used later)
Hashes will be diplayed (To be implemented)
First compile and install two versions of the FreeType libray
in different folders (with SUBPIXEL_RENDERING enabled in ftoption.h)
1) make sprite
(set resoluton in DPI by passing argument
example: make DPI=100, if not specified,default is 72)
2) Usage ./sprite <a> <b> <font_file> <pt_size> <render_mode>
(<a> is the libfreetype.so from the base vesion )
(<b> is the libfreetype.so from the test vesion )
The path to the "shared library" in usage should be absolute.
Sprite Sheets will be saved as sprite_$(glyph_index).png
Render modes similar to generating PNG(s).
NOTE: If the dimensions of the two glyphs to be compared are
different, comparison is done after aligning the glyphs.
This alignment will effect the 'Difference Metric' based on the
number of rows/columns added.
Testing Right Now: Aligning 'base' and 'test' glyphs
1. Using the bottom-left non-white pixel as reference.
2. Using the similarity between the glyphs ( maintaining a score based
on the number of non-white pixels overlapping )
/*******************************************************************/
(DEPRECATED)
To generate hashes and store it in the ./hashes folder,
@ -30,7 +64,7 @@ To generate hashes and store it in the ./hashes folder,
3 - lcd vertical
/*******************************************************************/
(DEPRECATED)
To generate 32-bit RGBA PNG(s) of all glyphs in a font\n
1) make png
@ -51,39 +85,7 @@ To generate 32-bit RGBA PNG(s) of all glyphs in a font\n
4 - lcd vertical-RGB
5 - lcd vertical-BGR
/*******************************************************************/
To generate sprite sheets in the /images folder and to generate the
"index.html" (List-View) of the glyphs.
By clicking on the Headers of the respective columns,they can be
arranged (in increasing/decreasing order) based on
-> Glyph-Index
-> Name
-> Difference Metric (right now it is the number of pixels that are
different between the base and the test glyph)
It displays the whole sprite sheet right now (will be used later)
Hashes will be dsplayed (To be implemented)
First compile and install two versions of the FreeType libray
in different folders (with SUBPIXEL_RENDERING enabled in ftoption.h)
1) make sprite
(set resoluton in DPI by passing argument
example: make DPI=100, if not specified,default is 72)
2) Usage ./sprite <a> <b> <font_file> <pt_size> <render_mode>
(<a> is the libfreetype.so from the base vesion )
(<b> is the libfreetype.so from the test vesion )
The path to the "shared library" in usage should be absolute.
Sprite Sheets will be saved as sprite_$(glyph_index).png
Render modes similar to generating PNG(s).

View File

@ -334,85 +334,6 @@ void Read_PNG(char *filename, IMAGE * after_effect) {
fclose(fp);
}
IMAGE* Adjust_Height(IMAGE* small, IMAGE* big){
int h_delta;
IMAGE* result = (IMAGE*)malloc(sizeof(IMAGE));
result->height = big->height;
result->width = small->width;
result->pixels =
(PIXEL*) malloc(result->width * result->height * sizeof(PIXEL));
h_delta = big->height - small->height;
for (int y = 0; y < h_delta; ++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 = h_delta; y < result->height; ++y)
{
for (int x = 0; x < result->width; ++x)
{
PIXEL * pixel_small = Pixel_At ( small, x, y - h_delta);
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;
}
}
return result;
}
IMAGE* Adjust_Width(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));
for (int x = small->width; x < big->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;
}
}
for (int y = 0; y < result->height; ++y)
{
for (int x = 0; x < small->width; ++x)
{
PIXEL * pixel_small = Pixel_At ( small, x, 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;
}
}
return result;
}
int Add_effect(IMAGE* base, IMAGE* test, IMAGE* out, int Effect_ID)
{
int pixel_diff = 0;
@ -540,3 +461,155 @@ void Print_Row( FILE* fp, int index, char* name, int diff,
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

@ -78,9 +78,13 @@ 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
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,
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);

View File

@ -434,18 +434,18 @@ int main(int argc, char const *argv[])
if (base_png->height < test_png->height)
{
base_png = Adjust_Height(base_png, test_png);
base_png = Append_Rows(base_png, test_png);
}else if (base_png->height > test_png->height)
{
test_png = Adjust_Height(test_png, base_png);
test_png = Append_Rows(test_png, base_png);
}
if (base_png->width < test_png->width)
{
base_png = Adjust_Width(base_png, test_png);
base_png = Append_Columns(base_png, test_png);
}else if (base_png->width > test_png->width)
{
test_png = Adjust_Width(test_png, base_png);
test_png = Append_Columns(test_png, base_png);
}
Add_effect( base_png, test_png, after_effect_1, 1);