//--------------------------------------------------------- // Lab11 // // A command line interpreter // // D. Searls // REPLACE THIS LINE WITH YOUR NAME!! // Asbury University //--------------------------------------------------------- //#include "graphics.h" #include #include #include using namespace std; // Each entry in the index consists of a description of the image // and the name of the corresponding file. The description consists // primarily of the color band used in generating the image. struct indexEntry { string description; string filename; }; // The index contains the location of the images, the width and // height in pixels, the number of images, and a list of the // image descriptions and corresponding file names. struct indexType { string location; int width; // Image width in pixels int height; // Image height in pixels int n; // Number of images indexEntry item[5]; // List of index entries }; // The list of index file names. const int NUMFILES = 7; const string IDX_FILE[NUMFILES] = { "BEARLAKE.IDX", "DC.IDX", "DULLES.IDX", "GLACIERPARK.IDX", "OHARE_76.IDX", "WESTPT.IDX", "MISC.IDX" }; //--------------------------------------------------------- // The imageType class provides a data structure to store, // display, and manipulate a grayscale image. The image // file is a binary file containing the grayscale value // (0 to 255) for each pixel in the image as a byte. The // file itself contains no information about the width or // height of the image. That information must be supplied // in order to properly load an image file. // // The graph of the corresponding frequency distribution of // pixel intensities is displayed in a separate window. //--------------------------------------------------------- class imageType { private: int width, height; // Dimensions of image int imageWin; // Image window id int graphWin; // Graph window id (for freq dist) int freq[256]; // Pixel intensity frequency distribution unsigned char* image; string winTitle; // The title of the image window //----------------------------------------------------- // displayImage // // Display this image in the image window. //----------------------------------------------------- void displayImage() { } //----------------------------------------------------- // applyFilter // // Apply the specified 3 x 3 convolution filter to this // image. // // In Parameter: filter //----------------------------------------------------- void applyFilter(double filter[3][3]) { } //----------------------------------------------------- // setFreqDist // // Set the frequency distribution of pixel intensities // for this image. //----------------------------------------------------- void setFreqDist() { } //--------------------------------------------------------- // displayFreqDist // // Display the frequency distribution in the graph window. // // In Parameter: freq //--------------------------------------------------------- void displayFreqDist() { } public: //----------------------------------------------------- // Construct a default (empty) image. //----------------------------------------------------- imageType() { width = 0; height = 0; image = NULL; } //----------------------------------------------------- // Class destructor //----------------------------------------------------- ~imageType() { } //----------------------------------------------------- // read // // Read the image from the specified file. // // The image will be displayed in the image window and // the corresponding frequency distribution of pixel // intensities will be displayed in the graph window. // The image window will have the specified title. // // In Parameters: width, height, filename, title //----------------------------------------------------- bool read(int imageWidth, int imageHeight, string filename, string title) { return true; } //----------------------------------------------------- // enlarge // // Enlarge the image to twice its current size. The new // width will be twice the original width and the new // height will be twice the original height. // // The enlarged image will be displayed in the image // window and the corresponding frequency distribution // of pixel intensities will be displayed in the graph // window. //----------------------------------------------------- void enlarge() { cout << "Enlarge image.\n"; } //----------------------------------------------------- // reduce // // Reduce this image to half its current size. That is, // the new width will be half the original width and // the new height will be half the original height. // // The reduced image will be displayed in the image // window and the corresponding frequency distribution // of pixel intensities will be displayed in the graph // window. //----------------------------------------------------- void reduce() { cout << "Reduce image.\n"; } //----------------------------------------------------- // adjustBrightness // // Adjust the brightness of this image. If autoAdjust // is true, the brightness will automatically be // adjusted so that the median pixel intensity will // be 128. In that case, the value of delta will be // ignored. // // If autoAdjust is false, the delta value will be // added to the intensity of every pixel. A positive // delta will brighten the image and a negative delta // will darken the image. // // In Parameters: autoAdjust, delta //----------------------------------------------------- void adjustBrightness(bool autoAdjust, int delta) { cout << "Adjust Brightness"; if (autoAdjust) { cout << " automatically.\n"; } else { cout << " by adding " << delta << ".\n"; } } //----------------------------------------------------- // adjustContrast // // Adjust the contrast of this image. If autoAdjust // is true, the adjust will stretch the range of pixel // intensities to fill the full range of possible // values and the low and high parameters will be // ignored. // // If autoAdjust is false, intensities less than or // equal to low will map to 0 and intensities greater // than or equal to high will map to 255. Other pixel // intensities will be mapped based on the linear // mapping function determined by low and high. // // In Parameters: autoAdjust, low, high //----------------------------------------------------- void adjustContrast(bool autoAdjust, int low, int high) { cout << "Adjust contrast"; if (autoAdjust) { cout << " automatically.\n"; } else { cout << " from " << low << " to " << high << ".\n"; } } //----------------------------------------------------- // sharpen // // Sharpen the image. // // The sharpened image will be displayed in the image // window and the corresponding frequency distribution // of pixel intensities will be displayed in the graph // window. //----------------------------------------------------- void sharpen() { cout << "Sharpen image.\n"; } //----------------------------------------------------- // blur // // Blur this image. // // The blurred image will be displayed in the image // window and the corresponding frequency distribution // of pixel intensities will be displayed in the graph // window. //----------------------------------------------------- void blur() { cout << "Blur image.\n"; } }; //********************************************************* // G L O B A L V A R I A B L E S //********************************************************* imageType myImage; indexType myIndex; //--------------------------------------------------------- // toLower // // Return the lowercase version of the specified string. // // In Parameter: str //--------------------------------------------------------- string toLower(string str) { string newString(str); for (unsigned int i = 0; i < str.length(); i++) { newString.at(i) = tolower(newString.at(i)); } return newString; } //--------------------------------------------------------- // displayHelp // // Explain how to use the commands. //--------------------------------------------------------- void displayHelp() { cout << endl; cout << "In all the commands, items within square brackets are optional. For ex-\n"; cout << "ample, the help command can be entered as \"h\" or as \"help\". Commands\n"; cout << "are not case sensitive so the help command could also be entered as \"H\".\n\n"; cout << "a[djust] b[rightness] [delta#] - Adjust the brightness of the image. If\n"; cout << " delta is specified, the value of delta will be added to the inten-\n"; cout << " sity of each pixel. If this optional value is omitted, the bright-\n"; cout << " ness will be adjusted so that the median intensity of the image\n"; cout << " will be equal to 128.\n\n"; cout << "a[djust] c[ontrast] [low# high#] - Adjust the contrast of the image. If\n"; cout << " low and high are specified, pixels whose intensities are less than\n"; cout << " or equal to low (an integer value) will map to zero and pixels whose\n"; cout << " intensities are greater than or equal to high will map to 255. If\n"; cout << " these optional values are not present, the contrast will be automat-\n"; cout << " ically adjusted.\n\n"; cout << "b[lur] - Blur the image.\n\n"; cout << "e[nlarge] - Enlarge the image to twice its current size.\n\n"; cout << "h[elp] - Display this help message.\n\n"; cout << "l[oad] i[ndex] or li - Load an image index file.\n\n"; cout << "l[oad] f[ile] or lf - Load an image file.\n\n"; cout << "q[uit] - Terminate the application.\n\n"; cout << "r[educe] - Reduce the image to half its current size.\n\n"; cout << "s[harpen] - Sharpen the current image.\n\n"; } //--------------------------------------------------------- // loadIndexFile // // Load an index file into memory //--------------------------------------------------------- void loadIndexFile() { cout << "Load index file.\n"; } //--------------------------------------------------------- // loadImageFile // // Load an image file into memory //--------------------------------------------------------- void loadImageFile() { cout << "Load image file\n"; } //--------------------------------------------------------- // execute // // Execute the task specified by the command line. // // In Parameter: line //--------------------------------------------------------- void execute(string line) { } //********************************************************* // M A I N D R I V E R //********************************************************* int main() { string command; cout << "Image Viewer\n\n"; cout << "This is a command line interface. To see a list of the available\n"; cout << "commands enter the \"help\" command.\n\n"; do { cout << "> "; getline(cin, command); command = toLower(command); execute(command); } while (command != "q" && command != "quit"); return 0; }