diff options
author | Kushal K S V S <kkushal32@gmail.com> | 2017-07-11 23:45:50 +0530 |
---|---|---|
committer | Kushal K S V S <kkushal32@gmail.com> | 2018-03-18 20:40:44 +0530 |
commit | 51347b348b99d5734006f7f1a4be67ae0bc0b277 (patch) | |
tree | 1ecc1c097a1f783708ee310abd22acff66d1c0cf | |
parent | 6bf7bcd3787c61f1882013ab4a1f0070056edf49 (diff) | |
download | freetype2-51347b348b99d5734006f7f1a4be67ae0bc0b277.tar.gz |
Read PNG function
-rw-r--r-- | tests/make_png/bitmap.c | 66 | ||||
-rw-r--r-- | tests/make_png/bitmap.h | 3 |
2 files changed, 67 insertions, 2 deletions
diff --git a/tests/make_png/bitmap.c b/tests/make_png/bitmap.c index 104acdc1c..deeff15c3 100644 --- a/tests/make_png/bitmap.c +++ b/tests/make_png/bitmap.c @@ -279,4 +279,68 @@ void Make_PNG(FT_Bitmap* bitmap,char* name,int i,int render_mode){ Generate_PNG (& fruit, file_name, render_mode); free (fruit.pixels); -}
\ No newline at end of file +} + +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; + + printf("%d %d\n",width,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]; + + printf("%d %d %d %d\n", pixel->red, + pixel->green, + pixel->blue, + pixel->alpha ); + } + } + + fclose(fp); +} + diff --git a/tests/make_png/bitmap.h b/tests/make_png/bitmap.h index 426d62218..bed203db9 100644 --- a/tests/make_png/bitmap.h +++ b/tests/make_png/bitmap.h @@ -64,4 +64,5 @@ PIXEL * Pixel_At (IMAGE * bitmap, int x, int y); // Returns a pointer to pixel void Make_PNG(FT_Bitmap* bitmap,char* name,int i,int render_mode); // Image to file int Generate_PNG (IMAGE *bitmap, const char *path,int render_mode); - +// Read PNG +void Read_PNG(char *filename, IMAGE * after_effect); |