Module: wine Branch: master Commit: 2683be090b470b4787d87259efbb75577347fd02 URL: https://source.winehq.org/git/wine.git/?a=commit;h=2683be090b470b4787d87259e...
Author: Ziqing Hui zhui@codeweavers.com Date: Sat Jul 18 11:18:22 2020 +0800
windowscodecs: Add support for decoding cube maps.
Signed-off-by: Ziqing Hui zhui@codeweavers.com Signed-off-by: Esme Povirk esme@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/windowscodecs/ddsformat.c | 23 +++++++++++++++++++++-- dlls/windowscodecs/tests/ddsformat.c | 6 ------ 2 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/dlls/windowscodecs/ddsformat.c b/dlls/windowscodecs/ddsformat.c index b972b41b30..447eaf4178 100644 --- a/dlls/windowscodecs/ddsformat.c +++ b/dlls/windowscodecs/ddsformat.c @@ -14,6 +14,16 @@ * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + * + * Note: + * + * Uncompressed image: + * For uncompressed formats, a block is equivalent to a pixel. + * + * Cube map: + * A cube map is equivalent to a 2D texture array which has 6 textures. + * A cube map array is equivalent to a 2D texture array which has cubeCount*6 textures. */
#include "config.h" @@ -436,6 +446,7 @@ static void get_dds_info(dds_info* info, DDS_HEADER *header, DDS_HEADER_DXT10 *h } info->frame_count *= info->array_size; } + if (info->dimension == WICDdsTextureCube) info->frame_count *= 6; }
static inline DdsDecoder *impl_from_IWICBitmapDecoder(IWICBitmapDecoder *iface) @@ -910,7 +921,11 @@ static HRESULT WINAPI DdsDecoder_GetFrame(IWICBitmapDecoder *iface, return WINCODEC_ERR_WRONGSTATE; }
- frame_per_texture = This->info.frame_count / This->info.array_size; + if (This->info.dimension == WICDdsTextureCube) { + frame_per_texture = This->info.mip_levels; + } else { + frame_per_texture = This->info.frame_count / This->info.array_size; + } array_index = index / frame_per_texture; slice_index = index % frame_per_texture; depth = This->info.depth; @@ -1021,7 +1036,11 @@ static HRESULT WINAPI DdsDecoder_Dds_GetFrame(IWICDdsDecoder *iface, hr = WINCODEC_ERR_WRONGSTATE; goto end; } - if (arrayIndex >= This->info.array_size || mipLevel >= This->info.mip_levels || sliceIndex >= This->info.depth) { + + if ((arrayIndex >= This->info.array_size && This->info.dimension != WICDdsTextureCube) || + (arrayIndex >= This->info.array_size * 6) || + (mipLevel >= This->info.mip_levels) || + (sliceIndex >= This->info.depth)) { hr = E_INVALIDARG; goto end; } diff --git a/dlls/windowscodecs/tests/ddsformat.c b/dlls/windowscodecs/tests/ddsformat.c index cfe4d9b781..b8ca452a43 100644 --- a/dlls/windowscodecs/tests/ddsformat.c +++ b/dlls/windowscodecs/tests/ddsformat.c @@ -541,7 +541,6 @@ static void test_dds_decoder_image_parameters(void) hr = IWICBitmapDecoder_GetFrameCount(decoder, &frame_count); ok(hr == S_OK, "Test %u: GetFrameCount failed, hr %#x\n", i, hr); if (hr == S_OK) { - todo_wine_if(test_data[i].expected_parameters.Dimension == WICDdsTextureCube) ok(frame_count == test_data[i].expected_frame_count, "Test %u: Expected frame count %u, got %u\n", i, test_data[i].expected_frame_count, frame_count); } @@ -794,11 +793,6 @@ static void test_dds_decoder_frame(IWICBitmapDecoder *decoder, int i) UINT frame_count, j; WICDdsParameters params;
- if (test_data[i].expected_parameters.Dimension == WICDdsTextureCube) { - skip("Frame tests for cube maps will crash\n"); - return; - } - hr = IWICBitmapDecoder_GetFrameCount(decoder, &frame_count); ok(hr == S_OK, "Test %u: GetFrameCount failed, hr %#x\n", i, hr); if (hr != S_OK) return;