diff options
author | jstebbins <[email protected]> | 2014-06-18 21:26:44 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2014-06-18 21:26:44 +0000 |
commit | 80a124ff2567ac45b26a606d425420a1ee590506 (patch) | |
tree | c298a7164dc5fd1d21e730fbd3ae66dc7820272b /libhb | |
parent | c152bd90aec1ab2d28edd26a08f3d4760d01b167 (diff) |
macui/cli/libhb: cleanup
macui: Simplifies code in Controller.m and fixes a few bugs
macui: Fixes "Windows 8 Phone" preset aspect ratio problem
macui: round up to next mod boundary when limiting to title dimensions - crop
libhb: Eliminates hb_fix_aspect and hb_set_size functions.
libhb: Makes hb_validate_size a passthru to hb_set_anamorphic_size
cli: eliminage use of hb_validate_size
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6215 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/common.c | 85 | ||||
-rw-r--r-- | libhb/common.h | 3 | ||||
-rw-r--r-- | libhb/hb.c | 119 | ||||
-rw-r--r-- | libhb/hb.h | 1 |
4 files changed, 15 insertions, 193 deletions
diff --git a/libhb/common.c b/libhb/common.c index 25bc74f69..60b926d94 100644 --- a/libhb/common.c +++ b/libhb/common.c @@ -2332,74 +2332,6 @@ void hb_limit_rational64( int64_t *x, int64_t *y, int64_t num, int64_t den, int6 } /********************************************************************** - * hb_fix_aspect - ********************************************************************** - * Given the output width (if HB_KEEP_WIDTH) or height - * (HB_KEEP_HEIGHT) and the current crop values, calculates the - * correct height or width in order to respect the DVD aspect ratio - *********************************************************************/ -void hb_fix_aspect( hb_job_t * job, int keep ) -{ - hb_title_t * title = job->title; - int i; - int min_width; - int min_height; - int modulus; - - /* don't do anything unless the title has complete size info */ - if ( title->height == 0 || title->width == 0 || title->aspect == 0 ) - { - hb_log( "hb_fix_aspect: incomplete info for title %d: " - "height = %d, width = %d, aspect = %.3f", - title->index, title->height, title->width, title->aspect ); - return; - } - - // min_width and min_height should be multiples of modulus - min_width = 32; - min_height = 32; - modulus = job->modulus ? job->modulus : 16; - - for( i = 0; i < 4; i++ ) - { - // Sanity check crop values are zero or positive multiples of 2 - if( i < 2 ) - { - // Top, bottom - job->crop[i] = MIN( EVEN( job->crop[i] ), EVEN( ( title->height / 2 ) - ( min_height / 2 ) ) ); - job->crop[i] = MAX( 0, job->crop[i] ); - } - else - { - // Left, right - job->crop[i] = MIN( EVEN( job->crop[i] ), EVEN( ( title->width / 2 ) - ( min_width / 2 ) ) ); - job->crop[i] = MAX( 0, job->crop[i] ); - } - } - - 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; - - // Dimensions must be greater than minimum and multiple of modulus - if( keep == HB_KEEP_WIDTH ) - { - job->width = MULTIPLE_MOD( job->width, modulus ); - job->width = MAX( min_width, job->width ); - job->height = MULTIPLE_MOD( (uint64_t)( (double)job->width * ar ), modulus ); - job->height = MAX( min_height, job->height ); - } - else - { - job->height = MULTIPLE_MOD( job->height, modulus ); - job->height = MAX( min_height, job->height ); - job->width = MULTIPLE_MOD( (uint64_t)( (double)job->height / ar ), modulus ); - job->width = MAX( min_width, job->width ); - } -} - -/********************************************************************** * hb_list implementation ********************************************************************** * Basic and slow, but enough for what we need @@ -3036,14 +2968,15 @@ static void job_setup( hb_job_t * job, hb_title_t * title ) } job->width = title->width - job->crop[2] - job->crop[3]; - hb_fix_aspect( job, HB_KEEP_WIDTH ); - if( job->height > title->height - job->crop[0] - job->crop[1] ) - { - job->height = title->height - job->crop[0] - job->crop[1]; - hb_fix_aspect( job, HB_KEEP_HEIGHT ); - } - - job->keep_ratio = 1; + job->height = title->height - job->crop[0] - job->crop[1]; + job->anamorphic.keep_display_aspect = 1; + + int width, height, par_width, par_height; + hb_set_anamorphic_size(job, &width, &height, &par_width, &par_height); + job->width = width; + job->height = height; + job->anamorphic.par_width = par_width; + job->anamorphic.par_height = par_height; job->vcodec = HB_VCODEC_FFMPEG_MPEG4; job->vquality = -1.0; diff --git a/libhb/common.h b/libhb/common.h index a5ba78730..778918db2 100644 --- a/libhb/common.h +++ b/libhb/common.h @@ -139,7 +139,6 @@ void hb_limit_rational64( int64_t *x, int64_t *y, int64_t num, int64_t den, int6 #define HB_KEEP_WIDTH 0x01 #define HB_KEEP_HEIGHT 0x02 #define HB_KEEP_DISPLAY_ASPECT 0x04 -void hb_fix_aspect( hb_job_t * job, int keep ); void hb_job_set_encoder_preset (hb_job_t *job, const char *preset); void hb_job_set_encoder_tune (hb_job_t *job, const char *tune); @@ -444,7 +443,6 @@ struct hb_job_s deinterlace: 0 or 1 width: must be a multiple of 2 height: must be a multiple of 2 - keep_ratio: used by UIs grayscale: black and white encoding pixel_ratio: store pixel aspect ratio in the video pixel_aspect_width: numerator for pixel aspect ratio @@ -457,7 +455,6 @@ struct hb_job_s hb_list_t * list_filter; int width; int height; - int keep_ratio; int grayscale; struct diff --git a/libhb/hb.c b/libhb/hb.c index d1e494195..5476e7482 100644 --- a/libhb/hb.c +++ b/libhb/hb.c @@ -1303,119 +1303,12 @@ void hb_add_filter( hb_job_t * job, hb_filter_object_t * filter, const char * se */ void hb_validate_size( hb_job_t * job ) { - if ( job->anamorphic.mode ) - { - hb_set_anamorphic_size( job, &job->width, &job->height, - &job->anamorphic.par_width, &job->anamorphic.par_height ); - } - else - { - if ( job->maxHeight && ( job->height > job->maxHeight ) ) - { - job->height = job->maxHeight; - hb_fix_aspect( job, HB_KEEP_HEIGHT ); - hb_log( "Height out of bounds, scaling down to %i", - job->maxHeight ); - hb_log( "New dimensions %i * %i", job->width, job->height ); - } - if ( job->maxWidth && ( job->width > job->maxWidth ) ) - { - job->width = job->maxWidth; - hb_fix_aspect( job, HB_KEEP_WIDTH ); - hb_log( "Width out of bounds, scaling down to %i", - job->maxWidth ); - hb_log( "New dimensions %i * %i", job->width, job->height ); - } - } -} - -/** - * Calculates job width, height, and cropping parameters. - * @param job Handle to hb_job_t. - * @param aspect Desired aspect ratio. Value of -1 uses title aspect. - * @param pixels Maximum desired pixel count. - */ -void hb_set_size( hb_job_t * job, double aspect, int pixels ) -{ - hb_title_t * title = job->title; - - int croppedWidth = title->width - title->crop[2] - title->crop[3]; - int croppedHeight = title->height - title->crop[0] - title->crop[1]; - double croppedAspect = title->aspect * title->height * croppedWidth / - croppedHeight / title->width; - int addCrop; - int i, w, h; - - if( aspect <= 0 ) - { - /* Keep the best possible aspect ratio */ - aspect = croppedAspect; - } - - /* Crop if necessary to obtain the desired ratio */ - memcpy( job->crop, title->crop, 4 * sizeof( int ) ); - if( aspect < croppedAspect ) - { - /* Need to crop on the left and right */ - addCrop = croppedWidth - aspect * croppedHeight * title->width / - title->aspect / title->height; - if( addCrop & 3 ) - { - addCrop = ( addCrop + 1 ) / 2; - job->crop[2] += addCrop; - job->crop[3] += addCrop; - } - else if( addCrop & 2 ) - { - addCrop /= 2; - job->crop[2] += addCrop - 1; - job->crop[3] += addCrop + 1; - } - else - { - addCrop /= 2; - job->crop[2] += addCrop; - job->crop[3] += addCrop; - } - } - else if( aspect > croppedAspect ) - { - /* Need to crop on the top and bottom */ - addCrop = croppedHeight - croppedWidth * title->aspect * - title->height / aspect / title->width; - if( addCrop & 3 ) - { - addCrop = ( addCrop + 1 ) / 2; - job->crop[0] += addCrop; - job->crop[1] += addCrop; - } - else if( addCrop & 2 ) - { - addCrop /= 2; - job->crop[0] += addCrop - 1; - job->crop[1] += addCrop + 1; - } - else - { - addCrop /= 2; - job->crop[0] += addCrop; - job->crop[1] += addCrop; - } - } - - /* Compute a resolution from the number of pixels and aspect */ - for( i = 0;; i++ ) - { - w = 16 * i; - h = MULTIPLE_16( (int)( (double)w / aspect ) ); - if( w * h > pixels ) - { - break; - } - } - i--; - job->width = 16 * i; - job->height = MULTIPLE_16( (int)( (double)job->width / aspect ) ); + int width, height, par_width, par_height; + hb_set_anamorphic_size(job, &width, &height, &par_width, &par_height); + job->width = width; + job->height = height; + job->anamorphic.par_width = par_width; + job->anamorphic.par_height = par_height; } /** diff --git a/libhb/hb.h b/libhb/hb.h index e958d68d9..cad630650 100644 --- a/libhb/hb.h +++ b/libhb/hb.h @@ -71,7 +71,6 @@ int hb_save_preview( hb_handle_t * h, int title, int preview, hb_buffer_t * hb_read_preview( hb_handle_t * h, int title_idx, int preview ); void hb_get_preview( hb_handle_t *, hb_job_t *, int, uint8_t * ); -void hb_set_size( hb_job_t *, double ratio, int pixels ); void hb_set_anamorphic_size2(hb_geometry_t *src_geo, hb_ui_geometry_t *ui_geo, hb_geometry_t *result); |