[Bf-blender-cvs] [898498c] master: Fix for IMB_(un)premultiply_rect_float() not doing right business

Sergey Sharybin noreply at git.blender.org
Thu Jan 23 11:53:32 CET 2014


Commit: 898498c8008078b0c5d311b9a0a362b5a0ad23be
Author: Sergey Sharybin
Date:   Thu Jan 23 16:51:32 2014 +0600
https://developer.blender.org/rB898498c8008078b0c5d311b9a0a362b5a0ad23be

Fix for IMB_(un)premultiply_rect_float() not doing right business

- Made them receive number of channels rather than number of planes.
  This matches to how ImBuf structure stored planes and channels.
- IMB_premultiply_rect_float() was called with channels passed instead
  of planes already :S.

===================================================================

M	source/blender/imbuf/intern/IMB_filter.h
M	source/blender/imbuf/intern/divers.c
M	source/blender/imbuf/intern/filter.c

===================================================================

diff --git a/source/blender/imbuf/intern/IMB_filter.h b/source/blender/imbuf/intern/IMB_filter.h
index 6bd5f44..6565610 100644
--- a/source/blender/imbuf/intern/IMB_filter.h
+++ b/source/blender/imbuf/intern/IMB_filter.h
@@ -39,10 +39,10 @@ struct ImBuf;
 void imb_filterx(struct ImBuf *ibuf);
 
 void IMB_premultiply_rect(unsigned int *rect, char planes, int w, int h);
-void IMB_premultiply_rect_float(float *rect_float, char planes, int w, int h);
+void IMB_premultiply_rect_float(float *rect_float, int channels, int w, int h);
 
 void IMB_unpremultiply_rect(unsigned int *rect, char planes, int w, int h);
-void IMB_unpremultiply_rect_float(float *rect_float, char planes, int w, int h);
+void IMB_unpremultiply_rect_float(float *rect_float, int channels, int w, int h);
 
 void imb_onehalf_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1);
 
diff --git a/source/blender/imbuf/intern/divers.c b/source/blender/imbuf/intern/divers.c
index e147b81..6f6169b 100644
--- a/source/blender/imbuf/intern/divers.c
+++ b/source/blender/imbuf/intern/divers.c
@@ -552,8 +552,7 @@ void IMB_rect_from_float(ImBuf *ibuf)
 	IMB_colormanagement_transform(buffer, ibuf->x, ibuf->y, ibuf->channels, from_colorspace, ibuf->rect_colorspace->name, true);
 
 	/* convert from float's premul alpha to byte's straight alpha */
-	if (ibuf->channels == 4)
-		IMB_unpremultiply_rect_float(buffer, ibuf->planes, ibuf->x, ibuf->y);
+	IMB_unpremultiply_rect_float(buffer, ibuf->channels, ibuf->x, ibuf->y);
 
 	/* convert float to byte */
 	IMB_buffer_byte_from_float((unsigned char *) ibuf->rect, buffer, ibuf->channels, ibuf->dither, IB_PROFILE_SRGB, IB_PROFILE_SRGB,
@@ -647,7 +646,6 @@ void IMB_float_from_rect(ImBuf *ibuf)
 	/* byte buffer is straight alpha, float should always be premul */
 	IMB_premultiply_rect_float(rect_float, ibuf->channels, ibuf->x, ibuf->y);
 
-
 	if (ibuf->rect_float == NULL) {
 		ibuf->rect_float = rect_float;
 		ibuf->mall |= IB_rectfloat;
diff --git a/source/blender/imbuf/intern/filter.c b/source/blender/imbuf/intern/filter.c
index 9193954..d0d7fc2 100644
--- a/source/blender/imbuf/intern/filter.c
+++ b/source/blender/imbuf/intern/filter.c
@@ -565,19 +565,12 @@ void IMB_premultiply_rect(unsigned int *rect, char planes, int w, int h)
 	}
 }
 
-void IMB_premultiply_rect_float(float *rect_float, char planes, int w, int h)
+void IMB_premultiply_rect_float(float *rect_float, int channels, int w, int h)
 {
 	float val, *cp;
 	int x, y;
 
-	if (planes == 24) {   /* put alpha at 1.0 */
-		cp = rect_float;
-
-		for (y = 0; y < h; y++)
-			for (x = 0; x < w; x++, cp += 4)
-				cp[3] = 1.0;
-	}
-	else {
+	if (channels == 4) {
 		cp = rect_float;
 		for (y = 0; y < h; y++) {
 			for (x = 0; x < w; x++, cp += 4) {
@@ -600,7 +593,7 @@ void IMB_premultiply_alpha(ImBuf *ibuf)
 		IMB_premultiply_rect(ibuf->rect, ibuf->planes, ibuf->x, ibuf->y);
 
 	if (ibuf->rect_float)
-		IMB_premultiply_rect_float(ibuf->rect_float, ibuf->planes, ibuf->x, ibuf->y);
+		IMB_premultiply_rect_float(ibuf->rect_float, ibuf->channels, ibuf->x, ibuf->y);
 }
 
 void IMB_unpremultiply_rect(unsigned int *rect, char planes, int w, int h)
@@ -630,19 +623,12 @@ void IMB_unpremultiply_rect(unsigned int *rect, char planes, int w, int h)
 	}
 }
 
-void IMB_unpremultiply_rect_float(float *rect_float, char planes, int w, int h)
+void IMB_unpremultiply_rect_float(float *rect_float, int channels, int w, int h)
 {
 	float val, *fp;
 	int x, y;
 
-	if (planes == 24) {   /* put alpha at 1.0 */
-		fp = rect_float;
-
-		for (y = 0; y < h; y++)
-			for (x = 0; x < w; x++, fp += 4)
-				fp[3] = 1.0;
-	}
-	else {
+	if (channels == 4) {
 		fp = rect_float;
 		for (y = 0; y < h; y++) {
 			for (x = 0; x < w; x++, fp += 4) {
@@ -665,5 +651,5 @@ void IMB_unpremultiply_alpha(ImBuf *ibuf)
 		IMB_unpremultiply_rect(ibuf->rect, ibuf->planes, ibuf->x, ibuf->y);
 
 	if (ibuf->rect_float)
-		IMB_unpremultiply_rect_float(ibuf->rect_float, ibuf->planes, ibuf->x, ibuf->y);
+		IMB_unpremultiply_rect_float(ibuf->rect_float, ibuf->channels, ibuf->x, ibuf->y);
 }




More information about the Bf-blender-cvs mailing list