示例#1
0
void
copyFunctionArg
    (const Box2i transformWindow,
     size_t firstSample,
     size_t numSamples,
     const FunctionArgPtr &src,
     const Slice &dst)
{
    assert (src->isVarying());

    if (dst.xSampling != 1 || dst.ySampling != 1)
	throwSliceSampling();

    long w = transformWindow.max.x - transformWindow.min.x + 1;
    long x = transformWindow.min.x + modp (firstSample, w);
    long y = transformWindow.min.y + divp (firstSample, w);
    const char *srcData = (src->data());
    size_t srcStride = src->type()->alignedObjectSize();

    switch (dst.type)
    {
      case HALF:

	if (!src->type().cast<HalfType>())
	    throwDstSliceTypeMismatch (src, "HALF");

	for (size_t i = 0; i < numSamples; ++i)
	{
	    *(half *)(dst.base + x * dst.xStride + y * dst.yStride) =
		*(half *)srcData;

	    srcData += srcStride;
	    x += 1;

	    if (x > transformWindow.max.x)
	    {
		y += 1;
		x = transformWindow.min.x;
	    }
	}

	break;

	  case Imf::FLOAT:

	if (!src->type().cast<FloatType>())
	    throwDstSliceTypeMismatch (src, "FLOAT");

	for (size_t i = 0; i < numSamples; ++i)
	{
	    *(float *)(dst.base + x * dst.xStride + y * dst.yStride) =
		*(float *)srcData;

	    srcData += srcStride;
	    x += 1;

	    if (x > transformWindow.max.x)
	    {
		y += 1;
		x = transformWindow.min.x;
	    }
	}

	break;

	  case Imf::UINT:

	if (!src->type().cast<UIntType>())
	    throwDstSliceTypeMismatch (src, "UINT");

	for (size_t i = 0; i < numSamples; ++i)
	{
	    *(unsigned int *)(dst.base + x * dst.xStride + y * dst.yStride) =
		*(unsigned int *)srcData;

	    srcData += srcStride;
	    x += 1;

	    if (x > transformWindow.max.x)
	    {
		y += 1;
		x = transformWindow.min.x;
	    }
	}

	break;
    }
}
void
copyFunctionArg
    (const Box2i transformWindow,
     size_t firstSample,
     size_t numSamples,
     const Slice &src,
     const FunctionArgPtr &dst)
{
    assert (dst->isVarying());

    if (src.xSampling != 1 || src.ySampling != 1)
	throwSliceSampling();

    long w = transformWindow.max.x - transformWindow.min.x + 1;
    long x = transformWindow.min.x + modp (firstSample, w);
    long y = transformWindow.min.y + divp (firstSample, w);
    char *dstData = (dst->data());
    size_t dstStride = dst->type()->alignedObjectSize();

    switch (src.type)
    {
      case HALF:

	if (!dst->type().cast<HalfType>())
	    throwSrcSliceTypeMismatch ("HALF", dst);

	for (size_t i = 0; i < numSamples; ++i)
	{
	    *(half *)dstData =
		*(half *)(src.base + x * src.xStride + y * src.yStride);

	    dstData += dstStride;
	    x += 1;

	    if (x > transformWindow.max.x)
	    {
		y += 1;
		x = transformWindow.min.x;
	    }
	}

	break;

	  case Imf::FLOAT:

	if (!dst->type().cast<FloatType>())
	    throwSrcSliceTypeMismatch ("FLOAT", dst);

	for (size_t i = 0; i < numSamples; ++i)
	{
	    *(float *)dstData =
		*(float *)(src.base + x * src.xStride + y * src.yStride);

	    dstData += dstStride;
	    x += 1;

	    if (x > transformWindow.max.x)
	    {
		y += 1;
		x = transformWindow.min.x;
	    }
	}

	break;

	  case Imf::UINT:

	if (!dst->type().cast<UIntType>())
	    throwSrcSliceTypeMismatch ("UINT", dst);

	for (size_t i = 0; i < numSamples; ++i)
	{
	    *(unsigned int *)dstData =
		*(unsigned int *)(src.base + x * src.xStride + y * src.yStride);

	    dstData += dstStride;
	    x += 1;

	    if (x > transformWindow.max.x)
	    {
		y += 1;
		x = transformWindow.min.x;
	    }
	}

	break;

		default:
		// eat NUM_PIXELTYPES
		break;
    }
}