Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Converting image bit depth

    Cinema 4D SDK
    c++
    2
    4
    688
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • WickedPW
      WickedP
      last edited by

      Hi Folks,

      I need to transfer some images into different bit depths (mainly 8 and 32-bits). I see inside Cinema4D there's a few commands for these, such as ID 170657 and ID 170659.

      Is it possible to use these in code, for example, to convert an 8-bit to 32-bit? If so, how?

      WP.

      wickedp.com

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @WickedP
        last edited by ferdinand

        Hello @WickedP,

        Thank you for reaching out to us. First, the classic API image saver frontend, the BitmapSaver plugins, provide little granular control these days, and unlike for the scene loaders and savers, you often cannot control things like bit depths and format options by setting values in the settings container of the saver.

        For anything but the simplest bitmap IO operations, you must use the Image API. Your question is also slightly ambiguous, as you do not specify if you want to do this conversion in memory only or if the output should be written to disk. Let me unpack things in bullet points. Color management and pixel formats are also unfortunately not a trivial subject, so there is quite a bit of ground to cover.

        • BaseBitmap::Save can save image data to disk but does not offer you any more granularity than the bitmap savers themselves. You can of course reconstruct an image pixel by pixel with a new bit depth, but I would really recommend using the Image API instead.
        • BaseBitmap::GetImageRef: Returns the underlying Image API ImageInterface representation of a BaseBitmap. The ImageInterface is the actual entity which represents bitmap data these days in Cinema 4D and BaseBitmap is just a hollow wrapper around it.
        • ImageInterface Manual: Showcases the basics of the Image API, including saving an image to disk. Note that you must insert your ImageRef under a ImageTextureRef as shown in the example, as only ImageTextureInterface has the Save method.
        • Color Management Manual: Demonstrates pixel format and color space conversions of image data using the Image API. The Color Convert Bitmap Data example should be quite close to what you want to do. Your "bit depth" task is covered by the pixel format one is choosing in this example. So, when you pick RGB::U8 as an input and RGBA::F32 as an output format, you would convert data in the 8bit uint RGB format to a 32bit float RGBA format.
        • When you just want to convert image buffers without writing them to disk, things are mostly the same, but you should then look at the Color Convert Singular Pixels and Color Convert Chunks of Pixel Data examples instead.

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • WickedPW
          WickedP
          last edited by WickedP

          Thanks @ferdinand,

          Conversion is in memory only. I may output at a later stage, though I do save using BaseBitmap->Save() for those times.

          This episode turned out to be quite more than I bargained for in the end. Had to make some serious project changes. But I do believe I've now solved my image problems (albeit, for now!).

          WP.

          wickedp.com

          ferdinandF 1 Reply Last reply Reply Quote 0
          • ferdinandF
            ferdinand @WickedP
            last edited by

            Hey @WickedP,

            Good to hear that you solved your problem. And I know that the color management and pixel format stuff can be a royal pain in the ***, you have my sympathies. Things tend to also get REALLY lovely when you also must deal with OCIO.

            Please do not hesitate to reach out again when you run in further troubles.

            Cheers,
            ferdinand

            MAXON SDK Specialist
            developers.maxon.net

            1 Reply Last reply Reply Quote 0
            • First post
              Last post