Ticket #1641: bug_1641.diff

File bug_1641.diff, 3.5 KB (added by quetschke@…, 16 years ago)

Patch to add proposed functionality.

  • libmpcodecs/vf_cropdetect.c

     
    9292    dmpi->height=mpi->height;
    9393
    9494if(++vf->priv->fno>0){  // ignore first 2 frames - they may be empty
     95    int round_sig = 1;
    9596
    9697    // Reset the crop area every reset_count frames, if reset_count is > 0
    9798    if(vf->priv->reset_count > 0 && vf->priv->fno > vf->priv->reset_count){
     
    130131        }
    131132    }
    132133
    133     // round x and y (up), important for yuv colorspaces
    134     // make sure they stay rounded!
    135     x=(vf->priv->x1+1)&(~1);
    136     y=(vf->priv->y1+1)&(~1);
     134    if (vf->priv->round < 0)
     135        round_sig = -1;
    137136
     137    x = vf->priv->x1;
     138    y = vf->priv->y1;
     139
     140    // make sure x and y are rounded to even number
     141    if (x%2)
     142        x += round_sig;
     143    if (y%2)
     144        y += round_sig;
     145
    138146    w = vf->priv->x2 - x + 1;
    139147    h = vf->priv->y2 - y + 1;
    140148
    141     // w and h must be divisible by 2 as well because of yuv
    142     // colorspace problems.
    143     if (vf->priv->round <= 1)
    144       vf->priv->round = 16;
    145     if (vf->priv->round % 2)
    146       vf->priv->round *= 2;
     149    // w and h must be divisible by 2 because of yuv colorspace problems.
     150    // This is always true as round is even number != 0
    147151
    148     shrink_by = w % vf->priv->round;
     152    // Modulus with negative divisor is implementation-defined, avoid
     153    // problems.
     154    shrink_by = w % abs(vf->priv->round);
     155    if (shrink_by && vf->priv->round < 0)
     156        shrink_by += vf->priv->round;
     157
    149158    w -= shrink_by;
    150     x += (shrink_by / 2 + 1) & ~1;
     159    x += shrink_by / 2;
    151160
    152     shrink_by = h % vf->priv->round;
     161    shrink_by = h % abs(vf->priv->round);
     162    if (shrink_by && vf->priv->round < 0)
     163        shrink_by += vf->priv->round;
     164
    153165    h -= shrink_by;
    154     y += (shrink_by / 2 + 1) & ~1;
     166    y += shrink_by / 2;
    155167
     168    // make sure x and y stay rounded to even number
     169    x = (x%2 ? x+round_sig : x);
     170    y = (y%2 ? y+round_sig : y);
     171
    156172    mp_msg(MSGT_VFILTER, MSGL_INFO, MSGTR_MPCODECS_CropArea,
    157173        vf->priv->x1,vf->priv->x2,
    158174        vf->priv->y1,vf->priv->y2,
     
    175191//===========================================================================//
    176192
    177193static int open(vf_instance_t *vf, char* args){
     194    int round_sig = 1;
    178195    vf->config=config;
    179196    vf->put_image=put_image;
    180197    vf->query_format=query_format;
     
    186203    &vf->priv->limit,
    187204    &vf->priv->round,
    188205    &vf->priv->reset_count);
     206
     207    if (vf->priv->round < 0)
     208        round_sig = -1;
     209
     210    if (abs(vf->priv->round) <= 1)
     211      vf->priv->round = 16*round_sig;
     212    if (vf->priv->round % 2)
     213        vf->priv->round += round_sig; // Increase by one, keep sign
     214
    189215    return 1;
    190216}
    191217
  • DOCS/man/en/mplayer.1

     
    58055805Value which the width/\:height should be divisible by (default: 16).
    58065806The offset is automatically adjusted to center the video.
    58075807Use 2 to get only even dimensions (needed for 4:2:2 video).
    5808 16 is best when encoding to most video codecs.
     580816 is best when encoding to most video codecs.  Usually the crop values
     5809for width and height are rounded down to avoid black bars, but a round up
     5810mode can be forced by choosing a negative round value.  This will leave
     5811black borders around the picture and is therefore not optimal for compression
     5812efficiency, but it will avoid that picture information is lost.
    58095813.br
    58105814.IPs <reset>
    58115815Counter that determines after how many frames cropdetect will reset