--- trunk/xvidcore/vfw/src/codec.c 2010/12/22 16:52:12 1917 +++ trunk/xvidcore/vfw/src/codec.c 2011/01/27 13:13:16 1945 @@ -19,7 +19,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * $Id: codec.c,v 1.29 2010-12-22 16:52:12 Isibaar Exp $ + * $Id: codec.c,v 1.32 2011-01-27 13:13:06 Isibaar Exp $ * *************************************************************************/ @@ -437,16 +437,24 @@ if ((profiles[codec->config.profile].flags & PROFILE_RESYNCMARKER) && codec->config.num_slices != 1) { if (codec->config.num_slices == 0) { /* auto */ - int rows = (lpbiInput->bmiHeader.biHeight + 15) / 16; - int slices = (rows > 36) ? 2 : 1; + int mb_width = (lpbiInput->bmiHeader.biWidth + 15) / 16; + int mb_height = (lpbiInput->bmiHeader.biHeight + 15) / 16; - create.num_slices = (rows > 45) ? 4 : slices; + int slices = (int)((mb_width*mb_height) / 811); /* use multiple slices only above SD resolutions for now */ - if (create.num_slices > create.num_threads) - create.num_slices = create.num_threads; + if (slices > 1) { + if (create.num_threads <= 1) + slices &= ~1; /* make even */ + else if (create.num_threads <= slices) + slices = (slices / create.num_threads) * create.num_threads; /* multiple of threads */ + else if (create.num_threads % slices) + slices = (!(create.num_threads%2)) ? (create.num_threads/2) : (create.num_threads/3); + } + + create.num_slices = slices; } else { - create.num_slices = codec->config.num_slices; + create.num_slices = codec->config.num_slices; /* force manual value - by registry edit */ } } @@ -911,13 +919,14 @@ { BITMAPINFOHEADER * inhdr = &lpbiInput->bmiHeader; BITMAPINFOHEADER * outhdr = &lpbiOutput->bmiHeader; + int in_csp = XVID_CSP_NULL, out_csp = XVID_CSP_NULL; if (lpbiInput == NULL) { return ICERR_ERROR; } - if (inhdr->biCompression != FOURCC_XVID && inhdr->biCompression != FOURCC_DIVX && inhdr->biCompression != FOURCC_DX50 && get_colorspace(inhdr) == XVID_CSP_NULL) + if (inhdr->biCompression != FOURCC_XVID && inhdr->biCompression != FOURCC_DIVX && inhdr->biCompression != FOURCC_DX50 && (in_csp = get_colorspace(inhdr)) != XVID_CSP_YV12) { return ICERR_BADFORMAT; } @@ -927,9 +936,12 @@ return ICERR_OK; } + out_csp = get_colorspace(outhdr); + if (inhdr->biWidth != outhdr->biWidth || inhdr->biHeight != outhdr->biHeight || - get_colorspace(outhdr) == XVID_CSP_NULL) + out_csp == XVID_CSP_NULL || + (in_csp == XVID_CSP_YV12 && in_csp != out_csp)) { return ICERR_BADFORMAT; }