How to transform a ID3D11Texture2D into any picture format - directx

I have a ID3D11Texture2D and want to write it to disk using literally any picture format (png, bmp, jpeg, ...).
I have already tried to read the docs https://learn.microsoft.com/en-us/windows/win32/api/d3d11/nn-d3d11-id3d11texture2d, which are less than helpful, and i have found an NVIDIA tutorial of how to take individual ID3D11Texture2D and convert them into a video: https://github.com/NVIDIA/video-sdk-samples/tree/master/nvEncDXGIOutputDuplicationSample
However, I dont find anything how to simply write it to disk in any format. I'm sure I'm missing something obvious, any hint would be appreciated.
To experiment, I used https://github.com/NVIDIA/video-sdk-samples/tree/master/nvEncDXGIOutputDuplicationSample, set the frames to capture to 1, and try to write the ID3D11Texture2D to file before encoding to video.

I have a solution for exactly this in the ScreenGrab module which captures a texture (if not already in Map-supporting memory), and then writes it out as a picture using WIC. It handles some edge-cases like "typeless" resources and MSAA as well.
The 'standalone' version is on GitHub here as part of the DirectXTex package:
https://github.com/microsoft/DirectXTex/blob/main/ScreenGrab/ScreenGrab11.h
https://github.com/microsoft/DirectXTex/blob/main/ScreenGrab/ScreenGrab11.cpp
Documentation is here.
ScreenGrab is also included in the DirectX Tool Kit for DX11 and DX12. There's also a basic DX9 version in the DirectXTex package as well.
ScreenGrab can write to any file container supported by WIC. It also has buit-in support for writing DDS files directly without using WIC.
In addition to using ScreenGrab (which is intended as a light-weight screenshot solution), you can also use the DirectTex library to capture a texture and then save it to DDS, HDR, TGA, or any WIC-supported file format.

Related

Looking for a way to create compressed png files in lua/luajit

I'm writing a mod for a game that uses lua/luajit as a scripting language and I would like to create a png file dynamically using lua. I've been googling for a png library/module but could only find ones that merely read pngs (like https://github.com/Didericis/png-lua or https://luapower.com/libpng), or create uncompressed pngs: https://github.com/wyozi/lua-pngencoder
On my search I have stumbled upon libpng and thought, maybe I could simply load that dll using ffi and use the functions that way. But the problem is that is waaaay too complicated for me, since I'm not familiar with C and furthermore libpng seems to be a huuuuuge complicated library.
So, is there any simple way (module/library) that I missed and didn't find on google?
I just need very simple functionality, create a png, set the pixels, save it as a compressed png file.

How to convert jpg or png to svg in iOS?

I like to convert an .jpg or .png file to an .svg format that can be displayed in UIImageView. Is there a way to do this in Objective-C?
You shouldn't use SVG images in Xcode:
it is recommended that you use PNG or JPEG files for most images in your app. Image objects are optimized for reading and displaying both formats, and those formats offer better performance than most other image formats. Because the PNG format is lossless, it is especially recommended for the images you use in your app’s interface.
Also, there's an SVGKit that according to many devs is buggy so use it at your own risk.
SVG is an XML-based vector and in Xcode you can also use vectors but using a PDF format and follow this tutorial.
In a nutshell:
Generate PDFs With the #1x Asset (During compile time it will generate #2 and #3)
Set the Scale Factors to Single Vector:
Drag and Drop Your PDF Into the All, Universal Section
Refer to Your Image by Its Name, Like for any PNG File
[UIImage imageNamed:#”Home”]
Also, stackoverflow (perhaps) related answer
To convert PNG to SVG (Which is a very sensible and valid thing to do) you need an app or library called a "tracer". It will trace the outlines of shapes, gradients, etc and convert them into vector representations.
For simple cases, this is easy for a computer to do; for complex cases (e.g. gradients), this is a very hard AI / Computer-Vision problem and you'd need to spend $$$ on high-end coding solutions and/or find PhD-level research that solves the problem!
A free tracer that does a very good job is built-in to Inkscape (open-source) - google "inkscape trace" for tutorials on how to use it, and to generate a .svg file that you can use. This is a manual process.
To use this in-app, you need to find a tracing library for iOS. The libraries that Inkscape uses are all open-source, so you could try converting them to iOS - they're written in C, so it could be quite easy.

How do I generate a texture with texturetool that pvr2atf will accept?

The Adobe docs for the new ATF SDK (http://www.adobe.com/devnet/flashruntimes/articles/atf-users-guide.html) state that the pvr2atf file is specifically designed to let you convert textures created with texturetool into ATF textures. I have a PNG texture (with transparency), and when I create an ATF with it directly, I get some odd artifacts around the edges of the non-transparent pixels. When I create a PVRTC texture with texturetool from the same source image, the preview generated by texture tool looks great. So, I was hoping I'd then be able to convert that into a clean ATF that I could then use on iOS in a Starling app.
However, when I use the texture created by this command:
texturetool -e PVRTC -o atlas0.pvrtc -p atlas0-preview.png -f PVR atlas0.png
pvr2atf complains:
Illegal pvrtc texture type.
(Hint 1: In PVRTexTool CL type needs to be OGLPVRTC4)
(Hint 2: In PVRTexTool UI select the 'OpenGL ES2.0' tab in the 'Encode Texture:' dialog and select 'PVRTC 4BPP')
Conversion failed!
I've tried a few different options to the texturetool, but have not managed to generate a single texture that pvr2atf doesn't have a problem with. Has anybody managed to do this? These tools are very new, and there's not a lot of info out there, aside from what Adobe has written (and in some cases their docs directly contradict the result of the tools, such as in the case of when transparency is supported).
I am downloading PVRTexTool now to see if I have better luck there, but I need this eventually to be automatible so needing a GUI tool would be a major bummer.
For starters download the Imagination PowerVR SDK from here
Dont use texturetool, it isnt updated as much as this tool which is from the developers of PowerVR:
In here you will get a GUI version of the texture packing tool called PVRTexTool, thats much easier to use. In here you can open your PNG and then manipulate it including the format the texture is set to. Click the box at the top with the 3 yellow arrows pointing down to see compression formats
It would appear you need to use PVRTCII 4bpp which defines a compressed texture 4 bits per pixel for OpenGLES 2.0. This also allows you to see all the other formats and have a play around if that format doesn't work.

Using EXR images in OpenCV

I'm currently working on a project with OpenEXR and I would like to implement some Blob detection algorithms. To do this I figured that I could use OpenCV as it says in the documentation that it can open OpenEXR format files.
I have all the libraries installed and working as I've been doing other things. I open a simple jpg file with openCV cvLoadImage. It works fine. But when i try to open any .exr file it doesn't seam to like it. I get a gray window where there should be the image display.
Has anyone done any tests with OpenCV and OpenEXR libraries working together? Have they worked for you? What do you think?
Thanks.
Yes, that's done, I posted a Ticket in the OpenCV project at willowGarage and they made all needed changes, you now can use OpenEXR with OpenCV as before!
Great
My HDR tone mapping algorithm will work again, cool
Have a nice programming now ;o)
Alex
Well Alex!
My news aren't really encouraging... I tried to use OpenEXR with OpenCV but it's not doing it's work. It says in the documentation that OpenCV 2.0 has OpenEXR support but...
I've searched the web to find some example of working EXR images in OpenCV but had no luck.
At this time I've developed myself a function to convert an image read with the OpenEXR libraries that uses Ilm::Rgba* structure to save the pixels of the image and convert it to char* that OpenCV uses with images. The IlpImage structure is the one I use. Actually I'm working with an example from OpenFrameworks and using they're Image structure...
It's a really early stage in my development because I had to start over...
I hope this can help you... but if you enter the world of OpenEXR it's a pretty dark world in terms of documentation, so all I can say is good luck!
Feel free to contact me and I'll see if I can help you!
This question is rather old now, but I noticed whilst reading the OpenEXR manual today that it says (whilst talking about reading named channels)
If one of those channels is not present in the image file, the corresponding memory buffer for the pixels will be filled with an appropriate default value.
I'd speculate here that the grey image you are seeing is an "appropriate default value".

Problem with showing some JPG files in Delphi

i have tried to open some JPEG files in Delphi with TImage component. i also added the Jpeg unit. i can open most of jpg files and there is no problem.
but when i try to open some JPGs, the program just throw an exception.
i also tried to load that images in design mode, but there is some problem. in design mode the exception is:
Access violation at address 402672A1 in module 'vcljpeg70.bpl'. Write of address 08E84000
Why i cannot open that JPGs? they are not corrupted. i checked them in some tools like savantools EXIF viewer.
here is the URL of one of that images:
http://xs842.xs.to/xs842/09340/backpic435.jpg
Thanks so much
PS:
My Delphi version is 7. Borland Delphi 7
The reason you may be encountering this problem is due to the file type. Delphi has issues displaying JPEG images that have been encoded using CMYK, rather than the default RGB encoding. CMYK is a format that is generally used for Print design, try and always encode your images to RGB format to avoid this issue with Delphi.
Patch for Delphi jpeg.dcu
Bye.
Interesting. Neither Internet Explorer nor Google Chrome will display that JPEG image you linked to. I do not get 404 Not Found errors, I simply get an image placeholder, indicating that the image could not be opened/displayed correctly.
FireFox does display the image.
Are you certain that there is not something fishy, or at least slightly unusual, about the JPG files involved?
UPDATE: The file linked to in the question opens in PaintShop Pro (an old version 6.0 installation) - if I then simply re-save as a Standard Encoding JPEG, IE and Chrome both display the newly saved image as I'd expect. There would definitely appear to be something a bit "odd-ball" about the encoding of the original JPEG that some JPEG apps can handle but not all, including some "major players", not just Delphi. :)
Check out the Free Image library for alternative JPEG support in Delphi if the native one has problems. Free Image is an open source lib that lets you work with JPEG/PNG/... from Delphi/BCB/and others. Very nice library IMHO.
http://freeimage.sourceforge.net/
I've looked at the file with a hex editor, and found 3 JFIF headers. After extracting each part, I found 2 thumbnails and an image. Nothing special, because embedded thumbnails seem to be part of the EXIF2 standard.
The thumbnails themselves load fine in Delphi, and converting the file to something readable can be done with almost every piece of software that I've tried.
Anyway, this page will give you very detailed information about the picture, and what headers are inside (just paste the url of your image in the textbox):
http://www.monster-submit.com/resources/jpeganalyzer/
I get the same error. This appears to be a bug in Delphi's JPEG lib. You should report it to QC.
SimDesign's NativeJpg can open that file. It's a JPEG library written entirely in Delphi, and the author has been good about adding support for new extensions and color spaces when we've run into them. In addition to a TGraphic descendant for TImage support it exposes lots of lower-level interfaces for manipulating JPEGs, though I haven't used them.

Resources