Hi,
When your kernel reads pixel at a location different from the active
pixel, make sure:
1) To use the destCoord() as destination coordinate and sample(image,
samplerTransform(image, ...))
2) You define a region of interest (ROI) for your kernels. Check out
examples in /Developer/Examples/Quartz Composer/Compositions/Core
Image Filters and look at the Core Image documentation.
Kevin
On Dec 10, 2007, at 4:49 PM, Alex Drinkwater wrote:
I'm having some problems applying CICrop using
JavaScript in a Core Image Filter patch.
The Core Image Filter code is:
= = = Kernel Code = = =
// SUPPORTING FUNCTIONS
// Used by makeStrip (returns coord of pixel to be
sampled)
vec2 sampleHere(vec2 xy, float cellWidth, float
cellHeight, float cols)
{
// Calculate Row and Column for current iteration
float rowNum = ceil(xy.x / cols);
float colNum = xy.x - ((rowNum - 1.0) * cols);
// Calculate position of pixel to copy
xy.x = colNum * cellWidth;
xy.y = rowNum * cellHeight;
// Return coord for sampler
return xy;
}
// MAIN KERNEL FUNCTIONS (RETURN IMAGES)
// Pixellates image with exact dimensions for pixel
tiles' width and height
kernel vec4 xy_pixellate(sampler Image, float
CellWidth, float CellHeight)
{
// Current pixel location
vec2 xy = samplerCoord(Image);
// Left and right of tile
float x1 = floor(xy.x / CellWidth) * CellWidth;
float x2 = (ceil(xy.x / CellWidth)) * CellWidth;
// Top and bottom of tile
float y1 = (floor(xy.y / CellHeight) * CellHeight);
float y2 = (ceil(xy.y / CellHeight)) * CellHeight;
// Average left and right pixels
vec4 avgX = (sample(Image, vec2(x1,
y1))+(sample(Image, vec2(x2, y1)))) / 2.0;
// Average top and bottom pixels
vec4 avgY = (sample(Image, vec2(x1,
y1))+(sample(Image, vec2(x1, y2)))) / 2.0;
// Centre pixel
vec4 avgC = sample(Image, vec2(x1+(CellWidth/2.0),
y2+(CellHeight/2.0))); // Average the averages +
centre
vec4 outPix = (avgX+avgY+avgC) / 3.0;
// Output
return outPix;
}
// Creates 1-pixel-high strip from input image
kernel vec4 makeStrip(sampler Image, float CellWidth,
float CellHeight, float CellNum, float Cols)
{
// Current pixel position
vec2 xy = samplerCoord(Image);
vec2 samplePos = (xy.x > CellNum) ? vec2(0.0,0.0) :
(xy.y > 10.0) ? vec2(0.0,0.0) : sampleHere(xy,
CellWidth, CellHeight, Cols);
// Output
return sample(Image, vec2(samplePos));
}
= = = = JavaScript = = = = =
function __image main(__image Image, __number Rows,
__number Cols)
{
// CREATE CONTROL VALUES
// Input image dimensions
var Width = Image.extent.width;
var Height = Image.extent.height;
// Dimensions of Pixellation cells
var CellWidth = Width / (Math.ceil(Rows));
var CellHeight = Height / (Math.ceil(Cols));
// Total number of cells
var CellNum = Rows * Cols;
// IMAGE OPERATIONS
// Pixellate image
imagePixellated =
xy_pixellate.apply(Image.definition, null, Image,
CellWidth, CellHeight);
// Create strip
imageStrip =
makeStrip.apply(imagePixellated.definition, null,
imagePixellated, CellWidth, CellHeight, CellNum,
Cols);
// Crop
imageCropped = Filter.Crop(imageStrip, new Vec(0.0,
0.0, CellNum, 1.0));
// Output
return imageCropped;
}
The idea is, the input image is pixellated, then each
pixel-tile (or cell) is sampled, and a horizontal
strip of pixels is created from the color-values of
each tile. For some reason, everything except the
final stage seems to work.
Am I doing anything obviously wrong here?
If I return imagePixellated, everything looks fine.
If I return imageCropped, I get the expected result.
I just can't work out why I can't crop the image as I
need to.
Is it something to do with the 'Define output image
Domain of Definition as union of input images DODs'
option (which is ticked, but greyed-out)?
Anyone any thoughts?
I've attached the pesky file concerned.
Cheers guys,
alx
http://www.toneburst.net
http://machinesdontcare.wordpress.com
__________________________________________________________
Sent from Yahoo! Mail - a smarter inbox http://uk.mail.yahoo.com
<cubeFieldPreprocessor.qtz.zip>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartzcomposer-dev mailing list ([email protected]
)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartzcomposer-dev/kquennesson%40apple.com
This email sent to [EMAIL PROTECTED]
-----------
Kevin Quennesson
Quartz Composer Team
Apple Inc.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartzcomposer-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartzcomposer-dev/archive%40mail-archive.com
This email sent to [EMAIL PROTECTED]