Skip to content
This repository has been archived by the owner. It is now read-only.

Bitmap.FromWicBitmap return wrong object on Win8 ARM #182

Closed
cpCr4zy opened this issue Oct 21, 2013 · 7 comments

Comments

Projects
None yet
3 participants
@cpCr4zy
Copy link

commented Oct 21, 2013

I'm using SharpDX for my WinRT application. For the pixel shaders I try to load the image with this code

private Bitmap LoadImage(System.IO.Stream stream)
{
var bitmapDecoder = new SharpDX.WIC.BitmapDecoder(
this.deviceManager.WICFactory,
stream,
SharpDX.WIC.DecodeOptions.CacheOnLoad);

var converter = new SharpDX.WIC.FormatConverter(this.deviceManager.WICFactory);
converter.Initialize(
bitmapDecoder.GetFrame(0),
SharpDX.WIC.PixelFormat.Format32bppPBGRA,
SharpDX.WIC.BitmapDitherType.None,
null,
0.0f,
SharpDX.WIC.BitmapPaletteType.Custom);

return Bitmap.FromWicBitmap(this.deviceManager.ContextDirect2D, converter);
}

It works perfect within simulator or on the tablets with Intel CPU (for example Acer Iconia). But I have a strange error on tablets with ARM processor (Windows Surface, Asus). The Bitmap.FromWicBitmap returns a Bitmap object, it is not null, has right DPI and PixelFormat informations, but the Size.Width and Size.Height are 0. No exception occurred, but the loaded Bitmap has no data (-> black image). The images to load are normal jpg or png files and have a small size (f.e. 256x1 pix).

@ArtiomCiumac

This comment has been minimized.

Copy link
Contributor

commented Oct 21, 2013

If it works correctly on x86 CPU and in simulator - most likely there is some capabilities mismatch. Try to enforce the minimum feature level (FeatureLevel.Level_9_1) - in this case the issue should reproduce on emulator also (here is an old discussion regarding a similar issue).

As a guess - try to load a texture with power-of-two sizes (32x32, for example) - according to this table, the support for NPOT textures is quite limited on WinRT-ARM platform.

@cpCr4zy

This comment has been minimized.

Copy link
Author

commented Oct 21, 2013

Hi Artiom,
i tried to enforce the FeatureLevel.Level_9_1 with the same result. On emulator and Intel CPU tablet no errors, on the ARM table the Bitmap size is empty. Power of two textures does not affect too.
I can use any texture (from my images set) in the BitmapSourceEffect:
(from SDK sample)
this.bitmapSourceEffect = new SharpDX.Direct2D1.Effects.BitmapSourceEffect(this.deviceManager.ContextDirect2D);
this.bitmapSourceEffect.WicBitmapSource = formatConverter;

but if i use the same image and converter object for Bitmap.FromWicBitmap(), a have the described behavior.

Regards
Павел

@ArtiomCiumac

This comment has been minimized.

Copy link
Contributor

commented Oct 21, 2013

Hm.. what kind of image is contained in the stream? Try to use a concrete decoder class - like PngBitmapDecoder instead of the abstract BitmapDecoder as you are not specifying what is the format of image from source stream.

I don't own an ARM device - so I cannot debug this issue. Try to use a remote debugger to see what is going on there. Try different image file formats (png/dds/bmp).

As another suggestion - try to adapt the code from the Direct2D1\OfflineImageProcessingApp sample - it is known to work correctly on x86 CPUs, so if it will not work on ARM - then it is a bug in WIC/D2D runtime.

The method Bitmap.FromWicBitmap is a direct call to the underlying unmanaged API - so it is very unlikely that there is a bug in SharpDX.

@cpCr4zy

This comment has been minimized.

Copy link
Author

commented Oct 22, 2013

  1. Using the concrete encoding - no affect. I can't use png/dds/bmp file formats. I must use the customer photos, the jpegs.
  2. I wrote small app base on OfflineImageProcessingApp (you can download the solution from www.denebspace.com/files/ImageProcessing.zip). On the ARM tablet, the inputBitmap object (MainPage.xaml.cs, Line 98) after executing has Size = {0;0}

I tried on Win 8.0, Win 8.1 with SharpDX 2.5, Sharp 2.5.1 Dev

Btw. the Win8\D2DCustomPixelShaderEffect project don't work properly on the Win 8.1 (on simulator and tablet)
The image flickering in the SurfaceImageSource mode. I tried to film this effect www.denebspace.com/files/SharpDX.avi

@ArtiomCiumac

This comment has been minimized.

Copy link
Contributor

commented Oct 22, 2013

As I said - I can't debug this on an ARM device. By suggesting another file format - I meant to check if the issue is present just for one format or it is for all of them. If the method Bitmap.FromWicBitmap doesn't work only on ARM - we can't do anything there. As a workaround you can try to copy pixel data directly to avoid this method.

Regarding the Win8\D2DCustomPixelShaderEffect sample - these are quick-and-dirty ports of original WinRT C++ samples and were implemented only to test if something works. There is no guarantee that they do not contain any bugs. However, if something there must be fixed - please report it as separate issue.

@ArtiomCiumac

This comment has been minimized.

Copy link
Contributor

commented Oct 25, 2013

@cpCr4zy have you managed to solve this issue? I am closing it for now as it is not clear if it is a SharpDX or underlying DirectX API bug (or a wrong API usage) - feel free to reopen this issue if it is caused by SharpDX.

@xoofx

This comment has been minimized.

Copy link
Member

commented Oct 25, 2013

I forgot to mention, but I remember that on ARM, the Bitmap.Size was reported by someone to be zero. As I did'nt have an ARM surface at that time so I was not able to make a clear diagnostic. My fear is that it is a bug in the generation of ASM code by the JIT on ARM. Will try to look at this next week, as we have a Surface tablet at work.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.