# Problems

[Page 127 (continued)]

 4.1 What is meant by each of the following? PixelKilobyteRGBLoop[Page 128]HSVFlowchartInfinite loopVariable scopeArrayMatrixJPEGColumn-major orderPixelizationLuminance 4.2 Why don't we see red, green, and blue spots at each position in our picture? 4.3 Why is the maximum value of any color channel 255? 4.4 The color encoding we're using is "RGB". What does that mean, in terms of the amount of memory required to represent color? Is there a limit to the number of colors that we can represent? Can we represent enough colors in RGB? 4.5 Program 5 (page 97) is obviously too much color reduction. Write a version that only decreases the red by 10%, and one that reduces red by 20%. Which seems to be more useful? Note that you can always repeatedly reduce the redness in a picture, but you don't want to have to do it too many times, either. 4.6 Each of the below is equivalent to Program 6 (page 106). Test them and convince yourself that they are equivalent. Which do you prefer and why? `/** * Method to increase the amount of red by 1.3 */ public void increaseRed2() { Pixel[] pixelArray = this.getPixels(); int value = 0; // loop through all the pixels for (int i = 0; i < pixelArray.length; i++) { // set the red value to 1.3 times what it was value = pixelArray[i].getRed(); pixelArray[i].setRed((int) (value * 1.3)); } } [Page 129] /** * Method to increase the amount of red by 1.3 */ public void increaseRed3() { Pixel[] pixelArray = this.getPixels(); Pixel pixel = null; int red = 0; int green = 0; int blue = 0; int newRed = 0; // loop through all the pixels for (int i = 0; i < pixelArray.length; i++) { // get the current pixel pixel = pixelArray[i]; // get the color values red = pixel.getRed(); green = pixel.getGreen(); blue = pixel.getBlue(); // calculate the new red value newRed = (int) (red * 1.3); // set the pixel color to the new color pixel.setColor(new Color(newRed,green,blue)); } }` 4.7 Change any of the methods that used a while loop to use a for loop. Compile and run the changed method and make sure it still works. 4.8 Change a variable name in any of the given methods. Make sure you change all instances of the variable name to the new name. Compile and run the changed method and make sure it still works. 4.9 Write new methods like Program 7 (page 108) to clear red and green. For each of these, which would be the most useful in actual practice? How about combinations of these? 4.10 Write a method to keep just the blue color. This means to set all the green and red values to zero. Write a method to keep just the red color. Write a method to keep just the green color. 4.11 Write a new method to maximize blue (i.e., setting it to 255) instead of clearing it use Program 7 (page 108) as a starting point. Is this useful? Would the red or green versions be useful? 4.12 Write a method that modifies the red, green, and blue values of a picture by different amounts. Try it out on different pictures to see if you get any nice results. [Page 130] 4.13 How do we get the height from a Picture object? 4.14 How do we get the width from a Picture object? 4.15 How many pixels are in a picture with a width of 200 and a height of 100? 4.16 How many pixels are in a picture with a width of 640 and a height of 480? 4.17 How do you get an array of Pixel objects from a Picture object? 4.18 How do you get the red value from a Pixel object? 4.19 How do you set the red value in a Pixel object? 4.20 There is more than one way to compute the right grayscale value for a color value. The simple method that we use in Program 16 (page 123) may not be what your grayscale printer uses when printing a color picture. Compare the color (relatively unconverted by the printer) grayscale image using our simple algorithm in with what your printer produces when you print the image. How do the two pictures differ? Introduction to Computing & Programming Algebra in Java(c) A Multimedia Approach
ISBN: N/A
EAN: N/A
Year: 2007
Pages: 191