Пример #1
0
static PCPATCH_UNCOMPRESSED *
pc_patch_uncompressed_filter(const PCPATCH_UNCOMPRESSED *pu, const PCBITMAP *map)
{
	int i = 0, j = 0;
	size_t sz = pu->schema->size;
	PCPATCH_UNCOMPRESSED *fpu = pc_patch_uncompressed_make(pu->schema, map->nset);
	uint8_t *buf = pu->data;
	uint8_t *fbuf = fpu->data;

	assert(map->npoints == pu->npoints);

	while ( i < pu->npoints )
	{
		if ( pc_bitmap_get(map, i) )
		{
			memcpy(fbuf, buf, sz);
			fbuf += sz;
		}
		buf += sz;
		i++;
	}

	fpu->maxpoints = fpu->npoints = map->nset;

	if ( PC_FAILURE == pc_patch_uncompressed_compute_extent(fpu) )
	{
		pcerror("%s: failed to compute patch extent", __func__);
		return NULL;
	}

	if ( PC_FAILURE == pc_patch_uncompressed_compute_stats(fpu) )
	{
		pcerror("%s: failed to compute patch stats", __func__);
		return NULL;
	}

	return fpu;
}
PCPATCH_UNCOMPRESSED *
pc_patch_uncompressed_from_pointlist(const PCPOINTLIST *pl)
{
	PCPATCH_UNCOMPRESSED *pch;
	const PCSCHEMA *s;
	PCPOINT *pt;
	uint8_t *ptr;
	int i;
	uint32_t numpts;

	if ( ! pl )
	{
		pcerror("%s: null PCPOINTLIST passed in", __func__);
		return NULL;
	}

	numpts = pl->npoints;
	if ( ! numpts )
	{
		pcerror("%s: zero size PCPOINTLIST passed in", __func__);
		return NULL;
	}

	/* Assume the first PCSCHEMA is the same as the rest for now */
	/* We will check this as we go along */
	pt = pc_pointlist_get_point(pl, 0);
	s = pt->schema;

	/* Confirm we have a schema pointer */
	if ( ! s )
	{
		pcerror("%s: null schema encountered", __func__);
		return NULL;
	}

	/* Confirm width of a point data buffer */
	if ( ! s->size )
	{
		pcerror("%s: invalid point size", __func__);
		return NULL;
	}

	/* Make our own data area */
	pch = pcalloc(sizeof(PCPATCH_UNCOMPRESSED));
	pch->datasize = s->size * numpts;
	pch->data = pcalloc(pch->datasize);
	ptr = pch->data;

	/* Initialize bounds */
	pc_bounds_init(&(pch->bounds));

	/* Set up basic info */
	pch->readonly = PC_FALSE;
	pch->maxpoints = numpts;
	pch->type = PC_NONE;
	pch->schema = s;
	pch->npoints = 0;

	for ( i = 0; i < numpts; i++ )
	{
		pt = pc_pointlist_get_point(pl, i);
		if ( pt )
		{
			if ( pt->schema->pcid != s->pcid )
			{
				pcerror("%s: points do not share a schema", __func__);
				return NULL;
			}
			memcpy(ptr, pt->data, s->size);
			pch->npoints++;
			ptr += s->size;
		}
		else
		{
			pcwarn("%s: encountered null point", __func__);
		}
	}

	if ( PC_FAILURE == pc_patch_uncompressed_compute_extent(pch) )
	{
		pcerror("%s: failed to compute patch extent", __func__);
		return NULL;
	}

	if ( PC_FAILURE == pc_patch_uncompressed_compute_stats(pch) )
	{
		pcerror("%s: failed to compute patch stats", __func__);
		return NULL;
	}

	return pch;
}