is it possible to create SVS files at all? - image-processing

I read a lot of resources saying that creating svs files is impossible. Is there any way to tweak the tif file contents in such a way that it can be saved as a SVS file by any chance. I was able to create a Aperio Tif slide using this tutorial.
Can anyone please help me in creating a SVS file or any tips ? I am also open to manual suggestions where I have to tweak the file properties manually.
Thank you!
Trying to create SVS Files

You can create an SVS file, but it's not easy. Aperio's SVS file is really a TIFF file. But it applies some parts of the TIFF standard wrong, so it's a TIFF file with errors.
LibTIFF will not output a file identical to an SVS. It simply refuses to do things wrong. So if you want to write an SVS file, you'd have to either write a correct TIFF file and then tweak some of the tags after the fact, or write the incorrect TIFF file manually (i.e. figure out which bytes to output in which order, following the SVS specification). Neither of these is easy to accomplish, and you should be well versed in the TIFF standard and binary file manipulation before you attempt this.
On the other hand, unless you are trying to fool someone with a fake SVS file, you really shouldn't need to do this. Most software tools that read SVS files also read compliant TIFF files. I would suggest writing your image out as a tiled, pyramidal TIFF file and seeing if that works in your application.

Related

How to transform a ID3D11Texture2D into any picture format

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.

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.

The best way to verify a zip file function in Elixir

I have a path library which has a zip function in it, and while writing the unit test, I tried to find the best way to verify that the zip function works correctly.
Can someone please show me the best way to verify that the zip function works correctly ?
The few ways I can think of are:
Comparing the md5 of the resultant zip file against a sample zip file
Listing out the contents of the zip file and ensuring the content are correct
However, both ways seems a little long winded and I am guessing not exactly idiomatic Elixir. Can someone please show me a better way ?
I would create a directory of test files to zip up in your unit test, zip it up using a trusted utility and get the resulting md5. Then for your unit test, perform the zip function, take the md5, and compare with your verified md5.
If I am correct, there are some parameters that can affect the result of zip processing (like block size). So, unless your purpose is to check exhaustively that your zip process reproduces all or a subset of the zip features, I find more interesting to validate that various files from your system (or/and some random files) can be compresses with your function, and uncompressed outside using different unzip tools, and finally compare that the files are identical to the original. (of course it takes more time, but it can be easily automated).
Concerning the usage of MD5 rather than file comparison, I think that on one hand file comparison is easy to write and in the other hand you need to read the whole file to calculate the MD5, so I don't think it is worth to use this trick to accelerate the comparison - (especially if files are different :o).

Decompress PNG directly to disk

I have a large PNG that I want uncompressed to a file, but I don't have the memory capacity on the device to expand the PNG in memory, then to a file.
Is there a native iOS method to uncompress a PNG for each scan line? Alternatives?
Libpng - Reading image data - http://www.libpng.org/pub/png/libpng-1.2.5-manual.html#section-3.8
For non-interlaced PNGs
png_read_rows(png_ptr, row_pointers, NULL, number_of_rows);
As and idea how to start:
Take a look how is doing Java the png decompressing algorithm. Java should have open-source those files. Maybe has the iOS too idk. Just get the uncompress algorithm idea. It should be around 1k-5k lines of code.
When you know how to do it, than implement at iOS but read a chunk of file and than export to a file, read another chunk and process and export it. I know it is easy to say and at least theoretically it is working. Maybe is public in some site. Libpng can be a good starting point.
Png is a looseness compression like zip. There as I have remember runtime is built a data table. Those table depends how big is, maybe need to be swapped to to disk, which will makes longer the decompression process.
Good luck!

Resources