summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKushal K S V S <kkushal32@gmail.com>2017-07-11 23:45:50 +0530
committerKushal K S V S <kkushal32@gmail.com>2017-07-11 23:45:50 +0530
commitf3321c3c6f0f5717da2c2af814a7a06090ed7647 (patch)
tree594681547b79b5dc539954c20e750ff04aed8a60
parent131719213c4f64c5687d7d7e1ee86d999fab738d (diff)
downloadfreetype2-f3321c3c6f0f5717da2c2af814a7a06090ed7647.tar.gz
Read PNG function
-rw-r--r--tests/make_png/bitmap.c66
-rw-r--r--tests/make_png/bitmap.h3
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);