[Bf-blender-cvs] [9952699] master: Bake-API: use size_t instead of width, height

Dalai Felinto noreply at git.blender.org
Thu Jul 31 05:43:21 CEST 2014


Commit: 9952699978a132e4866acd26817fb9cfec23419d
Author: Dalai Felinto
Date:   Mon Jul 28 14:29:03 2014 -0300
Branches: master
https://developer.blender.org/rB9952699978a132e4866acd26817fb9cfec23419d

Bake-API: use size_t instead of width, height

(original patch by Sergey Sharybin)

Note: RNA API can't use size_t at the moment. Once it does this patch
can be tweaked a bit to fully benefit from size_t larger dimensions.
(right now num_pixels is passed as int)

Reviewed By: sergey, campbellbarton
Differential Revision: https://developer.blender.org/D688

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

M	source/blender/editors/object/object_bake_api.c
M	source/blender/render/extern/include/RE_bake.h
M	source/blender/render/intern/source/bake_api.c
M	source/blender/render/intern/source/external_engine.c

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

diff --git a/source/blender/editors/object/object_bake_api.c b/source/blender/editors/object/object_bake_api.c
index c3bb6d9..57b7bab 100644
--- a/source/blender/editors/object/object_bake_api.c
+++ b/source/blender/editors/object/object_bake_api.c
@@ -178,7 +178,7 @@ static bool write_internal_bake_pixels(
 	void *lock;
 	bool is_float;
 	char *mask_buffer = NULL;
-	const int num_pixels = width * height;
+	const size_t num_pixels = width * height;
 
 	ibuf = BKE_image_acquire_ibuf(image, NULL, &lock);
 
@@ -311,7 +311,7 @@ static bool write_external_bake_pixels(
 	/* margins */
 	if (margin > 0) {
 		char *mask_buffer = NULL;
-		const int num_pixels = width * height;
+		const size_t num_pixels = (size_t)width * (size_t)height;
 
 		mask_buffer = MEM_callocN(sizeof(char) * num_pixels, "Bake Mask");
 		RE_bake_mask_fill(pixel_array, num_pixels, mask_buffer);
@@ -514,10 +514,10 @@ static void build_image_lookup(Main *bmain, Object *ob, BakeImages *bake_images)
 /*
  * returns the total number of pixels
  */
-static int initialize_internal_images(BakeImages *bake_images, ReportList *reports)
+static size_t initialize_internal_images(BakeImages *bake_images, ReportList *reports)
 {
 	int i;
-	int tot_size = 0;
+	size_t tot_size = 0;
 
 	for (i = 0; i < bake_images->size; i++) {
 		ImBuf *ibuf;
@@ -576,7 +576,7 @@ static int bake(
 
 	BakeImages bake_images = {NULL};
 
-	int num_pixels;
+	size_t num_pixels;
 	int tot_materials;
 	int i;
 
@@ -633,7 +633,7 @@ static int bake(
 	else {
 		/* when saving extenally always use the size specified in the UI */
 
-		num_pixels = width * height * bake_images.size;
+		num_pixels = (size_t)width * (size_t)height * bake_images.size;
 
 		for (i = 0; i < bake_images.size; i++) {
 			bake_images.data[i].width = width;
diff --git a/source/blender/render/extern/include/RE_bake.h b/source/blender/render/extern/include/RE_bake.h
index 8f2a0e3..481da45 100644
--- a/source/blender/render/extern/include/RE_bake.h
+++ b/source/blender/render/extern/include/RE_bake.h
@@ -39,7 +39,7 @@ typedef struct BakeImage {
 	struct Image *image;
 	int width;
 	int height;
-	int offset;
+	size_t offset;
 } BakeImage;
 
 typedef struct BakeImages {
@@ -72,35 +72,35 @@ bool RE_bake_has_engine(struct Render *re);
 
 bool RE_bake_engine(
         struct Render *re, struct Object *object, const BakePixel pixel_array[],
-        const int num_pixels, const int depth, const ScenePassType pass_type, float result[]);
+        const size_t num_pixels, const int depth, const ScenePassType pass_type, float result[]);
 
 /* bake.c */
 int RE_pass_depth(const ScenePassType pass_type);
 bool RE_bake_internal(
         struct Render *re, struct Object *object, const BakePixel pixel_array[],
-        const int num_pixels, const int depth, const ScenePassType pass_type, float result[]);
+        const size_t num_pixels, const int depth, const ScenePassType pass_type, float result[]);
 
 bool RE_bake_pixels_populate_from_objects(
         struct Mesh *me_low, BakePixel pixel_array_from[],
-        BakeHighPolyData highpoly[], const int tot_highpoly, const int num_pixels, const bool is_custom_cage,
+        BakeHighPolyData highpoly[], const int tot_highpoly, const size_t num_pixels, const bool is_custom_cage,
         const float cage_extrusion, float mat_low[4][4], float mat_cage[4][4], struct Mesh *me_cage);
 
 void RE_bake_pixels_populate(
         struct Mesh *me, struct BakePixel *pixel_array,
-        const int num_pixels, const struct BakeImages *bake_images, const char *uv_layer);
+        const size_t num_pixels, const struct BakeImages *bake_images, const char *uv_layer);
 
-void RE_bake_mask_fill(const BakePixel pixel_array[], const int num_pixels, char *mask);
+void RE_bake_mask_fill(const BakePixel pixel_array[], const size_t num_pixels, char *mask);
 
 void RE_bake_margin(struct ImBuf *ibuf, char *mask, const int margin);
 
 void RE_bake_normal_world_to_object(
-        const BakePixel pixel_array[], const int num_pixels, const int depth, float result[],
+        const BakePixel pixel_array[], const size_t num_pixels, const int depth, float result[],
         struct Object *ob, const BakeNormalSwizzle normal_swizzle[3]);
 void RE_bake_normal_world_to_tangent(
-        const BakePixel pixel_array[], const int num_pixels, const int depth, float result[],
+        const BakePixel pixel_array[], const size_t num_pixels, const int depth, float result[],
         struct Mesh *me, const BakeNormalSwizzle normal_swizzle[3], float mat[4][4]);
 void RE_bake_normal_world_to_world(
-        const BakePixel pixel_array[], const int num_pixels, const int depth, float result[],
+        const BakePixel pixel_array[], const size_t num_pixels, const int depth, float result[],
         const BakeNormalSwizzle normal_swizzle[3]);
 
 void RE_bake_ibuf_clear(struct Image *image, const bool is_tangent);
diff --git a/source/blender/render/intern/source/bake_api.c b/source/blender/render/intern/source/bake_api.c
index 15ad605..08fea63 100644
--- a/source/blender/render/intern/source/bake_api.c
+++ b/source/blender/render/intern/source/bake_api.c
@@ -120,7 +120,7 @@ static void store_bake_pixel(void *handle, int x, int y, float u, float v)
 	BakePixel *pixel;
 
 	const int width = bd->bk_image->width;
-	const int offset = bd->bk_image->offset;
+	const size_t offset = bd->bk_image->offset;
 	const int i = offset + y * width + x;
 
 	pixel = &bd->pixel_array[i];
@@ -134,9 +134,9 @@ static void store_bake_pixel(void *handle, int x, int y, float u, float v)
 	pixel->dv_dy = bd->dv_dy;
 }
 
-void RE_bake_mask_fill(const BakePixel pixel_array[], const int num_pixels, char *mask)
+void RE_bake_mask_fill(const BakePixel pixel_array[], const size_t num_pixels, char *mask)
 {
-	int i;
+	size_t i;
 	if (!mask)
 		return;
 
@@ -438,10 +438,10 @@ static void mesh_calc_tri_tessface(
 
 bool RE_bake_pixels_populate_from_objects(
         struct Mesh *me_low, BakePixel pixel_array_from[],
-        BakeHighPolyData highpoly[], const int tot_highpoly, const int num_pixels, const bool is_custom_cage,
+        BakeHighPolyData highpoly[], const int tot_highpoly, const size_t num_pixels, const bool is_custom_cage,
         const float cage_extrusion, float mat_low[4][4], float mat_cage[4][4], struct Mesh *me_cage)
 {
-	int i;
+	size_t i;
 	int primitive_id;
 	float u, v;
 	float imat_low [4][4];
@@ -594,11 +594,11 @@ static void bake_differentials(BakeDataZSpan *bd, const float *uv1, const float
 
 void RE_bake_pixels_populate(
         Mesh *me, BakePixel pixel_array[],
-        const int num_pixels, const BakeImages *bake_images, const char *uv_layer)
+        const size_t num_pixels, const BakeImages *bake_images, const char *uv_layer)
 {
 	BakeDataZSpan bd;
-	int i, a;
-	int p_id;
+	size_t i;
+	int a, p_id;
 
 	MTFace *mtface;
 	MFace *mface;
@@ -725,11 +725,11 @@ static void normal_compress(float out[3], const float in[3], const BakeNormalSwi
  * This function converts an object space normal map to a tangent space normal map for a given low poly mesh
  */
 void RE_bake_normal_world_to_tangent(
-        const BakePixel pixel_array[], const int num_pixels, const int depth,
+        const BakePixel pixel_array[], const size_t num_pixels, const int depth,
         float result[], Mesh *me, const BakeNormalSwizzle normal_swizzle[3],
         float mat[4][4])
 {
-	int i;
+	size_t i;
 
 	TriTessFace *triangles;
 
@@ -756,7 +756,7 @@ void RE_bake_normal_world_to_tangent(
 		float tsm[3][3]; /* tangent space matrix */
 		float itsm[3][3];
 
-		int offset;
+		size_t offset;
 		float nor[3]; /* texture normal */
 
 		bool is_smooth;
@@ -834,16 +834,16 @@ void RE_bake_normal_world_to_tangent(
 }
 
 void RE_bake_normal_world_to_object(
-        const BakePixel pixel_array[], const int num_pixels, const int depth,
+        const BakePixel pixel_array[], const size_t num_pixels, const int depth,
         float result[], struct Object *ob, const BakeNormalSwizzle normal_swizzle[3])
 {
-	int i;
+	size_t i;
 	float iobmat[4][4];
 
 	invert_m4_m4(iobmat, ob->obmat);
 
 	for (i = 0; i < num_pixels; i++) {
-		int offset;
+		size_t offset;
 		float nor[3];
 
 		if (pixel_array[i].primitive_id == -1)
@@ -862,13 +862,13 @@ void RE_bake_normal_world_to_object(
 }
 
 void RE_bake_normal_world_to_world(
-        const BakePixel pixel_array[], const int num_pixels, const int depth,
+        const BakePixel pixel_array[], const size_t num_pixels, const int depth,
         float result[], const BakeNormalSwizzle normal_swizzle[3])
 {
-	int i;
+	size_t i;
 
 	for (i = 0; i < num_pixels; i++) {
-		int offset;
+		size_t offset;
 		float nor[3];
 
 		if (pixel_array[i].primitive_id == -1)
@@ -908,12 +908,12 @@ void RE_bake_ibuf_clear(Image *image, const bool is_tangent)
 /**
  * not the real UV, but the internal per-face UV instead
  * I'm using it to test if everything is correct */
-static bool bake_uv(const BakePixel pixel_array[], const int num_pixels, const int depth, float result[])
+static bool bake_uv(const BakePixel pixel_array[], const size_t num_pixels, const int depth, float result[])
 {
-	int i;
+	size_t i;
 
 	for (i=0; i < num_pixels; i++) {
-		int offset = i * depth;
+		size_t offset = i * depth;
 		copy_v2_v2(&result[offset], pixel_array[i].uv);
 	}
 
@@ -922,7 +922,7 @@ static bool bake_uv(const BakePixel pixel_array[], const int num_pixels, const i
 
 bool RE_bake_internal(
         Render *UNUSED(re), Object *UNUSED(object), const BakePixel pixel_array[],
-        const int num_pixels, const int depth, const ScenePassType pass_type, float result[])
+        const size_t num_pixels, const int depth, const ScenePassType pass_type, float result[])
 {
 	switch (pass_type) {
 		case SCE_PASS_UV:
diff --git a/source/blender/render/intern/source/external_engine.c b/source/blender/render/intern/source/external_engine.c
index 58e3038..3c35d50 100644
--- a/source/blender/render/intern/source/external_engine.c
+++ b/source/blender/render/intern/source/external_engine.c
@@ -425,7 +425,7 @@ bool RE_bake_has_engine(Render *re)
 
 bool RE_bake_engine(
         Render *re, Object *object, const BakePixel pixel_array[],
-        const int num_pixels, const int depth,
+        const size_t num_pixels, const int

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list