Example #1
0
static void
HALF_fill(npy_half *buffer, npy_intp length, void *NPY_UNUSED(ignored))
{
    npy_intp i;
    float start = half_to_float(buffer[0]);
    float delta = half_to_float(buffer[1]);

    delta -= start;
    for (i = 2; i < length; ++i) {
        buffer[i] = float_to_half(start + i*delta);
    }
}
Example #2
0
static void
HALF_dot(char *ip1, npy_intp is1, char *ip2, npy_intp is2, char *op, npy_intp n,
           void *NPY_UNUSED(ignore))
{
    float tmp = 0.0f;
    npy_intp i;

    for (i = 0; i < n; i++, ip1 += is1, ip2 += is2) {
        tmp += half_to_float(*((npy_half *)ip1)) *
               half_to_float(*((npy_half *)ip2));
    }
    *((npy_half *)op) = float_to_half(tmp);
}
Example #3
0
	void File::readFloat16BE(float *dest) {
		if (!readSafeCheck(dest)) return;
		
		unsigned short v=0;
		readInt16BE(&v);
		unsigned int f=half_to_float(v);
		*dest = *(float*)&(f);
	}
Example #4
0
static void read_vertex_buffer(el_file_ptr file, float* buffer, const Uint32 vertex_count,
	const Uint32 vertex_size, const Uint32 options, const Uint32 format)
{
	float temp[3];
	Uint16 tmp[3];
	Uint32 i, idx, offset;
	Uint8 color[4];

	idx = 0;

	offset = el_tell(file);

	for (i = 0; i < vertex_count; i++)
	{
		el_seek(file, offset + i * vertex_size, SEEK_SET);

		if (half_uv(format))
		{
			el_read(file, 2 * sizeof(Uint16), tmp);

			temp[0] = half_to_float(SDL_SwapLE16(tmp[0]));
			temp[1] = half_to_float(SDL_SwapLE16(tmp[1]));
		}
		else
		{
			el_read(file, 2 * sizeof(float), temp);

			temp[0] = SwapLEFloat(temp[0]);
			temp[1] = SwapLEFloat(temp[1]);
		}

		buffer[idx + 0] = temp[0];
		buffer[idx + 1] = temp[1];

		idx += 2;

		if (has_secondary_texture_coordinate(options))
		{
			if (half_extra_uv(format))
			{
				el_seek(file, 2 * sizeof(Uint16), SEEK_CUR);
			}
			else
			{
				el_seek(file, 2 * sizeof(float), SEEK_CUR);
			}
		}

		if (has_normal(options))
		{
			if (compressed_normal(format))
			{
				el_read(file, sizeof(Uint16), tmp);

				uncompress_normal(SDL_SwapLE16(tmp[0]), temp);
			}
			else
			{
				el_read(file, 3 * sizeof(float), temp);

				temp[0] = SwapLEFloat(temp[0]);
				temp[1] = SwapLEFloat(temp[1]);
				temp[2] = SwapLEFloat(temp[2]);
			}

			buffer[idx + 0] = temp[0];
			buffer[idx + 1] = temp[1];
			buffer[idx + 2] = temp[2];

			idx += 3;
		}

		if (has_tangent(options))
		{
			if (compressed_normal(format))
			{
				el_seek(file, sizeof(Uint16), SEEK_CUR);
			}
			else
			{
				el_seek(file, 3 * sizeof(float), SEEK_CUR);
			}
		}

		if (half_position(format))
		{
			el_read(file, 3 * sizeof(Uint16), tmp);

			temp[0] = half_to_float(SDL_SwapLE16(tmp[0]));
			temp[1] = half_to_float(SDL_SwapLE16(tmp[1]));
			temp[2] = half_to_float(SDL_SwapLE16(tmp[2]));
		}
		else
		{
			el_read(file, 3 * sizeof(float), temp);

			temp[0] = SwapLEFloat(temp[0]);
			temp[1] = SwapLEFloat(temp[1]);
			temp[2] = SwapLEFloat(temp[2]);
		}

		buffer[idx + 0] = temp[0];
		buffer[idx + 1] = temp[1];
		buffer[idx + 2] = temp[2];

		idx += 3;

		if (has_color(options))
		{
			el_read(file, 4 * sizeof(Uint8), color);
			memcpy(&buffer[idx], color, 4 * sizeof(Uint8));
			idx += 1;
		}
	}
}