0

I am looking for a demo/tutorial on how i would pass images from my Windows Runtime components to my native algorithms.

1) Should i pass paths to the files on the system and have my naive library load the images?

2) Should i pass byte arrays?

Can i handle it to use both file system and maybe a live stream from the camera?

Comments: I might have left out some information, sorry, the algorithm used to process the images are a cross-platform implementation in c++. I want to expose this to WP8 and Win8 apps. Therefor i need to get the images from the UI to the Runtime-Components and then to the c++ libraries. I agree that i dont want to decode it multiply times. I just need some advice/example how this would look in code. I agree that it somehow would be to pass pointers to the Runtime Component(API between the algorithm and App).

Therefor it would also be nice if there are any way to handle how the memory layout of the image are presented at the application such it fits into the Algorithm design. OpenCV ect would have BGRBGRBGR layout for a 1x3 pixel rgb image. (I hope this makes my question more clear)

Poul K. Sørensen
  • 16,950
  • 21
  • 126
  • 283
  • Just link the library, heavily prefer the static library version so you don't have to worry about packaging. Have you tried? – Hans Passant Jan 26 '13 at 21:15

1 Answers1

0

C++/CX is native code and there shouldn't be a need to duplicate the data passing it between a C++/CX assembly to a pure C++ one. Decoding a compressed image twice is something that is best to avoid since it takes a bit of time, so this is the main reason why I would recommend passing a pointer to the bitmap data and not duplicate the bytes, unless it is really necessary and the image isn't too big. Ideally you would use a format of the bitmap that could be used both to display the image (if you want to display it) and process the bytes, e.g. use a WriteableBitmap to display the image and access the pixels to process it or use DirectX for both. Note how much memory your bitmap uses before you decide to duplicate it - a decoded 8MP photo probably uses about 32MB of memory.

EDIT* (more details)

I believe Silverlight uses PRGBA pixel format in general, including WriteableBitmap that you usually use there for image processing. Since you mentioned neither Silverlight nor DirectX, I assume you use the Silverlight APIs for your app. In that case your simple choice is to just use Silverlight to display an image and use WIC in your library to decode it again into a bitmap buffer using the correct pixel format so you can pass it to your image processing algorithm library, then use WIC again to encode it back (to png or jpg most likely). A better solution might be to use DirectX interop to avoid the need to go through decoding/encoding/decoding(...) sequence every time you want to process an image and display it on screen. I think you might then decode the image to a buffer with WIC and then use DirectX to display it since I think DirectX should be able to display the image regardless of the pixel format used.

Filip Skakun
  • 31,624
  • 6
  • 74
  • 100