Graphics Programming using Allegro

Practice Test

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.

Answer and Explanation

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

Answer and Explanation

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

Answer and Explanation

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

Answer and Explanation

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.

Answer and Explanation

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.

Answer and Explanation

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.

Answer and Explanation

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.

Answer and Explanation

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

Answer and Explanation

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

Answer and Explanation

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).

Answer and Explanation

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).

Answer and Explanation

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.

Answer and Explanation

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.

Answer and Explanation

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.

Answer and Explanation

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.

Answer and Explanation



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

 


Answers and Explanations


Answer 16

True

Explanation 16

Back to Question 16


Answer 15

False - The maximum value is 255, not 1024

Explanation 15

Back to Question 15


Answer 14

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

Explanation 14

Back to Question 14


Answer 13

True

Explanation 13

Back to Question 13


Answer 12

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

Explanation 12

Back to Question 12


Answer 11

True

Explanation 11

Back to Question 11


Answer 10

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

Explanation 10

Back to Question 10


Answer 9

True

Explanation 9

Back to Question 9


Answer 8

False - subtract from 255, not divide by 255

Explanation 8

Back to Question 8


Answer 7

True

Explanation 7

Back to Question 7


Answer 6

False - subtract from 255, not 256

Explanation 6

Back to Question 6


Answer 5

True

Explanation 5

Back to Question 5


Answer 4

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

Explanation 4

Back to Question 4


Answer 3

True

Explanation 3

Back to Question 3


 

Answer 2

False

Explanation 2

Back to Question 2


Answer 1

True

Explanation 1

Back to Question 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-