'**SUMMARY**
Adapative Scale is used in the Display to automatically
adjust image size to match the display size. This method attempts to scale
an image to the desired resolution while keeping the aspect ratio the same.
If fit is False we simply crop and center the image to the resolution.
In general this method should look a lot better than arbitrary cropping and scaling.
**PARAMETERS**
* *resolution* - The size of the returned image as a (width,height) tuple.
* *fit* - If fit is true we try to fit the image while maintaining the aspect ratio.
If fit is False we crop and center the image to fit the resolution.
**RETURNS**
A SimpleCV Image.
**EXAMPLE**
This is typically used in this instance:
>>> d = Display((800,600))
>>> i = Image((640, 480))
>>> i.save(d)
Where this would scale the image to match the display size of 800x600'

def adaptiveScale(self, resolution, fit=True):

    wndwAR = (float(resolution[0]) / float(resolution[1]))
    imgAR = (float(self.width) / float(self.height))
    img = self
    targetx = 0
    targety = 0
    targetw = resolution[0]
    targeth = resolution[1]
    if (self.size() == resolution):
        retVal = self
    elif ((imgAR == wndwAR) and fit):
        retVal = img.scale(resolution[0], resolution[1])
        return retVal
    elif fit:
        retVal = np.zeros((resolution[1], resolution[0], 3), dtype='uint8')
        wscale = (float(self.width) / float(resolution[0]))
        hscale = (float(self.height) / float(resolution[1]))
        if (wscale > 1):
            wscale = (1 - (1.0 / wscale))
        else:
            wscale = (1.0 - wscale)
        if (hscale > 1):
            hscale = (1 - (1.0 / hscale))
        else:
            hscale = (1.0 - hscale)
        if (wscale == 0):
            targetx = 0
            targety = ((resolution[1] - self.height) / 2)
            targetw = img.width
            targeth = img.height
        elif (hscale == 0):
            targetx = ((resolution[0] - img.width) / 2)
            targety = 0
            targetw = img.width
            targeth = img.height
        elif (wscale < hscale):
            sfactor = (float(resolution[0]) / float(self.width))
            targetw = int((float(self.width) * sfactor))
            targeth = int((float(self.height) * sfactor))
            if ((targetw > resolution[0]) or (targeth > resolution[1])):
                sfactor = (float(resolution[1]) / float(self.height))
                targetw = int((float(self.width) * sfactor))
                targeth = int((float(self.height) * sfactor))
                targetx = ((resolution[0] - targetw) / 2)
                targety = 0
            else:
                targetx = 0
                targety = ((resolution[1] - targeth) / 2)
            img = img.scale(targetw, targeth)
        else:
            sfactor = (float(resolution[1]) / float(self.height))
            targetw = int((float(self.width) * sfactor))
            targeth = int((float(self.height) * sfactor))
            if ((targetw > resolution[0]) or (targeth > resolution[1])):
                sfactor = (float(resolution[0]) / float(self.width))
                targetw = int((float(self.width) * sfactor))
                targeth = int((float(self.height) * sfactor))
                targetx = 0
                targety = ((resolution[1] - targeth) / 2)
            else:
                targetx = ((resolution[0] - targetw) / 2)
                targety = 0
            img = img.scale(targetw, targeth)
    elif ((self.width <= resolution[0]) and (self.height <= resolution[1])):
        retVal = np.zeros((resolution[1], resolution[0], 3), dtype='uint8')
        targetx = ((resolution[0] / 2) - (self.width / 2))
        targety = ((resolution[1] / 2) - (self.height / 2))
        targeth = self.height
        targetw = self.width
    elif ((self.width > resolution[0]) and (self.height > resolution[1])):
        targetw = resolution[0]
        targeth = resolution[1]
        targetx = 0
        targety = 0
        x = ((self.width - resolution[0]) / 2)
        y = ((self.height - resolution[1]) / 2)
        img = img.crop(x, y, targetw, targeth)
        return img
    elif ((self.width <= resolution[0]) and (self.height > resolution[1])):
        retVal = np.zeros((resolution[1], resolution[0], 3), dtype='uint8')
        targetw = self.width
        targeth = resolution[1]
        targetx = ((resolution[0] - self.width) / 2)
        targety = 0
        x = 0
        y = ((self.height - resolution[1]) / 2)
        img = img.crop(x, y, targetw, targeth)
    elif ((self.width > resolution[0]) and (self.height <= resolution[1])):
        retVal = np.zeros((resolution[1], resolution[0], 3), dtype='uint8')
        targetw = resolution[0]
        targeth = self.height
        targetx = 0
        targety = ((resolution[1] - self.height) / 2)
        x = ((self.width - resolution[0]) / 2)
        y = 0
        img = img.crop(x, y, targetw, targeth)
    retVal[targety:(targety + targeth), targetx:(targetx + targetw), :] = img.getNumpyCv2()
    retVal = Image(retVal, cv2image=True)
    return retVal
