[gthumb: 125/129] set the alpha channel to 255 if present



commit 3ea5fec4f604626f406d2503c300dfd486ca842d
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Wed Apr 27 19:52:12 2011 +0200

    set the alpha channel to 255 if present

 extensions/file_tools/gdk-pixbuf-rotate.c |   75 +++++++++++++++--------------
 1 files changed, 39 insertions(+), 36 deletions(-)
---
diff --git a/extensions/file_tools/gdk-pixbuf-rotate.c b/extensions/file_tools/gdk-pixbuf-rotate.c
index bee2aaa..3f59b4c 100644
--- a/extensions/file_tools/gdk-pixbuf-rotate.c
+++ b/extensions/file_tools/gdk-pixbuf-rotate.c
@@ -57,7 +57,7 @@ _gdk_pixbuf_rotate_get_cropping_parameters (GdkPixbuf *src_pixbuf,
 	angle = CLAMP (angle, -90.0, 90.0);
 
 	angle_rad = fabs (angle) / 180.0 * PI;
-	
+
 	cos_angle = cos (angle_rad);
 	sin_angle = sin (angle_rad);
 
@@ -92,13 +92,13 @@ _gdk_pixbuf_rotate_get_cropping_region (GdkPixbuf *src_pixbuf,
 	double new_width;
 
 	double xx1, yy1, xx2, yy2;
-	
+
 	angle = CLAMP (angle, -90.0, 90.0);
 	p1    = CLAMP (p1,      0.0,  1.0);
 	p2    = CLAMP (p2,      0.0,  1.0);
 
 	angle_rad = fabs (angle) / 180.0 * PI;
-	
+
 	cos_angle = cos (angle_rad);
 	sin_angle = sin (angle_rad);
 
@@ -106,21 +106,21 @@ _gdk_pixbuf_rotate_get_cropping_region (GdkPixbuf *src_pixbuf,
 	src_height = gdk_pixbuf_get_height (src_pixbuf) - 1;
 
 	if (src_width > src_height) {
-	
+
 		xx1 = p1 * src_width * cos_angle + src_height * sin_angle;
 		yy1 = p1 * src_width * sin_angle;
-	
+
 		xx2 = (1 - p2) * src_width * cos_angle;
 		yy2 = (1 - p2) * src_width * sin_angle + src_height * cos_angle;
 	}
 	else {
 		xx1 = p1       * src_height * sin_angle;
 		yy1 = (1 - p1) * src_height * cos_angle;
-	
+
 		xx2 = (1 - p2) * src_height * sin_angle + src_width * cos_angle;
 		yy2 = p2       * src_height * cos_angle + src_width * sin_angle;
 	}
-	
+
 	if (angle < 0) {
 
 		new_width  = cos_angle * src_width + sin_angle * src_height;
@@ -131,7 +131,7 @@ _gdk_pixbuf_rotate_get_cropping_region (GdkPixbuf *src_pixbuf,
 
 	region->x = ROUND (MIN (xx1, xx2));
 	region->y = ROUND (MIN (yy1, yy2));
-	
+
 	region->width  = ROUND (MAX (xx1, xx2)) - region->x + 1;
 	region->height = ROUND (MAX (yy1, yy2)) - region->y + 1;
 }
@@ -145,7 +145,7 @@ rotate (GdkPixbuf *src_pixbuf,
 	const guchar R0 = 0;
 	const guchar G0 = 0;
 	const guchar B0 = 0;
-	
+
 	GdkPixbuf *new_pixbuf;
 
 	double     angle_rad;
@@ -162,7 +162,7 @@ rotate (GdkPixbuf *src_pixbuf,
 	double     fx, fy;
 	guchar    *p_src, *p_new;
 	guchar    *p_src2, *p_new2;
-	
+
 	guchar     r00, r01, r10, r11;
 	guchar     g00, g01, g10, g11;
 	guchar     b00, b01, b10, b11;
@@ -170,7 +170,7 @@ rotate (GdkPixbuf *src_pixbuf,
 	angle = CLAMP (angle, -90.0, 90.0);
 
 	angle_rad = angle / 180.0 * PI;
-	
+
 	cos_angle = cos (angle_rad);
 	sin_angle = sin (angle_rad);
 
@@ -179,7 +179,7 @@ rotate (GdkPixbuf *src_pixbuf,
 
 	new_width  = ROUND (      cos_angle  * src_width + fabs(sin_angle) * src_height);
 	new_height = ROUND (fabs (sin_angle) * src_width +      cos_angle  * src_height);
-	
+
 	new_pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src_pixbuf),
 				     gdk_pixbuf_get_has_alpha (src_pixbuf),
 				     gdk_pixbuf_get_bits_per_sample (src_pixbuf),
@@ -193,57 +193,60 @@ rotate (GdkPixbuf *src_pixbuf,
 	new_rowstride = gdk_pixbuf_get_rowstride (new_pixbuf);
 
 	n_channels = gdk_pixbuf_get_n_channels (src_pixbuf);
-	
+
 	for (yi = 0; yi < new_height; yi++) {
-	
+
 		p_new2 = p_new;
-		
+
 		y = yi - new_height / 2.0;
-		
+
 		for (xi = 0; xi < new_width; xi++) {
-		
+
 			x = xi - new_width / 2.0;
-			
+
 			x2 = cos_angle * x - sin_angle * y + src_width  / 2.0;
 			y2 = sin_angle * x + cos_angle * y + src_height / 2.0;
-			
+
 			if (high_quality) {
-			
+
 				// Bilinear interpolation
-			
+
 				x2min = (int) floor (x2);
 				y2min = (int) floor (y2);
-			
+
 				x2max = x2min + 1;
 				y2max = y2min + 1;
-			
+
 				fx = x2 - x2min;
 				fy = y2 - y2min;
-			
+
 				GET_VALUES (r00, g00, b00, x2min, y2min);
 				GET_VALUES (r01, g01, b01, x2max, y2min);
 				GET_VALUES (r10, g10, b10, x2min, y2max);
 				GET_VALUES (r11, g11, b11, x2max, y2max);
-			
+
 				p_new2[RED_PIX]   = CLAMP (INTERPOLATE (r00, r01, r10, r11, fx, fy), 0, 255);
 				p_new2[GREEN_PIX] = CLAMP (INTERPOLATE (g00, g01, g10, g11, fx, fy), 0, 255);
 				p_new2[BLUE_PIX]  = CLAMP (INTERPOLATE (b00, b01, b10, b11, fx, fy), 0, 255);
 			}
 			else {
 				// Nearest neighbor
-			
+
 				x2min = ROUND (x2);
 				y2min = ROUND (y2);
-				
+
 				GET_VALUES (p_new2[RED_PIX], p_new2[GREEN_PIX], p_new2[BLUE_PIX], x2min, y2min);
 			}
-			
+
+			if (n_channels == 4)
+				p_new2[ALPHA_PIX] = 255;
+
 			p_new2 += n_channels;
 		}
-		
+
 		p_new += new_rowstride;
 	}
-	
+
 	return new_pixbuf;
 }
 
@@ -256,10 +259,10 @@ _gdk_pixbuf_rotate_get_align_angle (gboolean vertical,
 	double angle;
 
 	if (! vertical) {
-	
+
 		if (p1.y == p2.y)
 			return 0.0;
-			
+
 		if (p2.x > p1.x)
 			angle = -atan2 (p2.y - p1.y, p2.x - p1.x);
 		else
@@ -269,16 +272,16 @@ _gdk_pixbuf_rotate_get_align_angle (gboolean vertical,
 
 		if (p1.x == p2.x)
 			return 0.0;
-			
+
 		if (p2.y > p1.y)
 			angle = atan2 (p2.x - p1.x, p2.y - p1.y);
 		else
 			angle = atan2 (p1.x - p2.x, p1.y - p2.y);
 	}
-	
+
 	angle = angle * 180.0 / PI;
 	angle = ROUND (angle * 10.0) / 10.0;
-	
+
 	return angle;
 }
 
@@ -289,7 +292,7 @@ _gdk_pixbuf_rotate (GdkPixbuf *src_pixbuf,
 		    gboolean   high_quality)
 {
 	GdkPixbuf *new_pixbuf;
-	
+
 	if (angle == 0.0) {
 		new_pixbuf = src_pixbuf;
 		g_object_ref (new_pixbuf);



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