## Processing Individual Pixels, Negate an Image

Published:  September 9, 2008
By Richard G. Baldwin

File: Allegro00145PracticeTest

## Questions

1.  True or False:  In addition to being a good way to illustrate the processing of individual pixels, pixel negation has a practical use as well.  It is used by many computer programs, including Microsoft Word and Microsoft FrontPage, to indicate that an image has been selected.

2.  True or False:  While pixel negation is a good way to illustrate the processing of individual pixels, it has no practical value.

3.  True or False:  The pixel negation process is computationally cheap and totally reversible.

4.  True or False:  The pixel negation process is computationally cheap and irreversible.

5.  True or False:  All that is necessary to negate a pixel is to subtract each of the red, green, and blue color values from 255.

6.  True or False:  All that is necessary to negate a pixel is to subtract each of the red, green, and blue color values from 256.

7.  True or False:  All that is necessary to reverse the pixel negation process and restore the pixel to its normal value is to subtract each of the negated red, green, and blue color values from 255.

8.  True or False:  All that is necessary to reverse the pixel negation process and restore the pixel to its normal value is to divide each of the negated red, green, and blue color values by 255.

9.  True or False:  Assuming that picA points to a bitmap image in a memory buffer and that the variables named pixel, red, green, and blue have been declared, the code shown below can be used to negate the pixels in a rectangular portion of a bitmap image in the memory buffer.

 ``` for(int row = 0;row < 330;row++){ for(int column = 0;column < 324;column++){ pixel = getpixel(picA,column,row); red = getr(pixel); green = getg(pixel); blue = getb(pixel); putpixel(picA,column,row,makecol( 255-red,255-green,255-blue)); }//end loop on row }//end loop on column```

10.  True or False:  Assuming that picA points to a bitmap image in a memory buffer and that the variables named pixel, red, green, and blue have been declared, the code shown below calls standard Allegro library functions to negate the pixels in a rectangular portion of a bitmap image in the memory buffer.

 ``` for(int row = 0;row < 330;row++){ for(int column = 0;column < 324;column++){ pixel = getPixel(picA,column,row); red = getRed(pixel); green = getGreen(pixel); blue = getBlue(pixel); putPixel(picA,column,row,makecol( 255-red,255-green,255-blue)); }//end loop on row }//end loop on column```

11.  True or False:  A pixel value returned by the getpixel function is a numeric value of type int composed of red, green, and blue color values (and possibly a transparency value, commonly known as alpha as well).

12.  True or False:  A pixel value returned by the getpixel function is an object instantiated by the C++ class named Pixel  that encapsulates red, green, and blue color values (and possibly a transparency value, commonly known as alpha as well).

13.  True or False:  Once you have a pixel value, you can call the getr, getg, and getb functions in the standard Allegro library to get the red, green, and blue color values respectively.

14.  True or False:  Once you have a pixel value, you can call the getRed, getGreen, and getBlue functions in the standard Allegro library to get the red, green, and blue color values respectively.

15.  Fact:  The getr, getg, and getb functions all return a value of type int.

True or False:    Each individual color value in a pixel ranges from 0 to 1024.  A value of 0 indicates the total absence of that color component and a color value of 1024 indicates the presence of the maximum intensity of that color component.  Values in between the extremes indicate a proportional amount of the color component.

16Fact:  The getr, getg, and getb functions all return a value of type int.

True or False:    Each individual color value in a pixel ranges from 0 to 255.  A value of 0 indicates the total absence of that color component and a color value of 255 indicates the presence of the maximum intensity of that color component.  Values in between the extremes indicate a proportional amount of the color component.

Copyright 2008, Richard G. Baldwin.  Reproduction in whole or in part in any form or medium without express written permission from Richard Baldwin is prohibited.

Richard Baldwin is a college professor (at Austin Community College in Austin, TX) and private consultant whose primary focus is a combination of Java, C#, and XML. In addition to the many platform and/or language independent benefits of Java and C# applications, he believes that a combination of Java, C#, and XML will become the primary driving force in the delivery of structured information on the Web.

Richard has participated in numerous consulting projects and he frequently provides onsite training at the high-tech companies located in and around Austin, Texas.  He is the author of Baldwin's Programming Tutorials, which have gained a worldwide following among experienced and aspiring programmers. He has also published articles in JavaPro magazine.

In addition to his programming expertise, Richard has many years of practical experience in Digital Signal Processing (DSP).  His first job after he earned his Bachelor's degree was doing DSP in the Seismic Research Department of Texas Instruments.  (TI is still a world leader in DSP.)  In the following years, he applied his programming and DSP expertise to other interesting areas including sonar and underwater acoustics.

Richard holds an MSEE degree from Southern Methodist University and has many years of experience in the application of computer technology to real-world problems.

Baldwin@DickBaldwin.com

True

### Explanation 16

Back to Question 16

False - The maximum value is 255, not 1024

### Explanation 15

False - getRed, getGreen, and getBlue are not functions in the standard Allegro library

True

### Explanation 13

False - A pixel value returned by the getpixel function is simply a numeric value of type int

True

### Explanation 11

False - the function calls are not calls to standard Allegro library functions.

True

### Explanation 9

False - subtract from 255, not divide by 255

True

### Explanation 7

False - subtract from 255, not 256

True

### Explanation 5

False - The pixel negation process is computationally cheap and totally reversible

True

False

True

### Explanation 1

Copyright 2008, Richard G. Baldwin.  Reproduction in whole or in part in any form or medium without express written permission from Richard Baldwin is prohibited.

Richard Baldwin is a college professor (at Austin Community College in Austin, TX) and private consultant whose primary focus is a combination of Java, C#, and XML. In addition to the many platform and/or language independent benefits of Java and C# applications, he believes that a combination of Java, C#, and XML will become the primary driving force in the delivery of structured information on the Web.

Richard has participated in numerous consulting projects and he frequently provides onsite training at the high-tech companies located in and around Austin, Texas.  He is the author of Baldwin's Programming Tutorials, which have gained a worldwide following among experienced and aspiring programmers. He has also published articles in JavaPro magazine.

In addition to his programming expertise, Richard has many years of practical experience in Digital Signal Processing (DSP).  His first job after he earned his Bachelor's degree was doing DSP in the Seismic Research Department of Texas Instruments.  (TI is still a world leader in DSP.)  In the following years, he applied his programming and DSP expertise to other interesting areas including sonar and underwater acoustics.

Richard holds an MSEE degree from Southern Methodist University and has many years of experience in the application of computer technology to real-world problems.

Baldwin@DickBaldwin.com

-end-