Chapter 6. Implementation ConsiderationsIN THIS CHAPTER C++ ConceptsMemory AlignmentHandles and Rep objectsIterators (pixel and STL)Exception-Safe Locking Image Framework ConceptsImage DatatypesImage CoordinatesImage StorageImage Object (Final Design)Image Filtering FunctionsInterfaces to Third-Party Software In this chapter, we apply what we have learned through prototyping and examples to finalize the design for the image framework. The components of the framework are shown in Figure 6.1. Figure 6.1. Image Framework ComponentsOur design has had many iterations, using a variety of C++ techniques. We started by using inheritance to create a framework that could handle numerous image types. It quickly became apparent in our subsequent prototype that templates both improved and simplified the design by eliminating most of the object hierarchy. However, we were still including image storage as a component of the image class, instead of separating it as an image component. We also explored using handles, but found they did nothing to improve the design. Once we prototyped a solution that separated storage from the image class, we knew that the final design was close at hand.Each prototype was incomplete, but collectively they allowed us to test different design principles. We used a single, trivial, image processing function (computing thumbnail images) to observe the merits of each design. And, we wrote a unit test for each prototype to verify the correctness and the behavior of memory allocation, and to verify how pixels are accessed.Often, the final design grows out of one or more prototypes. Sometimes it is obvious that you have hit on the right design, and other times it becomes an iterative process. From our prototypes, we applied the following ideas:Image storage should be separate from the image processing functions. The image storage classes are independent of the image processing functions (but not vice versa).Templates should be used for a more efficient design, allowing us to: produce a single version of code that works with any pixel type; optimize performance where needed by using specialization; and adapt our image storage component to use other memory allocators. |