Commit ff9b2936 authored by Ziqing Hui's avatar Ziqing Hui Committed by Alexandre Julliard

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

parent 234fa052
......@@ -120,6 +120,21 @@ static BYTE test_dds_array[] = {
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;
......@@ -278,22 +293,6 @@ static void test_dds_decoder_global_properties(IWICBitmapDecoder *decoder)
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;
HRESULT hr;
WICDdsParameters parameters;
......@@ -368,28 +367,94 @@ static void test_dds_decoder_image_parameters(void)
}
}
static void test_dds_decoder_frame_size(IWICBitmapDecoder *decoder, IWICBitmapFrameDecode *frame_decode,
UINT frame_count, int i, int frame_index)
{
HRESULT hr;
WICDdsParameters params;
IWICDdsDecoder *dds_decoder;
UINT width, height ,expected_width, expected_height, slice_index, depth;
hr = IWICBitmapDecoder_QueryInterface(decoder, &IID_IWICDdsDecoder, (void **)&dds_decoder);
ok(hr == S_OK, "%d: QueryInterface failed, hr=%x\n", i, hr);
if (hr != S_OK) goto end;
hr = IWICDdsDecoder_GetParameters(dds_decoder, &params);
ok (hr == S_OK, "%d: GetParameters failed, hr=%x\n", i, hr);
if (hr != S_OK) goto end;
hr = IWICBitmapFrameDecode_GetSize(frame_decode, &width, &height);
todo_wine ok (hr == S_OK, "%d: GetSize failed for frame %d, hr=%x\n", i, frame_index, hr);
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:
if (dds_decoder) IWICDdsDecoder_Release(dds_decoder);
}
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_dds_image, sizeof(test_dds_image));
if (!stream) goto end;
stream = create_stream(test_data[i].data, test_data[i].size);
if (!stream) goto next;
decoder = create_decoder();
if (!decoder) goto end;
if (!decoder) goto next;
hr = init_decoder(decoder, stream, S_OK, -1);
if (hr != S_OK) goto end;
if (hr != S_OK) goto next;
test_dds_decoder_initialize();
test_dds_decoder_global_properties(decoder);
test_dds_decoder_image_parameters();
test_dds_decoder_frame(decoder, i);
end:
next:
if (decoder) IWICBitmapDecoder_Release(decoder);
if (stream) IWICStream_Release(stream);
}
}
START_TEST(ddsformat)
......
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