Core Image Conundrum

cybero's picture

I wonder why this Core Image kernel code isn't working for me. It was found on the fromaremotevillage blog. http://fromaremotevillage.blogspot.com/2007/03/cocoa-application-with-cu...

/*
A Core Image kernel routine that computes a convolution effect.
The code looks up the source pixel in the sampler and then multiplies it by the value passed to the routine.
*/
 
kernel vec4 Convolution3by3(sampler image,
float r00, float r01, float r02,
float r10, float r11, float r12,
float r20, float r21, float r22)
{
  vec2 loc;
  vec4 result = vec4(0,0,0,0);
  //0,0 in my mind is left and up.
  loc = vec2(1.0,0.0);
  vec4 p12 = unpremultiply(sample(image, (samplerCoord(image) + loc) ));
  result.rgb += p12.rgb * r12;
 
  loc = vec2(-1.0,-1.0);
  vec4 p20 = unpremultiply(sample(image, (samplerCoord(image) + loc) ));
  result.rgb += p20.rgb * r20;
 
  loc = vec2(0.0,-1.0);
  vec4 p21 = unpremultiply(sample(image, (samplerCoord(image) + loc) ));
  result.rgb += p21.rgb * r21;
 
  loc = vec2(1.0,-1.0);
  vec4 p22 = unpremultiply(sample(image, (samplerCoord(image) + loc) ));
  result.rgb += p22.rgb * r22;
 
  result = premultiply( result );
  return result;
}

Currently produces nothing more than blank empty space when run in QC 4.5 on Lion. Haven't tried it in Snow or earlier as yet.

PreviewAttachmentSize
CoreImageConundrumConvolution3by3.qtz35.26 KB

gtoledo3's picture
Re: Core Image Conundrum

Try twiddling:

vec4 result = vec4(0,0,0,0);

To:

vec4 result = vec4(0,0,0,1);

cybero's picture
Re: Core Image Conundrum

Cheers, gtoledo.

That, in all probability, is it, will give that a try shortly.

That 4 lane channel escaped my increasingly tired attention.

Just tried it and it works beautifully.

:-)