Exemple #1
0
def _load_image_frimgldr(fname):
    import freeimgldr
    width, height, bpp = freeimgldr.QueryImage(fname)
    if bpp > 32:
        im = ImagePRGBA(width, height)
    else:
        im = ImageRGBA(width, height)
    addr, pitch = im.address_info()
    freeimgldr.GetImage(fname, addr, width, height, bpp)
    return im
Exemple #2
0
    def test_set_prgba(self):
        code = """
val = (0.67, 0.88, 0.11, 0.55)
v1 = set_rgba(image1, 10, 10, val)
        """
        image = ImagePRGBA(200, 200)
        p1 = StructArg('image1', image)
        shader = Shader(code=code, args=[p1])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        r, g, b, a = image.get_pixel(10, 10)
        self.assertAlmostEqual(r, 0.67)
        self.assertAlmostEqual(g, 0.88)
        self.assertAlmostEqual(b, 0.11)
        self.assertAlmostEqual(a, 0.55)
Exemple #3
0
    def test_set_prgba(self):
        code = """
val = (0.67, 0.88, 0.11, 0.55)
v1 = set_rgba(image1, 10, 10, val)
        """
        image = ImagePRGBA(200, 200)
        p1 = StructArg('image1', image)
        shader = Shader(code=code, args=[p1])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        r, g, b, a = image.get_pixel(10, 10)
        self.assertAlmostEqual(r, 0.67)
        self.assertAlmostEqual(g, 0.88)
        self.assertAlmostEqual(b, 0.11)
        self.assertAlmostEqual(a, 0.55)
Exemple #4
0
    def test_get_prgba(self):
        code = """
v1 = get_rgba(image1, 10, 10)
        """
        image = ImagePRGBA(200, 200)
        image.set_pixel(10, 10, 0.23, 0.28, 0.55, 0.8)
        p1 = StructArg('image1', image)
        p2 = Vec4Arg('v1', Vector4(0.0, 0.0, 0.0, 0.0))

        shader = Shader(code=code, args=[p1, p2])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        val = shader.get_value('v1')
        self.assertAlmostEqual(val.x, 0.23)
        self.assertAlmostEqual(val.y, 0.28)
        self.assertAlmostEqual(val.z, 0.55)
        self.assertAlmostEqual(val.w, 0.8)
Exemple #5
0
    def test_get_prgba(self):
        code = """
v1 = get_rgba(image1, 10, 10)
        """
        image = ImagePRGBA(200, 200)
        image.set_pixel(10, 10, 0.23, 0.28, 0.55, 0.8)
        p1 = StructArg('image1', image)
        p2 = Vec4Arg('v1', Vector4(0.0, 0.0, 0.0, 0.0))

        shader = Shader(code=code, args=[p1, p2])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        val = shader.get_value('v1')
        self.assertAlmostEqual(val.x, 0.23)
        self.assertAlmostEqual(val.y, 0.28)
        self.assertAlmostEqual(val.z, 0.55)
        self.assertAlmostEqual(val.w, 0.8)
Exemple #6
0
def create_image(objects, args):
    pix_format, width, height = args.split(',')
    if pix_format == 'RGBA':
        img = ImageRGBA(int(width), int(height))
    elif pix_format == 'BGRA':
        img = ImageBGRA(int(width), int(height))
    elif pix_format == 'PRGBA':
        img = ImagePRGBA(int(width), int(height))
    else:
        raise ValueError("Unknown pixel format", pix_format)

    objects[str(id(img))] = img
    return str(id(img))
Exemple #7
0
def _read_scanlines(f, header, width, height):
    if width < 8 or width > 32767:
        raise ValueError("Not yet implemented reading of uncompressed image!!!")
        pass # read uncompressed image
    max_gg = 0.0
    img = ImagePRGBA(width, height)
    for i in range(height, 0, -1):
        rgbe = f.read(4)
        if int(rgbe[0]) != 2 or int(rgbe[1]) != 2 or bool(rgbe[2] & 0x80):
            #this file is not run legnth encode
            #read uncompressed image
            raise ValueError("Not yet implemented reading of uncompressed image!!!")
            return None
        scanline_width = int(int(rgbe[2]) << 8 | rgbe[3]) 
        if scanline_width != width:
            return None
        red_scanline = _read_one_scanline(f, scanline_width)
        green_scanline = _read_one_scanline(f, scanline_width)
        blue_scanline = _read_one_scanline(f, scanline_width)
        exponent = _read_one_scanline(f, scanline_width)
    
        _convert_scanline_to_pixels(red_scanline, green_scanline, blue_scanline, exponent, i-1, img)
    return img