Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search

Parsing PSD layers in MultipassBitmap

Author
Message
  Topic Search Topic Search
Rick Barrett View Drop Down
Forum Moderator
Forum Moderator


Joined: 2002 Oct 29
Location: United States
Online Status: Offline
Posts: 58
Direct Link To This Post Topic: Parsing PSD layers in MultipassBitmap
    Posted: 2006 Dec 02 at 6:29pm

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));


Back to Top
Rick Barrett View Drop Down
Forum Moderator
Forum Moderator


Joined: 2002 Oct 29
Location: United States
Online Status: Offline
Posts: 58
Direct Link To This Post Posted: 2006 Dec 02 at 6:32pm
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.

Back to Top
Rick Barrett View Drop Down
Forum Moderator
Forum Moderator


Joined: 2002 Oct 29
Location: United States
Online Status: Offline
Posts: 58
Direct Link To This Post Posted: 2006 Dec 13 at 2:11pm
Any help here? Is this possible?

Back to Top
Matthias Bober View Drop Down
Forum Moderator
Forum Moderator


Joined: 2006 Oct 16
Location: Germany
Online Status: Offline
Posts: 2204
Direct Link To This Post Posted: 2006 Dec 18 at 2:11am
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
MAXON
developer support
Back to Top
Rick Barrett View Drop Down
Forum Moderator
Forum Moderator


Joined: 2002 Oct 29
Location: United States
Online Status: Offline
Posts: 58
Direct Link To This Post Posted: 2006 Dec 18 at 9:48am
Thanks Matthias - I just need some method to get the layers of the bitmap - otherwise this plugin I'm working on is toast.
Back to Top
Matthias Bober View Drop Down
Forum Moderator
Forum Moderator


Joined: 2006 Oct 16
Location: Germany
Online Status: Offline
Posts: 2204
Direct Link To This Post Posted: 2006 Dec 18 at 12:18pm
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
MAXON
developer support
Back to Top
Matthias Bober View Drop Down
Forum Moderator
Forum Moderator


Joined: 2006 Oct 16
Location: Germany
Online Status: Offline
Posts: 2204
Direct Link To This Post Posted: 2007 Sep 17 at 7:00am
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
MAXON
developer support
Back to Top
tbrandt View Drop Down
Member
Member


Joined: 2008 Nov 25
Location: United States
Online Status: Offline
Posts: 7
Direct Link To This Post Posted: 2008 Nov 25 at 10:18am
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;
}
Back to Top
tbrandt View Drop Down
Member
Member


Joined: 2008 Nov 25
Location: United States
Online Status: Offline
Posts: 7
Direct Link To This Post Posted: 2008 Nov 25 at 10:30am
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!!!
Back to Top
tbrandt View Drop Down
Member
Member


Joined: 2008 Nov 25
Location: United States
Online Status: Offline
Posts: 7
Direct Link To This Post Posted: 2008 Nov 25 at 10:30am
In short, I am looking for anyway to bake out the Luminance layersets from the .psd file without the LayerMask applied.

Thanks!
Back to Top
tbrandt View Drop Down
Member
Member


Joined: 2008 Nov 25
Location: United States
Online Status: Offline
Posts: 7
Direct Link To This Post Posted: 2008 Nov 26 at 10:11am
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!





Back to Top

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.125 seconds.