# Recipe 36: Convert a picture to sepia tones

def sepiaTint(picture):

  # Convert image to greyscale
  greyScaleNew(picture)

  # Loop through picture to tint pixels
  for p in getPixels(picture):
    red = getRed(p)
    blue = getBlue(p)

    # Tint shadows
    if (red < 63):
      red = red*1.1
      blue = blue*0.9

    # Tint midtones
    if (red > 62 and red < 192):
      red = red*1.15
      blue = blue*0.85

    # Tint highlights
    if (red > 191):
      red = red*1.08
      if (red > 255):
        red = 255    # Why this here.. and not above?
      blue = blue*0.93

    # Set the new color values
    setBlue(p, blue)
    setRed(p, red)

