diff options
author | titer <[email protected]> | 2006-03-21 17:15:21 +0000 |
---|---|---|
committer | titer <[email protected]> | 2006-03-21 17:15:21 +0000 |
commit | 730315edc4113269902d908e7c4d41954d5a3d5d (patch) | |
tree | 5516faccaf70bf431c07c843b790aa255f7b90db /libhb/hb.c | |
parent | a9f5eb56c4ba2f1b4c22bf949a64cb1d21612ab3 (diff) |
Adds presets for iPod/H.264 and iPod/MPEG-4 + small UI fixes
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@47 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/hb.c')
-rw-r--r-- | libhb/hb.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/libhb/hb.c b/libhb/hb.c index 0e78b1e2c..7bc41be8e 100644 --- a/libhb/hb.c +++ b/libhb/hb.c @@ -251,6 +251,70 @@ void hb_get_preview( hb_handle_t * h, hb_title_t * title, int picture, free( buf4 ); } +void hb_set_size( hb_job_t * job, int 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]; + int croppedAspect = title->aspect * title->height * croppedWidth / + croppedHeight / title->width; + int addCrop; + + 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 */ + /* TODO */ + } + + /* Compute a resolution from the number of pixels and aspect */ + int i, w, h; + for( i = 0;; i++ ) + { + w = 16 * i; + h = MULTIPLE_16( w * HB_ASPECT_BASE / aspect ); + if( w * h > pixels ) + { + break; + } + } + i--; + job->width = 16 * i; + job->height = MULTIPLE_16( 16 * i * HB_ASPECT_BASE / aspect ); +} + int hb_count( hb_handle_t * h ) { return hb_list_count( h->jobs ); |