dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.04k stars 1.16k forks source link

Cannot open DDS file (file generated by GIMP) #5432

Open mcDandy opened 2 years ago

mcDandy commented 2 years ago

  | Name | Value | Type
-- | -- | -- | --
◢ | $exception | {"Zobrazení nelze dekódovat. Může být poškozená jeho hlavička."} | System.IO.FileFormatException
  | ◢ Data | {System.Collections.ListDictionaryInternal} | System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
  | Count | 0 | int
  | IsFixedSize | false | bool
  | IsReadOnly | false | bool
  | IsSynchronized | false | bool
  | ▶ Keys | {System.Collections.ListDictionaryInternal.NodeKeyValueCollection} | System.Collections.ICollection {System.Collections.ListDictionaryInternal.NodeKeyValueCollection}
  | ▶ SyncRoot | {System.Collections.ListDictionaryInternal} | object {System.Collections.ListDictionaryInternal}
  | ▶ Values | {System.Collections.ListDictionaryInternal.NodeKeyValueCollection} | System.Collections.ICollection {System.Collections.ListDictionaryInternal.NodeKeyValueCollection}
  | ▶ Non-Public members |   |  
  | ▶ Results View | Expanding the Results View will enumerate the IEnumerable |  
  | HResult | -2146233033 | int
  | HelpLink | null | string
  | ◢ InnerException | {"Hlavička obrázku nebyla rozpoznána. (0x88982F61)"} | System.Exception {System.Runtime.InteropServices.COMException}
  | ▶ Data | {System.Collections.ListDictionaryInternal} | System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
  | ErrorCode | -2003292319 | int
  | HResult | -2003292319 | int
  | HelpLink | null | string
  | ▶ InnerException | null | System.Exception
  | Message | "Hlavička obrázku nebyla rozpoznána. (0x88982F61)" | string
  | Source | null | string
  | StackTrace | null | string
  | TargetSite | null | System.Reflection.MethodBase
  | ▶ Static members |   |  
  | ▶ Non-Public members |   |  
  | Message | "Zobrazení nelze dekódovat. Může být poškozená jeho hlavička." | string
  | Source | "PresentationCore" | string
  | ▶ SourceUri | null | System.Uri
  | StackTrace | "   at System.Windows.Media.Imaging.BitmapDecoder.SetupDecoderFromUriOrStream(Uri uri, Stream stream, BitmapCacheOption cacheOption, Guid& clsId, Boolean& isOriginalWritable, Stream& uriStream, UnmanagedMemoryStream& unmanagedMemoryStream, SafeFileHandle& safeFilehandle)\r\n   at System.Windows.Media.Imaging.BitmapDecoder.CreateFromUriOrStream(Uri baseUri, Uri uri, Stream stream, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, RequestCachePolicy uriCachePolicy, Boolean insertInDecoderCache)\r\n   at System.Windows.Media.Imaging.BitmapImage.FinalizeCreation()\r\n   at System.Windows.Media.Imaging.BitmapImage.EndInit()\r\n   at System.Windows.Media.Imaging.BitmapImage..ctor(Uri uriSource, RequestCachePolicy uriCachePolicy)\r\n   at System.Windows.Media.Imaging.BitmapImage..ctor(Uri uriSource)\r\n   at WpfApp2.MainWindow..ctor() in C:\\Users\\Daniel Martinek\\source\\repos\\WpfApp2\\WpfApp2\\MainWindow.xaml.cs:line 40" | string
  | ◢ TargetSite | {System.Windows.Media.SafeMILHandle SetupDecoderFromUriOrStream(System.Uri, System.IO.Stream, System.Windows.Media.Imaging.BitmapCacheOption, System.Guid ByRef, Boolean ByRef, System.IO.Stream ByRef, System.IO.UnmanagedMemoryStream ByRef, Microsoft.Win32.SafeHandles.SafeFileHandle ByRef)} | System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
  | Attributes | Assembly \| Static \| HideBySig | System.Reflection.MethodAttributes
  | CallingConvention | Standard | System.Reflection.CallingConventions
  | ContainsGenericParameters | false | bool
  | CustomAttributes | Method System.Reflection.MemberInfo.get_CustomAttributes cannot be called in this context. | System.Collections.Generic.IEnumerable<System.Reflection.CustomAttributeData>
  | ▶ DeclaringType | {Name = "BitmapDecoder" FullName = "System.Windows.Media.Imaging.BitmapDecoder"} | System.Type {System.RuntimeType}
  | IsAbstract | false | bool
  | IsAssembly | true | bool
  | IsCollectible | Method System.Reflection.RuntimeMethodInfo.get_IsCollectible cannot be called in this context. | bool
  | IsConstructedGenericMethod | Method System.Reflection.MethodBase.get_IsConstructedGenericMethod cannot be called in this context. | bool
  | IsConstructor | false | bool
  | IsFamily | false | bool
  | IsFamilyAndAssembly | false | bool
  | IsFamilyOrAssembly | false | bool
  | IsFinal | false | bool
  | IsGenericMethod | false | bool
  | IsGenericMethodDefinition | false | bool
  | IsHideBySig | true | bool
  | IsPrivate | false | bool
  | IsPublic | false | bool
  | IsSecurityCritical | Method System.Reflection.RuntimeMethodInfo.get_IsSecurityCritical cannot be called in this context. | bool
  | IsSecuritySafeCritical | Method System.Reflection.RuntimeMethodInfo.get_IsSecuritySafeCritical cannot be called in this context. | bool
  | IsSecurityTransparent | Method System.Reflection.RuntimeMethodInfo.get_IsSecurityTransparent cannot be called in this context. | bool
  | IsSpecialName | false | bool
  | IsStatic | true | bool
  | IsVirtual | false | bool
  | MemberType | Method | System.Reflection.MemberTypes
  | MetadataToken | 100684918 | int
  | ▶ MethodHandle | {System.RuntimeMethodHandle} | System.RuntimeMethodHandle
  | MethodImplementationFlags | Method System.Reflection.MethodBase.get_MethodImplementationFlags cannot be called in this context. | System.Reflection.MethodImplAttributes
  | ▶ Module | {PresentationCore.dll} | System.Reflection.Module {System.Reflection.RuntimeModule}
  | Name | "SetupDecoderFromUriOrStream" | string
  | ▶ ReflectedType | '((System.Reflection.RuntimeMethodInfo)($exception).TargetSite).ReflectedType' threw an exception of type 'System.NotSupportedException' | System.Type {System.NotSupportedException}
  | ▶ ReturnParameter | {System.Windows.Media.SafeMILHandle } | System.Reflection.ParameterInfo
  | ▶ ReturnType | {Name = "SafeMILHandle" FullName = "System.Windows.Media.SafeMILHandle"} | System.Type {System.RuntimeType}
  | ReturnTypeCustomAttributes | Method System.Reflection.RuntimeMethodInfo.get_ReturnTypeCustomAttributes cannot be called in this context. | System.Reflection.ICustomAttributeProvider
  | ▶ Non-Public members |   |  
  | ▶ Static members |   |  
  | ▶ Non-Public members |   |  

Expected behavior: transtest.zip would open

Minimal repro:

WpfApp2.zip

vishalmsft commented 2 years ago

@mcDandy As stated in the issue: "I discovered that .net should be able to open dds files" Can you please help us by providing where is the information available?

It may be easier to implement this by using converter, instead of framework changes. And if it is supported in .NET Core, then, it is even quicker to write the converter.

mcDandy commented 2 years ago

I used code which reads it from registry. http://james-ramsden.com/get-file-types-supported-by-bitmapimage/

If it is only unsupported codec then why does it tells about wrong header

Ok probably unsupported codec image

ThomasGoulet73 commented 2 years ago

Hey @mcDandy, if you look at the code of BitmapImageCheck.recalculateExtensions() from the blog post, you'll see that .DDS is manually added to the list of supported formats, it's not from the registry (nativeExtensions = new string[] { ".BMP", ".GIF", ".ICO", ".JPEG", ".PNG", ".TIFF", ".DDS", ".JPG", ".JXR", ".HDP", ".WDP" };). I looked at the documentation from Microsoft and it doesn't say anything about the support of DDS files (https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.media.imaging.bitmapimage?view=winrt-22000#remarks).

A feature request would be more appropriate. Since WPF uses DirectX internally for its rendering, supporting DirectDraw Surface, a DirectX technology, does not seem like an invalid request.

miloush commented 2 years ago

Okay so the hardcoded list is most likely based on this documentation: https://docs.microsoft.com/en-us/windows/win32/wic/dds-format-overview which suggests DDS should indeed be a natively supported format in WIC and therefore WPF.

However, it also lists only 3 pixel formats that are supported for decoding:

These are all 565 bitmap formats, see https://docs.microsoft.com/en-us/windows/win32/direct3d11/texture-block-compression-in-direct3d-11.

The format of the attached file however is DDPF_ALPHAPIXELS | DDPF_RGB - uncompressed 0xAARRGGBB format and therefore unsupported by the native codec.

As a feature request it should go to the owner of the WIC DDS codec.