X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=libhb%2Fcommon.c;h=073abb9777c76c0ed0d67ed79edd3b01397c2bd6;hb=533776bbad20db93fe964bc69975f108b2a30888;hp=457ef894f093609a76b59c7fc47368781ccf4250;hpb=a82ce2af14d596e0f9e001aff398e7d4271a220c;p=handbrake-jp%2Fhandbrake-jp-git.git diff --git a/libhb/common.c b/libhb/common.c index 457ef894..073abb97 100644 --- a/libhb/common.c +++ b/libhb/common.c @@ -7,7 +7,6 @@ #include #include #include -#include #include "common.h" @@ -83,18 +82,26 @@ const char * hb_mixdown_get_short_name_from_mixdown( int amixdown ) *********************************************************************/ void hb_reduce( int *x, int *y, int num, int den ) { - int lower = MIN( num, den ); - int i; - *x = num; - *y = den; - for( i = lower - 1; i > 1; --i ) + // find the greatest common divisor of num & den by Euclid's algorithm + int n = num, d = den; + while ( d ) { - if( ( num % i == 0 ) && ( den % i == 0 ) ) - { - *x = num / i; - *y = den / i; - break; - } + int t = d; + d = n % d; + n = t; + } + + // at this point n is the gcd. if it's non-zero remove it from num + // and den. Otherwise just return the original values. + if ( n ) + { + *x = num / n; + *y = den / n; + } + else + { + *x = num; + *y = den; } } @@ -144,22 +151,18 @@ void hb_fix_aspect( hb_job_t * job, int keep ) } } + double par = (double)title->width / ( (double)title->height * title->aspect ); + double cropped_sar = (double)( title->height - job->crop[0] - job->crop[1] ) / + (double)(title->width - job->crop[2] - job->crop[3] ); + double ar = par * cropped_sar; if( keep == HB_KEEP_WIDTH ) { - job->height = MULTIPLE_16( - (uint64_t) job->width * title->width * HB_ASPECT_BASE * - ( title->height - job->crop[0] - job->crop[1] ) / - ( (uint64_t) title->height * title->aspect * - ( title->width - job->crop[2] - job->crop[3] ) ) ); + job->height = MULTIPLE_16( (uint64_t)( (double)job->width * ar ) ); job->height = MAX( 16, job->height ); } else { - job->width = MULTIPLE_16( - (uint64_t) job->height * title->height * title->aspect * - ( title->width - job->crop[2] - job->crop[3] ) / - ( (uint64_t) title->width * HB_ASPECT_BASE * - ( title->height - job->crop[0] - job->crop[1] ) ) ); + job->width = MULTIPLE_16( (uint64_t)( (double)job->height / ar ) ); job->width = MAX( 16, job->width ); } } @@ -546,6 +549,44 @@ void hb_log( char * log, ... ) fprintf( stderr, "%s", string ); } +int global_verbosity_level; //Necessary for hb_deep_log +/********************************************************************** + * hb_deep_log + ********************************************************************** + * If verbose mode is >= level, print message with timestamp. Messages + * longer than 360 characters are stripped ;p + *********************************************************************/ +void hb_deep_log( hb_debug_level_t level, char * log, ... ) +{ + char string[362]; /* 360 chars + \n + \0 */ + time_t _now; + struct tm * now; + va_list args; + + if( global_verbosity_level < level ) + { + /* Hiding message */ + return; + } + + /* Get the time */ + _now = time( NULL ); + now = localtime( &_now ); + sprintf( string, "[%02d:%02d:%02d] ", + now->tm_hour, now->tm_min, now->tm_sec ); + + /* Convert the message to a string */ + va_start( args, log ); + vsnprintf( string + 11, 349, log, args ); + va_end( args ); + + /* Add the end of line */ + strcat( string, "\n" ); + + /* Print it */ + fprintf( stderr, "%s", string ); +} + /********************************************************************** * hb_error ********************************************************************** @@ -664,8 +705,13 @@ void hb_filter_close( hb_filter_object_t ** _f ) *********************************************************************/ hb_audio_t *hb_audio_copy(const hb_audio_t *src) { - hb_audio_t *audio = calloc(1, sizeof(*audio)); - memcpy(audio, src, sizeof(*audio)); + hb_audio_t *audio = NULL; + + if( src ) + { + audio = calloc(1, sizeof(*audio)); + memcpy(audio, src, sizeof(*audio)); + } return audio; } @@ -676,8 +722,6 @@ hb_audio_t *hb_audio_copy(const hb_audio_t *src) *********************************************************************/ void hb_audio_config_init(hb_audio_config_t * audiocfg) { - assert(audiocfg != NULL); - /* Set read only paramaters to invalid values */ audiocfg->in.codec = 0xDEADBEEF; audiocfg->in.bitrate = -1; @@ -704,9 +748,6 @@ void hb_audio_config_init(hb_audio_config_t * audiocfg) *********************************************************************/ int hb_audio_add(const hb_job_t * job, const hb_audio_config_t * audiocfg) { - assert(job != NULL); - assert(audiocfg != NULL); - hb_title_t *title = job->title; hb_audio_t *audio; @@ -753,7 +794,6 @@ int hb_audio_add(const hb_job_t * job, const hb_audio_config_t * audiocfg) hb_audio_config_t * hb_list_audio_config_item(hb_list_t * list, int i) { - assert(list != NULL); hb_audio_t *audio = NULL; if( (audio = hb_list_item(list, i)) )