diff options
-rw-r--r-- | recordmydesktop/include/recordmydesktop.h | 9 | ||||
-rw-r--r-- | recordmydesktop/src/parseargs.c | 3 | ||||
-rw-r--r-- | recordmydesktop/src/recordmydesktop.c | 8 | ||||
-rw-r--r-- | recordmydesktop/src/setbrwindow.c | 134 |
4 files changed, 96 insertions, 58 deletions
diff --git a/recordmydesktop/include/recordmydesktop.h b/recordmydesktop/include/recordmydesktop.h index 77f0d78..da56503 100644 --- a/recordmydesktop/include/recordmydesktop.h +++ b/recordmydesktop/include/recordmydesktop.h @@ -283,8 +283,12 @@ unsigned char Yr[256],Yg[256],Yb[256], #define DEFAULT_ARGS(args){\ (args)->delay=0;\ - (args)->display=(char *)malloc(strlen(getenv("DISPLAY"))+1);\ - strcpy((args)->display,getenv("DISPLAY"));\ + if(getenv("DISPLAY")!=NULL){\ + (args)->display=(char *)malloc(strlen(getenv("DISPLAY"))+1);\ + strcpy((args)->display,getenv("DISPLAY"));\ + }\ + else\ + (args)->display=NULL;\ (args)->windowid=(args)->x=(args)->y\ =(args)->width=(args)->height=(args)->quietmode\ =(args)->nosound=(args)->scshot=(args)->full_shots=0;\ @@ -446,5 +450,6 @@ void *EncodeSoundBuffer(void *pdata); snd_pcm_t *OpenDev(const char *pcm_dev,unsigned int *channels,unsigned int *frequency,snd_pcm_uframes_t *periodsize,unsigned int *periodtime,int *hardpause); void InitEncoder(ProgData *pdata,EncData *enc_data_t); void MakeMatrices(); +void SizePack2_8_16(int *start,int *size,int limit); #endif diff --git a/recordmydesktop/src/parseargs.c b/recordmydesktop/src/parseargs.c index 55dfbcd..cc64fc2 100644 --- a/recordmydesktop/src/parseargs.c +++ b/recordmydesktop/src/parseargs.c @@ -133,7 +133,8 @@ int ParseArgs(int argc,char **argv,ProgArgs *arg_return){ } else if(!strcmp(argv[i],"-display")){ if(i+1<argc){ - free(arg_return->display); + if(arg_return->display!=NULL) + free(arg_return->display); arg_return->display=malloc(strlen(argv[i+1])+1); strcpy(arg_return->display,argv[i+1]); } diff --git a/recordmydesktop/src/recordmydesktop.c b/recordmydesktop/src/recordmydesktop.c index 41a8bca..50e6e78 100644 --- a/recordmydesktop/src/recordmydesktop.c +++ b/recordmydesktop/src/recordmydesktop.c @@ -39,8 +39,12 @@ int main(int argc,char **argv){ if(ParseArgs(argc,argv,&pdata.args)){ exit(1); } - pdata.dpy = XOpenDisplay(pdata.args.display); - + if(pdata.args.display!=NULL) + pdata.dpy = XOpenDisplay(pdata.args.display); + else{ + fprintf(stderr,"No display specified for connection!\n"); + exit(1); + } if (pdata.dpy == NULL) { fprintf(stderr, "Cannot connect to X server %s\n",pdata.args.display); exit(1); diff --git a/recordmydesktop/src/setbrwindow.c b/recordmydesktop/src/setbrwindow.c index dafcc89..5177dac 100644 --- a/recordmydesktop/src/setbrwindow.c +++ b/recordmydesktop/src/setbrwindow.c @@ -26,10 +26,88 @@ #include <recordmydesktop.h> +void SizePack2_8_16(int *start,int *size,int limit){ + int octoffset,hexoffset; + + //align in two + //an odd x can always go down and still be in recording area. + //Resolutions come in even numbers + //so if x is an odd numer, width max is an odd number, too + //thus since x will go down one then width can go up one too and still + //be inbounds + (*size)+=((*size)%2)|((*start)%2); + //but if x goes down 1 and width is already even,it becomes odd so: + (*size)+=((*size)%2); + (*start)-=(*start)%2; + + + //32 bit pack align + //we already have disible by two width,so + //it's 2, 4 or 6 + octoffset=((*size)%8); + if(octoffset==2){ + (*size)-=2; + + } + else if(octoffset==6){ + if((*size)+(*start)+2<=limit) + (*size)+=2; + else if((*start)>=2){ + (*start)-=2; + (*size)+=2; + } + else{ + (*start)+=2; + (*size)-=4; + } + } + + else if(octoffset==4){ + if(((*size)+(*start)+2<=limit)&&((*start)>=2)){ + (*start)-=2; + (*size)+=4; + } + else if((*size)+(*start)+4<=limit){ + (*size)+=4; + } + else if((*start)>=4){ + (*start)-=4; + (*size)+=4; + } + else{ + (*start)+=2; + (*size)-=4; + } + } + + //16 divisble width(needed for shared memory only,but applied anyway since theora wants it, too) + //we already have divisibility by 8 so module + //by 16 is euther 8 or 0 + hexoffset=((*size)%16); + if(hexoffset){ + if(((*size)+(*start)+4<=limit)&&((*start)>=4)){ + (*start)-=4; + (*size)+=8; + } + else if((*size)+(*start)+8<=limit){ + (*size)+=8; + } + else if((*start)>=8){ + (*start)-=8; + (*size)+=8; + } + else{ + (*start)+=4; + (*size)-=8; + } + } + +} + + int SetBRWindow(Display *dpy,BRWindow *brwin,DisplaySpecs *specs,ProgArgs *args){ //before we start recording we have to make sure the ranges are valid - int octoffset=0; if(args->windowid==0){//root window //first set it up brwin->windowid=specs->root; @@ -40,7 +118,6 @@ int SetBRWindow(Display *dpy,BRWindow *brwin,DisplaySpecs *specs,ProgArgs *args) brwin->rgeom.y=args->y; brwin->rgeom.width=((args->width)?args->width:specs->width-brwin->rgeom.x); brwin->rgeom.height=((args->height)?args->height:specs->height-brwin->rgeom.y); -// brwin->nbytes=(brwin->rgeom.width*brwin->rgeom.height*4); //and then check validity if((brwin->rgeom.x+brwin->rgeom.width>specs->width)|| (brwin->rgeom.y+brwin->rgeom.height>specs->height)){ @@ -83,58 +160,9 @@ int SetBRWindow(Display *dpy,BRWindow *brwin,DisplaySpecs *specs,ProgArgs *args) fprintf(stderr, "Initial recording window is set to:\n" "X:%d Y:%d Width:%d Height:%d\n" ,brwin->rgeom.x,brwin->rgeom.y,brwin->rgeom.width,brwin->rgeom.height); - //align in two - //an odd x can always go down and still be in recording area. - //Resolutions come in even numbers - //so if x is an odd numer, width max is an odd number, too - //thus since x will go down one then width can go up one too and still - //be inbounds - brwin->rgeom.width+=(brwin->rgeom.width%2)|(brwin->rgeom.x%2); - brwin->rgeom.height+=(brwin->rgeom.height%2)|(brwin->rgeom.y%2); - //but if x goes down 1 and width is already even,it becomes odd so: - brwin->rgeom.width+=(brwin->rgeom.width%2); - brwin->rgeom.height+=(brwin->rgeom.height%2); - brwin->rgeom.x-=brwin->rgeom.x%2; - brwin->rgeom.y-=brwin->rgeom.y%2; + SizePack2_8_16(&brwin->rgeom.x,&brwin->rgeom.width,specs->width); + SizePack2_8_16(&brwin->rgeom.y,&brwin->rgeom.height,specs->height); - //32 bit pack align - //we already have disible by two width,so - //it's 2, 4 or 6 - octoffset=(brwin->rgeom.width%8); - if(octoffset==2){ - brwin->rgeom.width-=2; - - } - else if(octoffset==6){ - if(brwin->rgeom.width+brwin->rgeom.x+2<=specs->width) - brwin->rgeom.width+=2; - else if(brwin->rgeom.x>=2){ - brwin->rgeom.x-=2; - brwin->rgeom.width+=2; - } - else{ - brwin->rgeom.x+=2; - brwin->rgeom.width-=4; - } - } - - else if(octoffset==4){ - if((brwin->rgeom.width+brwin->rgeom.x+2<=specs->width)&&(brwin->rgeom.x>=2)){ - brwin->rgeom.x-=2; - brwin->rgeom.width+=4; - } - else if(brwin->rgeom.width+brwin->rgeom.x+4<=specs->width){ - brwin->rgeom.width+=4; - } - else if(brwin->rgeom.x>=4){ - brwin->rgeom.x-=4; - brwin->rgeom.width+=4; - } - else{ - brwin->rgeom.x+=2; - brwin->rgeom.width-=4; - } - } fprintf(stderr, "Adjusted recording window is set to:\n" "X:%d Y:%d Width:%d Height:%d\n" ,brwin->rgeom.x,brwin->rgeom.y,brwin->rgeom.width,brwin->rgeom.height); |