2.1 Image Class Design


Both the original grayscale image and the generated thumbnail image share some common properties. For example, both are two-dimensional images that can be stored in a file or manipulated in memory. The only differences are the size and contents of the images. For example, a thumbnail image produced by our class could also be used as the input image. For this design, an image class has the following properties:

  • It is a two-dimensional array of grayscale pixels. In our example, a pixel can be expressed as an 8-bit unsigned quantity (i.e., unsigned char ). The size of the image is specified by its width and height.

  • It allows random read/write access to the pixels in the image. Every pixel in an image has coordinates ( x , y ) to describe its location. We specify the image origin ( , ) as the top left corner of the image, and ( width-1 , height-1 ) represents the pixel in the bottom right corner of the image.

  • It uses a simple memory allocation scheme for image data. Memory for an image whose x-dimension is width and y-dimension is height is allocated by:

     unsigned char* pixels = new unsigned char [width * height]; 

    The address of any pixel ( x , y ) in the image is:

     unsigned char* address = pixels + y*width + x; 
  • It throws a C++ exception, rangeError , if any attempts are made to reference pixels not within the image.

Our initial design for the image class is this simple. On the surface, it appears to meet the design objectives. The image class definition is shown in Section 2.3.1 on page 12.



Applied C++
Applied C++: Practical Techniques for Building Better Software
ISBN: 0321108949
EAN: 2147483647
Year: 2003
Pages: 59

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net