Ejemplo n.º 1
0
static status_t
add_to_message(TReadHelper& source, BMessage& target, tiff_tag& tag,
	const char* name, type_code type)
{
	type_code defaultType = B_INT32_TYPE;
	double doubleValue = 0.0;
	int32 intValue = 0;

	switch (tag.type) {
		case TIFF_STRING_TYPE:
		{
			if (type != B_ANY_TYPE && type != B_STRING_TYPE)
				return B_BAD_VALUE;

			char* buffer = (char*)malloc(tag.length);
			if (buffer == NULL)
				return B_NO_MEMORY;

			source(buffer, tag.length);

			// remove trailing spaces
			int32 i = tag.length;
			while ((--i > 0 && isspace(buffer[i])) || !buffer[i]) {
				buffer[i] = '\0';
			}

			status_t status = target.AddString(name, buffer);
			free(buffer);

			return status;
		}

		case TIFF_UNDEFINED_TYPE:
		{
			if (type != B_ANY_TYPE && type != B_STRING_TYPE && type != B_RAW_TYPE)
				return B_BAD_VALUE;

			char* buffer = (char*)malloc(tag.length);
			if (buffer == NULL)
				return B_NO_MEMORY;

			source(buffer, tag.length);

			status_t status;
			if (type == B_STRING_TYPE)
				status = target.AddString(name, buffer);
			else
				status = target.AddData(name, B_RAW_TYPE, buffer, tag.length);

			free(buffer);

			return status;
		}

		// unsigned
		case TIFF_UINT8_TYPE:
			intValue = source.Next<uint8>();
			break;
		case TIFF_UINT16_TYPE:
			defaultType = B_INT32_TYPE;
			intValue = source.Next<uint16>();
			break;
		case TIFF_UINT32_TYPE:
			defaultType = B_INT32_TYPE;
			intValue = source.Next<uint32>();
			break;
		case TIFF_UFRACTION_TYPE:
		{
			defaultType = B_DOUBLE_TYPE;
			double value = source.Next<uint32>();
			doubleValue = value / source.Next<uint32>();
			break;
		}

		// signed
		case TIFF_INT8_TYPE:
			intValue = source.Next<int8>();
			break;
		case TIFF_INT16_TYPE:
			intValue = source.Next<int16>();
			break;
		case TIFF_INT32_TYPE:
			intValue = source.Next<int32>();
			break;
		case TIFF_FRACTION_TYPE:
		{
			defaultType = B_DOUBLE_TYPE;
			double value = source.Next<int32>();
			doubleValue = value / source.Next<int32>();
			break;
		}

		// floating point
		case TIFF_FLOAT_TYPE:
			defaultType = B_FLOAT_TYPE;
			doubleValue = source.Next<float>();
			break;
		case TIFF_DOUBLE_TYPE:
			defaultType = B_DOUBLE_TYPE;
			doubleValue = source.Next<double>();
			break;

		default:
			return B_BAD_VALUE;
	}

	if (defaultType == B_INT32_TYPE)
		doubleValue = intValue;
	else
		intValue = int32(doubleValue + 0.5);

	if (type == B_ANY_TYPE)
		type = defaultType;

	switch (type) {
		case B_INT32_TYPE:
			return target.AddInt32(name, intValue);
		case B_FLOAT_TYPE:
			return target.AddFloat(name, doubleValue);
		case B_DOUBLE_TYPE:
			return target.AddDouble(name, doubleValue);

		default:
			return B_BAD_VALUE;
	}
}
Ejemplo n.º 2
0
status_t add_rel_time(BMessage& msg, const char* name, AmTime timeVal)
{
	return msg.AddDouble(name, double(timeVal)/PPQN);
}