Пример #1
0
static void set_ffmpeg_property_option(AVCodecContext *c, IDProperty *prop)
{
	char name[128];
	char *param;
	const AVOption *rv = NULL;

	PRINT("FFMPEG expert option: %s: ", prop->name);

	BLI_strncpy(name, prop->name, sizeof(name));

	param = strchr(name, ':');

	if (param) {
		*param++ = 0;
	}

	switch (prop->type) {
		case IDP_STRING:
			PRINT("%s.\n", IDP_String(prop));
			av_set_string3(c, prop->name, IDP_String(prop), 1, &rv);
			break;
		case IDP_FLOAT:
			PRINT("%g.\n", IDP_Float(prop));
			rv = av_set_double(c, prop->name, IDP_Float(prop));
			break;
		case IDP_INT:
			PRINT("%d.\n", IDP_Int(prop));

			if (param) {
				if (IDP_Int(prop)) {
					av_set_string3(c, name, param, 1, &rv);
				}
				else {
					return;
				}
			}
			else {
				rv = av_set_int(c, prop->name, IDP_Int(prop));
			}
			break;
	}

	if (!rv) {
		PRINT("ffmpeg-option not supported: %s! Skipping.\n", prop->name);
	}
}
Пример #2
0
static void set_ffmpeg_property_option(AVCodecContext *c, IDProperty *prop, AVDictionary **dictionary)
{
	char name[128];
	char *param;

	PRINT("FFMPEG expert option: %s: ", prop->name);

	BLI_strncpy(name, prop->name, sizeof(name));

	param = strchr(name, ':');

	if (param) {
		*param++ = 0;
	}

	switch (prop->type) {
		case IDP_STRING:
			PRINT("%s.\n", IDP_String(prop));
			av_dict_set(dictionary, name, IDP_String(prop), 0);
			break;
		case IDP_FLOAT:
			PRINT("%g.\n", IDP_Float(prop));
			ffmpeg_dict_set_float(dictionary, prop->name, IDP_Float(prop));
			break;
		case IDP_INT:
			PRINT("%d.\n", IDP_Int(prop));

			if (param) {
				if (IDP_Int(prop)) {
					av_dict_set(dictionary, name, param, 0);
				}
				else {
					return;
				}
			}
			else {
				ffmpeg_dict_set_int(dictionary, prop->name, IDP_Int(prop));
			}
			break;
	}
}
static float get_property(Bone *bone, const char *key, float def)
{
	float result = def;
	if (bone->prop) {
		IDProperty *property = IDP_GetPropertyFromGroup(bone->prop, key);
		if (property) {
			switch (property->type) {
				case IDP_INT:
					result = (float)(IDP_Int(property));
					break;
				case IDP_FLOAT:
					result = (float)(IDP_Float(property));
					break;
				case IDP_DOUBLE:
					result = (float)(IDP_Double(property));
					break;
				default:
					result = def;
			}
		}
	}
	return result;
}
Пример #4
0
static PyObject *idprop_py_from_idp_int(const IDProperty *prop)
{
    return PyLong_FromLong((long)IDP_Int(prop));
}
Пример #5
0
/* use for both array and group */
static Py_hash_t BPy_IDGroup_hash(BPy_IDProperty *self)
{
    return _Py_HashPointer(self->prop);
}

static PyObject *BPy_IDGroup_repr(BPy_IDProperty *self)
{
    return PyUnicode_FromFormat("<bpy id prop: owner=\"%s\", name=\"%s\", address=%p>",
                                self->id ? self->id->name : "<NONE>", self->prop->name, self->prop);
}

PyObject *BPy_IDGroup_WrapData(ID *id, IDProperty *prop, IDProperty *parent)
{
    switch (prop->type) {
    case IDP_STRING:
        return idprop_py_from_idp_string(prop);
    case IDP_INT:
        return idprop_py_from_idp_int(prop);
    case IDP_FLOAT:
        return idprop_py_from_idp_float(prop);
    case IDP_DOUBLE:
        return idprop_py_from_idp_double(prop);
    case IDP_GROUP:
        return idprop_py_from_idp_group(id, prop, parent);
    case IDP_ARRAY:
        return idprop_py_from_idp_array(id, prop);
    case IDP_IDPARRAY:
        return idprop_py_from_idp_idparray(id, prop); /* this could be better a internal type */
    default:
        Py_RETURN_NONE;
    }
}

#if 0 /* UNUSED, currently assignment overwrites into new properties, rather than setting in-place */
static int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject *value)
{
    switch (prop->type) {
    case IDP_STRING:
    {
        char *st;
        if (!PyUnicode_Check(value)) {
            PyErr_SetString(PyExc_TypeError, "expected a string!");
            return -1;
        }
        /* NOTE: if this code is enabled, bytes support needs to be added */
#ifdef USE_STRING_COERCE
        {
            int alloc_len;
            PyObject *value_coerce = NULL;

            st = (char *)PyC_UnicodeAsByte(value, &value_coerce);
            alloc_len = strlen(st) + 1;

            st = _PyUnicode_AsString(value);
            IDP_ResizeArray(prop, alloc_len);
            memcpy(IDP_Array(prop), st, alloc_len);
            Py_XDECREF(value_coerce);
        }
#else
        st = _PyUnicode_AsString(value);
        IDP_ResizeArray(prop, strlen(st) + 1);
        strcpy(IDP_Array(prop), st);
#endif

        return 0;
    }

    case IDP_INT:
    {
        int ivalue = PyLong_AsSsize_t(value);
        if (ivalue == -1 && PyErr_Occurred()) {
            PyErr_SetString(PyExc_TypeError, "expected an int type");
            return -1;
        }
        IDP_Int(prop) = ivalue;
        break;
    }
    case IDP_FLOAT:
    {
        float fvalue = (float)PyFloat_AsDouble(value);
        if (fvalue == -1 && PyErr_Occurred()) {
            PyErr_SetString(PyExc_TypeError, "expected a float");
            return -1;
        }
        IDP_Float(self->prop) = fvalue;
        break;
    }
    case IDP_DOUBLE:
    {
        double dvalue = PyFloat_AsDouble(value);
        if (dvalue == -1 && PyErr_Occurred()) {
            PyErr_SetString(PyExc_TypeError, "expected a float");
            return -1;
        }
        IDP_Double(self->prop) = dvalue;
        break;
    }
    default:
        PyErr_SetString(PyExc_AttributeError, "attempt to set read-only attribute!");
        return -1;
    }
    return 0;
}
Пример #6
0
int BKE_ffmpeg_property_add_string(RenderData *rd, const char *type, const char *str)
{
	AVCodecContext c;
	const AVOption *o = 0;
	const AVOption *p = 0;
	char name_[128];
	char *name;
	char *param;
	IDProperty *prop = NULL;
	
	avcodec_get_context_defaults3(&c, NULL);

	strncpy(name_, str, sizeof(name_));

	name = name_;
	while (*name == ' ') name++;

	param = strchr(name, ':');

	if (!param) {
		param = strchr(name, ' ');
	}
	if (param) {
		*param++ = 0;
		while (*param == ' ') param++;
	}
	
	o = av_opt_find(&c, name, NULL, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
	if (!o) {
		PRINT("Ignoring unknown expert option %s\n", str);
		return 0;
	}
	if (param && o->type == AV_OPT_TYPE_CONST) {
		return 0;
	}
	if (param && o->type != AV_OPT_TYPE_CONST && o->unit) {
		p = av_opt_find(&c, param, o->unit, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
		if (p) {
			prop = BKE_ffmpeg_property_add(rd, (char *) type, p, o);
		}
		else {
			PRINT("Ignoring unknown expert option %s\n", str);
		}
	}
	else {
		prop = BKE_ffmpeg_property_add(rd, (char *) type, o, NULL);
	}
		

	if (!prop) {
		return 0;
	}

	if (param && !p) {
		switch (prop->type) {
			case IDP_INT:
				IDP_Int(prop) = atoi(param);
				break;
			case IDP_FLOAT:
				IDP_Float(prop) = atof(param);
				break;
			case IDP_STRING:
				strncpy(IDP_String(prop), param, prop->len);
				break;
		}
	}
	return 1;
}
Пример #7
0
int ffmpeg_property_add_string(RenderData *rd, const char * type, const char * str)
{
	AVCodecContext c;
	const AVOption * o = 0;
	const AVOption * p = 0;
	char name_[128];
	char * name;
	char * param;
	IDProperty * prop;
	
	avcodec_get_context_defaults(&c);

	strncpy(name_, str, sizeof(name_));

	name = name_;
	while (*name == ' ') name++;

	param = strchr(name, ':');

	if (!param) {
		param = strchr(name, ' ');
	}
	if (param) {
		*param++ = 0;
		while (*param == ' ') param++;
	}
	
	o = my_av_find_opt(&c, name, NULL, 0, 0);	
	if (!o) {
		return 0;
	}
	if (param && o->type == FF_OPT_TYPE_CONST) {
		return 0;
	}
	if (param && o->type != FF_OPT_TYPE_CONST && o->unit) {
		p = my_av_find_opt(&c, param, o->unit, 0, 0);	
		prop = ffmpeg_property_add(rd,
			(char*) type, p - c.av_class->option, 
			o - c.av_class->option);
	} else {
		prop = ffmpeg_property_add(rd,
			(char*) type, o - c.av_class->option, 0);
	}
		

	if (!prop) {
		return 0;
	}

	if (param && !p) {
		switch (prop->type) {
		case IDP_INT:
			IDP_Int(prop) = atoi(param);
			break;
		case IDP_FLOAT:
			IDP_Float(prop) = atof(param);
			break;
		case IDP_STRING:
			strncpy(IDP_String(prop), param, prop->len);
			break;
		}
	}
	return 1;
}