Parsing PSD layers in MultipassBitmap



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 02/12/2006 at 18:29, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   10.008 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------

    I'm trying to iterate through layers of a psd file using multipass bitmap, but the multipass bitmap is always reporting a Layer Count of 0, although the fn object is pointed to a PSD with multiple layers.

    Here's the basic code I'm using - any help accomplishing this would be greatly appreciated.

      
    AutoAlloc<BaseBitmap> bmp;  
    LONG result = bmp->Init(fn, -1, NULL);  
                
    MultipassBitmap* mbmp = MultipassBitmap::AllocWrapper(bmp);  
    GePrint("Layer Count: " + FormatNumber(mbmp->GetLayerCount(), FORMAT_LONG, 0));  
    


  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 02/12/2006 at 18:32, xxxxxxxx wrote:

    BTW - I also tried allocating a new MultipassBitmap of the proper size and depth and init-ing the MultipassBitmap from the file, but I'm getting a result of 0 in that case.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 13/12/2006 at 14:11, xxxxxxxx wrote:

    Any help here? Is this possible?



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 18/12/2006 at 02:11, xxxxxxxx wrote:

    I can confirm this problem and reported it to the developers. First reactions were that it is maybe not possible to load multilayer images. We are investigating. I let you know when I know more about it.

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 18/12/2006 at 09:48, xxxxxxxx wrote:

    Thanks Matthias - I just need some method to get the layers of the bitmap - otherwise this plugin I'm working on is toast.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 18/12/2006 at 12:18, xxxxxxxx wrote:

    Got word from the developers, at the moment it's not possible to load multilayer images through the MultipassBitmap class. It's used for rendering and displaying only. Loading of multilayer images happens with internal classes only at the moment. So yes, your plugin is probably toast, sorry about that. The only solution is to write your own PSD file reader. On the bright side the developers are now aware of a need to load multipass within plugins, so chances are that the necassary changes are made for the SDK in future versions.

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 17/09/2007 at 07:00, xxxxxxxx wrote:

    A bit late but maybe still of interest for you and other developers. You can load and access multilayer images through the PaintTexture, PaintLayer classes and the SendpainterCommand function. Unfortunatly there are currently not included in the documentation. Here an example how to load a multilayer image:

      
    static void StepThruLayers(PaintLayer *layer)  
    {  
         while (layer)  
         {  
              if (layer)  
              {  
                   GePrint("layer");  
              }  
              StepThruLayers((PaintLayer* )layer->GetDown());  
              layer = (PaintLayer* )layer->GetNext();  
         }  
    }  
      
    Bool MenuTest::Execute(BaseDocument *doc)  
    {  
         Filename fn;  
         if(!fn.FileSelect(FSTYPE_IMAGES, 0, NULL)) return TRUE;  
      
         PaintTexture *tex = NULL;  
         BaseContainer bc;  
         bc.SetFilename(LOADTEXTURE_FILENAME, fn);  
         tex = (PaintTexture* )SendPainterCommand(PAINTER_LOADTEXTURE, doc, NULL, &bc;);  
      
         if(!tex) return TRUE;  
      
         PaintLayer *layer = NULL;  
         layer = tex->GetFirstLayer();  
      
         StepThruLayers(layer);  
      
         return TRUE;  
    }  
    

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 25/11/2008 at 10:18, xxxxxxxx wrote:

    Thank You for the example. I am having some issues, though.

    I have a Plugin which saves out the Luminance and Alpha channel textures to disk for each material. Unfortunately, the Luminance channel texture only has data in the image where the alpha has data. I believe this is because the LayerMask is applied. I have been trying to figure out how to temporarily disable this LayerMask when writing the Luminance. I thought this example would be helpful, since you are showing how to walk the Layers.

    The first thing I was attempting to do with your example is to load a BaseBitmap object from each Layer (using PaintBitmap's ReCalc method), and save it out to disk. Unfortunately, I am only able to get a valid BaseBitmap object from a PaintTexture object, and not a PaintLayer object.

    Any help is appreciated. My hope is that by grabbing a BaseBitmap straight from the PaintLayers, the Luminance data will not have the LayerMask applied. If it does, it would also be nice to know how to disable it.

    Thanks - here is my modified version of your example :

    void C4dMaterial::StepThruLayers(PaintLayer *layer)
    {
         while (layer)
         {
              if (layer)
              {
                  LONG sb = SAVEBIT_16b*tchANNELS;
        
                  //if(layer->Save('/mcp/poop.tif', FILTER_TIF, NULL, sb) == IMAGE_OK)
        
                  PaintTexture *pntTexture = layer->GetPaintTexture();
                  if ( pntTexture )
                  {
                      
                   if (layer->ReCalc(NULL,0,0,layer->GetBw(),layer->GetBh(),merge,RECALC_NOGRID|RECALC_INITBMP,0))
                      {   
                          std::string tmpPath_tif_str = "/mcp/" + CspUtilsGeneral::ToStdString( layer->GetName() ) + "_" + ".tif";
                         
                          Filename tmpPath_tif = Filename( tmpPath_tif_str.c_str() );
                         
                          BaseContainer data;
                          if (!merge->Save(tmpPath_tif, FILTER_TIF, &data;, sb))
                          {
                              std::cerr << "Error saving image \n";
                          }
                      }
                  } else
                  {   
                      std::cerr << "No Paint Texture!!!!!" << std::endl;
                  }
              }
              StepThruLayers((PaintLayer* )layer->GetDown());
              layer = (PaintLayer* )layer->GetNext();
         }
    }

    bool C4dMaterial::printLayers(BaseDocument *doc)
    {
         Filename fn;
         if(!fn.FileSelect(FSTYPE_IMAGES, 0, NULL)) return TRUE;

    PaintTexture *tex = NULL;
         BaseContainer bc;
         bc.SetFilename(LOADTEXTURE_FILENAME, fn);
         tex = (PaintTexture* )SendPainterCommand(PAINTER_LOADTEXTURE, doc, NULL, &bc;);

    if(!tex) return TRUE;
         
         PaintLayer *layer = NULL;
         layer = tex->GetFirstLayer();

    StepThruLayers(layer);

    return TRUE;
    }



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 25/11/2008 at 10:30, xxxxxxxx wrote:

    Sorry, the last example was missing a line. Please use this one :

    void C4dMaterial::StepThruLayers(PaintLayer *layer)
    {
         while (layer)
         {
              if (layer)
              {

    LONG sb = SAVEBIT_16b*tchANNELS;
        
                  PaintTexture *pntTexture = layer->GetPaintTexture();
                  if ( pntTexture )
                  {
                      AutoAlloc<BaseBitmap> bitmap;
                      
                      if (layer->ReCalc(NULL,0,0,layer->GetBw(),layer->GetBh(), bitmap,RECALC_NOGRID|RECALC_INITBMP,0))
                      {   
                          std::string tmpPath_tif_str = "/mcp/" + CspUtilsGeneral::ToStdString( layer->GetName() ) + "_" + ".tif";
                         
                          Filename tmpPath_tif = Filename( tmpPath_tif_str.c_str() );
                         
                          BaseContainer data;
                          if (!bitmap->Save(tmpPath_tif, FILTER_TIF, &data;, sb))
                          {
                              std::cerr << "Error saving image \n";
                          }
                      }
                  } else
                  {   
                      std::cerr << "No Paint Texture!!!!!" << std::endl;
                  }
              }
              StepThruLayers((PaintLayer* )layer->GetDown());
              layer = (PaintLayer* )layer->GetNext();
         }
    }

    bool C4dMaterial::printLayers(BaseDocument *doc)
    {
         Filename fn;
         if(!fn.FileSelect(FSTYPE_IMAGES, 0, NULL)) return TRUE;

    PaintTexture *tex = NULL;
         BaseContainer bc;
         bc.SetFilename(LOADTEXTURE_FILENAME, fn);
         tex = (PaintTexture* )SendPainterCommand(PAINTER_LOADTEXTURE, doc, NULL, &bc;);

    if(!tex) return TRUE;
         
         PaintLayer *layer = NULL;
         layer = tex->GetFirstLayer();

    StepThruLayers(layer);

    return TRUE;
    }

    Here's the deal - when I call Recalc on the PaintTexture object :

    (pntTexture->ReCalc(NULL,0,0,pntTexture->GetBw(),pntTexture->GetBh(), bitmap,RECALC_NOGRID|RECALC_INITBMP,0))
    I get a valid BaseBitmap object back (bitmap), and can save out a texture (which of course is the entire .psd flattened down).

    So, in attempting to save out each individual layer, I am calling ReCalc on each PaintLayer object in the above example (it is inherited from PaintBitmap, after all) :
    (layer->ReCalc(NULL,0,0,layer->GetBw(),layer->GetBh(), bitmap,RECALC_NOGRID|RECALC_INITBMP,0))

    This ReCalc call returns true, but I am not able to save the bitmap to disk.

    Any help is appreciated!!!



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 25/11/2008 at 10:30, xxxxxxxx wrote:

    In short, I am looking for anyway to bake out the Luminance layersets from the .psd file without the LayerMask applied.

    Thanks!



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 26/11/2008 at 10:11, xxxxxxxx wrote:

    Ok, with help of my collegue Andrea Solis, I think we've wrapped our heads around this one.

    There is a visibility bit on the layer objects you set with the 'SetShowBit' method :

    layer->SetShowBit( FALSE, 0 );

    You can grab the alphaMask for the layer using the following :
    layer->GetAlphaFirst()

    This is also a LayerObject, you can set it's visibility the same way :
    layer->GetAlphaFirst()->SetShowBit( FALSE, 0 );

    So, essentially, you walk the layers from the PaintTexture object, set the desired visibility on them and their alphas, and then save the PaintTexture out to disk.

    This can be done either via
    SendPainterCommand(PAINTER_SAVETEXTURE, NULL, tex, &bc;);

    or, by fetching the Bitmap via ReCalc :

    if (tex->ReCalc(NULL,0,0,tex->GetBw(),tex->GetBh(), bitmap,RECALC_NOGRID|RECALC_INITBMP,0))
                {   
                   if (!bitmap->Save(tmpPath_tif, FILTER_TIF, NULL, sb))
                   {
                        std::cerr << "Error saving image \n";
                   }
    }

    I think that's it!


Log in to reply