# # Lighten.py, James Tam # Version 2: June 10, 2009 # # This program takes the picture called mediumLion.jpg (which must be in the same location where the # JES program resides) and lightens the image pixel-by-pixel. The modified image is then saved at # the location specified by the user (at the start of the program). Be sure that the name of the image # includes the proper filename suffix e.g., mediumLion.jpg is a JPEG type of image so it needs to end # in the suffix ".jpg" in order for the operating system to properly recognize the file and image type. # Also the complete location where the image is to be saved must also be specified. # e.g., when prompted for a location and file name the user could specify the path as "C:\JES\modified.jpg" # A new image called 'modified.jpg' would appear in the 'JES' folder which resides on the 'C' drive of the # computer where JES is running. def lighten (): # Prompt the user for the location and filename of the modified image. path = raw_input ("Enter the location and name of the file to save the changes to (make sure it ends with the proper suffix: ") # The name of the picture to be modified is fixed. To run this program properly an image with this exact name must # reside in the same folder as the "JES" program or the program must be modified to accomodate something else. Caution: # using an image that is large will take a long time for this program to execute! aPicture = makePicture ("mediumLion.jpg") # Show the original picture. show (aPicture) # Get all the pictures from the picture (so the program can iterate or step through them in the loop. allPixels = getPixels (aPicture) # Iterate through each pixel in the image. for pixel in allPixels: # Get and store the current color (red, blue, green) levels for each pixel. red = getRed (pixel) blue = getBlue (pixel) green = getGreen (pixel) # If increasing the color level of the pixel won't push it past the allowable maximum of 255 then lighten up # the pixel's color level. if ((red + 50) <= 255): setRed (pixel, (red+50)) if ((blue + 50) <= 255): setBlue (pixel, (blue+50)) if ((green + 50) <= 255): setGreen (pixel, (green+50)) # After all the sub-pixels of each pixel in the image have been modified and the loop has been completed show the # modified picture onscreen. repaint (aPicture) # Save the modified picture to the location and under the filename specified by the user at the start of the program. writePictureTo (aPicture, path)