windowscodecs: Introduce is_compressed(). And fix some format checks.
Signed-off-by: Ziqing Hui <zhui@codeweavers.com> Signed-off-by: Esme Povirk <esme@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
15f04f5779
commit
e74d39c32d
|
@ -105,7 +105,6 @@ typedef struct dds_info {
|
||||||
UINT frame_count;
|
UINT frame_count;
|
||||||
UINT data_offset;
|
UINT data_offset;
|
||||||
UINT bytes_per_block;
|
UINT bytes_per_block;
|
||||||
BOOL compressed;
|
|
||||||
DXGI_FORMAT format;
|
DXGI_FORMAT format;
|
||||||
WICDdsDimension dimension;
|
WICDdsDimension dimension;
|
||||||
WICDdsAlphaMode alpha_mode;
|
WICDdsAlphaMode alpha_mode;
|
||||||
|
@ -187,6 +186,16 @@ static struct dds_format {
|
||||||
{ { sizeof(DDS_PIXELFORMAT), DDPF_LUMINANCE, 0, 8, 0xFF,0,0,0 }, DXGI_FORMAT_R8_UNORM }
|
{ { sizeof(DDS_PIXELFORMAT), DDPF_LUMINANCE, 0, 8, 0xFF,0,0,0 }, DXGI_FORMAT_R8_UNORM }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static DXGI_FORMAT compressed_formats[] = {
|
||||||
|
DXGI_FORMAT_BC1_TYPELESS, DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC1_UNORM_SRGB,
|
||||||
|
DXGI_FORMAT_BC2_TYPELESS, DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_BC2_UNORM_SRGB,
|
||||||
|
DXGI_FORMAT_BC3_TYPELESS, DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_BC3_UNORM_SRGB,
|
||||||
|
DXGI_FORMAT_BC4_TYPELESS, DXGI_FORMAT_BC4_UNORM, DXGI_FORMAT_BC4_SNORM,
|
||||||
|
DXGI_FORMAT_BC5_TYPELESS, DXGI_FORMAT_BC5_UNORM, DXGI_FORMAT_BC5_SNORM,
|
||||||
|
DXGI_FORMAT_BC6H_TYPELESS, DXGI_FORMAT_BC6H_UF16, DXGI_FORMAT_BC6H_SF16,
|
||||||
|
DXGI_FORMAT_BC7_TYPELESS, DXGI_FORMAT_BC7_UNORM, DXGI_FORMAT_BC7_UNORM_SRGB
|
||||||
|
};
|
||||||
|
|
||||||
static HRESULT WINAPI DdsDecoder_Dds_GetFrame(IWICDdsDecoder *, UINT, UINT, UINT, IWICBitmapFrameDecode **);
|
static HRESULT WINAPI DdsDecoder_Dds_GetFrame(IWICDdsDecoder *, UINT, UINT, UINT, IWICBitmapFrameDecode **);
|
||||||
|
|
||||||
static inline BOOL has_extended_header(DDS_HEADER *header)
|
static inline BOOL has_extended_header(DDS_HEADER *header)
|
||||||
|
@ -273,13 +282,22 @@ static UINT get_bytes_per_block_from_format(DXGI_FORMAT format)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static BOOL is_compressed(DXGI_FORMAT format)
|
||||||
|
{
|
||||||
|
UINT i;
|
||||||
|
|
||||||
|
for (i = 0; i < ARRAY_SIZE(compressed_formats); i++)
|
||||||
|
{
|
||||||
|
if (format == compressed_formats[i]) return TRUE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static void get_dds_info(dds_info* info, DDS_HEADER *header, DDS_HEADER_DXT10 *header_dxt10)
|
static void get_dds_info(dds_info* info, DDS_HEADER *header, DDS_HEADER_DXT10 *header_dxt10)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
UINT depth;
|
UINT depth;
|
||||||
|
|
||||||
info->compressed = !(header->ddspf.flags & (DDPF_RGB | DDPF_LUMINANCE));
|
|
||||||
|
|
||||||
info->width = header->width;
|
info->width = header->width;
|
||||||
info->height = header->height;
|
info->height = header->height;
|
||||||
info->depth = 1;
|
info->depth = 1;
|
||||||
|
@ -303,10 +321,10 @@ static void get_dds_info(dds_info* info, DDS_HEADER *header, DDS_HEADER_DXT10 *h
|
||||||
info->pixel_format = (info->alpha_mode == WICDdsAlphaModePremultiplied) ?
|
info->pixel_format = (info->alpha_mode == WICDdsAlphaModePremultiplied) ?
|
||||||
&GUID_WICPixelFormat32bppPBGRA : &GUID_WICPixelFormat32bppBGRA;
|
&GUID_WICPixelFormat32bppPBGRA : &GUID_WICPixelFormat32bppBGRA;
|
||||||
|
|
||||||
if (info->compressed) {
|
if (header->ddspf.flags & (DDPF_RGB | DDPF_ALPHA | DDPF_LUMINANCE)) {
|
||||||
info->bytes_per_block = get_bytes_per_block_from_format(info->format);
|
|
||||||
} else {
|
|
||||||
info->bytes_per_block = header->ddspf.rgbBitCount / 8;
|
info->bytes_per_block = header->ddspf.rgbBitCount / 8;
|
||||||
|
} else {
|
||||||
|
info->bytes_per_block = get_bytes_per_block_from_format(info->format);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get frame count */
|
/* get frame count */
|
||||||
|
@ -685,7 +703,10 @@ static HRESULT WINAPI DdsDecoder_Initialize(IWICBitmapDecoder *iface, IStream *p
|
||||||
hr = IWICWineDecoder_Initialize(&This->IWICWineDecoder_iface, pIStream, cacheOptions);
|
hr = IWICWineDecoder_Initialize(&This->IWICWineDecoder_iface, pIStream, cacheOptions);
|
||||||
if (FAILED(hr)) goto end;
|
if (FAILED(hr)) goto end;
|
||||||
|
|
||||||
if (!This->info.compressed || This->info.dimension == WICDdsTextureCube) {
|
if (This->info.dimension == WICDdsTextureCube ||
|
||||||
|
(This->info.format != DXGI_FORMAT_BC1_UNORM &&
|
||||||
|
This->info.format != DXGI_FORMAT_BC2_UNORM &&
|
||||||
|
This->info.format != DXGI_FORMAT_BC3_UNORM)) {
|
||||||
IStream_Release(pIStream);
|
IStream_Release(pIStream);
|
||||||
This->stream = NULL;
|
This->stream = NULL;
|
||||||
This->initialized = FALSE;
|
This->initialized = FALSE;
|
||||||
|
@ -911,7 +932,7 @@ static HRESULT WINAPI DdsDecoder_Dds_GetFrame(IWICDdsDecoder *iface,
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes_per_block = This->info.bytes_per_block;
|
bytes_per_block = This->info.bytes_per_block;
|
||||||
if (This->info.compressed) {
|
if (is_compressed(This->info.format)) {
|
||||||
block_width = DDS_BLOCK_WIDTH;
|
block_width = DDS_BLOCK_WIDTH;
|
||||||
block_height = DDS_BLOCK_HEIGHT;
|
block_height = DDS_BLOCK_HEIGHT;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -331,7 +331,6 @@ static HRESULT init_decoder(IWICBitmapDecoder *decoder, IWICStream *stream, HRES
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
ok(hr == S_OK || wine_init, "Decoder initialize failed, hr %#x\n", hr);
|
ok(hr == S_OK || wine_init, "Decoder initialize failed, hr %#x\n", hr);
|
||||||
} else {
|
} else {
|
||||||
todo_wine_if(index == 9 || index == 10 || index == 11)
|
|
||||||
ok(hr == expected, "Test %u: Expected hr %#x, got %#x\n", index, expected, hr);
|
ok(hr == expected, "Test %u: Expected hr %#x, got %#x\n", index, expected, hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -608,7 +607,7 @@ static void test_dds_decoder_frame_properties(IWICBitmapFrameDecode *frame_decod
|
||||||
ok(format_info.DxgiFormat == test_data[i].expected_parameters.DxgiFormat,
|
ok(format_info.DxgiFormat == test_data[i].expected_parameters.DxgiFormat,
|
||||||
"Test %u, frame %u: Expected DXGI format %#x, got %#x\n",
|
"Test %u, frame %u: Expected DXGI format %#x, got %#x\n",
|
||||||
i, frame_index, test_data[i].expected_parameters.DxgiFormat, format_info.DxgiFormat);
|
i, frame_index, test_data[i].expected_parameters.DxgiFormat, format_info.DxgiFormat);
|
||||||
todo_wine_if(i == 4 || i == 5 || i == 6) {
|
todo_wine_if(i == 4 || i == 5 || i == 6)
|
||||||
ok(format_info.BytesPerBlock == test_data[i].expected_bytes_per_block,
|
ok(format_info.BytesPerBlock == test_data[i].expected_bytes_per_block,
|
||||||
"Test %u, frame %u: Expected bytes per block %u, got %u\n",
|
"Test %u, frame %u: Expected bytes per block %u, got %u\n",
|
||||||
i, frame_index, test_data[i].expected_bytes_per_block, format_info.BytesPerBlock);
|
i, frame_index, test_data[i].expected_bytes_per_block, format_info.BytesPerBlock);
|
||||||
|
@ -618,7 +617,7 @@ static void test_dds_decoder_frame_properties(IWICBitmapFrameDecode *frame_decod
|
||||||
ok(format_info.BlockHeight == expected_block_height,
|
ok(format_info.BlockHeight == expected_block_height,
|
||||||
"Test %u, frame %u: Expected block height %u, got %u\n",
|
"Test %u, frame %u: Expected block height %u, got %u\n",
|
||||||
i, frame_index, expected_block_height, format_info.BlockHeight);
|
i, frame_index, expected_block_height, format_info.BlockHeight);
|
||||||
}
|
|
||||||
|
|
||||||
/* size in blocks tests */
|
/* size in blocks tests */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue