Commit: 3ce594226eaaf332bb30ea0d193c9f9d930711b9
Author: Bastien Montagne
Date:   Tue Nov 4 10:06:08 2014 +0100
Branches: master
https://developer.blender.org/rB3ce594226eaaf332bb30ea0d193c9f9d930711b9

Add missing `CustomData_duplicate_referenced_layer_n` and deduplicate code.

CustomData_duplicate_referenced_layer_n not used in master currently, but need 
it
in mesh tranfer branch.

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

M       source/blender/blenkernel/BKE_customdata.h
M       source/blender/blenkernel/intern/customdata.c

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

diff --git a/source/blender/blenkernel/BKE_customdata.h 
b/source/blender/blenkernel/BKE_customdata.h
index 51c7894..30a5889 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -173,6 +173,7 @@ int CustomData_number_of_layers_typemask(const struct 
CustomData *data, CustomDa
 /* duplicate data of a layer with flag NOFREE, and remove that flag.
  * returns the layer data */
 void *CustomData_duplicate_referenced_layer(struct CustomData *data, const int 
type, const int totelem);
+void *CustomData_duplicate_referenced_layer_n(struct CustomData *data, const 
int type, const int n, const int totelem);
 void *CustomData_duplicate_referenced_layer_named(struct CustomData *data,
                                                   const int type, const char 
*name, const int totelem);
 bool CustomData_is_referenced_layer(struct CustomData *data, int type);
diff --git a/source/blender/blenkernel/intern/customdata.c 
b/source/blender/blenkernel/intern/customdata.c
index 7684c5a..fb0135b 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -1873,14 +1873,14 @@ int CustomData_number_of_layers_typemask(const 
CustomData *data, CustomDataMask
        return number;
 }
 
-void *CustomData_duplicate_referenced_layer(struct CustomData *data, const int 
type, const int totelem)
+static void *customData_duplicate_referenced_layer_index(CustomData *data, 
const int type,
+                                                         const int 
layer_index, const int totelem)
 {
        CustomDataLayer *layer;
-       int layer_index;
 
-       /* get the layer index of the first layer of type */
-       layer_index = CustomData_get_active_layer_index(data, type);
-       if (layer_index == -1) return NULL;
+       if (layer_index == -1) {
+               return NULL;
+       }
 
        layer = &data->layers[layer_index];
 
@@ -1896,8 +1896,9 @@ void *CustomData_duplicate_referenced_layer(struct 
CustomData *data, const int t
                        typeInfo->copy(layer->data, dest_data, totelem);
                        layer->data = dest_data;
                }
-               else
+               else {
                        layer->data = MEM_dupallocN(layer->data);
+               }
 
                layer->flag &= ~CD_FLAG_NOFREE;
        }
@@ -1905,37 +1906,37 @@ void *CustomData_duplicate_referenced_layer(struct 
CustomData *data, const int t
        return layer->data;
 }
 
-void *CustomData_duplicate_referenced_layer_named(struct CustomData *data,
-                                                  const int type, const char 
*name, const int totelem)
+void *CustomData_duplicate_referenced_layer(CustomData *data, const int type, 
const int totelem)
 {
        CustomDataLayer *layer;
        int layer_index;
 
-       /* get the layer index of the desired layer */
-       layer_index = CustomData_get_named_layer_index(data, type, name);
-       if (layer_index == -1) return NULL;
+       /* get the layer index of the first layer of type */
+       layer_index = CustomData_get_active_layer_index(data, type);
 
-       layer = &data->layers[layer_index];
+       return customData_duplicate_referenced_layer_index(data, type, 
layer_index, totelem);
+}
 
-       if (layer->flag & CD_FLAG_NOFREE) {
-               /* MEM_dupallocN won't work in case of complex layers, like e.g.
-                * CD_MDEFORMVERT, which has pointers to allocated data...
-                * So in case a custom copy function is defined, use it!
-                */
-               const LayerTypeInfo *typeInfo = layerType_getInfo(layer->type);
+void *CustomData_duplicate_referenced_layer_n(CustomData *data, const int 
type, const int n, const int totelem)
+{
+       CustomDataLayer *layer;
+       int layer_index;
 
-               if (typeInfo->copy) {
-                       char *dest_data = MEM_mallocN(typeInfo->size * totelem, 
"CD duplicate ref layer");
-                       typeInfo->copy(layer->data, dest_data, totelem);
-                       layer->data = dest_data;
-               }
-               else
-                       layer->data = MEM_dupallocN(layer->data);
+       /* get the layer index of the desired layer */
+       layer_index = CustomData_get_layer_index_n(data, type, n);
 
-               layer->flag &= ~CD_FLAG_NOFREE;
-       }
+       return customData_duplicate_referenced_layer_index(data, type, 
layer_index, totelem);
+}
 
-       return layer->data;
+void *CustomData_duplicate_referenced_layer_named(CustomData *data, const int 
type, const char *name, const int totelem)
+{
+       CustomDataLayer *layer;
+       int layer_index;
+
+       /* get the layer index of the desired layer */
+       layer_index = CustomData_get_named_layer_index(data, type, name);
+
+       return customData_duplicate_referenced_layer_index(data, type, 
layer_index, totelem);
 }
 
 bool CustomData_is_referenced_layer(struct CustomData *data, int type)

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to