ColoradoBill
Programmer
Hello I am creating a small imaging library. When I load an image from file I don't know until the header is read how many samples are in each pixel. For example if I load a JPEG it may be grayscale (8 bit pp) or rgb (24 bit pp). In addition, I have added the option for the client to specify an RGB or BGR pixel layout in the constructor of all the ImageReader classes in the hirearchy. Since other classes utilize my ImageReader's and iterate through all the pixels they need to know the layout of the pixels including the number of bands and RGB vs. BGR. The way I have been dealing with this so far is to use type fields for the pixel layout. Unfortunately every time I add a new ImageReader I need to update all the switch statements that check the type field for pixel layout. What are some object oriented solutions to this problem? Obviously inheritance and virtul functions would be an option but I would still need the switch statements to check the type (using dynamic_cast or typeid) of each ImageReader in order to properly iterate through the pixels.