Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    Scaling MultipassBitmap with Alpha [SOLVED]

    SDK Help
    0
    8
    554
    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.
    • H
      Helper
      last edited by

      On 16/07/2015 at 12:17, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:    
      Platform:      
      Language(s) :

      ---------
      Having an issue where a multiples bitmap will not keep its alpha when scaled.

      bitmap is a multipass bitmap with alpha.  That has been verified in code and with a render to disk.

      The scaling is anamorphic.

      MultipassBitmap *scaled_bitmap = MultipassBitmap::Alloc(20,60,COLORMODE_RGB);
      scaled_bitmap->AddChannel(true,true);
      bitmap->ScaleIt(scaled_bitmap,256,true,true);

      What is saved is a tif without alpha.  If I simply change to saving bitmap I get the correct render with alpha.

      What can I do to keep the alpha and have it scale?

      thank you,
      Ama

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 16/07/2015 at 13:43, xxxxxxxx wrote:

        ScaleIt() is only defined in BaseBitmap which would make me think that it can't handle a MultipassBitmap properly or without some consideration.  Or it is something about using AddChannel()  - again only defined in BaseBitmap.  Why do you not allocate using COLORMODE_ARGB or use the MultipassBitmap::AddAlpha()?

        Hopefully you do not need to resort to GetLayers() and using ScaleIt() on each BaseBitmap in the returned array.

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 16/07/2015 at 13:46, xxxxxxxx wrote:

          I was rendering a document and using the suggested functions in the documentation.  MultipassBitmap seemed to be the only way it worked.

          thank you,
          Ama

          Originally posted by xxxxxxxx

          ScaleIt() is only defined in BaseBitmap which would make me think that it can't handle a MultipassBitmap properly or without some consideration.  Or it is something about using AddChannel()  - again only defined in BaseBitmap.  Why do you not allocate using COLORMODE_ARGB or use the MultipassBitmap::AddAlpha()?

          Hopefully you do not need to resort to GetLayers() and using ScaleIt() on each BaseBitmap in the returned array.

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            On 17/07/2015 at 06:47, xxxxxxxx wrote:

            Hello,

            MultipassBitmap actually overrides AddChannel() internally and does not create a "channel" but a alpha layer. But ScaleIt() is indeed a method that can only handle BaseBitmaps and their internal channels, so it cannot scale layers.

            So you either stick to BaseBitmaps or you have to handle the layers/channels manually.

            Best wishes,
            Sebastian

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              On 17/07/2015 at 07:01, xxxxxxxx wrote:

              What is the appropriate way to create a basebitmap from the multiples bitmap with alpha?

              Ama

              Originally posted by xxxxxxxx

              Hello,

              MultipassBitmap actually overrides AddChannel() internally and does not create a "channel" but a alpha layer. But ScaleIt() is indeed a method that can only handle BaseBitmaps and their internal channels, so it cannot scale layers.

              So you either stick to BaseBitmaps or you have to handle the layers/channels manually.

              Best wishes,
              Sebastian

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                On 17/07/2015 at 07:30, xxxxxxxx wrote:

                Is there a way to create a basebitmap with alpha to work with renderdocument?

                Ama

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  On 20/07/2015 at 04:56, xxxxxxxx wrote:

                  Hello,

                  as discussed on different threads, one must use a MultipassBitmap to render alpha layers with RenderDocument.

                  It seems there is no build-in functionality to handle your specific use case. So you might have to copy an alpha layer yourself into a BaseBitmap. This could look like this:

                    
                  const Int32 alphaLayerCount = mpBitmap->GetAlphaLayerCount();  
                    
                  for(Int32 i = 0; i < alphaLayerCount; ++i)  
                  {  
                    
                   MultipassBitmap* alphaChannel = mpBitmap->GetAlphaLayerNum(i);  
                    
                    const Int32 h = alphaChannel->GetBh();  
                   const Int32 w = alphaChannel->GetBw();  
                    
                   // create basebitmap  
                   BaseBitmap* temp = BaseBitmap::Alloc();  
                   temp->Init(w, h, COLORMODE_RGBf);  
                    
                    
                   // copy  
                    
                   UChar* buf= NewMem(UChar, w);  
                   Float32* rgbBuf = NewMem(Float32, w * 3);  
                    
                   for(Int32 line = 0; line < h; ++line)  
                   {  
                       // get pixels  
                       alphaChannel->GetPixelCnt(0, line, w, buf, 1, COLORMODE_GRAY, PIXELCNT_0);  
                    
                       for(Int32  x = 0; x < w; ++x)  
                       {  
                           // read  
                           UChar grey = buf[x];  
                    
                           Float greyF =  Float32(grey) / 256.0;  
                    
                           // write  
                           rgbBuf[3*x] = greyF;  
                           rgbBuf[3*x+1] = greyF;  
                           rgbBuf[3*x+2] = greyF;  
                       }  
                    
                       // set pixels  
                       temp->SetPixelCnt(0,line,w,(UChar* )rgbBuf,3 * sizeof(Float32),COLORMODE_RGBf,PIXELCNT_0);  
                   }  
                   // free memory  
                   DeleteMem(buf);  
                   DeleteMem(rgbBuf);  
                    
                   // create small bitmap and scale  
                   BaseBitmap* smallBitmap = BaseBitmap::Alloc();  
                   smallBitmap->Init(400, 300, COLORMODE_RGBf);  
                   temp->ScaleIt(smallBitmap, 256, true, false);  
                         
                    // show results  
                    ShowBitmap(temp);  
                    ShowBitmap(smallBitmap);  
                    
                    // free memory  
                    BaseBitmap::Free(smallBitmap);  
                    BaseBitmap::Free(temp);  
                  }  
                  

                  best wishes,
                  Sebastian

                  1 Reply Last reply Reply Quote 0
                  • H
                    Helper
                    last edited by

                    On 20/07/2015 at 05:01, xxxxxxxx wrote:

                    Thank you!

                    Ama

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