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)
def testCmap(self): cmap = fract4dc.cmap_create( [(0.0, 255, 0, 100, 255), (1.0, 0, 255, 50, 255)]) self.assertEqual(fract4dc.cmap_lookup(cmap, 0.0), (255, 0, 100, 255)) self.assertEqual( fract4dc.cmap_lookup( cmap, 1.0 - 1e-10), (0, 254, 50, 255)) self.assertEqual(fract4dc.cmap_lookup(cmap, 1.0), (0, 255, 50, 255)) self.assertEqual(fract4dc.cmap_lookup(cmap, 0.5), (127, 127, 75, 255)) self.assertEqual( fract4dc.cmap_lookup( cmap, 0.00000001), (254, 0, 99, 255)) cmap = fract4dc.cmap_create( [(0.0, 255, 0, 100, 255)]) expc1 = (255, 0, 100, 255) self.assertEqual(fract4dc.cmap_lookup(cmap, 0.0), expc1) self.assertEqual(fract4dc.cmap_lookup(cmap, 1.0), expc1) self.assertEqual(fract4dc.cmap_lookup(cmap, 0.4), expc1) colors = [] for i in range(256): colors.append( (i / 255.0, (i * 17) % 256, 255 - i, i // 2, i // 2 + 127)) cmap = fract4dc.cmap_create(colors) for i in range(256): self.assertEqual(fract4dc.cmap_lookup( cmap, i / 255.0), colors[i][1:], i)
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)
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)
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)
def test_stop_calculating(self): message_handler = MockMessageHandler() self.controller.set_message_handler(message_handler) color_map = Fract4dc.cmap_create(COLOR_MAP) image = ImageWrapper(TILE_SIZE, TILE_SIZE).get_img() initial_statuses_history = message_handler.get_statuses_history().copy( ) self.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=image, ) first_status = message_handler.get_statuses_history()[0] self.controller.stop_calculating() last_status = message_handler.get_statuses_history()[-1] self.assertEqual(0, len(initial_statuses_history)) self.assertEqual(1, first_status) self.assertEqual(0, last_status)
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)
def testCmap(self): cmap = fract4dc.cmap_create( [(0.0,255,0,100,255), (1.0, 0, 255, 50, 255)]) self.assertEqual(fract4dc.cmap_lookup(cmap,0.0), (255,0,100,255)) self.assertEqual(fract4dc.cmap_lookup(cmap,1.0-1e-10), (0,254,50,255)) self.assertEqual(fract4dc.cmap_lookup(cmap,1.0), (0,255,50,255)) self.assertEqual(fract4dc.cmap_lookup(cmap,0.5), (127,127,75,255)) self.assertEqual(fract4dc.cmap_lookup(cmap,0.00000001), (254,0,99,255)) cmap = fract4dc.cmap_create( [(0.0,255,0,100,255)]) expc1 = (255,0,100,255) self.assertEqual(fract4dc.cmap_lookup(cmap,0.0),expc1) self.assertEqual(fract4dc.cmap_lookup(cmap,1.0),expc1) self.assertEqual(fract4dc.cmap_lookup(cmap,0.4),expc1) colors = [] for i in range(256): colors.append((i/255.0,(i*17)%256,255-i,i//2,i//2+127)) cmap = fract4dc.cmap_create(colors) for i in range(256): self.assertEqual(fract4dc.cmap_lookup(cmap,i/255.0),colors[i][1:],i)
def testTransfers(self): # test fates cmap = fract4dc.cmap_create( [(0.0, 33, 33, 33, 255)]) # make inner transfer func none fract4dc.cmap_set_transfer(cmap, 1, 0) # inside should be all-black by default, outside should never be index = 0.0 while index < 2.0: color = fract4dc.cmap_lookup_flags(cmap, index, 0, 1) self.assertEqual(color, (0, 0, 0, 255)) color = fract4dc.cmap_lookup_flags(cmap, index, 0, 0) self.assertEqual(color, (33, 33, 33, 255)) index += 0.1 # test setting solid colors and transfers fract4dc.cmap_set_solid(cmap, 0, 166, 166, 166, 255) fract4dc.cmap_set_solid(cmap, 1, 177, 177, 177, 255) fract4dc.cmap_set_transfer(cmap, 0, 0) index = 0.0 while index < 2.0: color = fract4dc.cmap_lookup_flags(cmap, index, 0, 1) self.assertEqual(color, (177, 177, 177, 255)) color = fract4dc.cmap_lookup_flags(cmap, index, 0, 0) self.assertEqual(color, (166, 166, 166, 255)) index += 0.1 # make inner linear fract4dc.cmap_set_transfer(cmap, 1, 1) index = 0.0 while index < 2.0: color = fract4dc.cmap_lookup_flags(cmap, index, 0, 1) self.assertEqual(color, (33, 33, 33, 255)) color = fract4dc.cmap_lookup_flags(cmap, index, 0, 0) self.assertEqual(color, (166, 166, 166, 255)) index += 0.1 # test that solid overrides color = fract4dc.cmap_lookup_flags(cmap, 0.1, 1, 1) self.assertEqual(color, (177, 177, 177, 255)) color = fract4dc.cmap_lookup_flags(cmap, 0.1, 1, 0) self.assertEqual(color, (166, 166, 166, 255))
def testTransfers(self): # test fates cmap = fract4dc.cmap_create( [(0.0,33,33,33,255)]) # make inner transfer func none fract4dc.cmap_set_transfer(cmap,1,0) # inside should be all-black by default, outside should never be index = 0.0 while index < 2.0: color = fract4dc.cmap_lookup_flags(cmap,index,0,1) self.assertEqual(color,(0,0,0,255)) color = fract4dc.cmap_lookup_flags(cmap,index,0,0) self.assertEqual(color,(33,33,33,255)) index += 0.1 # test setting solid colors and transfers fract4dc.cmap_set_solid(cmap,0,166,166,166,255) fract4dc.cmap_set_solid(cmap,1,177,177,177,255) fract4dc.cmap_set_transfer(cmap,0,0) index = 0.0 while index < 2.0: color = fract4dc.cmap_lookup_flags(cmap,index,0,1) self.assertEqual(color,(177,177,177,255)) color = fract4dc.cmap_lookup_flags(cmap,index,0,0) self.assertEqual(color,(166,166,166,255)) index += 0.1 # make inner linear fract4dc.cmap_set_transfer(cmap,1,1) index = 0.0 while index < 2.0: color = fract4dc.cmap_lookup_flags(cmap,index,0,1) self.assertEqual(color,(33,33,33,255)) color = fract4dc.cmap_lookup_flags(cmap,index,0,0) self.assertEqual(color,(166,166,166,255)) index += 0.1 # test that solid overrides color = fract4dc.cmap_lookup_flags(cmap,0.1,1,1) self.assertEqual(color,(177,177,177,255)) color = fract4dc.cmap_lookup_flags(cmap,0.1,1,0) self.assertEqual(color,(166,166,166,255))
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
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
def checkColorMapAndGradientEquivalent(self, colorlist, maxdiff=0): grad = gradient.Gradient() grad.load_list(colorlist, maxdiff) self.assertWellFormedGradient(grad) if maxdiff != 0: # don't have any robust metric for how close this will be return cmap = fract4dc.cmap_create(colorlist) for i in range(1000): fi = i / 1000.0 (r, g, b, a) = grad.get_color_at(fi) cmap_color = fract4dc.cmap_lookup(cmap, fi) grad_color = (int(r * 255.0), int(g * 255.0), int(b * 255.0), int(a * 255.0)) self.assertNearlyEqual( grad_color, cmap_color, "colorlist(%s) = %s but gradient(%s) = %s" % (fi, cmap_color, fi, grad_color), 1.5) return grad
def checkColorMapAndGradientEquivalent(self,colorlist,maxdiff=0): grad = gradient.Gradient() grad.load_list(colorlist,maxdiff) self.assertWellFormedGradient(grad) if maxdiff != 0: # don't have any robust metric for how close this will be return cmap = fract4dc.cmap_create(colorlist) for i in range(1000): fi = i / 1000.0 (r,g,b,a) = grad.get_color_at(fi) cmap_color = fract4dc.cmap_lookup(cmap, fi) grad_color = (int(r*255.0), int(g*255.0), int(b*255.0), int(a*255.0)) self.assertNearlyEqual( grad_color, cmap_color, "colorlist(%s) = %s but gradient(%s) = %s" % \ (fi, cmap_color, fi, grad_color), 1.5) return grad
0.0, 0.0 # XY XZ XW YZ YW ZW planes (4D stuff) ] # 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,
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])
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
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)
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])
def test_create_color_map(self): color_map = Fract4dc.cmap_create(COLOR_MAP) self.assertTrue(color_map)
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
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