'**SUMMARY**
writeFrame copies the given Image object to the display, you can also use
Image.save()
Write frame trys to fit the image to the display with the minimum ammount
of distortion possible. When fit=True write frame will decide how to scale
the image such that the aspect ratio is maintained and the smallest amount
of distorition possible is completed. This means the axis that has the minimum
scaling needed will be shrunk or enlarged to match the display.
**PARAMETERS**
* *img* -  the SimpleCV image to save to the display.
* *fit* - When fit=False write frame will crop and center the image as best it can.
If the image is too big it is cropped and centered. If it is too small
it is centered. If it is too big along one axis that axis is cropped and
the other axis is centered if necessary.
**RETURNS**
Nothing.
**EXAMPLE**
>>> img = Image("lenna")
>>> disp = Display((512,512))
>>> disp.writeFrame(img)'

def writeFrame(self, img, fit=True):

    wndwAR = (float(self.resolution[0]) / float(self.resolution[1]))
    imgAR = (float(img.width) / float(img.height))
    self.sourceresolution = img.size()
    self.sourceoffset = (0, 0)
    self.imgw = img.width
    self.imgh = img.height
    self.xscale = 1.0
    self.yscale = 1.0
    self.xoffset = 0
    self.yoffset = 0
    if (img.size() == self.resolution):
        s = img.getPGSurface()
        self.screen.blit(s, s.get_rect())
        pg.display.flip()
    elif (imgAR == wndwAR):
        self.xscale = (float(img.width) / float(self.resolution[0]))
        self.yscale = (float(img.height) / float(self.resolution[1]))
        img = img.scale(self.resolution[0], self.resolution[1])
        s = img.getPGSurface()
        self.screen.blit(s, s.get_rect())
        pg.display.flip()
    elif fit:
        wscale = (float(img.width) / float(self.resolution[0]))
        hscale = (float(img.height) / float(self.resolution[1]))
        targetw = img.width
        targeth = img.height
        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 = ((self.resolution[1] - img.height) / 2)
            targetw = img.width
            targeth = img.height
            s = img.getPGSurface()
        elif (hscale == 0):
            targetx = ((self.resolution[0] - img.width) / 2)
            targety = 0
            targetw = img.width
            targeth = img.height
            s = img.getPGSurface()
        elif (wscale < hscale):
            sfactor = (float(self.resolution[0]) / float(img.width))
            targetw = int((float(img.width) * sfactor))
            targeth = int((float(img.height) * sfactor))
            if ((targetw > self.resolution[0]) or (targeth > self.resolution[1])):
                sfactor = (float(self.resolution[1]) / float(img.height))
                targetw = int((float(img.width) * sfactor))
                targeth = int((float(img.height) * sfactor))
                targetx = ((self.resolution[0] - targetw) / 2)
                targety = 0
            else:
                targetx = 0
                targety = ((self.resolution[1] - targeth) / 2)
            img = img.scale(targetw, targeth)
            s = img.getPGSurface()
        else:
            sfactor = (float(self.resolution[1]) / float(img.height))
            targetw = int((float(img.width) * sfactor))
            targeth = int((float(img.height) * sfactor))
            if ((targetw > self.resolution[0]) or (targeth > self.resolution[1])):
                sfactor = (float(self.resolution[0]) / float(img.width))
                targetw = int((float(img.width) * sfactor))
                targeth = int((float(img.height) * sfactor))
                targetx = 0
                targety = ((self.resolution[1] - targeth) / 2)
            else:
                targetx = ((self.resolution[0] - targetw) / 2)
                targety = 0
            img = img.scale(targetw, targeth)
            s = img.getPGSurface()
        black = pg.Surface((self.resolution[0], self.resolution[1]))
        black.fill((0, 0, 0))
        self.screen.blit(black, black.get_rect())
        self.screen.blit(s, (targetx, targety))
        self.sourceoffset = (targetx, targety)
        pg.display.flip()
        self.xoffset = targetx
        self.yoffset = targety
        self.xscale = (float(self.imgw) / float(targetw))
        self.yscale = (float(self.imgh) / float(targeth))
    else:
        self.doClamp = False
        targetx = 0
        targety = 0
        cornerx = 0
        cornery = 0
        if ((img.width <= self.resolution[0]) and (img.height <= self.resolution[1])):
            targetx = ((self.resolution[0] / 2) - (img.width / 2))
            targety = ((self.resolution[1] / 2) - (img.height / 2))
            cornerx = targetx
            cornery = targety
            s = img.getPGSurface()
        elif ((img.width > self.resolution[0]) and (img.height > self.resolution[1])):
            targetw = self.resolution[0]
            targeth = self.resolution[1]
            targetx = 0
            targety = 0
            x = ((img.width - self.resolution[0]) / 2)
            y = ((img.height - self.resolution[1]) / 2)
            cornerx = ((-1) * x)
            cornery = ((-1) * y)
            img = img.crop(x, y, targetw, targeth)
            s = img.getPGSurface()
        elif ((img.width < self.resolution[0]) and (img.height >= self.resolution[1])):
            targetw = img.width
            targeth = self.resolution[1]
            targetx = ((self.resolution[0] - img.width) / 2)
            targety = 0
            x = 0
            y = ((img.height - self.resolution[1]) / 2)
            cornerx = targetx
            cornery = ((-1) * y)
            img = img.crop(x, y, targetw, targeth)
            s = img.getPGSurface()
        elif ((img.width > self.resolution[0]) and (img.height <= self.resolution[1])):
            targetw = self.resolution[0]
            targeth = img.height
            targetx = 0
            targety = ((self.resolution[1] - img.height) / 2)
            x = ((img.width - self.resolution[0]) / 2)
            y = 0
            cornerx = ((-1) * x)
            cornery = targety
            img = img.crop(x, y, targetw, targeth)
            s = img.getPGSurface()
        self.xoffset = cornerx
        self.yoffset = cornery
        black = pg.Surface((self.resolution[0], self.resolution[1]))
        black.fill((0, 0, 0))
        self.screen.blit(black, black.get_rect())
        self.screen.blit(s, (targetx, targety))
        pg.display.flip()
