SharpDX WARP - minimal code to get a drawable surface - c#

I asked another question about generating high quality graphics in a service on Windows Server and SharpDX looks like a reasonable possibility. However I am finding it difficult to find current how-to style documentation. I am specifically interested in the WARP device context.
My use-case is for generation of png format images, and steps of interest are initialisation, loading existing images, drawing graphics and text on them, a resizing / scaling, and saving to png format. I mention this as a large part of the potential use cases for SharpDX are game-related and focus on buffer chains and rendering to forms, which I do not need to do.
This is question 1 then - what is the minimal C# code required to create a drawable 2D surface using WARP in SharpDx in preparation for the above use case.
Other code I have found via Google is either game-focussed, not using WARP, or is simply too complex as it covers more basis.

Related

losing quality when resizing with ImageResizer

I'm using the ImageResizer .net library. It works as expected, but one image messes around.
I've uploaded the image below. I've already tried some things like format=jpg&quality=100, only width=220, also different sizes, but it always adds this blurry border around the image.
The original image is a png.
This one is the original image:
This one is resized by the ImageResizer:
And this one is resized with photoshop:
EDIT:
If you're running into the same issue. Try to set up the SpeedOrQuality Plugin. I've set it to speed=3 and the image is sharp again.
Vector graphics require different resampling algorithms than photographs.
ImageResizer V4 includes higher quality image resampling options under the FastScaling plugin.
For graphics (non-photographic images), I suggest playing with &f.sharpen=0..100, &down.preserve=-5..5, and &down.filter=Robidoux. Make sure &fastscale=true and FastScaling is installed.
You can certainly find a good configuration for your rasterized vector art and set up a preset for it. FastScaling is capable of much better resampling than Photoshop - on par with Lightroom, in fact.
Enabling fastscaling alone helps substantially (?width=200&fastscale=true):
Adding sharpening gives a very clear result: (?width=220&fastscale=true&f.sharpen=100):
Visibly crisper than Photoshop:
Each time you save a jpeg, you loose quality (the image is reencoded).
I would recommend using the same quality as the original image was save against, it should give the best results.
Using a higher quality is not recommended as it will artificially try to improve quality, mistaking approximations done by previous encoding for details, resulting in things like the blurry border.
Aside that, usually, one should not use a quality over 95 for jpeg encoding.

Draw on PNG without System.Drawing.Graphics

For debugging purposes, I'd like to draw on an image in my c# app (I have lots of tiles and I'd like to know which one is which). However, when trying to do it via System.Drawing.Graphics, I run into the fact that the image I'm trying to draw on is a GIF (which I don't have any choice over). Is there another way to draw on images in c#/.NET without using the classes in System.Drawing?
Technically, this isn't the question you asked, but I'm guessing the reason you're not able to draw on the Bitmap from your GIF is that the pixel format is indexed. If so, that's easy to work around by making a copy with a non-indexed format using the Bitmap.Clone method. Just give it the full bitmap size and PixelFormat.Format32bppArgb.
I don't know any other standard drawing API's in .NET that are convenient for this purpose.

Fast pixel drawing in WPF

I would like to write a simple ray tracer using WPF. It is a learning project and thus I favour configurability over performance (otherwise I'd go for C++).
I still want relatively fast pixel drawing. A previous question on StackOverflow contains code to achieve this in WPF, by obtaining a GDI bitmap. From the relatively little I know about Windows programming,
GDI is slow
DirectX is fast
WPF uses DirectX underneath (not sure which parts of WPF though)
Is it possible to obtain pixel-level access using DirectX (not GDI) through the WPF Canvas (or similar)?
I will also consider suggestions for incorporating DirectX API calls within a WPF window (alongside other WPF controls) if that is possible.
Thanks in advance.
Interesting, but with raytracing, writing the pixels to the screen will (should) not be the slow part. You can use WriteableBitmap for the purpose, though. It's certainly quick enough for what you want.
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.aspx
(For info, I use it in this emu/IDE - http://0x10c-devkit.com/ - and it can refresh a low res display with great performance. There's the source to that on the github repository, the LEM1802 plugin.)
Ah, this bit: https://github.com/kierenj/0x10c-DevKit/blob/master/PluginAPI/NyaElektriska.LEM1802/GPU.cs - see UpdateDisplay.
Another solution is WriteableBitmapEx. It extends the builtin WriteableBitmap.
There is an open Source Project Called Direct Canvas wich is A hardware accelerated, 2D drawing API that supports vector graphics, multimedia files, extensible pixel shaders, blending modes and more!
http://directcanvas.codeplex.com/
Demo http://www.youtube.com/user/jdollah69#p/u

Native WPF vs. Custom DirectX for displaying large images

I need to speed up my image viewer, and wondering if I should be looking into creating my own DirectX control to do so.
My image viewer displays medical images. They can be pretty large. We're talking 55mb when it comes to mammography. The pixel data is 16bit greyscale stored in a ushort array. Without getting into the gory details, my current approach is loading the pixel data into an ImageSource, and using the WPF Image control.
I've never done anything with DirectX. Is it worth diving into it? Would it be any faster than the native WPF stuff? If so how significantly? Or, should I just forget about DirectX and look into areas where I can improve my current approach?
Before somebody says so, I know WPF utilize DirectX. I'm wondering If removing the WPF layer and writing the DirectX myself will improve performance.
I have some experience drawing multi-gigabyte satellite and chart imagery. Working with imagery around 55MB should probably work okay even without trying to optimize it too much. You haven't really given enough detail to recommend one alternative over the other, so I will give my opinion on the pros and cons.
Using 2D windows APIs will be the simplest to implement and should always be fast enough if you don't need to rotate and simply want to display an image and zoom and pan around. If you treat it as one large image the performance will not be as good when you zoom out if you are drawing with halftoning to give a nice smooth image. This is because it will effectively have to read all 55mb of image every time it draws.
To get around this performance issue you can make multiple bitmaps, effectively mip-mapping your image. As you zoom out you can pick the reduced resolution image closest to the resolution you are trying to draw . If you are not familiar with mip-mapping here is a Wikipedia link:
http://en.wikipedia.org/wiki/Mipmap
Implementing it with DirectX will be 10x as difficult. Different graphics hardware has different maximum texture sizes. Most likely you will need to break your image up in to multiple textures to draw and you will also have to keep track of render states, viewing matrices, etc.
However, if you do use DirectX, you can implement lots of real-time photo adjustments You can do real-time rotation by simply adjusting view matrices. You can do real-time contrast, brightness, gamma, and sharpness easily in a pixel shader.
There are two other API's I might suggest. If you are willing to limit yourself to Vista or later then Direct2D would be a little simpler than Direct3D. Also if you ever will need to implement it on a non-windows platform I would suggest using OpenGL instead. My current project is in Direct3D because a few years ago when we started it OpenGL was falling behind and I didn't forsee the popularity of Android devices. I now wish we had used OpenGL instead.
Try profiling to see where WPF is spending its time. Are you displaying the images at their native resolution? If not it might be worthwhile to do some preprocessing and create 1/2 resolution versions.

Image API/App which can perform image manipulation on the fly?

Do any of you know an API or application which can handle real time image manipulation?
Basically if I provided an image, this app would output perhaps a silhouetted version, or perform some other form of image manipulation, like roshak type blotting?
If you don't know of an application like this, do you know if this is possible using WPF?
I know some of you might respond with "hire someone" to do it. I basically want to determine how much work is involved prior to that. I'm an ASP.NET dev with no experience with WPF but if it's something that isn't extremely involved, I'd love to take a shot at it and get my WPF feet wet.
Thanks guys.
Pixel shaders, pixel shaders, pixel shaders.
WPF has built-in support for these since .NET 3.5, and from what I've seen it's not too tough to set them up. Not to mention there are tons of examples out there already.
You could look into GDI+ for any image transformation/filtering needs There are a number of tutorials out there, this series can get you going (5 parts):
Image Processing for Dummies with C# and GDI+ Part 1 - Per Pixel Filters
Image Processing for Dummies with C# and GDI+ Part 2 - Convolution Filters
Image Processing for Dummies with C# and GDI+ Part 3 - Edge Detection Filters
Image Processing for Dummies with C# and GDI+ Part 4 - Bilinear Filters and Resizing
Image Processing for Dummies with C# and GDI+ Part 5 - Displacement filters, including swirl
EDIT: WPF has quite a few Pixel Shaders, per Charlie's response below, that look good, wasn't aware of those as I haven't taken the WPF plunge yet.

Categories

Resources