Commit e497f0e8 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

mfplat/mediatype: Implement implicit MFInitMediaTypeFromVideoInfoHeader subtype.

parent 2692cd8b
......@@ -2697,13 +2697,14 @@ struct uncompressed_video_format
static int __cdecl uncompressed_video_format_compare(const void *a, const void *b)
{
const GUID *guid = a;
const struct uncompressed_video_format *format = b;
return memcmp(guid, format->subtype, sizeof(*guid));
const struct uncompressed_video_format *a_format = a, *b_format = b;
return memcmp(a_format->subtype, b_format->subtype, sizeof(GUID));
}
static const struct uncompressed_video_format video_formats[] =
static struct uncompressed_video_format video_formats[] =
{
{ &MFVideoFormat_RGB1, 1, 0, 1, 0, BI_RGB },
{ &MFVideoFormat_RGB4, 4, 0, 1, 0, BI_RGB },
{ &MFVideoFormat_RGB24, 24, 3, 1, 0, BI_RGB },
{ &MFVideoFormat_ARGB32, 32, 3, 1, 0, BI_RGB },
{ &MFVideoFormat_RGB32, 32, 3, 1, 0, BI_RGB },
......@@ -2736,14 +2737,26 @@ static const struct uncompressed_video_format video_formats[] =
{ &MEDIASUBTYPE_RGB32, 32, 3, 1, 0, BI_RGB },
};
static BOOL WINAPI mf_video_formats_init(INIT_ONCE *once, void *param, void **context)
{
qsort(video_formats, ARRAY_SIZE(video_formats), sizeof(*video_formats), uncompressed_video_format_compare);
return TRUE;
}
static struct uncompressed_video_format *mf_get_video_format(const GUID *subtype)
{
return bsearch(subtype, video_formats, ARRAY_SIZE(video_formats), sizeof(*video_formats),
static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;
struct uncompressed_video_format key = {.subtype = subtype};
InitOnceExecuteOnce(&init_once, mf_video_formats_init, NULL, NULL);
return bsearch(&key, video_formats, ARRAY_SIZE(video_formats), sizeof(*video_formats),
uncompressed_video_format_compare);
}
static unsigned int mf_get_stride_for_format(const struct uncompressed_video_format *format, unsigned int width)
{
if (format->bpp < 8) return (width * format->bpp) / 8;
return (width * (format->bpp / 8) + format->alignment) & ~format->alignment;
}
......@@ -3743,14 +3756,22 @@ HRESULT WINAPI MFInitMediaTypeFromVideoInfoHeader(IMFMediaType *media_type, cons
DWORD height;
LONG stride;
FIXME("%p, %p, %u, %s.\n", media_type, vih, size, debugstr_guid(subtype));
TRACE("%p, %p, %u, %s.\n", media_type, vih, size, debugstr_guid(subtype));
IMFMediaType_DeleteAllItems(media_type);
if (!subtype)
{
FIXME("Implicit subtype is not supported.\n");
return E_NOTIMPL;
switch (vih->bmiHeader.biBitCount)
{
case 1: subtype = &MFVideoFormat_RGB1; break;
case 4: subtype = &MFVideoFormat_RGB4; break;
case 8: subtype = &MFVideoFormat_RGB8; break;
case 16: subtype = &MFVideoFormat_RGB555; break;
case 24: subtype = &MFVideoFormat_RGB24; break;
case 32: subtype = &MFVideoFormat_RGB32; break;
default: return E_INVALIDARG;
}
}
height = abs(vih->bmiHeader.biHeight);
......
......@@ -9854,10 +9854,8 @@ static void test_MFInitMediaTypeFromVideoInfoHeader(void)
memset(&vih, 0, sizeof(vih));
hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, 0, NULL);
todo_wine
ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), NULL);
todo_wine
ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), &GUID_NULL);
......@@ -9974,7 +9972,6 @@ static void test_MFInitMediaTypeFromVideoInfoHeader(void)
/* biBitCount is used for implicit RGB format if GUID is NULL */
hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), NULL);
todo_wine
ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
for (vih.bmiHeader.biBitCount = 1; vih.bmiHeader.biBitCount <= 32; vih.bmiHeader.biBitCount++)
......@@ -9984,35 +9981,31 @@ static void test_MFInitMediaTypeFromVideoInfoHeader(void)
hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), NULL);
if (vih.bmiHeader.biBitCount != 1 && vih.bmiHeader.biBitCount != 4 && vih.bmiHeader.biBitCount != 8
&& vih.bmiHeader.biBitCount != 16 && vih.bmiHeader.biBitCount != 24 && vih.bmiHeader.biBitCount != 32)
todo_wine ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
else
{
todo_wine
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
memset(&guid, 0xcd, sizeof(guid));
hr = IMFMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &guid);
todo_wine
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
if (vih.bmiHeader.biBitCount == 32)
todo_wine ok(IsEqualGUID(&guid, &MFVideoFormat_RGB32), "Unexpected guid %s.\n", debugstr_guid(&guid));
ok(IsEqualGUID(&guid, &MFVideoFormat_RGB32), "Unexpected guid %s.\n", debugstr_guid(&guid));
else if (vih.bmiHeader.biBitCount == 24)
todo_wine ok(IsEqualGUID(&guid, &MFVideoFormat_RGB24), "Unexpected guid %s.\n", debugstr_guid(&guid));
ok(IsEqualGUID(&guid, &MFVideoFormat_RGB24), "Unexpected guid %s.\n", debugstr_guid(&guid));
else if (vih.bmiHeader.biBitCount == 16)
todo_wine ok(IsEqualGUID(&guid, &MFVideoFormat_RGB555), "Unexpected guid %s.\n", debugstr_guid(&guid));
ok(IsEqualGUID(&guid, &MFVideoFormat_RGB555), "Unexpected guid %s.\n", debugstr_guid(&guid));
else if (vih.bmiHeader.biBitCount == 8)
todo_wine ok(IsEqualGUID(&guid, &MFVideoFormat_RGB8), "Unexpected guid %s.\n", debugstr_guid(&guid));
ok(IsEqualGUID(&guid, &MFVideoFormat_RGB8), "Unexpected guid %s.\n", debugstr_guid(&guid));
else if (vih.bmiHeader.biBitCount == 4)
todo_wine ok(IsEqualGUID(&guid, &MFVideoFormat_RGB4), "Unexpected guid %s.\n", debugstr_guid(&guid));
ok(IsEqualGUID(&guid, &MFVideoFormat_RGB4), "Unexpected guid %s.\n", debugstr_guid(&guid));
else if (vih.bmiHeader.biBitCount == 1)
todo_wine ok(IsEqualGUID(&guid, &MFVideoFormat_RGB1), "Unexpected guid %s.\n", debugstr_guid(&guid));
ok(IsEqualGUID(&guid, &MFVideoFormat_RGB1), "Unexpected guid %s.\n", debugstr_guid(&guid));
value32 = 0xdeadbeef;
hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
todo_wine
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
if (vih.bmiHeader.biBitCount > 1)
todo_wine
ok(value32 == 16 * vih.bmiHeader.biBitCount / 8, "Unexpected value %#x.\n", value32);
else
todo_wine ok(value32 == -4, "Unexpected value %#x.\n", value32);
......@@ -10025,27 +10018,20 @@ static void test_MFInitMediaTypeFromVideoInfoHeader(void)
value32 = 0xdeadbeef;
hr = IMFMediaType_GetUINT32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, &value32);
todo_wine
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
todo_wine
ok(value32 == 1, "Unexpected value %#x.\n", value32);
value32 = 0xdeadbeef;
hr = IMFMediaType_GetUINT32(media_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, &value32);
todo_wine
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
todo_wine
ok(value32 == 1, "Unexpected value %#x.\n", value32);
value32 = 0xdeadbeef;
vih.bmiHeader.biHeight = 32;
hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), NULL);
todo_wine
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
todo_wine
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
if (vih.bmiHeader.biBitCount > 1)
todo_wine
ok(value32 == -16 * vih.bmiHeader.biBitCount / 8, "Unexpected value %#x.\n", value32);
else
todo_wine ok(value32 == -4, "Unexpected value %#x.\n", value32);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment