windowscodecs/tests: Add tests for DdsDecoder_GetFrame() and DdsFrameDecode_GetSize().

Signed-off-by: Ziqing Hui <zhui@codeweavers.com>
Signed-off-by: Vincent Povirk <vincent@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Ziqing Hui 2020-05-22 11:17:31 +08:00 committed by Alexandre Julliard
parent 234fa052e8
commit ff9b2936ed
1 changed files with 96 additions and 31 deletions

View File

@ -120,6 +120,21 @@ static BYTE test_dds_array[] = {
0xCC, 0x55, 0xCC, 0x55, 0x0E, 0x84, 0x0E, 0x84, 0x00, 0x00, 0x00, 0x00 0xCC, 0x55, 0xCC, 0x55, 0x0E, 0x84, 0x0E, 0x84, 0x00, 0x00, 0x00, 0x00
}; };
static struct test_data {
void *data;
UINT size;
UINT expected_frame_count;
WICDdsParameters expected_parameters;
} test_data[] = {
{ test_dds_image, sizeof(test_dds_image), 1,
{ 4, 4, 1, 1, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTexture2D, WICDdsAlphaModePremultiplied } },
{ test_dds_mipmaps, sizeof(test_dds_mipmaps), 3,
{ 4, 4, 1, 3, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTexture2D, WICDdsAlphaModePremultiplied } },
{ test_dds_volume, sizeof(test_dds_volume), 7,
{ 4, 4, 4, 3, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTexture3D, WICDdsAlphaModePremultiplied } },
{ test_dds_array, sizeof(test_dds_array), 9,
{ 4, 4, 1, 3, 3, DXGI_FORMAT_BC1_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown } },
};
static IWICImagingFactory *factory = NULL; static IWICImagingFactory *factory = NULL;
@ -278,22 +293,6 @@ static void test_dds_decoder_global_properties(IWICBitmapDecoder *decoder)
static void test_dds_decoder_image_parameters(void) static void test_dds_decoder_image_parameters(void)
{ {
static struct test_data {
void *data;
UINT size;
UINT expected_frame_count;
WICDdsParameters expected_parameters;
} test_data[] = {
{ test_dds_image, sizeof(test_dds_image), 1,
{ 4, 4, 1, 1, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTexture2D, WICDdsAlphaModePremultiplied } },
{ test_dds_mipmaps, sizeof(test_dds_mipmaps), 3,
{ 4, 4, 1, 3, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTexture2D, WICDdsAlphaModePremultiplied } },
{ test_dds_volume, sizeof(test_dds_volume), 7,
{ 4, 4, 4, 3, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTexture3D, WICDdsAlphaModePremultiplied } },
{ test_dds_array, sizeof(test_dds_array), 9,
{ 4, 4, 1, 3, 3, DXGI_FORMAT_BC1_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown } },
};
int i; int i;
HRESULT hr; HRESULT hr;
WICDdsParameters parameters; WICDdsParameters parameters;
@ -368,28 +367,94 @@ static void test_dds_decoder_image_parameters(void)
} }
} }
static void test_dds_decoder(void) static void test_dds_decoder_frame_size(IWICBitmapDecoder *decoder, IWICBitmapFrameDecode *frame_decode,
UINT frame_count, int i, int frame_index)
{ {
HRESULT hr; HRESULT hr;
IWICStream *stream = NULL; WICDdsParameters params;
IWICBitmapDecoder *decoder = NULL; IWICDdsDecoder *dds_decoder;
UINT width, height ,expected_width, expected_height, slice_index, depth;
stream = create_stream(test_dds_image, sizeof(test_dds_image)); hr = IWICBitmapDecoder_QueryInterface(decoder, &IID_IWICDdsDecoder, (void **)&dds_decoder);
if (!stream) goto end; ok(hr == S_OK, "%d: QueryInterface failed, hr=%x\n", i, hr);
if (hr != S_OK) goto end;
decoder = create_decoder(); hr = IWICDdsDecoder_GetParameters(dds_decoder, &params);
if (!decoder) goto end; ok (hr == S_OK, "%d: GetParameters failed, hr=%x\n", i, hr);
hr = init_decoder(decoder, stream, S_OK, -1);
if (hr != S_OK) goto end; if (hr != S_OK) goto end;
test_dds_decoder_initialize(); hr = IWICBitmapFrameDecode_GetSize(frame_decode, &width, &height);
test_dds_decoder_global_properties(decoder); todo_wine ok (hr == S_OK, "%d: GetSize failed for frame %d, hr=%x\n", i, frame_index, hr);
test_dds_decoder_image_parameters(); if (hr != S_OK) goto end;
depth = params.Depth;
expected_width = params.Width;
expected_height = params.Height;
slice_index = frame_index % (frame_count / params.ArraySize);
while (slice_index >= depth)
{
if (expected_width > 1) expected_width /= 2;
if (expected_height > 1) expected_height /= 2;
slice_index -= depth;
if (depth > 1) depth /= 2;
}
ok (width == expected_width, "%d: Expected width %d for frame %d, got %d\n", i, expected_width, frame_index, width);
ok (height == expected_height, "%d: Expected height %d for frame %d, got %d\n", i, expected_height, frame_index, height);
end: end:
if (decoder) IWICBitmapDecoder_Release(decoder); if (dds_decoder) IWICDdsDecoder_Release(dds_decoder);
if (stream) IWICStream_Release(stream); }
static void test_dds_decoder_frame(IWICBitmapDecoder *decoder, int i)
{
HRESULT hr;
UINT frame_count, j;
hr = IWICBitmapDecoder_GetFrameCount(decoder, &frame_count);
ok (hr == S_OK, "%d: GetFrameCount failed, hr=%x\n", i, hr);
if (hr != S_OK) return;
for (j = 0; j < frame_count; j++)
{
IWICBitmapFrameDecode *frame_decode = NULL;
hr = IWICBitmapDecoder_GetFrame(decoder, j, &frame_decode);
ok (hr == S_OK, "%d: GetFrame failed for frame %d, hr=%x\n", i, j, hr);
if (hr != S_OK) {
IWICBitmapFrameDecode_Release(frame_decode);
continue;
}
test_dds_decoder_frame_size(decoder, frame_decode, frame_count, i, j);
}
}
static void test_dds_decoder(void)
{
int i;
HRESULT hr;
test_dds_decoder_initialize();
test_dds_decoder_image_parameters();
for (i = 0; i < ARRAY_SIZE(test_data); i++)
{
IWICStream *stream = NULL;
IWICBitmapDecoder *decoder = NULL;
stream = create_stream(test_data[i].data, test_data[i].size);
if (!stream) goto next;
decoder = create_decoder();
if (!decoder) goto next;
hr = init_decoder(decoder, stream, S_OK, -1);
if (hr != S_OK) goto next;
test_dds_decoder_global_properties(decoder);
test_dds_decoder_frame(decoder, i);
next:
if (decoder) IWICBitmapDecoder_Release(decoder);
if (stream) IWICStream_Release(stream);
}
} }
START_TEST(ddsformat) START_TEST(ddsformat)