Built-in WPF and Custom DirectX for displaying large images

I need to speed up the image viewer and wonder if I should look for creating my own DirectX control for this.

My image viewer displays medical images. They can be quite large. We talk about 55mb when it comes to mammography. The pixel data is a 16-bit gray scale stored in the ushort array. Without going into details, my current approach is to load pixel data into ImageSource and use WPF image management.

I have never done anything with DirectX. Is it worth diving into? Will it be faster than the native WPF stuff? If so, how significant is that? Or should I just forget about DirectX and look at areas where I can improve my current approach?

Before anyone says so, I know that WPF uses DirectX. I am wondering if deleting a WPF layer and writing DirectX themselves will improve performance.

+6
source share
2 answers

I have experience drawing multi-gigabyte satellite and graphic images. Working with images around 55 MB should probably work fine, without even trying to optimize it. You actually did not give enough details to recommend one alternative to the other, so I will give my opinion on the pros and cons.

Using 2D window APIs will be the easiest to implement and should always be fast enough if you don't need to rotate and just want to display the image, scale it and pan it. If you consider it as one large image, the performance will not be as good if you zoom out, if you draw with halftones to get a nice smooth image. This is due to the fact that every time he draws, he will have to read all 55 MB of image.

To get around this performance issue, you can create multiple bitmap images, effectively displaying the image. When you zoom out, you can select an image with a reduced resolution that is closest to the resolution you are trying to draw. If you are not familiar with mip-mapping, there is a Wikipedia link here:

http://en.wikipedia.org/wiki/Mipmap

Implementing it with DirectX will be more difficult 10 times. Different graphics devices have different maximum texture sizes. Most likely, you will need to split the image into several textures in order to draw, and you will also need to track visualization states, view matrices, etc.

However, if you use DirectX, you can implement many real-time photo adjustments. You can do the rotation in real time by simply adjusting the matrix of views. You can easily contrast real-time contrast, brightness, gamma and sharpness in a pixel shader.

There are two other APIs that I could offer. If you want to limit yourself to Vista or later, Direct2D will be a little easier than Direct3D. Also, if you need to implement it on a platform other than Windows, I would suggest using OpenGL instead. My current project is in Direct3D, because a few years ago when we started it, OpenGL was lagging, and I did not see the popularity of Android devices. Now I would like to use OpenGL instead.

+3
source

Try profiling to see where WPF is spending its time. Do you display images with their native resolution? If not, it might be worth doing some preprocessing and creating versions with a resolution of 1/2.

+1
source

Source: https://habr.com/ru/post/923601/


All Articles