Пример #1
0
 void Scene::computeColorsAntialiasing(std::function<void(int, int, ColorCRef)> paint, int threadCount, int level) {
     upto(threadCount, 1);
     downto(threadCount, 4);
     std::vector< std::vector <ColorFloat> > m(screen.width, std::vector<ColorFloat> (screen.height, ColorFloat()));
     computeColors([paint, &m](int x, int y, ColorCRef c) { m[x][y] = c; paint(x, y, c); }, threadCount);
     if (level > 1) {
         for (int x = 1; x + 1 < screen.width; x++) {
             for (int y = 1; y + 1 < screen.height; y++) {
                 int badness = 0;
                 for (int dx : {-1, 1})
                     for (int dy : {-1, 1})
                         badness += (m[x][y] - m[x + dx][y + dy]).norm();
                 if (badness > badnessLimit) {
                     paint(x, y, Color(255, 0, 0));
                 }
             }
         }
         int taskCount = 10;
         ThreadPool pool;
         for (int t = 0; t < taskCount; t++)
             pool.addTask([this, &paint, &m, level, t, taskCount]()
                          { multiThreadAntialiasePart(paint, m, level, t, taskCount); });
         pool.executeAll(threadCount);
     }
 }
Пример #2
0
void getmemmap(struct Bootinfo* boot)
{
    memset(charbuff, 0, 80 * 25 * 2); //清屏
    memset(MMAP, 0, MAXPAGE >> 3);
    memset(MTMAP, 0xff, 1024 >> 8);
    memset(PSL, 0, 0x100000);
    if (boot->flags & (1 << 6)) {
        struct memmap* map;
        for (map = boot->mmap_addr;
                (uint32)map < (uint32)boot->mmap_addr + boot->mmap_length;
                map = (struct memmap*)((uint32)map + map->size + sizeof(map->size))) {
            if (map->type == 1) {
                printf("Avalable memory,addr:0x%X%08X,lenth:0x%X%08X\n",
                       map->base_addrh,
                       map->base_addr,
                       map->lengthh,
                       map->length);
                uint8* tmpaddr = upto(map->base_addr, PAGESIZE);
                map->length -= (tmpaddr - map->base_addr);
                map->base_addr = tmpaddr;
                size_t count = map->length / PAGESIZE;
                size_t startp = (int)map->base_addr / PAGESIZE;
                int i;
                for (i = 0; i < count; ++i) {
                    setavl(MMAP, startp + i);
                }

            }
        }
    } else {
        printf("Can't get memory map!\n");
    }
    memset(MMAP, 0x00, RESPAGE >> 3);
}
Пример #3
0
	int sobel_argb32_3x3_partial(vbx_uword_t *sobel_out, vbx_uword_t *argb_in, const short image_width,
	                             const short image_height, const short image_pitch, const short renorm)
	{
		VBX::Prefetcher<vbx_uword_t> input(1,image_width,argb_in,argb_in+image_height*image_pitch,image_pitch);
		VBX::Vector<vbx_uword_t> output(image_width);
		VBX::Vector<vbx_uhalf_t>* luma[3];
		luma[0]=new VBX::Vector<vbx_uhalf_t>(image_width);
		luma[1]=new VBX::Vector<vbx_uhalf_t>(image_width);
		luma[2]=new VBX::Vector<vbx_uhalf_t>(image_width);
		VBX::Vector<vbx_uhalf_t> gradient_x(image_width);
		VBX::Vector<vbx_uhalf_t> gradient_y(image_width);
		VBX::Vector<vbx_uhalf_t>* sobel_rows[3];

		sobel_rows[0]=new VBX::Vector<vbx_uhalf_t>(image_width);
		sobel_rows[1]=new VBX::Vector<vbx_uhalf_t>(image_width);
		sobel_rows[2]=new VBX::Vector<vbx_uhalf_t>(image_width);
		input.fetch();
		int rowmod3=0;
		for(int row=0;row<image_height;row++){
			input.fetch();

			VBX::Vector<vbx_uhalf_t>& sobel_top= *sobel_rows[rowmod3];
			VBX::Vector<vbx_uhalf_t>& sobel_bot= *sobel_rows[mod3(rowmod3+2)];
			VBX::Vector<vbx_uhalf_t>& luma_top= *luma[rowmod3];
			VBX::Vector<vbx_uhalf_t>& luma_mid= *luma[mod3(rowmod3+1)];
			VBX::Vector<vbx_uhalf_t>& luma_bot= *luma[mod3(rowmod3+2)];
			rowmod3=mod3(rowmod3+1);
			argb_to_luma8(luma_bot,input[0]);
			sobel_row( sobel_bot ,luma_bot);
			if(row<2){
				continue;
			}

			gradient_y=absdiff(sobel_top,sobel_bot);
			gradient_x=luma_top +luma_bot + luma_mid*2;
			gradient_x[1 upto image_width-1]=absdiff(gradient_x[0 upto image_width-2],gradient_x[2 upto image_width]);

			output=((gradient_x + gradient_y) >> renorm);

			output.cond_move(output>0xFF,0xFF);

			output*=0x010101;

			//write to output buffer, skipping first and last elements
			output[1 upto (image_width -1)].dma_write(sobel_out+(row-1)*image_pitch +1);

		}
		output=0;
		output.dma_write(sobel_out);
		output.dma_write(sobel_out+ (image_height-1)*image_pitch);
		delete luma[0];
		delete luma[1];
		delete luma[2];
		delete sobel_rows[0];
		delete sobel_rows[1];
		delete sobel_rows[2];

		return 0;
	}
Пример #4
0
 void Scene::computeColors(std::function<void(int, int, ColorCRef)> paint, int threadCount) {
     figuresKDTree.init(figures);
     upto(threadCount, 1);
     downto(threadCount, 4);
     int taskCount = 10;
     ThreadPool pool;
     for (int t = 0; t < taskCount; t++)
         pool.addTask([this, &paint, t, taskCount]() { multiThreadComputePartOfColors(paint, t, taskCount); });
     pool.executeAll(threadCount);
 }
Пример #5
0
Файл: lab2.c Проект: gaibo/C
/* note: argc, argv not used, but included per convention */
int main(int argc, char *argv[])
{
  printf("/*** fib ***/\n");
  unsigned int f0 = fib(0);
  unsigned int f1 = fib(1);
  unsigned int f2 = fib(2);
  printf("fib(0)\t%d\n",f0);
  printf("fib(1)\t%d\n",f1);
  printf("fib(2)\t%d\n",f2);

  printf("/*** fact ***/\n");
  unsigned int t6 = fact(6);
  unsigned int t7 = fact(7);
  unsigned int t8 = fact(8);
  printf("fact(6)\t%9d\n",t6);
  printf("fact(7)\t%9d\n",t7);
  printf("fact(8)\t%9d\n",t8);

  printf("/*** int_new ***/\n");
  int* h = int_new(99);
  printf("h\t%p\n",h);
  printf("h+1\t%p\n",h+1);
  printf("*h\t%d\n",*h);
  free(h);

  printf("/*** upto ***/\n");
  unsigned int* arr10 = upto(10);
  int i;
  for (i=0; i<=10; i++)
    printf("arr10[%d]\t%2d\n",i,arr10[i]);
  free(arr10);

  printf("/*** num_evens ***/\n");
  unsigned int e = num_evens(upto(10),11);
  printf("num_evens(upto(10),11)\t%d\n",e);
  
  return 0;
}
Пример #6
0
int file_write(filedes *file,const void *ptr,size_t len) {
    uint32 tmpnode=file->curnode;
    file->updatetime=kernel_getnowtime();
    if(len+file->offset>file->length) {
        tmpnode=Fat_seek(file->curnode,
                         file->length/file->nodebytes-file->offset/file->nodebytes
                        );
        int c=Fat_expand(tmpnode,
                         (file->offset+len)/(file->nodebytes)-file->length/file->nodebytes,
                         FALSE
                        );
        if(c<=0){
            file->length=upto(file->length,file->nodebytes)+(-c)*file->nodebytes;
        }else{
            file->length=file->offset+len;
        }
    }
    return Fat_write(file,ptr,len);
}
Пример #7
0
/* If we see "int main(" then it's probably a main program. */
void scan_cfile(const char *cfile)
	{
	struct stat cstat;
	struct stat ostat;

	struct clist_entry *cdata = clist_push(&clist);

	cdata->need_compile = 0;
	bufd_put(&cdata->cfile, cfile);
	bufd_put(&cdata->ofile, opt_objdir.beg);
	bufd_dirslash(&cdata->ofile);
	bufd_put(&cdata->ofile, cfile);
	bufd_clip(&cdata->ofile, 1);
	bufd_putc(&cdata->ofile, 'o');

	statfile(cdata->cfile.beg, &cstat);
	statfile(cdata->ofile.beg, &ostat);

	if (opt_force || cmp_stat(&cstat, &ostat) > 0)
		cdata->need_compile = 1;

	fp = fopen(cfile,"r");

	while (getch() != EOF)
		{
		if (at("#""include"))
			{
			skipspace();
			if (ch == '"')
				{
				const char *hfile = upto('"');
				if (!cdata->need_compile)
					{
					struct stat hstat;
					statfile(hfile, &hstat);
					if (cmp_stat(&hstat, &ostat) > 0)
						cdata->need_compile = 1;
					}
				strq_push(&cdata->loc_include, hfile);
				}
			else if (ch == '<')
				{
				const char *hfile = upto('>');
				const char *lib = strq_assoc(&syshdr, hfile);
				if (lib)
					strq_push(&cdata->libs, lib);
				strq_push(&cdata->sys_include, hfile);
				}
			}
		else if (at("int") && isspace(ch) && skipspace() &&
			at("main") && skipspace() && ch == '(')
			{
			cdata->is_main = 1;
			}
		}

	if (fp)
		{
		fclose(fp);
		fp = 0;
		}

	if (opt_analyze)
		clist_entry_print(cdata);
	}
Пример #8
0
int main(int argc, char** argv) {

	// between
	ok(between('a','z','c'), "c is between a and z");
	fail(between('a','z','C'), "C is not between a and z");

	// num
	ok(num('0'), "0 is a number");
	ok(num('9'), "9 is a number");
	fail(num('/'), "/ is not a number");
	fail(num(':'), "0 is not a number");

	// alpha
	ok(alpha('a'), "a is a letter");	
	ok(alpha('z'), "z is a letter");	
	ok(alpha('A'), "A is a letter");	
	ok(alpha('Z'), "Z is a letter");	
	fail(alpha('@'), "@ is not a letter");	
	fail(alpha('['), "[ is not a letter");	
	fail(alpha('`'), "` is not a letter");	
	fail(alpha('{'), "{ is not a letter");	
	
	// alphanum
	ok(alphanum('a'), "a is alphanum");
	ok(alphanum('z'), "z is alphanum");
	ok(alphanum('A'), "A is alphanum");
	ok(alphanum('Z'), "Z is alphanum");
	ok(alphanum('0'), "0 is alphanum");
	ok(alphanum('9'), "9 is alphanum");
	fail(alpha('@'), "@ is not alphanum ");	
	fail(alpha('['), "[ is not alphanum");	
	fail(alpha('`'), "` is not alphanum");	
	fail(alpha('{'), "{ is not alphanum");	

	// space
	ok(space(' '), "space is space");
	fail(space('\n'), "new line is not space");
	fail(space('\r'), "cr is not space");
	fail(space('\t'), "tab is not space");

	// tab
	ok(tab('\t'), "tab is tab");
	fail(tab(' '), "space is not tab");
	fail(tab('\n'), "new line is not tab");
	fail(tab('\r'), "cr is not tab");
	
	// nl
	ok(nl('\n'), "new line is new line");
	fail(nl('\t'), "tab is not new line");
	fail(nl(' '), "space is not new line");
	fail(nl('\r'), "cr is not new line");
	
	// cr
	fail(cr('\n'), "new line is not cr");
	fail(cr('\t'), "tab is not cr");
	fail(cr(' '), "space is not cr");
	ok(cr('\r'), "cr is cr");
	
	// whitespace
	ok(whitespace('\n'), "new line is whitespace");
	ok(whitespace('\t'), "tab is whitespace");
	ok(whitespace(' '), "space is whitespace");
	ok(whitespace('\r'), "cr is whitespace");
	fail(whitespace('\b'), "backspace is not whitespace");

	// colon
	ok(colon(':'), "colon is colon");
	fail(colon(';'), "semicolon is not colon");

	// semi
	fail(semi(':'), "colon is not semicolon");
	ok(semi(';'), "semicolon is semicolon");

	// slash
	fail(slash('\\'), "\\ is not /");
	ok(slash('/'), "/ is /");

	// dot
	fail(dot('*'), "* is not .");
	ok(dot('.'), ". is .");
	
	// star
	ok(star('*'), "* is *");
	fail(star('.'), ". is not *");
	
	// question
	ok(question('?'), "? is ?");

	// hex
	ok(hex('a'), "a is hex");
	ok(hex('f'), "f is hex");
	ok(hex('A'), "A is hex");
	ok(hex('F'), "F is hex");
	ok(hex('0'), "0 is hex");
	ok(hex('9'), "9 is hex");
	fail(hex('g'), "g is not hex");
	fail(hex('G'), "G is not hex");
	
	// decimal
	ok(decimal('0'), "0 is decimal");
	ok(decimal('9'), "9 is decimal");
	ok(decimal('.'), ". is decimal");
	fail(decimal('a'), "a is not decimal");

	// ctrl
	ok(ctrl('\b'), "Backspace is ctrl");
	ok(ctrl('\a'), "Bell is ctrl");
	ok(ctrl(127), "Del is ctrl");
	fail(ctrl('a'), "a is not ctrl");

	// any 
	value(3,any(alpha,"abc123"), "three letters at abc123");
	value(0,any(num,"abc123"), "no numbers at abc123");
	value(6,any(alphanum,"abc123"), "six alphanum in abc123");
	
	// until
	value(5,until(space,"hello world!"), "5 letters until space");
	value(11,until(question,"hello world?"), "11 letters until question");
	value(12,until(ctrl,"hello world?"), "12 chacters till end");

	// crlf, eol, and upto
	value(6, upto(eol, "line 1\r\nline 1\r\n"), "6 chars upto crlf");
	value(0, upto(eol, "\r\n\r\n"), "0 characters to end of line");
	value(12, upto(eol, "hello world!"), "12 characters to eol");

	// all test
	value(5, all(dot, ".....\r\n"), "there are 5 dots");

	return done("test_parse");
}