04
Dec
07

Image > Pixellated Image > Pixel Strip

This code samples the input image at grid-points, and creates a single-pixel horizontal strip.

The idea is to feed the Kernel with a pixellated image, so that every pixel-tile of the input image becomes a single pixel at the output of the kernel.

It’s not meant as an effect in it’s own right. I’ll pass the resulting image through a Crop, and then pass this into the Iterator of the CubeField patch, instead of the full-sized original image.

I’m hoping this will make the whole thing much more efficient, but actually, I’m not certain this is the case. If anyone knows the answer to this one, let me know…

vec2 makeStrip(vec2 xy, float cellWidth, float cellHeight, float cols)
{
// Calculate Row and Column of pixel to sample
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;
}

kernel vec4 main(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 > 1.0) ? vec2(0.0,0.0) : makeStrip(xy, CellWidth, CellHeight, Cols);

// Output
return sample(Image, vec2(samplePos));
}

Advertisements

0 Responses to “Image > Pixellated Image > Pixel Strip”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Twitter

December 2007
M T W T F S S
« Nov   Jan »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Links

Blog Stats

  • 470,209 hits

%d bloggers like this: