Exemplo n.º 1
0
bool MCImageGetMetafileGeometry(IO_handle p_stream, uindex_t &r_width, uindex_t &r_height)
{
	bool t_success = true;
	bool t_is_meta = false;

	uindex_t t_stream_pos = MCS_tell(p_stream);
	uint8_t t_head[DRAWING_HEAD_SIZE];
	uindex_t t_size = DRAWING_HEAD_SIZE;

	t_success = IO_NORMAL == MCS_readfixed(t_head, t_size, p_stream) &&
		t_size == DRAWING_HEAD_SIZE;
    
   /* A drawing's header is of the form:
     *   0: LCD\0
     *   4: width
     *   8: height
     */
	if (t_success &&
        memcmp(t_head, "LCD\0", 4) == 0)
	{
        float t_width = *(const float *)(t_head + 4);
        float t_height = *(const float *)(t_head + 8);
        
        /* The engine deals with integer bounds on sub-pixel co-ords, so
         * take the ceiling of the computer (float) width/height. */
        r_width = (uindex_t)ceilf(t_width);
        r_height = (uindex_t)ceilf(t_height);
        
        t_is_meta = true;
    }
    
	MCS_seek_set(p_stream, t_stream_pos);
    
    return t_success && t_is_meta;
}
Exemplo n.º 2
0
IO_stat IO_read_to_eof(IO_handle stream, MCExecPoint &ep)
{
	uint4 nread;
	nread = (uint4)MCS_fsize(stream) - (uint4)MCS_tell(stream);
	char *dptr = ep.getbuffer(nread);
	MCS_read(dptr, 1, nread, stream);
	ep.setlength(nread);
	return IO_NORMAL;
}
Exemplo n.º 3
0
bool read_all(IO_handle p_stream, uint8_t *&r_data, uindex_t &r_data_size)
{
	bool t_success = true;

	uint8_t *t_buffer = nil;
	uindex_t t_size = 0;

	t_size = MCS_fsize(p_stream) - MCS_tell(p_stream);

	t_success = MCMemoryAllocate(t_size, t_buffer);
	if (t_success)
		t_success = IO_NORMAL == MCS_readfixed(t_buffer, t_size, p_stream);

	if (t_success)
	{
		r_data = t_buffer;
		r_data_size = t_size;
	}
	else
		MCMemoryDeallocate(t_buffer);

	return t_success;
}
Exemplo n.º 4
0
bool MCImageGetMetafileGeometry(IO_handle p_stream, uindex_t &r_width, uindex_t &r_height)
{
	bool t_success = true;
	bool t_is_meta = false;

	uindex_t t_stream_pos = MCS_tell(p_stream);
	uint8_t t_head[EMF_HEAD_SIZE];
	uindex_t t_size = META_HEAD_SIZE;

	t_success = IO_NORMAL == MCS_read(t_head, sizeof(uint8_t), t_size, p_stream) &&
		t_size == META_HEAD_SIZE;

	if (t_success)
	{
		// graphics metafile (wmf)
		if (memcmp(t_head, "\xD7\xCD\xC6\x9A", 4) == 0)
		{
			int16_t *t_bounds = (int16_t *)&t_head[6];
			r_width = ((t_bounds[2] - t_bounds[0]) * 72 + t_bounds[4] - 1) / t_bounds[4];
			r_height = ((t_bounds[3] - t_bounds[1]) * 72 + t_bounds[4] - 1) / t_bounds[4];
			t_is_meta = true;
		}
		// win32 metafile (emf)
		else if (memcmp(&t_head[40], "\x20\x45\x4D\x46", 4) == 0)
		{
			t_size = EMF_HEAD_SIZE;
			t_success = IO_NORMAL == MCS_seek_set(p_stream, t_stream_pos) &&
				IO_NORMAL == MCS_read(t_head, sizeof(uint8_t), t_size, p_stream) &&
				t_size == EMF_HEAD_SIZE;

			if (t_success)
			{
				int32_t *t_bounds;
				t_bounds = (int32_t*)&t_head[72];
				r_width = t_bounds[0];
				r_height = t_bounds[1];
				t_is_meta = true;
			}
		}
		else
		{
			uindex_t t_offset = 0;
			if (memcmp(t_head, "\0\0\0\0\0\0\0\0", 8) == 0)
			{
				t_size = META_HEAD_SIZE;
				t_offset = 512;
				t_success = IO_NORMAL == MCS_seek_set(p_stream, t_stream_pos + t_offset) &&
					IO_NORMAL == MCS_read(t_head, sizeof(uint8_t), t_size, p_stream) &&
					t_size == META_HEAD_SIZE;
			}

			// PICT file
			if (t_success && memcmp(&t_head[10], "\0\021\002\377", 4) == 0)
			{
				uint16_t *t_bounds = (uint16_t *)t_head;
				r_width = swap_uint2(&t_bounds[4]) - swap_uint2(&t_bounds[2]);
				r_height = swap_uint2(&t_bounds[3]) - swap_uint2(&t_bounds[1]);
				t_is_meta = true;
				t_stream_pos += t_offset;
			}
		}
	}

	MCS_seek_set(p_stream, t_stream_pos);

	return t_success && t_is_meta;
}