def uvCooToBitmapIndex(TGAXres, TGAYres, U, V):
    """ 
    
    This function takes UV coordinates and a bitmap resolution as input and 
    returns an index to the position of a pixel in the bitmap.
     
    UV coordinates are used to map 2D images to 3D surfaces. 
    In the case of the MakeHuman mesh, each face has 3 vertices each of which has 
    a pair of uv-coordinates that provide a horizontal and vertical value between 0 and 1 
    to point to the location on an image map from which to read a value.
    
    For an image with a resolution of Xn x Ym, any UV coordinate will lie within 
    a square whose bottom left corner has a pixel coordinate between <0,0> and 
    <Xn-1,Ym-1>. 
    This in turn can be transformed into a pixel index in the bitmap image by multiplying 
    the Y value by Xn and adding the X value. In the example on the right the UV coordinates
    <0.38,0.32> lie in the pixel whose bottom left coordinates are <3,2>, giving a pixel index 
    of 2x8+3 = 19. 
    (This will be the 20th pixel in the bitmap because the first is numbered '0'). 
    
    Parameters
    ----------

    TGAXres:
        *integer*. The X component of the resolution of the bitmap.
    TGAYres:
        *integer*. The Y component of the resolution of the bitmap.
    U:
        *float*. The horizontal component of the UV coordinates. A value between 0 and 1.
    V:
        *float*. The vertical component of the UV coordinate. A value between 0 and 1
    """

    # We use 'resolution - 1' in both dimensions as multiplication
    # factors to work out which pixel the UV coordinate sits in.
    # The calculated coordinates are integer values counting from '0'.

    UVimageCoordX = int(abs((TGAXres - 1) * U))
    UVimageCoordY = int(abs((TGAYres - 1) * V))
    pixelIndex = UVimageCoordX + UVimageCoordY * TGAXres
    return pixelIndex