<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8166430558448338624</id><updated>2011-04-21T14:37:58.666-07:00</updated><category term='OU'/><category term='NaNoWriMo'/><category term='Mass Writing'/><category term='Topography'/><category term='Processing IDE'/><category term='Waterstones'/><title type='text'>Darragh's Mass Writing Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://dbmasswriting.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8166430558448338624/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://dbmasswriting.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Darragh Buffini</name><uri>http://www.blogger.com/profile/05645005687415722225</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://2.bp.blogspot.com/_5fq1bEmORIg/SNI8jAOxxLI/AAAAAAAAAFY/4_1qVqQlF80/S220/DSCF1062.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8166430558448338624.post-7742459851511102015</id><published>2009-05-02T17:49:00.000-07:00</published><updated>2009-05-02T18:08:13.251-07:00</updated><title type='text'>Bit Shifting - Chunk 77</title><content type='html'>Before exploring the advantages of bit shifting to graphical processing, we should first consider this question - What is bit shifting? Basically put, it does exactly what it says on the bit... It performs a shift operation, either left or right, on a particular input, resulting in a changed output.&lt;br /&gt;&lt;br /&gt;They are not to be confused with bit-wise operations, or standard bit operations, such as NOT, AND and OR. These are a separate class of operations which we do not intend to cover in depth in this example. Instead we will focus  on the &lt;a class="zem_slink" href="http://en.wikipedia.org/wiki/Bitwise_operation" title="Bitwise operation" rel="wikipedia"&gt;bit-shift&lt;/a&gt; operations, from a basic perspective all the way up to their use for graphical processing in the example that will follow.&lt;br /&gt;&lt;br /&gt;As we know, a standard byte is made up of 8 bits. A standard &lt;a class="zem_slink" href="http://en.wikipedia.org/wiki/Integer_%28computer_science%29" title="Integer (computer science)" rel="wikipedia"&gt;integer&lt;/a&gt; is 4 bytes, so 32 bits. These bits are 1 or 0, and are then shunted back and forth between these states by means of the bit shift operations.  There are also two main classes of bit-shifting. These are:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;    Arithmetic shifts&lt;/li&gt;&lt;li&gt;    Logical shifts&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Before we continue, there are three important concepts to be aware of here:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;Most Significant Bit&lt;/span&gt;: The term most significant bit refers to the bit having the highest value in your number. Generally considered to be the left-most bit in most languages and representations. The least significant bit then is the lowest value bit, or right most bit. So in our example (chopped down for brevity's sake), we have "10 10 10", where the red 1 is the most significant/left most bit (&lt;a class="zem_slink" href="http://en.wikipedia.org/wiki/Most_significant_bit" title="Most significant bit" rel="wikipedia"&gt;MSB&lt;/a&gt;), and the blue 0 is the least significant/right most bit (&lt;a class="zem_slink" href="http://en.wikipedia.org/wiki/Least_significant_bit" title="Least significant bit" rel="wikipedia"&gt;LSB&lt;/a&gt;).&lt;/li&gt;&lt;li&gt;    &lt;span style="font-style: italic; font-weight: bold;"&gt;The Sign of the &lt;a class="zem_slink" href="http://en.wikipedia.org/wiki/Binary_numeral_system" title="Binary numeral system" rel="wikipedia"&gt;binary number&lt;/a&gt;&lt;/span&gt;:The MSB of a binary number is frequently taken to be the sign of the number, so for example 1 for negative, 0 for positive. If we had an 8 bit integer, 10110010, the this number would be counted as a negative because of the rightmost bit being 1. However, it is also important to note that the an integer can be declared as unsigned, meaning that the MSB is regarded as a art of the number and nothing more.&lt;/li&gt;&lt;li&gt;    &lt;span style="font-style: italic; font-weight: bold;"&gt;The Carry Bit:&lt;/span&gt; The &lt;a class="zem_slink" href="http://en.wikipedia.org/wiki/Carry_flag" title="Carry flag" rel="wikipedia"&gt;carry bit&lt;/a&gt; of a binary number does what you might think the name suggests - it carries over left over bits from operations. Lets say you have added two unsigned 8 bit integers (255 + 255) and gotten 510 as your result. Normally this would be represented as 1 11 11 11 10, but remember, we are 8 bit ints here... This means that in order to perserve our 8 bit interity, we have to drop the 9th bit from our normal representation and store it instead in a special bit, the carry bit. Our corrected output then becomes11 11 11 10 (254), and carry 1.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Arithmetic Shift&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Let start with Arithmetic shift operations. As mentioned previously, one int is made up of 4 bytes, 32 individual bits.&lt;br /&gt;&lt;br /&gt;A 32-bit integer represented in binary as :&lt;br /&gt;&lt;br /&gt;00 00 00 00 00 00 00 00 00 00 00 00 00 10 10 10&lt;br /&gt;&lt;br /&gt;Lets say we perform a left shift operation on this number, shifting it by two bits. This now gives us:&lt;br /&gt;&lt;br /&gt;00 00 00 00 00 00 00 00 00 00 00 00 10 10 10 00&lt;br /&gt;&lt;br /&gt;We can visualise the preceding operation from this illustration:&lt;br /&gt;&lt;br /&gt;Right shifting by two bits would instead have given us:&lt;br /&gt;&lt;br /&gt;00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 10&lt;br /&gt;&lt;br /&gt;As you can see, performing a straight forward left bit-shift operation on our 42 has changed the representation. the two left-most bits have dropped off, to be removed by the register storing the information, and two new bits, both 0, have been added to the right of the integer. Right shifting moved all of the digits to the right, dropping the trailing 10 from the right, and adding 00 (assuming the carry bit has been set to 0) to the left hand side.&lt;br /&gt;&lt;br /&gt;It is important to remember that while right shifting a bit, the sign of the number is always preserved, i.e. if the MSB is 0 or 1, this bit is preserved through all of the right shifting operations you can throw at it. The other implication to note is that the LSB is shifted rightward, into the carry bit. Each successive right shift operation will overwrite the carry bit with the current LSB.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;Logical shifting&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A logical shift is essentially the same as an arithmetic shift, with one very important difference - where the arithmetic shift uses the carry bit as the value to insert in right shift operations, the logical shift uses only 0s. What this means from a practical point of view is that a logical shift is the shift of choice for an unsigned int (no carry preserved), and an arithmetic shift is the choice for signed operations. See examples below:&lt;br /&gt;&lt;br /&gt;Logical right shift of 1 bit on 0011010101 (carry bit: 1) - 0110101010&lt;br /&gt;&lt;br /&gt;Arithmetic right shift of 1 bit on 0011010101 (carry bit: 1) - 0110101011&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Next to consider are the areas of &lt;a class="zem_slink" href="http://en.wikipedia.org/wiki/Rotation" title="Rotation" rel="wikipedia"&gt;Rotate&lt;/a&gt; (no carry), and Rotate (carry through). Both of these operations perform a rotation on the bits, essentially behaving as if the integer was circular and you were just spinning them around on a big wheel. However there is an important difference to note, and that difference concerns the carry bit.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;Rotate (no carry):&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This form of the rotation behaves exactly as you would expect, all bits are preserved as they are rotated, no information is lost at any stage. A standard application of this type of bit shift would be in cryptography. Consider the age old Caeser Cipher and you'll see what I mean.&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Rotate (carry through)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This form is slightly different - Instead of preserving bit fidelity on each pass, there is a change affected. The operation behaves as if the carry bit is a separator between the two ends of the integer, so instead of shifting the MSB to the LSB, or vice versa, these values are instead shifted in and out of the carry bit. What this gives us, in effect, is a situation where you might have our old friend (42) 101010, with carry bit 1. A 1-bit left rotation will then give us 010101 with carry bit 1. See illustration below for clarification.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Bit-Shifting Applications&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Finally, some real uses. There have been several major uses for bit-shifting over the years, all on semi-related themes - because bit-shifting is a very low-level operation, it became very useful for applications that needed to perform fast, and to work in close synch with the areas being acted upon, for example with &lt;a class="zem_slink" href="http://en.wikipedia.org/wiki/Device_driver" title="Device driver" rel="wikipedia"&gt;device drivers&lt;/a&gt;, &lt;a class="zem_slink" href="http://en.wikipedia.org/wiki/Image_processing" title="Image processing" rel="wikipedia"&gt;image processing&lt;/a&gt;, communications and so on. Think about it - instead of performing big fancy operations like multiplication and so on, which can incur an overhead (always an issue where these areas are concerned), would you prefer instead to be able to simply shift the bits right and left and come out with the same solution, just much faster?&lt;br /&gt;&lt;br /&gt;So why does this interest us? Say you are developing a program in Processing and you have a colour in an image that you want to manipulate. You might come up with something like this..&lt;br /&gt;&lt;br /&gt;&lt;blockquote style="font-family: courier new;"&gt;&lt;span style="font-size:85%;"&gt;PImage myImage = loadImage("LotsOfColours.jpg");&lt;br /&gt;&lt;br /&gt;loadPixels();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;for(int i = 0; i &lt; (myImage.width * myImage.height); i++)  {  int greenValue = myImage.pixels[i] &gt;&gt; 8 &amp;amp; 0xFF;&lt;br /&gt;int blueValue = myImage.pixels[i] &amp;amp; 0xFF;&lt;br /&gt;int alphaValue = myImage.pixels[i] &gt;&gt; 24 &amp;amp; 0xFF;&lt;br /&gt;&lt;br /&gt;// Recombine component colours&lt;br /&gt;myImage.pixels[i] = (alphaValue &lt;&lt; 24) | (greenValue &lt;&lt; 8) | blueValue; &lt;br /&gt;}  &lt;/span&gt;&lt;/blockquote&gt;  Lets examine this fragment and see what it does for us.. A we have seen previously, we can load an image into memory using the PImage and loadPixel comands. We have our array of pixels stored away. So far so good. But what if this was a particularly large image? We don't want to expend a lot of time and processor effort in just shifting a particular shade or range of colours out of our way, so we do it on the cheap using a bit shift. Take a look at the first line inside the for loop:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;int greenValue = myImage.pixels[i] &gt;&gt; 8 &amp;amp; 0xFF;&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;What we have happening here is quite simple and beautifully powerful - We take the current pixel, which evaluates to a 32 bit integer, and decide that since we know that range the green components of a colour live in the 8 bit range, we simply shift right by 8 bits and perform a bit-wise AND with 0xFF (an int consisting of all 1's) which gives us our original pixel with only the green components present. Simple, fast and effective!! And the beauty is it can be done for any colour or shade you might want.&lt;br /&gt;&lt;br /&gt;Obviously this is not the end of the story. We have extracted the green, blue and alpha components of our current colour into outside variables. We now need to do something with them, namely re-combine them back into our original source colour leaving out the components we did not want. To do this we use the line at the bottom of the for loop:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;myImage.pixels[i] = (alphaValue &lt;&lt;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;This could be a little daunting for anyone not used to bit work, so lets step through it piecemeal and see what it does.&lt;br /&gt;&lt;ul&gt;&lt;li&gt; &lt;span style="font-weight: bold;"&gt;(alphaValue &lt;&lt;&gt;&lt;span&gt; - Take our alpha component and shift it 24 bits to the right - Give us a 32 bit int with the alpha components in the correct position: 11111111000000000000000000000000  &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;(greenValue &lt;&lt;&gt;&lt;span&gt;- Take our green component and shift it 8 bits to the right - Give us a 32 bit int with the green components in the correct position: 0000000011011010000000000000000&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt; blueValue&lt;/span&gt; - Take our blue component and don't shift it at all (should already be in the correct position for blue):  0000000000000000000000011110001  &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Next we perform a bit-wise OR on all three of these integers...&lt;br /&gt;&lt;br /&gt; 11111111000000000000000000000000&lt;br /&gt;|   0000000011011010000000000000000&lt;br /&gt;|   0000000000000000000000011110001&lt;br /&gt;=  11111111110110100000000011110001 &lt;br /&gt;&lt;br /&gt;And last,but most definitely not least, we take our newly modified and red free colour and assign back to the current pixel in our image. Tada!! Our loop then hops on to the next pixel in line and does the same thing again. Very shortly our whole image has been processed and we have a beautifully dull and colour constrained image.&lt;br /&gt;&lt;br /&gt;By now you should be getting a rough idea of just how powerful this small and seemingly insignificant low-level process is. With a little imagination, and a firm grasp of the fact that full manipulation of every facet of a pixel is now yours to command, you can accomplish whatever the hell you like.  Take for instance the example given by Greenberg in his &lt;span style="font-style: italic;"&gt;Processing &lt;/span&gt;book - that of contrast manipulation. What exactly is the contrast of our image? Basically it is the signal to noise ratio of the colour components in a given set of colour components. So if, for example, you were to take a green component that evaluated to the decimal number 120 and then applied a multiplier to it of 1.5, you would achieve a result of 180, meaning that your green is now 50% stronger in effect. So in code this would look like:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-size:85%;"&gt;int contrastMultiplier= 1.5;&lt;br /&gt;&lt;br /&gt;for(int i = 0; i &lt; (myImage.width * myImage.height); i++) &lt;br /&gt;{ &lt;br /&gt;  int greenValue = myImage.pixels[i] &gt;&gt; 8 &amp;amp; 0xFF;&lt;br /&gt;  int blueValue = myImage.pixels[i] &amp;amp; 0xFF;&lt;br /&gt;  int alphaValue = myImage.pixels[i] &gt;&gt; 24 &amp;amp; 0xFF;&lt;br /&gt;&lt;br /&gt;  greenValue = greenValue * contrastMultiplier;&lt;br /&gt;&lt;br /&gt;  // Recombine component colours&lt;/span&gt;&lt;br /&gt;  &lt;span style="font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;myImage.pixels[i] = (alphaValue &lt;&lt; 24) | (greenValue &lt;&lt; 8) | blueValue;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;image(myImage, 0, 0);)&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;So now we have an image with no red at all, and a sharpened green component. In a grand total of five lines of image manipulation code. Not a bad return on investment.  The following program ties in all of the pieces we have demonstrated so far and produces a 4 image output...&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;float contrastMultiplier = 1.75;  &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;void setup()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;{ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    size (690, 726); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}  &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;void draw() &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;{ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    PImage image1 = loadImage("Beermotions.jpg");  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    PImage image2 = createImage(image1.width, image1.height, RGB); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    PImage image3 = createImage(image1.width, image1.height, RGB); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    PImage image4 = createImage(image1.width, image1.height, RGB);  &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    arraycopy(image1.pixels, image2.pixels); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    arraycopy(image1.pixels, image3.pixels); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    arraycopy(image1.pixels, image4.pixels);  &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    loadPixels();  &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    for (int i = 0; i &lt; (image1.width * image1.height); i++)  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    { &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        int redValue = image1.pixels[i] &gt;&gt; 16 &amp;amp; 0xFF;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        int greenValue = image1.pixels[i] &gt;&gt; 8 &amp;amp; 0xFF;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        int blueValue = image1.pixels[i] &amp;amp; 0xFF;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        int alphaValue = image1.pixels[i] &gt;&gt; 24 &amp;amp; 0xFF;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        redValue = int(redValue * contrastMultiplier);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        redValue = constrain(redValue, 0, 255);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        greenValue = int(greenValue * contrastMultiplier);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        greenValue = constrain(greenValue, 0, 255);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        blueValue = int(blueValue * contrastMultiplier);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        blueValue = constrain(blueValue, 0, 255);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        alphaValue = int(alphaValue * contrastMultiplier);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        alphaValue = constrain(alphaValue, 0, 255);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        // Recombine component colours&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        image1.pixels[i] = (alphaValue &lt;&lt;&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    for (int i = 0; i &lt; (image1.width * image1.height); i++) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    { &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        int greenValue = image2.pixels[i] &gt;&gt; 8 &amp;amp; 0xFF;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        int blueValue = image2.pixels[i] &amp;amp; 0xFF;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        int alphaValue = image2.pixels[i] &gt;&gt; 24 &amp;amp; 0xFF;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        // Recombine component colours&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        image2.pixels[i] = (alphaValue &lt;&lt;&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    }  &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    for (int i = 0; i &lt; (image1.width * image1.height); i++) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    { &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        int redValue = image3.pixels[i] &gt;&gt; 16 &amp;amp; 0xFF;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        int blueValue = image3.pixels[i] &amp;amp; 0xFF;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        int alphaValue = image3.pixels[i] &gt;&gt; 24 &amp;amp; 0xFF;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        // Recombine component colours&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        image3.pixels[i] = (alphaValue &lt;&lt;&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    }  &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    for (int i = 0; i &lt; (image1.width * image1.height); i++) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    { &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        int redValue = image4.pixels[i] &gt;&gt; 16 &amp;amp; 0xFF;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        int greenValue = image4.pixels[i] &gt;&gt; 8 &amp;amp; 0xFF;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        int alphaValue = image4.pixels[i] &gt;&gt; 24 &amp;amp; 0xFF;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        // Recombine component colours&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        image4.pixels[i] = (alphaValue &lt;&lt;&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    // Draw all 4 images&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    image(image1, 0, 0);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    image(image2, width/2, 0);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    image(image3, 0, height/2);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    image(image4, width/2, height/2);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;This program functions as a standalone artifact which encompasses all of the concepts we have covered in this chapter. All of the code snippets, and the program we have produced should be easily understandable by this point. What our final program does, in essence, is:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Take an input image and create three copies.&lt;/li&gt;&lt;li&gt;Process image 1 such that all colours are present in the final output, and have each of the colour components processed so that the contrast level of each has been magnified.&lt;/li&gt;&lt;li&gt;Process image 2 such that the contrast stays the same, but the red components have been completely removed.&lt;/li&gt;&lt;li&gt;Process image 3 such that the contrast stays the same, but the green components have been completely removed.&lt;/li&gt;&lt;li&gt;Process image 4 such that the contrast stays the same, but the blue components have been completely removed.&lt;/li&gt;&lt;li&gt;Draw all 4 images in 2*2  grid&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Hopefully Andy Warhol would have been proud of us.&lt;br /&gt;&lt;br /&gt;All simple ideas, but when combined and utilised in a creative fashion you can come up with some truly bizzare and astonishing effects. As a test of your comprehension, see if you can create a program which takes an input image and redraws several times a second with the colours shifted by some random variable.  If you're feeling particularly adventurous, apply a similar concept to a rotating sphere, or just go with whatever your imagination comes up with.&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"&gt;&lt;a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/fd1fe7ec-406e-4868-8a88-befa2508dbf7/" title="Reblog this post [with Zemanta]"&gt;&lt;img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=fd1fe7ec-406e-4868-8a88-befa2508dbf7" alt="Reblog this post [with Zemanta]" /&gt;&lt;/a&gt;&lt;span class="zem-script more-related pretty-attribution"&gt;&lt;script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"&gt;&lt;/script&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8166430558448338624-7742459851511102015?l=dbmasswriting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dbmasswriting.blogspot.com/feeds/7742459851511102015/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8166430558448338624&amp;postID=7742459851511102015' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8166430558448338624/posts/default/7742459851511102015'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8166430558448338624/posts/default/7742459851511102015'/><link rel='alternate' type='text/html' href='http://dbmasswriting.blogspot.com/2009/05/bit-shifting-chunk-77.html' title='Bit Shifting - Chunk 77'/><author><name>Darragh Buffini</name><uri>http://www.blogger.com/profile/05645005687415722225</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://2.bp.blogspot.com/_5fq1bEmORIg/SNI8jAOxxLI/AAAAAAAAAFY/4_1qVqQlF80/S220/DSCF1062.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8166430558448338624.post-3045799086525083731</id><published>2009-04-03T13:30:00.000-07:00</published><updated>2009-04-03T13:32:18.876-07:00</updated><title type='text'>Gone fishing...</title><content type='html'>... Forgot I still had this thing. I've shunted all of my blog stuff over to my new site http://darraghbuffini.com, and will be working off that from now on. &lt;br /&gt;&lt;br /&gt;Because this is the blog I originally registered for the project I'll also post my finished chunks here, but draft stuff will be over on the new one for the forseeable. Finally have some time to get properly suck into it at long last. Should be entertaining.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8166430558448338624-3045799086525083731?l=dbmasswriting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dbmasswriting.blogspot.com/feeds/3045799086525083731/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8166430558448338624&amp;postID=3045799086525083731' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8166430558448338624/posts/default/3045799086525083731'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8166430558448338624/posts/default/3045799086525083731'/><link rel='alternate' type='text/html' href='http://dbmasswriting.blogspot.com/2009/04/gone-fishing.html' title='Gone fishing...'/><author><name>Darragh Buffini</name><uri>http://www.blogger.com/profile/05645005687415722225</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://2.bp.blogspot.com/_5fq1bEmORIg/SNI8jAOxxLI/AAAAAAAAAFY/4_1qVqQlF80/S220/DSCF1062.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8166430558448338624.post-2328291908461186843</id><published>2008-12-20T03:42:00.000-08:00</published><updated>2008-12-20T03:47:17.178-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Waterstones'/><category scheme='http://www.blogger.com/atom/ns#' term='Mass Writing'/><title type='text'>Waterstone's</title><content type='html'>Am having sever trouble with the above. Ordered the book online from them so I could use the gift card (Waterstone's in Ireland won't take them), and have had nothing but trouble.&lt;br /&gt;&lt;br /&gt;Firstly, the order did not process the gift card, so the full amount got charged to my credit card. Very annoying.&lt;br /&gt;&lt;br /&gt;Secondly, I still haven't received it, and it is now headaing towards 4 weeks after my order, even though they assure me it has been posted. I have been on holiday for the last week, so it could have arrived in the meantime, but I doubt it.&lt;br /&gt;&lt;br /&gt;Thirdly, and this is the one that really got on my nerves, their customer services are SERIOUSLY bad. Absolutely atrocious. I asked the same 2 questions (why wasn't the gift card used, and when will it be delivered) 4 mails in a row and kept getting the same crappy canned answer back. Eventually gave up and demanded a manager, who preceeded to tell me the same thing. Oh the joys.&lt;br /&gt;&lt;br /&gt;I am currently considering options. I threatened to cancel the payment off my credit card and report them to a consumer body, so this may be the only way to go about it. Will decided if it's still not arrived when I get back.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8166430558448338624-2328291908461186843?l=dbmasswriting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dbmasswriting.blogspot.com/feeds/2328291908461186843/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8166430558448338624&amp;postID=2328291908461186843' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8166430558448338624/posts/default/2328291908461186843'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8166430558448338624/posts/default/2328291908461186843'/><link rel='alternate' type='text/html' href='http://dbmasswriting.blogspot.com/2008/12/waterstones.html' title='Waterstone&apos;s'/><author><name>Darragh Buffini</name><uri>http://www.blogger.com/profile/05645005687415722225</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://2.bp.blogspot.com/_5fq1bEmORIg/SNI8jAOxxLI/AAAAAAAAAFY/4_1qVqQlF80/S220/DSCF1062.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8166430558448338624.post-6595703972034488129</id><published>2008-11-15T03:47:00.000-08:00</published><updated>2008-11-15T03:56:58.735-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='NaNoWriMo'/><category scheme='http://www.blogger.com/atom/ns#' term='Topography'/><title type='text'>Book Token</title><content type='html'>Has been received. Haven't had time to get down to Waterstone's to pick up the book as yet, but will do either this weekend or on Monday at lunch. With the arrival of the token it gives the project a much more definite and immediate feel, makes you feel like things are getting started. Unfortunately I'm still in the middle of another project (NaNoWriMo), so have to finish that first at the end of this month before I can move in. But I have been planning...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I have a couple of ideas tossing around in the back of my mind, basically to do with what kind of images I can get it to produce. I have a friend who does a lot of mathematical work, and knows a good bit about topography, so she's hopefully going to supply some inspiration for this. It will be interesting if I can make it work, I may well end up playing with the software long after the project is finished just to see what I can make it do :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8166430558448338624-6595703972034488129?l=dbmasswriting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dbmasswriting.blogspot.com/feeds/6595703972034488129/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8166430558448338624&amp;postID=6595703972034488129' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8166430558448338624/posts/default/6595703972034488129'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8166430558448338624/posts/default/6595703972034488129'/><link rel='alternate' type='text/html' href='http://dbmasswriting.blogspot.com/2008/11/book-token.html' title='Book Token'/><author><name>Darragh Buffini</name><uri>http://www.blogger.com/profile/05645005687415722225</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://2.bp.blogspot.com/_5fq1bEmORIg/SNI8jAOxxLI/AAAAAAAAAFY/4_1qVqQlF80/S220/DSCF1062.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8166430558448338624.post-3882807684623450602</id><published>2008-10-28T13:24:00.000-07:00</published><updated>2008-10-28T13:35:01.227-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Processing IDE'/><category scheme='http://www.blogger.com/atom/ns#' term='OU'/><category scheme='http://www.blogger.com/atom/ns#' term='Mass Writing'/><title type='text'>Chunks bitten off</title><content type='html'>Successfully bit off the chunks I wanted from the project - bit processing and masking (77 &amp;amp; 78). Wanted these for two reasons:&lt;br /&gt;   - First: The bit processing is more low level code than the high level code/concepts that will be documented throughout a lot of the rest of the book, and its similar to the area I have most experience in.&lt;br /&gt;    - Second: The mask work is something I haven't dealt with before, and as such will push me out of my comfort zone. It will deal with more sophisticated errors of image processing than I have seen to date, and will give me a good background in newer methodologies.&lt;br /&gt;&lt;br /&gt;I'm looking forward to getting started on the project. Waiting patiently for the book token now to get a hold of the Greenberg text. I've started playing with the IDE and its pretty cool, looks like you can get a lot of advanced functionality for free, wondering now if there are similar (or the same) plugins for something for Eclipse, which would open things up even more...&lt;br /&gt;&lt;br /&gt;Interesting....&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8166430558448338624-3882807684623450602?l=dbmasswriting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dbmasswriting.blogspot.com/feeds/3882807684623450602/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8166430558448338624&amp;postID=3882807684623450602' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8166430558448338624/posts/default/3882807684623450602'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8166430558448338624/posts/default/3882807684623450602'/><link rel='alternate' type='text/html' href='http://dbmasswriting.blogspot.com/2008/10/chunks-bitten-off.html' title='Chunks bitten off'/><author><name>Darragh Buffini</name><uri>http://www.blogger.com/profile/05645005687415722225</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://2.bp.blogspot.com/_5fq1bEmORIg/SNI8jAOxxLI/AAAAAAAAAFY/4_1qVqQlF80/S220/DSCF1062.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8166430558448338624.post-7101537305344741976</id><published>2008-10-22T14:21:00.000-07:00</published><updated>2008-10-22T14:24:59.012-07:00</updated><title type='text'>Initial post on the OU Mass Writing Project</title><content type='html'>This blog will be used to track work done for the OU Mass Writing Project - details can be found at: http://incemasswriting.blogspot.com/. The project is a collaborative effort to create an academic book using current and past OU students.&lt;br /&gt;&lt;br /&gt;I have applied for chunks 77 and 78 of the project, with a deadline of April 09. Check back for updates and more detailed posts, including current progress and submission/code status.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8166430558448338624-7101537305344741976?l=dbmasswriting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dbmasswriting.blogspot.com/feeds/7101537305344741976/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8166430558448338624&amp;postID=7101537305344741976' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8166430558448338624/posts/default/7101537305344741976'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8166430558448338624/posts/default/7101537305344741976'/><link rel='alternate' type='text/html' href='http://dbmasswriting.blogspot.com/2008/10/initial-post-on-ou-mass-writing-project.html' title='Initial post on the OU Mass Writing Project'/><author><name>Darragh Buffini</name><uri>http://www.blogger.com/profile/05645005687415722225</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://2.bp.blogspot.com/_5fq1bEmORIg/SNI8jAOxxLI/AAAAAAAAAFY/4_1qVqQlF80/S220/DSCF1062.JPG'/></author><thr:total>0</thr:total></entry></feed>
