Here is the description of pixel problem for the forums:
What is the proper way to set up a matrix with transform_world() for doing a simple copy from a src_world to a dst_world mapping pixel (0,0) of the source to pixel (0,0) of the destination?
It would seem that the correct way to do this is to use an identity matrix however...
I have a strange "off-by-one pixel" issue that I'm seeing w/ transform_world(). Basically when I pass (essentially) the identity matrix to this function and attempt to copy from a source image to my destination image, I get a result that is off-by-one-pixel.
In AE, create a new composition w/ a single layer:
1) New Composition
2) New Layer -> Solid -> Make Composition Size -> OK
Then add an effect which copies from a user-specified layer using transform_world(). The matrix that I pass is just a scaling matrix to account for aspect ratio -- there is no translation.
My effect does the following:
const PF_InData* data = context->data;
PF_Err err = PF_Err_NONE;
compositeMode.xfer = PF_Xfer_COPY;
compositeMode.rand_seed = 0; // not used for PF_Xfer_COPY
compositeMode.opacity = PF_MAX_CHAN8; // 0 - 255
compositeMode.rgb_only = FALSE;
compositeMode.opacitySu = PF_MAX_CHAN16; // for deep color only
// Load the transformation matrix.
// Aspect ratio scaling
float downsamplex = data->downsample_x.den / (float)data->downsample_x.num;
float downsampley = data->downsample_y.den / (float)data->downsample_y.num;
float aspectratio = data->pixel_aspect_ratio.num / (float)data->pixel_aspect_ratio.den;
ComputeScaleMatrix( 1.0f/(aspectratio * downsamplex),
MultiplyMatrix( &scale, &mat, &mat );
dstRect.bottom = (A_short)data->height-1;
dstRect.top = 0;
dstRect.left = 0;
dstRect.right = (A_short)data->width-1;
Even if I use a pure identity matrix, the result is off-by-one. The SDK guide is not too clear on where the center of a pixel is located
So what is the correct way to setup a matrix for the mapping I desire? Is it necessary to apply a matrix that translates by (-0.5,-0.5) or (-1,-1). Indeed it seems that applying a matrix that transforms by (-1,-1) produces the expected mapping result but I don't understand why this would be the case
You can see on the attached picture the one pixel black line around my sample
I checked with my code, and it seems i don't get an offset like you describe when using transform_world().
such an offset occurs however when you sample pixels.
the position of (0,0) is the center of the top-left pixel, and not the top-left corner of that pixel,
so when you sample a pixel and composite it back to the same coordinates, you get a (0.5,0.5) offset.
it's in the sdk documentation.
another possible reason would be a wrong source or destination rectangle for the composition operation.
if it's neither of those, then i havn't a clue.