Image UtilityAvailability LightWave 6.0 This global provides functions for creating and saving still images. Also see the Image List global. Pixmaps, used by this global and identified by LWPixmapID, differ from the images in the image list, which are identified by LWImageID. Pixmaps are stills, and you can draw on them and save them. Once saved to a file, the image can be loaded into LightWave using the Image List load function. The pixmap returned by the Image List evaluate function is a copy of the image, and drawing on this copy does not change the original image. Global Call LWImageUtil *imgutil; imgutil = global( LWIMAGEUTIL_GLOBAL, GFUSE_TRANSIENT ); The global function returns a pointer to an LWImageUtil. typedef struct st_LWImageUtil { LWPixmapID (*create) (int w, int h, LWImageType); void (*destroy) (LWPixmapID); int (*save) (LWPixmapID, int saver, const char *name); void (*setPixel) (LWPixmapID, int x, int y, void *pix); void (*getPixel) (LWPixmapID, int x, int y, void *pix); void (*getInfo) (LWPixmapID, int *w, int *h, int *type); LWPixmapID (*resample) (LWPixmapID, int w, int h, int mode); int (*saverCount)(void); const char * (*saverName) (int saver); } LWImageUtil;
Example This example creates a rainbow image, saves it, and loads it into Layout's internal image list using the image list global. #include <lwserver.h> #include <lwimage.h> #include <lwhost.h> LWMessageFuncs *msg; LWImageUtil *imgutil; LWImageList *imglist; LWImageID image; LWPixmapID pixmap; int x, y, saver, nsavers; unsigned char rgb[ 3 ]; char *filename = "rainbow.tga"; imgutil = global( LWIMAGEUTIL_GLOBAL, GFUSE_TRANSIENT ); imglist = global( LWIMAGELIST_GLOBAL, GFUSE_TRANSIENT ); msg = global( LWMESSAGEFUNCS_GLOBAL, GFUSE_TRANSIENT ); if ( !imgutil || !imglist || !msg ) return AFUNC_BADGLOBAL; pixmap = imgutil->create( 256, 20, LWIMTYP_RGB24 ); if ( !pixmap ) { msg->error( "Couldn't create the image.", NULL ); return AFUNC_OK; } for ( x = 0; x < 256; x++ ) for ( y = 0; y < 20; y++ ) { hsv2rgb( 359.0f * x / 255.0f, y / 20.0f, 1.0f, rgb ); imgutil->setPixel( pixmap, x, y, rgb ); } nsavers = imgutil->saverCount(); for ( saver = 0; saver < nsavers; saver++ ) if ( !strcmp( "Targa Format (.tga)", imgutil->saverName( saver ))) break; if ( saver == nsavers ) msg->error( "Couldn't find the Targa saver.", NULL ); else imgutil->save( pixmap, saver, filename ); imgutil->destroy( pixmap ); image = imglist->load( filename ); The hsv2rgb function looks like this. void hsv2rgb( float h, float s, float v, char rgb[] ) { float r, g, b, p, q, f, t; int i; if ( s == 0 ) { rgb[ 0 ] = rgb[ 1 ] = rgb[ 2 ] = ( int )( v * 255 ); return; } h /= 60.0f; i = ( int ) h; f = h - i; p = v * ( 1.0f - s ); q = v * ( 1.0f - ( s * f )); t = v * ( 1.0f - ( s * ( 1.0f - f ))); switch ( i ) { case 0: r = v; g = t; b = p; break; case 1: r = q; g = v; b = p; break; case 2: r = p; g = v; b = t; break; case 3: r = p; g = q; b = v; break; case 4: r = t; g = p; b = v; break; case 5: r = v; g = p; b = q; break; } rgb[ 0 ] = ( int )( r * 255 ); rgb[ 1 ] = ( int )( g * 255 ); rgb[ 2 ] = ( int )( b * 255 ); } |