BaseBitmap Save TIF with LZW and save EXR using ZIP
-
Hi team!
Is it possible to using any of the compression algorithms with the classic BaseBitmap->Save, where we pass in a BaseContainer with settings? I would like to save out TIF files with LZW and also EXR with ZIP.
I do see that these compression algorithms are available in the new Maxon API. So perhaps an alternative question would be how can I use the Maxon API ImageSaverClasses to save a file with compression if I have a BaseBitmap as the source?
I will also outline what I want to actually achieve, and that is to downsize images from 8k to 4k, which is working fine, but I would just like to keep the original compression that we are using when saving the 4k versions. So a third alternative to solve my problem may actually be to use the Maxon API for everything, loading, resizing and then saving (with a specified compression).
I am open to using whatever is the easiest solution out of the above. If I can somehow tell the BaseBitmap saver to do what is needed then that is all I really need.
Thanks,
Kent -
Hello @kbar,
Thank you for reaching out to us. The Cinema Image API (i.e., things like
BaseBitmap
andMultipassBitmap
) are just an adapater/thin wrapper for the Maxon Image API, i.e., things likeImageInterface
. Internally, aBaseBitmap
just holds anImageRef
and pipes all method calls to it through. This internal data can be accessed with cinema::BaseBitmap::GetImageRef and allows you to directly operate with the Maxon Image API for a givenBaseBitmap
.Internally, there is also a smoke and mirrors
BitmapSaverData
plugin which handles all the Cinema API calls as for exampleBaseBitmap::Save
, and pipes them through to the correct Maxon API image saver classes. There is some setting conversion going on, but I cannot see any conversion for TIF (meaning all settings are meaningless). I would also say that the old (and now long defunct) Cinema API TIF saver never publicly supported compression, but I might be wrong.So, to do what you want to do, the general drill would be this (wrote this blind, this is 'pseudocode'):
// Some BaseBitmap we got somewhere in code and its underlying image ref. The details of the GetImageRef // call depend heavily on the input bitmap. cinema::BaseBitmap bmp; maxon::ImageRef image; bmp->GetImageRef(cinema::SAVEBIT::NONE, false, cinema::PIXELCNT::NONE, image); // Create the entity to which we will parent the raw image data and which we will use to save the image. maxon::ImageTextureRef texture = maxon::ImageTextureClasses::TEXTURE().Create() iferr_return; texture.AddChildren(maxon::IMAGEHIERARCHY::IMAGE, image, maxon::ImageBaseRef()) iferr_return; // Now create a settings dictionary to specify the compression method and set it on the texture. maxon::DataDictionary settings; settings.Set(maxon::MEDIASESSION::TIFF::EXPORT::COMPRESSION, maxon::MEDIASESSION::TIFF::EXPORT::COMPRESSION.ENUM_LZW) iferr_return; texture.Set(maxon::IMAGEPROPERTIES::IMAGE::EXPORTSETTINGS, settings) iferr_return; // Now create the stream handler for TIF and save the image. maxon::MediaOutputUrlRef handler = maxon::ImageSaverClasses::Tif().Create() iferr_return; const maxon::Url url ("file:///a/b/c.tif"_s); texture.Save(url, handler, maxon::MEDIASESSIONFLAGS::NONE) iferr_return;
The Image Manual will probably also be of some help. When you need more help, do not hesitate to reach out to us, I will then write a 'proper' example.
Cheers,
ferdinand -
Great! That makes it so much easier. I will give this a try today.
With the classic BaseBitmap API I also had to pass in that I wanted it to be INITBITMAPFLAGS::GRAYSCALE when saving a greyscale image. And I also passed in the SAVEBIT settings such as SAVEBIT::USE16BITCHANNELS. Does this still need to be done when using the Maxon API? I had a quick look at the docs page but couldn't find anything that relates directly to this, will have a closer look later today.
Thanks @ferdinand !
-
Hey Kent,
it depends a bit on the context. Generally, yes, flags and parameters passed to a
BaseBitmap
are piped through to the underlyingImageRef
. But as I hinted at with the TIF settings forBaseBitmap::Save
, some stuff is also ignored.For fundamental stuff like initializing a bitmap with a channel depth, color format, etc., I am not aware of cases where flags are being ignored. But as I wrote in my pseudocode example, the exact nature of the
BaseBitmap::GetImageRef
is also quite important.My very high level advice would be, use the Maxon Image API directly for simple things like loading, color converting, or saving an image, but avoiding it for complex tasks like for example assembling a multi layer image or drawing (not possible at all in the public API apart from 'dumb' pixel by pixel drawing). The problem with this is that when you must have a
BaseBitmap
output. Because while you can get anImageRef
from aBaseBitmap
instance, there is no 'sane' public way to construct aBaseBitmap
from anImageRef
you can of course copy over the buffer manually (not so sane) and there is a private way to do this but has its pitfalls (but is possible to do with the public API).As I said, I would invite you to reach out to us with some code and a concrete use case when you get stuck, I will then be able able to help you specifically.
Cheers,
FerdinandPS: We recently dropped the term 'classic API' in favour of 'Cinema API'. We also capitalize now 'Maxon API'. Just saying this for clarity.