예제 #1
0
int round_tensor_dimension(int dim, bool periodic, int padding) 
{
	if (periodic) return dim;

	const int tmp = 2*dim-1;
	if (tmp == 1) return 1;

	switch (padding) {
		case PADDING_DISABLE:             return tmp;
		case PADDING_ROUND_2:             return round2(tmp);
		case PADDING_ROUND_4:             return round4(tmp);
		case PADDING_ROUND_8:             return round8(tmp);
		case PADDING_ROUND_POT:           return round_pot(tmp);
		case PADDING_SMALL_PRIME_FACTORS: return round_small_prime_factors(tmp+1);
		default: throw std::runtime_error("Invalid padding strategy");
	}
}
예제 #2
0
파일: vidconvert.c 프로젝트: doolse/wingsos
int main(int argc, char *argv[]) {
    int j, seg=0, done=0, ch, frames, i, startframe = 1, endframe = 0;
    uint32 temp,len;
    char *filename, *prefilename;

    if(argc < 5) {
        printf("vidconvert USAGE %s [-g gamma][-b brightness][-c contrast] -f frames                         -n prefilename [-s startframe][-e endframe]\n",argv[0]);
        exit(1);
    }

    while ((ch = getopt(argc, argv, "g:b:c:f:n:s:e:")) != EOF) {
        switch(ch) {
        case 'g':
            gamma = atoi(optarg);
            break;
        case 'b':
            bright = atoi(optarg);
            break;
        case 'c':
            contrast = atoi(optarg);
            break;
        case 's':
            startframe = atoi(optarg);
            break;
        case 'e':
            endframe = atoi(optarg);
            break;
        case 'f':
            frames = atoi(optarg);
            break;
        case 'n':
            prefilename = strdup(optarg);
            break;
        default:
            printf("vidconvert USAGE %s [-g gamma][-b brightness][-c contrast] -f frames                         -n prefilename [-s startframe][-e endframe]\n",argv[0]);
        }
    }

    if(!endframe)
        endframe = frames;

    if(strlen(prefilename)>11) {
        printf("invalid prefilename length.\n");
        exit(1);
    }

    filename = malloc(17);

    sprintf(filename, "%s.rvd", prefilename);

    outfp = fopen(filename,"a");

    if(!outfp) {
        printf("couldn't open output stream.\n");
        exit(1);
    }

    maketab(); //generated from gamma contrast and brightness

    for(i = startframe; i<=frames; i++) {

        printf("Opening Frame %d\n", i);

        if(!endframe)
            break;
        endframe--;

        //Reset All variables...

        segbuf = NULL;
        seg = segsize = seglen = segin = yup = xup = ncomp = 0;
        heightDU = widthDU = colsDU = cols8 = maxy = linesize = restinv = ducount = 0;
        buff[0] = buff[1] = buff[2] = NULL;
        coltab = colloc = bmploc = bmpup = NULL;
        dc[0] = dc[1] = dc[2] = 0;

        reset();

        //take into account for the zeros with greater frame totals
        if(frames < 100) {
            if(i<10)
                sprintf(filename, "%s 0%d.jpg", prefilename, i);
            else
                sprintf(filename, "%s %d.jpg", prefilename,i);
        } else {
            if(i<10)
                sprintf(filename, "%s 00%d.jpg", prefilename, i);
            else if(i<100)
                sprintf(filename, "%s 0%d.jpg", prefilename, i);
            else
                sprintf(filename, "%s %d.jpg", prefilename,i);
        }

        filefd = open(filename, O_READ);
        if (filefd == -1) {
            printf("Unable to open file %s... re-using previous frame.\n", filename);
            j=1;
            while(i-j > 0) {
                if(frames < 500) {
                    if(i<10)
                        sprintf(filename, "%s 0%d.jpg", prefilename, i-j);
                    else
                        sprintf(filename, "%s %d.jpg", prefilename,i-j);
                } else {
                    if(i<10)
                        sprintf(filename, "%s 00%d.jpg", prefilename, i-j);
                    else if(i<100)
                        sprintf(filename, "%s 0%d.jpg", prefilename, i-j);
                    else
                        sprintf(filename, "%s %d.jpg", prefilename,i-j);
                }
                filefd = open(filename, O_READ);
                if(filefd == -1)
                    j++;
                else
                    break;
            }
            if(i-j < 1)
                continue;
        }

        seg = loadseg();

        if (seg == 0xd8)
            printf("It's a jpeg!\n");
        else {
            printf("Image file %s, is not a JPEG '%d'... skipping it.\n", filename, seg);
            exit(1);
        }

        while(seg != 0xda) {
            seg = loadseg();

            if(!seg)
                goto skiptonext;

            switch(seg) {
            case 0xdb:
                if(!segDQT())
                    goto skiptonext;
                break;
            case 0xc4:
                if(!segDHT())
                    goto skiptonext;
                break;
            case 0xda:
                segSOS();
                break;
            case 0xc0:
                segSOF();
                break;
            case 0xdd:
                segDRI();
                break;
            }
        }

        bmpwidth  = round8(width);
        bmpheight = round8(height);
        imgsize   = ((bmpheight*bmpwidth)/8) + ((bmpwidth*bmpheight)/64);
        width8    = bmpwidth/8;
        temp      = (uint32) width8 * bmpheight;
        len       = temp/8+temp;
        bmpup     = bmploc = calloc(len, 1);
        colloc    = bmploc+temp;

        while (!done) {
            imagedata();
            render();
            yup += heightDU;
            if (yup >= height) {
                done=1;
                printf("Finished rendering frame %d\n", i);
                rle();
                printf("Finished RLE encoding frame %d\n", i);
            }
        }
        done = 0;
skiptonext:
        close(filefd);
    }
    fclose(outfp);
    return(1);
}
예제 #3
0
파일: ParseFunction.c 프로젝트: BigEd/Cores
/*
 *      funcbody starts with the current symbol being either
 *      the first parameter id or the begin for the local
 *      block. If begin is the current symbol then funcbody
 *      assumes that the function has no parameters.
 */
int ParseFunction(SYM *sp)
{
	int poffset, i;
	int oldglobal;
    SYM *sp1, *sp2;
	Statement *stmt;

	if (sp==NULL) {
		fatal("Compiler error: ParseFunction: SYM is NULL\r\n");
	}
	sp->stkname = stkname;
	if (verbose) printf("Parsing function: %s\r\n", sp->name);
		oldglobal = global_flag;
        global_flag = 0;
        poffset = 24;            /* size of return block */
        nparms = 0;
		iflevel = 0;
		// There could be unnamed parameters in a function prototype.
        if(lastst == id || 1) {              /* declare parameters */
                //while(lastst == id) {
                //        names[nparms++] = litlate(lastid);
                //        NextToken();
                //        if( lastst == comma)
                //                NextToken();
                //        else
                //                break;
                //        }
                //needpunc(closepa);
//                dodecl(sc_member);      /* declare parameters */
				sp->parms = (SYM *)NULL;
				ParseParameterDeclarations(1);
                for(i = 0;i < nparms;++i) {
                        if( (sp1 = search(names[i],&lsyms)) == NULL)
                                sp1 = makeint(names[i]);
						//if( sp1->tp->size < 8 )
						//{
						//	sp1->value.i = poffset;// + (8 - sp1->tp->size);
						//	poffset += 8;
						//}
						//else
						//{
						//	sp1->value.i = poffset;
						//	poffset += sp1->tp->size;
						//}
						sp1->value.i = poffset;
						// Check for aggregate types passed as parameters. Structs
						// and unions use the type size. 
					//	if (sp1->tp->type==bt_struct || sp1->tp->type==bt_union) {
    						poffset += round8(sp1->tp->size);
    						if (round8(sp1->tp->size) > 8)
    						   sp->IsLeaf = FALSE;
                    //     }
                    //     else
                    //         poffset += 8;
						//sp1->value.i = poffset;
						//poffset += 8;
                        sp1->storage_class = sc_auto;
						sp1->nextparm = (SYM *)NULL;
						// record parameter list
						if (sp->parms == (SYM *)NULL) {
							sp->parms = sp1;
						}
						else {
							sp1->nextparm = sp->parms;
							sp->parms = sp1;
						}
					}
					// Process extra hidden parameter
					if (sp->tp->btp->type==bt_struct || sp->tp->btp->type==bt_union) {
                         sp1 = makeint(litlate("_pHiddenStructPtr"));
                         sp1->value.i = poffset;
                         poffset += 8;
                         sp1->storage_class = sc_auto;
  	  	 	 	 	 	 sp1->nextparm = (SYM *)NULL;
						// record parameter list
						if (sp->parms == (SYM *)NULL) {
							sp->parms = sp1;
						}
						else {
							sp1->nextparm = sp->parms;
							sp->parms = sp1;
						}
						nparms++;
                    }
                }
		if (lastst == closepa)
			NextToken();
		if (sp->tp->type == bt_pointer) {
			if (lastst==assign) {
				doinit(sp);
			}
			sp->IsNocall = isNocall;
			sp->IsPascal = isPascal;
			sp->IsKernel = isKernel;
			sp->IsInterrupt = isInterrupt;
			sp->IsTask = isTask;
			sp->NumParms = nparms;
			isPascal = FALSE;
			isKernel = FALSE;
			isOscall = FALSE;
			isInterrupt = FALSE;
			isTask = FALSE;
			isNocall = FALSE;
		    ReleaseLocalMemory();        /* release local symbols (parameters)*/
			global_flag = oldglobal;
			return 1;
		}
		if (lastst == semicolon) {	// Function prototype
			sp->IsPrototype = 1;
			sp->IsNocall = isNocall;
			sp->IsPascal = isPascal;
			sp->IsKernel = isKernel;
			sp->IsInterrupt = isInterrupt;
			sp->IsTask = isTask;
			sp->NumParms = nparms;
			isPascal = FALSE;
			isKernel = FALSE;
			isOscall = FALSE;
			isInterrupt = FALSE;
			isTask = FALSE;
			isNocall = FALSE;
		    ReleaseLocalMemory();        /* release local symbols (parameters)*/
			goto j1;
		}
		else if(lastst != begin) {
//			NextToken();
			ParseParameterDeclarations(2);
			// for old-style parameter list
			//needpunc(closepa);
			if (lastst==semicolon) {
				sp->IsPrototype = 1;
				sp->IsNocall = isNocall;
				sp->IsPascal = isPascal;
    			sp->IsKernel = isKernel;
				sp->IsInterrupt = isInterrupt;
    			sp->IsTask = isTask;
				sp->NumParms = nparms;
				isPascal = FALSE;
    			isKernel = FALSE;
				isOscall = FALSE;
				isInterrupt = FALSE;
    			isTask = FALSE;
				isNocall = FALSE;
				ReleaseLocalMemory();        /* release local symbols (parameters)*/
			}
			// Check for end of function parameter list.
			else if (funcdecl==2 && lastst==closepa) {
				;
			}
			else {
				sp->IsNocall = isNocall;
				sp->IsPascal = isPascal;
    			sp->IsKernel = isKernel;
				sp->IsInterrupt = isInterrupt;
    			sp->IsTask = isTask;
				isPascal = FALSE;
    			isKernel = FALSE;
				isOscall = FALSE;
				isInterrupt = FALSE;
    			isTask = FALSE;
				isNocall = FALSE;
				sp->NumParms = nparms;
				stmt = ParseFunctionBody(sp);
				funcbottom(stmt);
			}
		}
//                error(ERR_BLOCK);
        else {
			sp->IsNocall = isNocall;
			sp->IsPascal = isPascal;
			sp->IsKernel = isKernel;
			sp->IsInterrupt = isInterrupt;
			sp->IsTask = isTask;
			isPascal = FALSE;
			isKernel = FALSE;
			isOscall = FALSE;
			isInterrupt = FALSE;
			isTask = FALSE;
			isNocall = FALSE;
			sp->NumParms = nparms;
			stmt = ParseFunctionBody(sp);
			funcbottom(stmt);
        }
j1:
		global_flag = oldglobal;
		return 0;
}
예제 #4
0
파일: jpeg.c 프로젝트: doolse/wingsos
int main(int argc, char *argv[]) {
	int RcvId, xsize,ysize,minxsize,minysize;
	void *msg;
	void *App, *window, *bmp, *scr, *view;
	int seg=0,done=0,ch;
	uint32 temp,len;
        JMeta * metadata = malloc(sizeof(JMeta));	

	while ((ch = getopt(argc, argv, "g:b:c:")) != EOF) {
		switch(ch) {
		case 'g': 
			gamma = atoi(optarg);
			break;
		case 'b':
			bright = atoi(optarg);
			break;
		case 'c':
			contrast = atoi(optarg);
			break;
		}
			
	}
	if (argc-optind < 1)
		exit(1);
	filefd = open(argv[optind], O_READ);
	if (filefd == -1) {
		perror(argv[optind]);
		exit(1);
	}
	maketab();
	chan = makeChan();
	seg = loadseg();
	if (seg == 0xd8) {
		printf("It's a jpeg!\n");
	} else abort("Not a jpeg!\n");
	while(seg != 0xda) {
		seg = loadseg();
/*		printf("It's %2x, size %4x\n", seg, seglen); */
		switch(seg) {
			case 0xdb:
				segDQT();
				break;
			case 0xc4:
				segDHT();
				break;
			case 0xda:
				segSOS();
				break;
			case 0xc0:
				segSOF();
				break;
			case 0xdd:
				segDRI();
				break;
			default:
				printf("Unknown segment %d\n", seg);
				break;
		}
	}
	bmpwidth = round8(width);
	bmpheight = round8(height);

        metadata->launchpath = strdup(fpathname(argv[0],getappdir(),1));
        metadata->title = "Jpeg viewer";
        metadata->icon = app_icon;
        metadata->showicon = 1;
        metadata->parentreg = -1;

	App = JAppInit(NULL, chan);
	window = JWndInit(NULL, "Jpeg viewer by J. Maginnis and S. Judd", JWndF_Resizable,metadata);
        ((JCnt *)window)->Orient = JCntF_TopBottom;

        xsize = bmpwidth;
        ysize = bmpheight;

        if(xsize > 296)
          xsize = 296;
        else if(xsize < 64)
          xsize = 64;

        if(ysize > 160)
          ysize = 160;
        else if(ysize < 24)
          ysize = 24;

        if(xsize > 64)
          minxsize = 64;
        else
          minxsize = xsize;

        minysize = 24;

        JWSetBounds(window,0,0,xsize,ysize+16);
        JWSetMin(window,minxsize,minysize);
        JWSetMax(window,xsize+8,ysize+24);
        JAppSetMain(App,window);

	width8 = bmpwidth/8;
	temp = (uint32) width8 * bmpheight;
	len = temp/8+temp;
	bmpup = bmploc = calloc(len, 1);
	colloc = bmploc+temp;
	//printf("%dx%d, %lx bytes, %lx,%lx,%lx\n", bmpwidth, bmpheight, len, bmpup, colloc, bmpup+len);

	bmp = JBmpInit(NULL, bmpwidth, bmpheight, bmploc);
	view = JViewWinInit(NULL, bmp);
	scr = JScrInit(NULL, view, JScrF_VNotEnd|JScrF_HNotEnd);
        JWSetMin(scr,8,8);

	JCntAdd(window, scr);
       
        JWndSetProp(window);
	JWinShow(window);

    retexit(1);

	while(1) {
		while (!done && !chkRecv(chan)) {
			imagedata();
			render();
			JWReDraw(bmp);
			yup += heightDU;
			if (yup >= height) {
				FILE *fp;
				done=1;
				printf("Finished render\n");
/*				fp = fopen("bmpout","wb");
				if (fp) {
					fwrite(bmploc, 320*25+1000, 1, fp);
					fclose(fp);
				} */
			}
		}
		RcvId = recvMsg(chan, &msg);
		switch (* (int *)msg) {
		case WIN_EventRecv:
			JAppDrain(App);
			break;			
		}
		replyMsg(RcvId,0);
	}

	return 1;
}