This commit is contained in:
Kushal K S V S 2017-06-29 10:40:57 +05:30
parent 838c65dce2
commit 4d3200b4db
5 changed files with 84 additions and 49 deletions

View File

@ -1,35 +1,37 @@
To generate hashes and store it in the ./hashes folder, To generate hashes and store it in the ./hashes folder,
1) sudo make hash 1) sudo make hash
(set resoluton in DPI by passing argument (set resoluton in DPI by passing argument
example: sudo make DPI=100, if not specified,default is 72) example: sudo make DPI=100, if not specified,default is 72)
2) Usage ./hash <font_file> <pt_size> <render_mode> 2) Usage ./hash <font_file> <pt_size> <render_mode>
Hashes will be saved in a file named $(font)_$(pt_size)_$(render_mode).hash Hashes will be saved in a file named
$(font)_$(pt_size)_$(render_mode).hash
By default, hashes of 256-level gray bitmaps will be generated By default, hashes of 256-level gray bitmaps will be generated
Values for render_mode 0 - monochrome Values for render_mode 0 - monochrome
1 - anti-aliased 1 - anti-aliased
2 - lcd horizontal 2 - lcd horizontal
3 - lcd vertical 3 - lcd vertical
To generate 32-bit RGBA PNG(s) of all glyphs in a font\n To generate 32-bit RGBA PNG(s) of all glyphs in a font\n
1) sudo make png 1) sudo make png
(set resoluton in DPI by passing argument (set resoluton in DPI by passing argument
example: sudo make DPI=100, if not specified,default is 72) example: sudo make DPI=100, if not specified,default is 72)
2.Usage ./<exe> <font_file> <pt_size> <render_mode> 2.Usage ./<exe> <font_file> <pt_size> <render_mode>
Images will be saved in a file named $(font)_$(pt_size)_$(render_mode)_$(glyph_index).png Images will be saved in a file named
$(font)_$(pt_size)_$(render_mode)_$(glyph_index).png
By default, hashes of 256-level gray bitmaps will be generated By default, hashes of 256-level gray bitmaps will be generated
Values for render_mode 0 - monochrome Values for render_mode 0 - monochrome
1 - anti-aliased 1 - anti-aliased
2 - lcd horizontal-RGB 2 - lcd horizontal-RGB
3 - lcd horizontal-BGR 3 - lcd horizontal-BGR
4 - lcd vertical-RGB 4 - lcd vertical-RGB
5 - lcd vertical-BGR 5 - lcd vertical-BGR

View File

@ -1,28 +1,40 @@
#include "bitmap.h" #include "bitmap.h"
HASH_128 * Generate_Hash_x64_128(FT_Bitmap * bitmap, HASH_128 * murmur) 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), seed, murmur->hash); MurmurHash3_x64_128(bitmap->buffer,
(bitmap->pitch * bitmap->rows),
seed,
murmur->hash);
return murmur; return murmur;
} }
HASH_128 * Generate_Hash_x86_128(FT_Bitmap * bitmap, HASH_128 * murmur) 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), seed, murmur->hash); MurmurHash3_x86_128(bitmap->buffer,
(bitmap->pitch * bitmap->rows),
seed,
murmur->hash);
return murmur; return murmur;
} }
HASH_32 * Generate_Hash_x86_32(FT_Bitmap * bitmap, HASH_32 * murmur) 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), seed, murmur->hash); MurmurHash3_x86_32( bitmap->buffer,
(bitmap->pitch * bitmap->rows),
seed,
murmur->hash);
return murmur; return murmur;
} }
@ -32,7 +44,9 @@ PIXEL * Pixel_At (IMAGE * bitmap, int x, int y)
return bitmap->pixels + bitmap->width * y + x; return bitmap->pixels + bitmap->width * y + x;
} }
int Generate_PNG (IMAGE *bitmap, const char *path,int render_mode) int Generate_PNG (IMAGE *bitmap,
const char *path,
int render_mode)
{ {
FILE * fp; FILE * fp;
png_structp png_ptr = NULL; png_structp png_ptr = NULL;
@ -51,7 +65,10 @@ int Generate_PNG (IMAGE *bitmap, const char *path,int render_mode)
goto fopen_failed; goto fopen_failed;
} }
png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); png_ptr = png_create_write_struct ( PNG_LIBPNG_VER_STRING,
NULL,
NULL,
NULL);
if (png_ptr == NULL) { if (png_ptr == NULL) {
goto png_create_write_struct_failed; goto png_create_write_struct_failed;
} }
@ -75,11 +92,13 @@ int Generate_PNG (IMAGE *bitmap, const char *path,int render_mode)
PNG_COMPRESSION_TYPE_DEFAULT, PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT); PNG_FILTER_TYPE_DEFAULT);
row_pointers = png_malloc (png_ptr, bitmap->height * sizeof (png_byte *)); row_pointers = png_malloc ( png_ptr,
bitmap->height * sizeof (png_byte *));
for (y = 0; y < bitmap->height; y++) { 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; row_pointers[y] = row;
for (x = 0; x < bitmap->width; x++) { for (x = 0; x < bitmap->width; x++) {
@ -102,9 +121,17 @@ int Generate_PNG (IMAGE *bitmap, const char *path,int render_mode)
} }
} }
png_init_io (png_ptr, fp); png_init_io ( png_ptr,
png_set_rows (png_ptr, info_ptr, row_pointers); fp);
png_write_png (png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
png_set_rows (png_ptr,
info_ptr,
row_pointers);
png_write_png ( png_ptr,
info_ptr,
PNG_TRANSFORM_IDENTITY,
NULL);
status = 0; status = 0;
@ -136,7 +163,8 @@ void Make_PNG(FT_Bitmap* bitmap,char* name,int i,int 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.height = bitmap->rows;
fruit.pixels = calloc (fruit.width * fruit.height, sizeof (PIXEL)); fruit.pixels = calloc ( fruit.width * fruit.height,
sizeof (PIXEL));
for (y = 0; y < fruit.height; y++) { for (y = 0; y < fruit.height; y++) {
for (x = 0; x < fruit.width; x++) { for (x = 0; x < fruit.width; x++) {
@ -162,7 +190,8 @@ void Make_PNG(FT_Bitmap* bitmap,char* name,int i,int render_mode){
case 1 : fruit.width = bitmap->width; // MONO and GRAY case 1 : fruit.width = bitmap->width; // MONO and GRAY
fruit.height = bitmap->rows; fruit.height = bitmap->rows;
fruit.pixels = calloc (fruit.width * fruit.height, sizeof (PIXEL)); fruit.pixels = calloc ( fruit.width * fruit.height,
sizeof (PIXEL));
for (y = 0; y < fruit.height; y++) { for (y = 0; y < fruit.height; y++) {
for (x = 0; x < fruit.width; x++) { for (x = 0; x < fruit.width; x++) {
@ -184,7 +213,8 @@ void Make_PNG(FT_Bitmap* bitmap,char* name,int i,int render_mode){
case 3 : fruit.width = bitmap->width / 3; // LCD case 3 : fruit.width = bitmap->width / 3; // LCD
fruit.height = bitmap->rows; fruit.height = bitmap->rows;
fruit.pixels = calloc (fruit.width * fruit.height, sizeof (PIXEL)); fruit.pixels = calloc ( fruit.width * fruit.height,
sizeof (PIXEL));
for (y = 0; y < fruit.height; y++) { for (y = 0; y < fruit.height; y++) {
for (x = 0; x < fruit.width; x++) { for (x = 0; x < fruit.width; x++) {
@ -212,7 +242,8 @@ void Make_PNG(FT_Bitmap* bitmap,char* name,int i,int render_mode){
case 5 : fruit.width = bitmap->width; // LCD_V case 5 : fruit.width = bitmap->width; // LCD_V
fruit.height = bitmap->rows / 3; fruit.height = bitmap->rows / 3;
fruit.pixels = calloc (fruit.width * fruit.height, sizeof (PIXEL)); fruit.pixels = calloc ( fruit.width * fruit.height,
sizeof (PIXEL));
for (y = 0; y < fruit.height; y++) { for (y = 0; y < fruit.height; y++) {
for (x = 0; x < fruit.width; x++) { for (x = 0; x < fruit.width; x++) {
@ -243,9 +274,9 @@ void Make_PNG(FT_Bitmap* bitmap,char* name,int i,int render_mode){
char * file_name = ( char * )calloc(150,sizeof(char)); char * file_name = ( char * )calloc(150,sizeof(char));
sprintf(file_name, "%s_%d",name,i); sprintf(file_name, "%s_%d", name, i);
Generate_PNG (& fruit, file_name,render_mode); Generate_PNG (& fruit, file_name, render_mode);
free (fruit.pixels); free (fruit.pixels);
} }

View File

@ -50,17 +50,18 @@ typedef struct {
size_t height; size_t height;
} IMAGE; } IMAGE;
//------------------------------------------------------------------------------- //------------------------------------------------------------------------------
HASH_32 * Generate_Hash_x86_32(FT_Bitmap * bitmap, HASH_32 * murmur); 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_x86_128(FT_Bitmap * bitmap, HASH_128 * murmur);
HASH_128 * Generate_Hash_x64_128(FT_Bitmap * bitmap, HASH_128 * murmur); HASH_128 * Generate_Hash_x64_128(FT_Bitmap * bitmap, HASH_128 * murmur);
//------------------------------------------------------------------------------- //------------------------------------------------------------------------------
PIXEL * Pixel_At (IMAGE * bitmap, int x, int y); // Returns a pointer to pixel PIXEL * Pixel_At (IMAGE * bitmap, int x, int y); // Returns a pointer to pixel
// at (x,y) co-ordinate // at (x,y) co-ordinate
// buffer to image
void Make_PNG(FT_Bitmap* bitmap,char* name,int i,int render_mode); // buffer to image void Make_PNG(FT_Bitmap* bitmap,char* name,int i,int render_mode);
int Generate_PNG (IMAGE *bitmap, const char *path,int render_mode); // Image to file // Image to file
int Generate_PNG (IMAGE *bitmap, const char *path,int render_mode);

View File

@ -25,9 +25,10 @@ int main (int argc, char const *argv[])
if (argc != 4) if (argc != 4)
{ {
printf("\nTo generate MurmurHash3 hash values of all glyphs\n"); printf("\nTo generate MurmurHash3 hash values of all glyphs\n");
printf("Hashes will be saved in a file named $(font)_$(pt_size)_$(render_mode).hash \n\n"); printf("Hashes will be saved in a file named\n \
$(font)_$(pt_size)_$(render_mode).hash \n\n");
printf("By default, hashes of 256-level gray bitmaps will be generated\n\n"); printf("Default: hashes of 256-level gray bitmaps will be generated\n\n");
printf("Usage ./<exe> <font_file> <pt_size> <render_mode>\n\n"); printf("Usage ./<exe> <font_file> <pt_size> <render_mode>\n\n");

View File

@ -28,7 +28,7 @@ int main (int argc, char const *argv[])
printf("Images will be saved in a file named \n\ printf("Images will be saved in a file named \n\
$(font)_$(pt_size)_$(render_mode)_$(glyph_index).png \n\n"); $(font)_$(pt_size)_$(render_mode)_$(glyph_index).png \n\n");
printf("By default, hashes of 256-level gray bitmaps will be generated\n\n"); printf("Default: hashes of 256-level gray bitmaps will be generated\n\n");
printf("Usage ./<exe> <font_file> <pt_size> <render_mode>\n\n"); printf("Usage ./<exe> <font_file> <pt_size> <render_mode>\n\n");