CppEvaluatedImageLayers

From The Foundry MODO SDK wiki
Jump to: navigation, search

Description:

This example command goes through all image layers (as found in exr or psd files) and reads the first pixel

Code:

/*
 
Python equivalent:
 
import modo
lx.eval ('clip.addStill /home/ivo/modo/sdk/projects/CMakeLinuxTest/image/multipage_tiff_example.psd true')
 
im = modo.Scene().selected[2]
 
ch = im.channel('imageStack').get()
ift = lx.object.ImageFilter(ch)
image = ift.Generate(64,64, None)
 
storage = lx.object.storage('b', 4)
image.GetPixel( 0,0, lx.symbol.iIMV_RGBA, storage)
 
print [storage[i] for i in xrange(4)]
 
*/
 
#include <lxidef.h>
 
#include <lx_item.hpp>
#include <lx_plugin.hpp>
#include <lx_log.hpp>
#include <lx_image.hpp>
 
#include <lxu_command.hpp>
 
#include <vector>
#include <string>
 
 
static char *SERVER_NAME             = "imagetest";
static char *SERVER_USERNAME         = "Image Test";
static char *LOG_NAME                = "imagetest";
 
 
class CCmdImage : public CLxBasicCommand
{
public:
	static LXtTagInfoDesc           descInfo[];
 
	int basic_CmdFlags() LXx_OVERRIDE {
		return LXfCMD_UNDO;
	}
 
 
	void cmd_Execute(unsigned int flags) LXx_OVERRIDE {
 
		CLxLoc_SceneService svc;
		CLxSceneSelection sceneSelection;
		CLxUser_Scene scene;
		CLxUser_Item item;
 
		LXtItemType imgLayerType;
		uint count, t;
 
		svc.ItemTypeLookup(LXsITYPE_IMAGELAYER, &imgLayerType);
 
		sceneSelection.Get(scene);
		scene.ItemCount(imgLayerType, &count);
 
		for(t=0; t< count; t++)
		{
			scene.GetItem (imgLayerType,t,item);
 
			if(item.IsA (imgLayerType))
			{
				CLxUser_ChannelRead read;
				read.from (item, 0.0);
 
				CLxUser_ImageFilter filter;
				read.Object (item, LXsICHAN_VIDEOCLIP_IMAGESTACK, filter);
				bool test = filter.test();
 
				CLxUser_Image layimg;
				filter.Generate (64, 64, 0, layimg);
 
				test = layimg.test();
 
				LXtPixelFormat format = layimg.Format();
				if (format == LXiIMV_RGBA)
				{
					unsigned char pixel[4];
					LxResult result = layimg.GetPixel (0, 0, format, pixel);
				}
			}
		}
 
	}
 
 
};
 
 
LXtTagInfoDesc CCmdImage::descInfo[] = {
	{LXsSRV_LOGSUBSYSTEM, LOG_NAME},
	{LXsSRV_USERNAME, SERVER_USERNAME},
	{0}
};
 
 
void initialize()
{
	CLxGenericPolymorph *srv = new CLxPolymorph<CCmdImage>;
 
	srv->AddInterface(new CLxIfc_Command    <CCmdImage>);
	srv->AddInterface(new CLxIfc_StaticDesc <CCmdImage>);
 
	lx::AddServer(SERVER_NAME, srv);
}