freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2] GSoC-2017-kushal 1a872c1 17/52: Adding code to stitch 2 PNG


From: Kushal K S V S
Subject: [freetype2] GSoC-2017-kushal 1a872c1 17/52: Adding code to stitch 2 PNG files
Date: Fri, 25 Aug 2017 15:09:36 -0400 (EDT)

branch: GSoC-2017-kushal
commit 1a872c139cf7b9beee2b522e902ac7a7d1c4f5ec
Author: Kushal K S V S <address@hidden>
Commit: Kushal K S V S <address@hidden>

    Adding code to stitch 2 PNG files
---
 tests/make_png/bitmap.c | 46 +++++++++++++++++++++++++++++++++++++++++-----
 tests/make_png/bitmap.h |  2 ++
 2 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/tests/make_png/bitmap.c b/tests/make_png/bitmap.c
index 0f62321..a57e1cf 100644
--- a/tests/make_png/bitmap.c
+++ b/tests/make_png/bitmap.c
@@ -281,7 +281,7 @@ void Make_PNG(FT_Bitmap* bitmap,char* name,int i,int 
render_mode){
   free (fruit.pixels);
 }
 
-void Read_PNG(char *filename, IMAGE * after_effect) {
+void Read_PNG(char *filename, IMAGE * bitmap) {
 
   int width, height;
   png_bytep *row_pointers;
@@ -305,8 +305,8 @@ void Read_PNG(char *filename, IMAGE * after_effect) {
   width      = png_get_image_width(png, info);
   height     = png_get_image_height(png, info);
 
-  after_effect->width = width;
-  after_effect->height = height;
+  bitmap->width = width;
+  bitmap->height = height;
 
   row_pointers = (png_bytep*)malloc(sizeof(png_bytep) * height);
   for(int y = 0; y < height; y++) {
@@ -315,7 +315,7 @@ void Read_PNG(char *filename, IMAGE * after_effect) {
 
   png_read_image(png, row_pointers);
 
-  after_effect->pixels = (PIXEL*)malloc(width * height * sizeof(PIXEL));
+  bitmap->pixels = (PIXEL*)malloc(width * height * sizeof(PIXEL));
 
   for(int y = 0; y < height; y++) {
 
@@ -325,7 +325,7 @@ void Read_PNG(char *filename, IMAGE * after_effect) {
 
       png_bytep px = &(row[x * 4]);
 
-      PIXEL * pixel = Pixel_At ( after_effect, x, y);
+      PIXEL * pixel = Pixel_At ( bitmap, x, y);
 
       pixel->red = px[0];
       pixel->green = px[1];
@@ -379,3 +379,39 @@ void Add_effect_1(IMAGE* base, IMAGE* test, IMAGE* out){
     }
   }
 }
+
+void Stitch(IMAGE* left, IMAGE* right, IMAGE* result){
+
+  result->width = left->width + right->width;
+  result->height = left->height; // Horizontal clipping
+
+  result->pixels = (PIXEL*)malloc(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;
+    }
+  }
+
+  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;
+    }
+  }
+}
diff --git a/tests/make_png/bitmap.h b/tests/make_png/bitmap.h
index da3c03e..51609e8 100644
--- a/tests/make_png/bitmap.h
+++ b/tests/make_png/bitmap.h
@@ -70,3 +70,5 @@ void Read_PNG(char *filename, IMAGE * after_effect);
 // Base Glyph = Gray {127,0,0,255}
 // Differences = Red {255,0,0,255}
 void Add_effect_1(IMAGE* base, IMAGE* test, IMAGE* out);
+// Stitch two PNG files side by side
+void Stitch(IMAGE* left, IMAGE* right, IMAGE* result);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]