Example #1
0
    def testTiledImage(self):
        # check defaults work OK
        im = image.T(40, 30)
        self.assertEqual(40, im.total_xsize)
        self.assertEqual(30, im.total_ysize)
        self.assertEqual(0, im.xoffset)
        self.assertEqual(0, im.yoffset)

        # check a different total size is honored
        im = image.T(40, 30, 400, 300)
        self.assertEqual(400, im.total_xsize)
        self.assertEqual(300, im.total_ysize)
        self.assertEqual(0, im.xoffset)
        self.assertEqual(0, im.yoffset)

        # check offset has an effect
        im.set_offset(40, 30)
        self.assertEqual(40, im.xoffset)
        self.assertEqual(30, im.yoffset)

        # check offset bounds-checking
        self.assertRaises(ValueError, im.set_offset, 400, 0)
        self.assertRaises(ValueError, im.set_offset, 361, 0)
        self.assertRaises(ValueError, im.set_offset, 0, 300)
        self.assertRaises(ValueError, im.set_offset, 0, 271)
        self.assertRaises(ValueError, im.set_offset, -1, 0)
        self.assertRaises(ValueError, im.set_offset, 0, -1)

        # check offset wasn't changed
        self.assertEqual(40, im.xoffset)
        self.assertEqual(30, im.yoffset)
Example #2
0
    def testLookupOnePixel(self):
        im = image.T(1, 1)
        rgba = im.lookup(0, 0)
        self.assertEqual((0, 0, 0, 1.0), rgba)

        buf = im.image_buffer()
        buf[0] = 20
        buf[1] = 80
        buf[2] = 160

        rgba = im.lookup(0, 0)
        self.assertEqual((20.0 / 255.0, 80.0 / 255.0, 160.0 / 255.0, 1.0),
                         rgba)

        rgba = im.lookup(0.5, 0.5)
        self.assertEqual((20.0 / 255.0, 80.0 / 255.0, 160.0 / 255.0, 1.0),
                         rgba)

        rgba = im.lookup(-0.5, -0.5)
        self.assertEqual((20.0 / 255.0, 80.0 / 255.0, 160.0 / 255.0, 1.0),
                         rgba)

        rgba = im.lookup(10.5, -10.5)
        self.assertEqual((20.0 / 255.0, 80.0 / 255.0, 160.0 / 255.0, 1.0),
                         rgba)
Example #3
0
    def testLookupFourPixels(self):
        im = image.T(2, 2)
        buf = im.image_buffer()
        buf[0] = 0  # top left = black
        buf[1] = 0
        buf[2] = 0
        buf[3] = 255  # top right = red
        buf[4] = 0
        buf[5] = 0
        buf[6] = 0  # bottom left = green
        buf[7] = 255
        buf[8] = 0
        buf[9] = 255  # bottom right = white
        buf[10] = 255
        buf[11] = 255

        # halfway across middle of top pixel = half red
        self.assertEqual((0.5, 0.0, 0.0, 1.0), im.lookup(0.5, 0.25))

        # halfway down left-hand side = half green
        self.assertEqual((0.0, 0.5, 0.0, 1.0), im.lookup(0.25, 0.5))

        # halfway down right-hand side = red/white
        self.assertEqual((1.0, 0.5, 0.5, 1.0), im.lookup(0.75, 0.5))

        # halfway across bottom = green/white
        self.assertEqual((0.5, 1.0, 0.5, 1.0), im.lookup(0.5, 0.75))

        # center = blend of half-red and green/white
        self.assertEqual((0.5, 0.5, 0.25, 1.0), im.lookup(0.5, 0.5))
Example #4
0
    def __init__(self,comp,width,height,total_width=-1,total_height=-1):
        gobject.GObject.__init__(self)

        if 'win' == sys.platform[:3]:
            (self.readfd, self.writefd) = fract4dc.pipe()
        else:
            # This is the line that was screwing Windows up.. changed to be run only on Linux, for Windows, we want to do this in fract4dc..
            (self.readfd, self.writefd) = os.pipe()
        self.nthreads = 1

        self.compiler = comp

        self.x = self.y = 0
        self.button = 0
        self.last_progress = 0.0
        self.skip_updates = False
        self.running = False
        self.frozen = False # if true, don't emit signals

        self.site = fract4dc.fdsite_create(self.writefd)
        self.f = None
        self.try_init_fractal()

        self.input_add(self.readfd, self.onData)
        
        self.width = width
        self.height = height
        self.image = image.T(
            self.width,self.height,total_width,total_height)

        self.msgbuf = ""
        self.io_subsys = gtkio();
Example #5
0
    def __init__(self, comp, width, height, total_width=-1, total_height=-1):
        GObject.GObject.__init__(self)

        (self.readfd, self.writefd) = os.pipe()
        self.nthreads = 1

        self.compiler = comp

        self.x = self.y = 0
        self.button = 0
        self.last_progress = 0.0
        self.skip_updates = False
        self.running = False
        self.frozen = False  # if true, don't emit signals

        self.site = fract4dc.fdsite_create(self.writefd)
        self.f = None
        self.try_init_fractal()

        self.input_add(self.readfd, self.onData)

        self.width = width
        self.height = height
        self.image = image.T(
            self.width, self.height, total_width, total_height)

        self.msgbuf = b""
        self.io_subsys = gtkio()
Example #6
0
    def drawTwice(self, is_dirty, xsize):
        ysize = int(xsize * 3.0 / 4.0)
        im = image.T(xsize, ysize)
        siteobj = FractalSite()
        site = fract4dc.site_create(siteobj)

        file = self.compileColorMandel()
        handle = fract4dc.pf_load(file)
        pfunc = fract4dc.pf_create(handle)
        fract4dc.pf_init(pfunc, pos_params, self.color_mandel_params)

        cmap = fract4dc.cmap_create(
            [(1.0, 255, 255, 255, 255)])

        fract4dc.calc(
            params=[0.0, 0.0, 0.0, 0.0,
                    4.0,
                    0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            antialias=0,
            maxiter=100,
            yflip=0,
            nthreads=1,
            pfo=pfunc,
            cmap=cmap,
            auto_deepen=0,
            periodicity=1,
            render_type=0,
            image=im._img,
            site=site,
            dirty=is_dirty)

        # print "1st pass %s" % is_dirty
        #fract4dc.image_save(image, "/tmp/pass1%d.tga" % is_dirty)
        # self.print_fates(image,xsize,ysize)

        cmap = fract4dc.cmap_create(
            [(1.0, 76, 49, 189, 255)])

        fract4dc.calc(
            params=[0.0, 0.0, 0.0, 0.0,
                    4.0,
                    0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            antialias=0,
            maxiter=100,
            yflip=0,
            nthreads=1,
            pfo=pfunc,
            cmap=cmap,
            auto_deepen=0,
            periodicity=1,
            render_type=0,
            image=im._img,
            site=site,
            dirty=is_dirty)

        # print "2nd pass %s" % is_dirty
        # self.print_fates(image,xsize,ysize)
        im.save(os.path.join(Test.tmpdir.name, "pass2%d.tga" % is_dirty))

        return []  # fract4dc.image_buffer(image)
Example #7
0
 def createTestImage(self):
     # image is [ black, white, green, red]
     im = image.T(2, 2)
     buf = im.image_buffer()
     buf[3] = buf[4] = buf[5] = 255  # white
     buf[7] = 255  # green
     buf[9] = 255  # red
     return im
Example #8
0
    def testCalc(self):
        xsize = 64
        ysize = int(xsize * 3.0 / 4.0)
        im = image.T(xsize, ysize)
        siteobj = FractalSite()
        site = fract4dc.site_create(siteobj)

        file = self.compileColorMandel()
        handle = fract4dc.pf_load(file)
        pfunc = fract4dc.pf_create(handle)
        fract4dc.pf_init(pfunc, pos_params, self.color_mandel_params)
        cmap = fract4dc.cmap_create([(0.0, 0, 0, 0, 255),
                                     (1 / 256.0, 255, 255, 255, 255),
                                     (1.0, 255, 255, 255, 255)])
        fract4dc.calc(
            params=[0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            antialias=0,
            maxiter=100,
            yflip=0,
            nthreads=1,
            pfo=pfunc,
            cmap=cmap,
            auto_deepen=0,
            periodicity=1,
            render_type=0,
            image=im._img,
            site=site)

        self.assertEqual(siteobj.progress_list[-1], 0.0)
        self.assertEqual(siteobj.progress_list[-2], 1.0)

        self.assertTrue(siteobj.image_list[-1] == (0, 0, xsize, ysize))

        self.assertTrue(siteobj.status_list[0] == 1
                        and siteobj.status_list[-1] == 0)

        test2_tga = os.path.join(Test.tmpdir.name, "test2.tga")
        self.assertTrue(not os.path.exists(test2_tga))
        im.save(test2_tga)
        self.assertTrue(os.path.exists(test2_tga))

        # fate of all non-aa pixels should be known, aa-pixels unknown
        fate_buf = im.fate_buffer()
        i = 0
        for byte in fate_buf:
            d = im.get_color_index(
                (i % (im.FATE_SIZE * xsize)) // im.FATE_SIZE,
                i // (im.FATE_SIZE * xsize), i % im.FATE_SIZE)

            if i % 4 == 0:
                # no-aa
                self.assertNotEqual(byte, 255, "pixel %d is %d" % (i, byte))
                self.assertNotEqual("%g" % d, "inf")
            else:
                self.assertEqual(byte, 255)
            i += 1

        self.assertPixelCount(xsize, ysize, siteobj)
Example #9
0
    def testFractWorker(self):
        xsize = 8
        ysize = 8
        im = image.T(xsize, ysize)

        cmap = fract4dc.cmap_create([(1.0, 255, 255, 255, 255)])

        fract4dc.cmap_set_solid(cmap, 0, 0, 0, 0, 255)
        fract4dc.cmap_set_solid(cmap, 1, 0, 0, 0, 255)

        (fw, ff, site, handle, pfunc) = self.makeWorkerAndFunc(im._img, cmap)

        im.clear()
        fate_buf = im.fate_buffer()
        buf = im.image_buffer()

        # draw 1 pixel, check it's set properly
        fract4dc.fw_pixel(fw, 0, 0, 1, 1)
        self.assertPixelIs(im, 0, 0, [im.OUT] + [im.UNKNOWN] * 3)

        fract4dc.fw_pixel(fw, 0, 4, 1, 1)
        self.assertPixelIs(im, 0, 4, [im.IN] + [im.UNKNOWN] * 3)

        # draw it again, check no change.
        fract4dc.fw_pixel(fw, 0, 0, 1, 1)
        self.assertPixelIs(im, 0, 0, [im.OUT] + [im.UNKNOWN] * 3)

        # draw & antialias another pixel
        fract4dc.fw_pixel(fw, 2, 2, 1, 1)
        fract4dc.fw_pixel_aa(fw, 2, 2)
        self.assertPixelIs(im, 2, 2, [im.OUT, im.OUT, im.IN, im.OUT])

        # change cmap, draw same pixel again, check color changes
        cmap = fract4dc.cmap_create(
            [(1.0, 79, 88, 41, 255)])
        fract4dc.cmap_set_solid(cmap, 1, 100, 101, 102, 255)

        (fw, ff, site, handle, pfunc) = self.makeWorkerAndFunc(im._img, cmap)

        fract4dc.fw_pixel(fw, 0, 0, 1, 1)
        self.assertPixelIs(im, 0, 0, [im.OUT] + [im.UNKNOWN] * 3, [79, 88, 41])

        # redraw antialiased pixel
        fract4dc.fw_pixel_aa(fw, 2, 2)
        self.assertPixelIs(
            im, 2, 2, [im.OUT, im.OUT, im.IN, im.OUT],
            [79, 88, 41], [100, 101, 102])

        # draw large block overlapping existing pixels
        fract4dc.fw_pixel(fw, 0, 0, 4, 4)
        self.assertPixelIs(
            im, 0, 0, [im.OUT, im.UNKNOWN, im.UNKNOWN, im.UNKNOWN],
            [79, 88, 41], [100, 101, 102])

        self.assertPixelIs(
            im, 3, 1, [im.UNKNOWN] * 4,
            [79, 88, 41], [100, 101, 102], im.OUT)
Example #10
0
    def doTestSave(self, ext, format):
        f1 = os.path.join(Test.tmpdir.name, "save1.%s" % ext)
        f2 = os.path.join(Test.tmpdir.name, "save2.%s" % ext)
        im = image.T(640, 400)
        im.save(f1)
        self.assertTrue(os.path.exists(f1))
        self.assertImageFileFormat(f1, format)

        im = image.T(640, 40, 640, 400)
        im.start_save(f2)
        for (xoff, yoff, w, h) in im.get_tile_list():
            im.resize_tile(w, h)
            im.set_offset(xoff, yoff)
            im.save_tile()
        im.finish_save()
        self.assertTrue(os.path.exists(f2))
        self.assertImageFileFormat(f2, format)

        self.assertEqual(True, filecmp.cmp(f1, f2, False))
Example #11
0
    def testColossalImage(self):
        # aborts with 'std::bad_array_new_length'
        return

        try:
            im = image.T(400000, 300000)
            self.fail("Should have raised an exception")
        except MemoryError as err:
            pass

        im = image.T(40, 30)
        try:
            im.resize_full(400000, 300000)
            self.fail("Should have raised an exception")
        except MemoryError as err:
            # retains large size even if allocation fails
            self.assertEqual(400000, im.xsize)
            self.assertEqual(300000, im.ysize)
            pass
Example #12
0
    def testResize(self):
        im = image.T(10, 20)
        self.assertEqual(10, im.xsize)
        self.assertEqual(20, im.ysize)
        self.assertImageInvariants(im)

        im.resize_full(30, 17)
        self.assertEqual(30, im.xsize)
        self.assertEqual(17, im.ysize)
        self.assertImageInvariants(im)
Example #13
0
    def testClear(self):
        # check clear() works
        (xsize, ysize) = (61, 33)
        im = image.T(xsize, ysize)
        im.clear()

        fate_buf = im.fate_buffer()
        self.assertEqual(list(fate_buf),
                         [im.UNKNOWN] * im.FATE_SIZE * xsize * ysize)

        buf = im.image_buffer()
        self.assertEqual(list(buf), [0] * xsize * ysize * im.COL_SIZE)
Example #14
0
    def run_nogui(self):
        main = fractmain.T()
        print main.compiler.path_lists
        times = []
        last_time = now()
        for file in files:
            main.load(file)
            im = image.T(self.w, self.h)
            main.draw(im)
            im.save(file + ".png")
            new_time = now()
            times.append(new_time - last_time)

        return times
Example #15
0
    def testTileList(self):
        # a single tile
        im = image.T(100, 50)
        self.assertEqual([(0, 0, 100, 50)], im.get_tile_list())

        # 2 wide, 1 high
        im = image.T(100, 50, 200, 50)
        self.assertEqual([(0, 0, 100, 50), (100, 0, 100, 50)],
                         im.get_tile_list())

        # 2 high, 1 wide
        im = image.T(100, 50, 100, 100)
        self.assertEqual([(0, 0, 100, 50), (0, 50, 100, 50)],
                         im.get_tile_list())

        # not evenly divisible, odd-shaped chunks at edges
        im = image.T(100, 50, 101, 51)
        self.assertEqual([(0, 0, 100, 50), (100, 0, 1, 50), (
            0,
            50,
            100,
            1,
        ), (100, 50, 1, 1)], im.get_tile_list())
Example #16
0
    def testLookupTwoPixels(self):
        im = image.T(2, 1)
        rgba = im.lookup(0, 0)
        self.assertEqual((0, 0, 0, 1.0), rgba)

        buf = im.image_buffer()
        buf[0] = 0
        buf[1] = 0
        buf[2] = 0
        buf[3] = 255
        buf[4] = 255
        buf[5] = 255

        self.assertEqual(self.grey_pixel(0.5), im.lookup(0, 0))
        self.assertEqual(self.grey_pixel(0.0), im.lookup(0.25, 0.25))
        self.assertEqual(self.grey_pixel(1.0), im.lookup(0.75, 0.75))
Example #17
0
    def testAACalc(self):
        xsize = 64
        ysize = int(xsize * 3.0 / 4.0)
        im = image.T(xsize, ysize)
        siteobj = FractalSite()
        site = fract4dc.site_create(siteobj)

        file = self.compileColorMandel()
        handle = fract4dc.pf_load(file)
        pfunc = fract4dc.pf_create(handle)
        fract4dc.pf_init(pfunc, pos_params, self.color_mandel_params)
        cmap = fract4dc.cmap_create(
            [(0.0, 0, 0, 0, 255),
             (1 / 256.0, 255, 255, 255, 255),
             (1.0, 255, 255, 255, 255)])
        fract4dc.calc(
            params=[0.0, 0.0, 0.0, 0.0,
                    4.0,
                    0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            antialias=1,
            maxiter=100,
            yflip=0,
            nthreads=1,
            pfo=pfunc,
            cmap=cmap,
            auto_deepen=0,
            periodicity=1,
            render_type=0,
            image=im._img,
            site=site)

        # fate of all pixels should be known
        fate_buf = im.fate_buffer()
        i = 0
        for byte in fate_buf:
            d = im.get_color_index(
                (i % (im.FATE_SIZE * xsize)) // im.FATE_SIZE,
                i // (im.FATE_SIZE * xsize),
                i % im.FATE_SIZE)

            self.assertNotEqual("%g" % d, "inf", "index %d is %g" % (i, d))
            self.assertNotEqual(byte, 255,
                                "pixel %d is %d" % (i, byte))
            i += 1
Example #18
0
    def testBufferBounds(self):
        im = image.T(40, 30)
        im.resize_full(80, 60)
        buf = im.image_buffer()
        fate_buf = im.fate_buffer()

        self.assertRaises(ValueError, im.image_buffer, -1, 0)
        self.assertRaises(ValueError, im.image_buffer, 80, 0)
        self.assertRaises(ValueError, im.image_buffer, 41, 67)

        self.assertRaises(ValueError, im.fate_buffer, -1, 0)
        self.assertRaises(ValueError, im.fate_buffer, 80, 0)
        self.assertRaises(ValueError, im.fate_buffer, 41, 67)

        buf = im.image_buffer(5, 10)
        self.assertEqual(len(buf),
                         80 * 60 * im.COL_SIZE - (10 * 80 + 5) * im.COL_SIZE)

        buf = im.fate_buffer(5, 10)
        self.assertEqual(len(buf),
                         80 * 60 * im.FATE_SIZE - (10 * 80 + 5) * im.FATE_SIZE)
Example #19
0
    def setUp(self):
        self.f = fractal.T(Test.g_comp)
        self.f.render_type = 2
        self.f.set_formula("test.frm", "test_hypersphere")
        self.f.compile()

        handle = fract4dc.pf_load(self.f.outputfile)
        self.pfunc = fract4dc.pf_create(handle)
        self.cmap = fract4dc.cmap_create_gradient(
            self.f.get_gradient().segments)
        (r, g, b, a) = self.f.solids[0]
        fract4dc.cmap_set_solid(self.cmap, 0, r, g, b, a)
        (r, g, b, a) = self.f.solids[1]
        fract4dc.cmap_set_solid(self.cmap, 1, r, g, b, a)

        initparams = self.f.all_params()
        fract4dc.pf_init(self.pfunc, self.f.params, initparams)

        self.im = image.T(40, 30)
        siteobj = FractalSite()

        self.fw = fract4dc.fw_create(1, self.pfunc, self.cmap, self.im._img,
                                     self.f.site)

        self.ff = fract4dc.ff_create(
            [0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            2,
            100,
            0,
            1,
            self.pfunc,
            self.cmap,
            0,
            1,
            2,  # 3D
            self.im._img,
            self.f.site,
            self.fw,
            False,
            1.0E-9)
Example #20
0
    def testFDSite(self):
        xsize = 64
        ysize = int(xsize * 3.0 / 4.0)
        im = image.T(xsize, ysize)
        (rfd, wfd) = os.pipe()
        site = fract4dc.fdsite_create(wfd)

        file = self.compileColorMandel()

        for x in range(2):
            handle = fract4dc.pf_load(file)
            pfunc = fract4dc.pf_create(handle)
            fract4dc.pf_init(pfunc, pos_params, self.color_mandel_params)
            cmap = fract4dc.cmap_create([(0.0, 0, 0, 0, 255),
                                         (1 / 256.0, 255, 255, 255, 255),
                                         (1.0, 255, 255, 255, 255)])

            fract4dc.calc(
                params=[0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                antialias=0,
                maxiter=100,
                yflip=0,
                nthreads=1,
                pfo=pfunc,
                cmap=cmap,
                auto_deepen=0,
                periodicity=1,
                render_type=0,
                image=im._img,
                site=site,
                asynchronous=True)

            nrecved = 0
            while True:
                if nrecved == x:
                    # print "hit message count"
                    fract4dc.interrupt(site)

                nb = 2 * 4
                bytes = os.read(rfd, nb)
                if len(bytes) < nb:
                    self.fail("bad message with length %s, value %s" %
                              (len(bytes), bytes))
                    break

                (t, size) = struct.unpack("2i", bytes)
                # print "read %d, len %d" % (t,size)

                # read the rest of the message
                bytes = os.read(rfd, size)
                if len(bytes) < size:
                    self.fail("bad message")
                    break

                msg = messages.parse(t, bytes)
                # print "msg: %s" % msg.show()
                if msg.name == "Status" and msg.status == 0:
                    # done
                    # print "done"
                    break

                nrecved += 1
Example #21
0
    def testFDSite(self):
        xsize = 64
        ysize = int(xsize * 3.0 / 4.0)
        im = image.T(xsize, ysize)
        (rfd, wfd) = os.pipe()
        site = fract4dc.fdsite_create(wfd)

        file = self.compileColorMandel()

        handle = fract4dc.pf_load(file)
        pfunc = fract4dc.pf_create(handle)

        for x in range(2):
            fract4dc.pf_init(pfunc, pos_params, self.color_mandel_params)
            cmap = fract4dc.cmap_create(
                [(0.0, 0, 0, 0, 255),
                 (1 / 256.0, 255, 255, 255, 255),
                 (1.0, 255, 255, 255, 255)])

            fract4dc.calc(
                params=[0.0, 0.0, 0.0, 0.0,
                        4.0,
                        0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                antialias=0,
                maxiter=100,
                yflip=0,
                nthreads=1,
                pfo=pfunc,
                cmap=cmap,
                auto_deepen=0,
                periodicity=1,
                render_type=0,
                image=im._img,
                site=site,
                asynchronous=True)

            while True:
                # read message type and size
                # we use a buffer here like in gtkfractal.py "onData"
                nb = 2 * 4
                bytes = b""
                while True:
                    # wait up to 1 sec until we can read, otherwise we assume the counterpart is gone (an error ocurred on the C++ layer)
                    r, w, e = select.select([rfd], [], [], 1)
                    if rfd in r:
                        temp = os.read(rfd, nb - len(bytes))
                    else:
                        self.fail("no one on the other side")
                    bytes = bytes + temp
                    if (len(bytes) == nb):
                        break
                    elif temp == '':
                        self.fail(
                            "bad message with length %s, value %s" %
                            (len(bytes), bytes))
                (t, size) = struct.unpack("2i", bytes)

                # read the actual message
                bytes = os.read(rfd, size)
                if len(bytes) < size:
                    self.fail("bad message")
                    break
                msg = messages.parse(t, bytes)
                # if the fractal is done
                if msg.name == "Status" and msg.status == 0:
                    # fract4dc.interrupt(site)
                    break
Example #22
0
 def testDrawMBrot(self):
     self.f.set_formula("gf4d.frm", "Mandelbrot")
     self.f.compile()
     im = image.T(80, 60)
     self.f.draw(im)
Example #23
0
    def testVectors(self):
        siteobj = FractalSite()
        site = fract4dc.site_create(siteobj)

        file = self.compileColorDiagonal()
        handle = fract4dc.pf_load(file)
        pfunc = fract4dc.pf_create(handle)
        fract4dc.pf_init(pfunc, pos_params, self.color_diagonal_params)

        (w, h, tw, th) = (40, 20, 40, 20)
        im = image.T(w, h)

        cmap = fract4dc.cmap_create([(1.0, 255, 255, 255, 255)])

        fw = fract4dc.fw_create(1, pfunc, cmap, im._img, site)

        ff = fract4dc.ff_create(
            [0.0, 0.0, 0.0, 0.0,
             4.0,
             0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            2,
            100,
            0,
            1,
            pfunc,
            cmap,
            0,
            1,
            0,
            im._img,
            site,
            fw,
            False,
            1.0E-9)

        # check dx, dy and topleft
        dx = fract4dc.ff_get_vector(ff, fract4dc.DELTA_X)
        self.assertNearlyEqual(dx, [4.0 / tw, 0.0, 0.0, 0.0])

        dy = fract4dc.ff_get_vector(ff, fract4dc.DELTA_Y)
        self.assertNearlyEqual(dy, [0.0, -2.0 / th, 0.0, 0.0])

        topleft = fract4dc.ff_get_vector(ff, fract4dc.TOPLEFT)
        self.assertNearlyEqual(
            topleft, [-2.0 + 4.0 / (tw * 2), 1.0 - 2.0 / (th * 2), 0.0, 0.0])

        # check they are updated if image is bigger
        (w, h, tw, th) = (40, 20, 400, 200)
        im = image.T(w, h, tw, th)

        fw = fract4dc.fw_create(1, pfunc, cmap, im._img, site)

        ff = fract4dc.ff_create(
            [0.0, 0.0, 0.0, 0.0,
             4.0,
             0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            2,
            100,
            0,
            1,
            pfunc,
            cmap,
            0,
            1,
            0,
            im._img,
            site,
            fw,
            False,
            1.0E-9)

        # check dx, dy and topleft
        dx = fract4dc.ff_get_vector(ff, fract4dc.DELTA_X)
        self.assertNearlyEqual(dx, [4.0 / tw, 0.0, 0.0, 0.0])

        dy = fract4dc.ff_get_vector(ff, fract4dc.DELTA_Y)
        self.assertNearlyEqual(dy, [0.0, -2.0 / th, 0.0, 0.0])

        topleft = fract4dc.ff_get_vector(ff, fract4dc.TOPLEFT)
        self.assertNearlyEqual(
            topleft, [-2.0 + 4.0 / (tw * 2), 1.0 - 2.0 / (th * 2), 0.0, 0.0])

        offx = 40
        offy = 10
        im.set_offset(offx, offy)

        fw = fract4dc.fw_create(1, pfunc, cmap, im._img, site)

        ff = fract4dc.ff_create(
            [0.0, 0.0, 0.0, 0.0,
             4.0,
             0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            2,
            100,
            0,
            1,
            pfunc,
            cmap,
            0,
            1,
            0,
            im._img,
            site,
            fw,
            False,
            1.0E-9)

        # check dx, dy and topleft
        dx = fract4dc.ff_get_vector(ff, fract4dc.DELTA_X)
        self.assertNearlyEqual(dx, [4.0 / tw, 0.0, 0.0, 0.0])

        dy = fract4dc.ff_get_vector(ff, fract4dc.DELTA_Y)
        self.assertNearlyEqual(dy, [0.0, -2.0 / th, 0.0, 0.0])

        topleft = fract4dc.ff_get_vector(ff, fract4dc.TOPLEFT)
        self.assertNearlyEqual(topleft, [
            -2.0 + dx[0] * (offx + 0.5),
            1.0 + dy[1] * (offy + 0.5),
            0.0, 0.0])
Example #24
0
 def testFileExtensionLookup(self):
     im = image.T(40, 30)
     self.assertRaises(ValueError, im.file_type, "hello.gif")
     self.assertRaises(ValueError, im.file_type, "hello")
Example #25
0
 def doTestLoad(self, file):
     im = image.T(1, 1)
     im.load(file)
     cmp_image = self.createTestImage()
     self.assertImagesEqual(im, cmp_image)
Example #26
0
 def saveAndCheck(self, name, format):
     im = image.T(640, 400)
     im.save(name)
     self.assertTrue(os.path.exists(name))
     self.assertImageFileFormat(name, format)
Example #27
0
# 6th create a controller: this one handles the calculation process and informs about progress
controller = fract4dc.create_controller(compiled_library,
                                        formula_and_transfer_params,
                                        location_params)

# 7th create a message handler to receive updates from controller
message_handler = FractalSite()
controller.set_message_handler(message_handler)

# 8th create a color map to convert point fates (iterations needed to determine if the point scapes) into colors
color_map = fract4dc.cmap_create([(0.0, 0, 0, 0, 255),
                                  (1 / 256.0, 255, 255, 255, 255),
                                  (1.0, 255, 255, 255, 255)])

# 9th create an image: this one will hold the final result and provide utilities to save it into a file
im = image.T(640, 480)

# 10th launch the calculation process through the controller
# there's some additional params taking default values here, like asynchronous, tolerance ...
controller.start_calculating(
    params=location_params,
    antialias=0,
    maxiter=100,
    yflip=0,
    nthreads=1,
    cmap=color_map,
    auto_deepen=0,
    periodicity=1,
    render_type=0,
    image=im._img,
)