summaryrefslogtreecommitdiffstats
path: root/libhb
diff options
context:
space:
mode:
authordynaflash <[email protected]>2010-02-11 23:38:00 +0000
committerdynaflash <[email protected]>2010-02-11 23:38:00 +0000
commit748a83548709b07001f3a715dcb11279609d9395 (patch)
tree806ef5653b28b982537410fd3bb2d3823a842aa4 /libhb
parent5212b9a80b24015b8c638d49e789d253ddc70eb5 (diff)
Adjustable picture modulus: Base patch by BradleyS, Thanks BradleyS!
- Enables setting modulus for all anamorphic modes (including non-anamorphic) except strict. The job variable "anamorphic.modulus" is repurposed for this and is renamed to simply "modulus" - Other changes: Increases minimum output dimensions to 32x32 pixels in libhb (prevents possible crashes, notably in macgui). Better crop value and maximum crop value calculations to prevent crashes. Some code optimization / refactoring. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3113 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rw-r--r--libhb/common.c46
-rw-r--r--libhb/common.h10
-rw-r--r--libhb/hb.c2
-rw-r--r--libhb/work.c8
4 files changed, 34 insertions, 32 deletions
diff --git a/libhb/common.c b/libhb/common.c
index ce983987f..06fdedded 100644
--- a/libhb/common.c
+++ b/libhb/common.c
@@ -119,6 +119,9 @@ 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 )
@@ -129,44 +132,47 @@ void hb_fix_aspect( hb_job_t * job, int keep )
return;
}
- /* Sanity checks:
- Widths and heights must be multiples of 16 and greater than or
- equal to 16
- Crop values must be multiples of 2, greater than or equal to 0
- and less than half of the dimension */
- job->width = MULTIPLE_16( job->width );
- job->height = MULTIPLE_16( job->height );
- job->width = MAX( 16, job->width );
- job->height = MAX( 16, job->height );
+ // 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++ )
{
- job->crop[i] = EVEN( job->crop[i] );
- job->crop[i] = MAX( 0, job->crop[i] );
+ // Sanity check crop values are zero or positive multiples of 2
if( i < 2 )
{
- /* Top, bottom */
- job->crop[i] = MIN( job->crop[i], ( title->height / 2 ) - 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( job->crop[i], ( title->width / 2 ) - 2 );
+ // 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)( 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->height = MULTIPLE_16( (uint64_t)( (double)job->width * ar ) );
- job->height = MAX( 16, job->height );
+ 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->width = MULTIPLE_16( (uint64_t)( (double)job->height / ar ) );
- job->width = MAX( 16, job->width );
+ 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 );
}
}
diff --git a/libhb/common.h b/libhb/common.h
index ec45250da..0c06ba967 100644
--- a/libhb/common.h
+++ b/libhb/common.h
@@ -166,14 +166,14 @@ struct hb_job_s
/* Picture settings:
crop: must be multiples of 2 (top/bottom/left/right)
deinterlace: 0 or 1
- width: must be a multiple of 16
- height: must be a multiple of 16
+ 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
pixel_aspect_height: denominator for pixel aspect ratio
- modulus: set a number besides 16 for dimensions to be multiples of
+ modulus: set a number for dimensions to be multiples of
maxWidth: keep width below this
maxHeight: keep height below this */
int crop[4];
@@ -187,7 +187,6 @@ struct hb_job_s
struct
{
int mode;
- int modulus;
int itu_par;
int par_width;
int par_height;
@@ -195,7 +194,8 @@ struct hb_job_s
int dar_height;
int keep_display_aspect;
} anamorphic;
-
+
+ int modulus;
int maxWidth;
int maxHeight;
diff --git a/libhb/hb.c b/libhb/hb.c
index e4e42d350..0541b9fa7 100644
--- a/libhb/hb.c
+++ b/libhb/hb.c
@@ -660,7 +660,7 @@ void hb_set_anamorphic_size( hb_job_t * job,
int cropped_width = title->width - job->crop[2] - job->crop[3] ;
int cropped_height = title->height - job->crop[0] - job->crop[1] ;
double storage_aspect = (double)cropped_width / (double)cropped_height;
- int mod = job->anamorphic.modulus ? job->anamorphic.modulus : 16;
+ int mod = job->modulus ? job->modulus : 16;
double aspect = title->aspect;
int pixel_aspect_width = job->anamorphic.par_width;
diff --git a/libhb/work.c b/libhb/work.c
index 7a923a192..5a660bcee 100644
--- a/libhb/work.c
+++ b/libhb/work.c
@@ -212,13 +212,9 @@ void hb_display_job_info( hb_job_t * job )
{
hb_log( " + keeping source display aspect ratio");
}
- if( job->anamorphic.modulus != 16 )
- {
- hb_log( " + modulus: %i", job->anamorphic.modulus );
- }
- hb_log( " + storage dimensions: %d * %d -> %d * %d, crop %d/%d/%d/%d",
+ hb_log( " + storage dimensions: %d * %d -> %d * %d, crop %d/%d/%d/%d, mod %i",
title->width, title->height, job->width, job->height,
- job->crop[0], job->crop[1], job->crop[2], job->crop[3] );
+ job->crop[0], job->crop[1], job->crop[2], job->crop[3], job->modulus );
if( job->anamorphic.itu_par )
{
hb_log( " + using ITU pixel aspect ratio values");