Anda di halaman 1dari 4

5/14/14 12:24 PM Year of the Glitch

Page 1 of 4 http://yearoftheglitch.tumblr.com/post/83596363422/you-sir-are-a-pioneer-i-was-wondering-if-you-would-be
A Yearlong Glitch-A-Day Project by Phillip Stearns
About Resources Glitch Textiles Contact Questions? Submissions
APRIL 23, 2014
adamkilledeve asked: You sir, are a pioneer. I was wondering if you would be so kind as to make the source code
for your chris christie pixel sorting piece available? that would be amazing and helpful. (I am struggling to learn
processing, and any help would be greatly appreciated) Thank you!
/*
RGB Sorting
Made in Processing 2.1.2
By Phillip Stearns
A less glitchy approach to pixel sorting.
Part of the glitchiness, or glitch-like look and feel of Kim Asendorf's
brilliant ASDFPixelSort lies in the fact that when you apply the sort()
method to an array of pixels, you're actually sorting according to the
numeric value of that pixel. Processing treats the color of a pixel
as a single 32 bit number, ordered ARGB in 24 bit colorspace w/ alpha.
A 100% opaque red pixel would have the binary representation of
11111111111111110000000000000000
Alpha | Red | Green | Blue
^ ^
| |
MSB LSB
MSB = most significant bit, like the 9 in 900 for those used to base ten counting
LSB = least significant bit, like the 1 in 5 million and 21.
This also means that red pixel is a bigger number than a green pixel, which
is greater than a blue pixel.
It's not so much based on a perceptual color evaluation; pixel sorting
looks the way it does because the sorting criteria is based on numbers alone,
which don't quite line up with perception. Why things look interesting when you sort pixels this way is
a result of how we use numbers to describe the color of a pixel.
THIS little program sorts the channels separately, which has a slightly
different, smoother effect overall. Rather than sort the pixels according to their ARGB value, RGBsort first breaks up the image into R G B channels, sorts them individually, then recombines them. Have a look!
*/
PImage sourceImg;
int sortDirection;
void setup(){
sourceImg = loadImage("random.jpg");
size(sourceImg.width, sourceImg.height);
noLoop(); //stops the draw from looping
sortDirection = 0; //0 sorts all the rows, 1 sorts all the columns
}
void draw(){
Year of the Glitch RSS ARCHIVE
5/14/14 12:24 PM Year of the Glitch
Page 2 of 4 http://yearoftheglitch.tumblr.com/post/83596363422/you-sir-are-a-pioneer-i-was-wondering-if-you-would-be

//switch lets us do different things for different cases
switch(sortDirection) {

//ror sorting
case 0:
for(int row = 0 ; row < sourceImg.height ; row++){
RGBsortRow(sourceImg, row);
}
break;

//column sorting
case 1:
for(int col = 0 ; col < sourceImg.width ; col++){
RGBsortColumn(sourceImg, col);
}
break;
}

//display the sorted image
image(sourceImg, 0, 0);
}
void RGBsortRow(PImage image, int row){

int[] bufferR = new int[image.width];
int[] bufferG = new int[image.width];
int[] bufferB = new int[image.width];

//make sure that the row number exists
if (row < 0 || row >= height){
//if it doesn't, please let me know
println("Row value is out of range.");
} else{
//otherwise, please sort

for(int i = 0; i < image.width ; i++){
//basically we're walking through the row specified in the function arguments and separating the RGB values into their respective buffers
//to do this, we use the bitwise >> or shift right operator and mask the extraneous bits with the & (AND) 0xFF or 11111111
bufferR[i] = image.pixels[row*image.width+i] >> 16 & 0xFF;
bufferG[i] = image.pixels[row*image.width+i] >> 8 & 0xFF;
bufferB[i] = image.pixels[row*image.width+i] & 0xFF;
}

//sort the pixels in the buffers
bufferR = sort(bufferR);
bufferG = sort(bufferG);
bufferB = sort(bufferB);

//recombine the RGB values using the << shift left and | (OR) operator
for(int j = 0; j < image.width ; j++){
image.pixels[row*image.width+j] = (255 << 24) | (bufferR[j] << 16) | (bufferG[j] << 8) | (bufferB[j]);
}
}
}
//the column sorting works in the same manner
void RGBsortColumn(PImage image, int column){
int[] bufferR = new int[image.height];
int[] bufferG = new int[image.height];
5/14/14 12:24 PM Year of the Glitch
Page 3 of 4 http://yearoftheglitch.tumblr.com/post/83596363422/you-sir-are-a-pioneer-i-was-wondering-if-you-would-be
(Notes: 56) FILED UNDER: processing code pixel sorting this is not a glitch
int[] bufferB = new int[image.height];
if (column < 0 || column >= width){
println("Column value is out of range.");
} else{
for(int i = 0; i < image.height ; i++){
bufferR[i] = image.pixels[i*image.width+column] >> 16 & 0xFF;
bufferG[i] = image.pixels[i*image.width+column] >> 8 & 0xFF;
bufferB[i] = image.pixels[i*image.width+column] & 0xFF;
}
bufferR = sort(bufferR);
bufferG = sort(bufferG);
bufferB = sort(bufferB);
for(int j = 0; j < image.height ; j++){
image.pixels[j*image.width+column] = (255 << 24) | (bufferR[j] << 16) | (bufferG[j] << 8) | (bufferB[j]);
}
}
}
1:54AM | URL: http://tmblr.co/ZX7FGw1DskqQU

datamodel likes this
littlesunriise likes this
sandiela reblogged this from yearoftheglitch
vacantblock likes this
busyslayingmonsters likes this
philsphotostuff likes this
chromacle likes this
kalidaskope likes this
drewel likes this
adamferriss likes this
13666888 likes this
sammy-spock-dalek likes this
danedehaandjob likes this
somejew reblogged this from yearoftheglitch
berdinanimus likes this
troxide reblogged this from yearoftheglitch
troxide likes this
bibliusdealois likes this
elegantsips likes this
imaginationisthegirlcreation likes this
alessandrorigobello likes this
climb-trees likes this
deathrayofpeace likes this
formboy1 likes this
oraoraoraaura likes this
lisanngeorge likes this
benvancitters likes this
darokin likes this
5/14/14 12:24 PM Year of the Glitch
Page 4 of 4 http://yearoftheglitch.tumblr.com/post/83596363422/you-sir-are-a-pioneer-i-was-wondering-if-you-would-be
RSS feed: http://yearoftheglitch.tumblr.com/rss
Search
elisejakob likes this
quasilinear-equation likes this
jesorquadi likes this
dreamofelectricsheep likes this
eurobus likes this
bblacksheepp likes this
murix likes this
justjeorgia likes this
iloveprocessing reblogged this from yearoftheglitch
mavw likes this
primalmatter likes this
fatblood likes this
costantinot likes this
thechocolatedip likes this
tvsfolder likes this
separate-integrate likes this
puffvick likes this
aworldofsound likes this
vhdcrusher likes this
tohereknowswhere likes this
askchangeling likes this
Show more notes
PREVIOUS POST NEXT POST
Theme is The Atlantic by Peter Vidani for Tumblr.

Anda mungkin juga menyukai