- nb_rois = sd->size / sizeof(AVRegionOfInterest);
- roi = (AVRegionOfInterest*)sd->data;
- for (int count = 0; count < nb_rois; count++) {
- int starty = FFMIN(mby, roi->top / MB_SIZE);
- int endy = FFMIN(mby, (roi->bottom + MB_SIZE - 1)/ MB_SIZE);
- int startx = FFMIN(mbx, roi->left / MB_SIZE);
- int endx = FFMIN(mbx, (roi->right + MB_SIZE - 1)/ MB_SIZE);
+ // This list must be iterated in reverse because the first
+ // region in the list applies when regions overlap.
+ for (int i = nb_rois - 1; i >= 0; i--) {
+ int startx, endx, starty, endy;