![]()
Appendix F: Adding Image Plug-ins
Maya features an external plug-in module mechanism that lets you create your own image file translators. This system is specific for adding new image types to Maya and is different from the Maya API. These plug-in modules are available whenever you start your application. You can access them through the list of image file types presented where you access image files.
Plug-in image modules are implemented as dynamically shared objects (DSOs or DLLs), and can be written using C or C++. You only need to implement the algorithms that read and write the image files; the user interface and flow control are implicitly handled by Maya.
This document describes the protocol for writing an image plug-in module. It does not describe how to support multiple-frame or movie files. Sample code is provided in the image subdirectory of the Developer’s Kit.
This section discusses the following:
Overview
Maya invokes functions from your image plug-in primarily to read and write image files. One of the places where this can happen is in the rendering window. In this window, you can choose to save your image as a certain format. In addition, you can load an existing rendering image into this window. You are able to select a custom format that you have defined for the read and write operations of this window.
About entry points
Each plug-in must have a defined number of entry points.Maya uses these entry points to determine which features the image plug-in supports.
Some entry points are variables and others are functions. For example, the name of the plug-in is defined by the variable entry point
imageName, and the function that opens an image file for reading is defined by the function entry pointimageReadOpen.Some entry points are required, while others are optional. The mandatory entry points are described in the next section. Optional entry points are described in "Optional entry points."
Mandatory entry points
The following entry points must be defined:
programtypeversionimageKeyimageIsFileimageNameimageReadOpenand its associated look-up table reading, scanline reading, and close functions (unless your plug-in cannot read as specified by the imageAccess entry point).imageWriteOpenand its associated scanline writing and close functions (unless you specify otherwise with the imageAccess entry point).If a mandatory entry point is omitted, the plug-in will not be loaded, and its name will not appear in any menu.
program
Definition
char *programDescription
This entry point specifies the applications that can use the plug-in. This should be Wavefront so that all of your applications can read and write image files supported by this plug-in.
Example
char *program = "Wavefront";type
Definition
char *typeDescription
This entry point denotes the type of plug-in that is being built. A Maya image file plug-in is of type
image.Example
char *type = "image";version
Definition
char *versionDescription
This entry point denotes the version of the protocol for which the plug-in was written. Always use
IMF_PROTOCOL_CURRENT.Example
char *version = IMF_PROTOCOL_CURRENT;imageKey
Definition
char *imageKeyDescription
This entry point specifies a unique key to identify your plug-in.
Example
char *imageKey = "myFormat";imageName
Definition
char *imageNameDescription
This entry point defines the name of your plug-in as displayed in menus. Names should be unique so users can distinguish between them.
Example
char *imageName = "My Image Format";imageReadOpen
Definition
int imageReadOpen
(
IMF_OBJECT *imf
}
Parameter Type Description
imfModified
Image File Header
Return Value
IMF_C_NORMALif the image was successfully opened;IMF_C_if an error occurred.
Description
This function is called when a file is to be opened for reading.
The
imfparameter contains all of the information necessary for the reading of the file. Before callingimageReadOpen, it contains the filename. After executing this routine, it must also contain pointers to the routines which access the file, information about the size and other attributes of the image being read, buffers to read scanlines of the image into, etc.The basic steps to writing this function are as follows:
- Open the file.
- Read the header from the file. If the file includes a look-up table, read it at this time.
- Assign the
close,scanline read,and LUTreadroutines intoimf.- Define the parameters of the image in
imf->info.image[0].- Allocate buffers to contain the scanlines.
- Allocate private data defining the file descriptor, etc., and associate them with
imf->data.Some image files may contain multiple images, e.g., the full image and a thumbnail representation. For this discussion, we will assume that you will only be reading the main image from such files.
The detailed steps are as follows:
- If the filename is not fully qualified, complete it. Then, open the specified file. Continue only if the open was successful. If it fails, you must generate a message using
ERR_printf, setimf__errtoIMF_C_CANNOT_OPEN, and returnFALSE.- Set the image count to be 1, and allocate and initialize one image structure to contain information about this image:
imf->info.count = 1;
imf->info.image = malloc( sizeof( IMF_IMAGE ) );
(void) imf__init_ifd( imf );
- Save the format-specific information describing the file in your own data structure allocated using
malloc. This private data structure can contain items like the current file descriptor, last scanline read, active window, etc.:
private = malloc( sizeof( PRIVATE ) );
private->... = ...;
imf->data = malloc( sizeof( POINTER ) );
imf->data[0] = private;
- Assign your image access routines to
imf->scanandimf->close. If your image file contains a look-up table, also specify the routine that reads the look-up table inimf->lut_read.- If your file format defines input capabilities, extract those from
imf->info.settings. (See IMF_CAPABILITY for details.)- Read the header information from the file, and store this in your private data structure. You must also define various fields in the
imf->infoandimf->info.image[0]data structures.In the
imf->infostructure, set thelut_exists fieldaccording to whether the image has a look-up table.You can also set
program,machine,user,date,time,framenumber,job_num, and chromaticity information (red_pri,green_pri,blue_pri,white_pt) if these are stored in the file itself.You must also set all of the fields in
imf->info.image[0]. Theaux_format,aux_count,aux_type, andaux_bitsfields refer to z channel information. The fieldcurve.gammaneeds to be set to either the gamma defined in your file, or the default gamma by callingIMF_def_input_gamma.
- Allocate a scanline buffer into which your scanline reading routine reads a row of pixels:
private_data_ptr->buffer = IMF_chan_alloc(
imf->info.image, image_width,
imf->info.key, NULL );
- Return
TRUEif your function successfully opened and read the image file header, andFALSEif an error occurred.Scanline reading function
Definition
int your_scan_read_func
(
POINTER data,
int scan,
POINTER **line_buff
)
Description
This function is called by Maya to read a scanline from your image file. Image files are read according to the image's orientation, either from bottom to top, or from top to bottom.
Follow these steps to create your scanline reading function:
- Read the specified scanline. The scanline number is based on bottom-to-top ordering. For example, if your image size is 480 lines, and your orientation is
IMF_C_TOP_LEFT, the scanlines are read in the order 479 (top), 478 (second from top), 477, ... 0 (bottom). If the ordering isIMF_C_BOT_LEFT, they are read in the order 0 (bottom), 1 (second from bottom), 2, ... 479 (top).- Transfer the scanline into the buffer allocated in
imageReadOpen. The buffer allocated byIMF_chan_alloccontains 8-, 16-, or 32-bit unsigned numbers, according to the number of bits per channel in the file. (The number of bits per channel is rounded up to the nearest number above.)Each component of the scanline is stored in a separate contiguous buffer. These are returned in the parameter
line_buff, which is an array of pointers to the components that you allocated:
/*
* Unsigned char's are used for 1 to 8-bit values;
* unsigned short's, for 8 to 16-bit values;
* unsigned long's, for 17 to 32-bit values.
*/
*line_buff = data->buffer;
pr = (unsigned char *) data->buffer[0];
pg = (unsigned char *) data->buffer[1];
pb = (unsigned char *) data->buffer[2];
pm = (unsigned char *) data->buffer[3];
for ( i = 0; i < data->image_width; ++i )
{
*(pr++) = red_values[i];
*(pg++) = green_values[i];
*(pb++) = blue_values[i];
*(pm++) = matte_values[i];
}If the file contains a look-up table, you must still return RGB data, and not the indexes into the look-up table, in
line_buff.
- Return
IMF_C_BAD_SCAN,IMF_C_NORMAL, orIMF_C_READ_ERRas appropriate.Your scanline reading function must not expect to read the last scanline of the image because Maya may skip the last few scanlines if they do not need to be read. Your plug-in must allow Maya to call your close function at any time after calling
imageReadOpen.Close function
Definition
int your_close_func
(
IMF_OBJECT *imf
)
Description
This function is called whenever Maya is finished reading or writing your image file. Follow these steps to create your close function:
- Close the image file.
- Deallocate any private data pointed to by
imf->dataand setimf->datatoNULL. To deallocate the scanline buffer allocated in eitherimageReadOpenorimageWriteOpen, useIMF_chan_free.- Return
IMF_C_NORMALif file closing and memory clean-up is successful, andIMF_C_failure_codeif not.imageWriteOpen
Definition
int imageWriteOpen
(
IMF_OBJECT *imf
)
Parameter Type Description
imfModified
Image file descriptor.
Return Value
TRUEif the image was successfully opened;FALSEif an error occurred.
Description
This function is called when a file is to be opened for writing.
The
imfparameter contains all of the information necessary to write the file. Before callingimageWriteOpen, it contains the filename. After executing this routine, it must also contain pointers to the routines that access the file, information about the size and other attributes of the image being written, etc.The basic steps to creating this function are as follows:
- Open the file.
- Write the header. If the file includes a look-up table, you may need to write it at this time.
- Assign the
closeandscanlinewriteroutines toimf.- Allocate private data defining the file descriptor, etc., and associate them with
imf->data.Detailed steps are as follows:
- Open the specified file. Continue only if the open was successful. If it fails, you must generate a message using
ERR_printf, setimf__errtoIMF_C_CANNOT_OPEN, and returnFALSE.- Use
imf->infoandimf->info.image[0]to extract attributes about the file being written.- Save the format-specific information describing the file in your own data structure allocated using
malloc. This private data structure can contain items like the current file descriptor, active window, etc.:
private = malloc( sizeof( PRIVATE ) );
private->... = ...;
imf->data = malloc( sizeof( POINTER ) );
imf->data[0] = private;
- Specify the image access routines in
imf->scanandimf->close.- If your file format defines output capabilities, extract those from
imf->info.settings. (See IMF_CAPABILITY for details.)- Write the file header and look-up table, if defined.
- Return
IMF_C_NORMALif your function successfully opened and read the image file header. ReturnIMF_C_failure_codeif an error occurred.In the event of a failed attempt at opening an image file, Maya calls
imf__free_obj( imf )to free theIMF_OBJECTpassed toimageWriteOpen. Therefore, you must not callimf__free_objin your error-handling code.Scanline writing function
Definition
int your_scan_write_func
(
POINTER data,
int scan,
POINTER *line_buff
)
Description
This function is called by Maya to write a scanline to your image file. Image files are written according to the image's orientation, either from bottom to top, or from top to bottom.
Follow these steps to create your scanline writing function:
- Write the specified scanline. The scanline number is based on bottom-to-top ordering. For example, if your image size is 480 lines, and your orientation is
IMF_C_TOP_LEFT, the scanlines are written in the order 479 (top), 478 (second from top), 477, ... 0 (bottom). If the ordering isIMF_C_BOT_LEFT, they are written in the order 0 (bottom), 1 (second from bottom), 2, ... 479 (top).- Retrieve the red color channel information from
line_buff[0], green fromline_buff[1], and blue fromline_buff[2], whereline_buffis the scanline buffer passed in by Maya. If there is a matte channel, it is inline_buff[3]. The z channel, if it exists, is inline_buff[4]. The pixels are stored from left to right.
pr = (unsigned char *) line_buff[0];
pg = (unsigned char *) line_buff[1];
pb = (unsigned char *) line_buff[2];
pm = (unsigned char *) line_buff[3];
for ( i = 0; i < data->image_width; ++i )
{
red_values[i] = *(pr++);
green_values[i] = *(pg++);
blue_values[i] = *(pb++);
matte_values[i] = *(pm++);
}Convert the values to the format used by your file format and write the scanline to the file.
- Return
IMF_C_BAD_SCAN,IMF_C_NORMAL, orIMF_C_READ_ERR.Optional entry points
A number of additional entry points exist. If an optional entry point is not defined, a default value is used. Some optional entry points are ignored unless the feature is supported by your file format.
imageAccess
Definition
unsigned int imageAccessDescription
This variable specifies the reading and writing methods that your plug-in supports. The constants described are bit fields:
IMF_C_LUT_READindicates that your plug-in supports reading palettes from files. A LUT reading function must be defined and assigned to imf->lut_readin theimageReadOpenroutine.IMF_C_LUT_WRITEindicates that your plug-in supports writing palettes to files.IMF_C_READindicates that your plug-in supports the sequential reading of scanlines.IMF_C_READ_RANDOMindicates that your plug-in supports the random reading of scanlines.IMF_C_WRITEindicates that your plug supports the sequential writing of scanlines.IMF_C_WRITE_RANDOMindicates that your plug-in supports the random writing of scanlines.The default value is
IMF_C_READ|IMF_C_WRITE.Example
This example is for a file that supports look-up tables:
unsigned int imageAccess
= IMF_C_LUT_READ | IMF_C_LUT_WRITE | IMF_C_READ | IMF_C_WRITE;imageBitsPerChannel
Definition
unsigned int imageBitsPerChannelDescription
This variable defines the number of bits per color channel that are supported. This applies to the red, green, and blue channels only.
This variable is a bit field, used to define the number of bits (from 1 to 32) that each channel can support. Setting the lowest bit indicates that the format supports 1 bit per color channel; setting the highest bit indicates that the format supports 32 bits per color channel. You need to set bits in this variable according to all of the bits-per-channel that your format supports.
The default value is
0x00000080, or 8 bits per color channel.Example
The first example supports only 8 bits per color channel; the second example supports 8, 10, and 16 bits.
unsigned int imageBitsPerChannel = 0x00000080;
unsigned int imageBitsPerChannel = 0x00008280;imageBitsPerMatte
Definition
unsigned int imageBitsPerMatte;Description
This variable is identical to
imageBitsPerChannel, except that it describes the number of bits supported by the matte channel.The default value is
0x00000000, which means that the format does not support matte channels.Example
The first example supports only 8 bits in the matte channel; the second example supports 8, 10, and 16 bits.
unsigned int imageBitsPerMatte = 0x00000080;
unsigned int imageBitsPerMatte = 0x00008280;imageBitsPerZChannel
Definition
unsigned int imageBitsPerZChannelDescription
This variable is identical to
imageBitsPerChannel, except that it describes the number of bits supported by the z channel.The default value is
0x00000000, which means that the format does not support z channels.Example
The first example supports only 8 bits in the z channel; the second example supports 8, 10, and 16 bits.
unsigned int imageBitsPerZChannel = 0x00000080;
unsigned int imageBitsPerZChannel = 0x00008280;imageCapability
Definition
void imageCapability
(
IMF_CAPABILITY **capabilities,
int *num_input,
int *num_output,
int *total
)
Description
This function is called during initialization when Maya determines the capabilities to display in its menus. For more information on capabilities, see IMF_CAPABILITY.
Example
This generic code fragment loops through your plug-in's list of capabilities:
int i;
*capabilities = your_capabilities;
for ( *num_input = *num_output = *total = i = 0;
i < number_elements_in( your_capabilities );
++i )
{
if ( your_capabilities[i].imc_when_avail
& IMF_CAPABILITY_WHEN_INPUT )
{
++( *num_input );
}
if ( your_capabilities[i].imc_when_avail
& IMF_CAPABILITY_WHEN_OUTPUT )
{
++( *num_output );
}
if ( your_capabilities[i].imc_when_avail
& ( IMF_CAPABILITY_WHEN_INPUT
| IMF_CAPABILITY_WHEN_OUTPUT ) )
{
++( *total );
}
}imageDescription
Definition
char *imageDescriptionDescription
This variable is a string used to provide a more detailed description of the file format. It augments the
imageNamewhen displayed in menus.The default value is
NULL, which means that no additional description exists.Example
char *imageDescription = "Version 2";imageDone
Definition
void imageDone( void )Description
This optional routine is called when you exit Maya. If your plug-in requires special licensing, you should also release the license at this point.
imageExtension
Definition
char *imageExtensionDescription
This variable defines the default extension when generating filenames for your plug-in. It must include the preceding period. The default value is
NULL, which indicates that the format does not typically use an extension.This variable is used to determine the format of the image file when the file type is defined as
Determine from extension.Example
char *imageExtension = ".gif";imageFormatString
Definition
char *imageFormatStringDescription
This variable defines the default format of the filename, and includes the root name, frame number, and extension. It uses the same notation as
sprintf.The first
%sin the variable is used for the root name; the%dis used for the frame number; and the second%sis used for the extension. The default value is%s.%04.4d.%s.Example
This example defines a syntax where the root name is immediately followed by the non-zero padded frame number, and then followed by the period-separated extension.
char *imageFormatString = "%s%d.%s";imageHardLinkDuplicates (UNIX only??)
Definition
BOOLEAN imageHardLinkDuplicatesDescription
This variable indicates whether Maya should create hard links to identical files that are created in a sequence. For example, if
image.1.ext,image.2.ext, andimage.3.extare identical, setting this variable toTRUEallows Maya to create only one file, but make hard links from the other two files to the newly created one. If this variable wereFALSE, three separate but identical files would be created.The default value is
TRUE.Example
BOOLEAN imageHardLinkDuplicates = FALSE;imageInit
Definition
int imageInit( void )Description
If defined, this routine is invoked before your plug-in’s functionality is added to Maya. If the return value is
TRUE, the plug-in is loaded as usual. However, if it returnsFALSE, the plug-in is unloaded.This initialization routine can be used in conjunction with the
imageDoneroutine to provide a means of opening and closing any licensing schemes that you implement. If the plug-in offers multiple language support, this routine can be used to internationalize any strings. You can also set default values forimageExtensionandimageNameSyntaxwithin this call.imageIsFile
Definition
BOOLEAN imageIsFile(
char *fn,
FILE *fp
}
Parameter Type Descriptionchar*
Filename, used only if
fpisNULL.FILE*
File pointer.
Return Value
TRUEiffnorfprefer to a file supported by this plug-in.
Description
Checks whether a filename or pointer matches a type supported by this plug-in.
Example
if ( fp == NULL )
{
fp = fopen( fn, "r" ) );
}
/* Read the header from fp and check for a match with this plug-in */
fread( &magic, 1, sizeof( magic ), fp );
return ( magic & FORMATS_MAGIC_NUMBER )imageNameSyntax
Definition
char *imageNameSyntaxDescription
This variable defines the default format of the filename, and includes the root name, frame number, and extension.
The name syntax recognizes four strings:
Name, which represents the root name of the fileExt, which represents the extension#, which represents the frame number- punctuation, such as period (.), comma (,), and hyphen (-)
These can be combined in any way to produce the desired filename. Each of the name, frame number, and extension can occur at most once, but the # can be repeated to pad the frame number with leading zeroes.
The default value is
NULL.This string is not recognized by Maya.
Example
This example produces a name with at least two digits used for the frame number. There is no punctuation between the name and the frame number, but a period is placed between the frame number and extension.
char *imageNameSyntax = "Name##.Ext";imageNumberOfChannels
Definition
int imageNumberOfChannelsDescription
This variable defines the maximum number of color channels that your file format supports. It does not include the matte channel. Normally, this is
3for RGB images, and1for formats that support gray-scale only.The default value is
3.Example
int imageNumberOfChannels = 3;imageNumberOfMattes
Definition
int imageNumberOfMattes;Description
This variable defines the maximum number of matte, or alpha, channels that your file format supports. Normally, this is
1if your format supports matte, and0otherwise.The default value is
0.Example
int imageNumberOfMattes = 1;imageNumberOfZChannels
Definition
int imageNumberOfZChannelsDescription
This variable defines the maximum number of z, or depth, channels that your file format supports. Normally, this is
1if your format supports z, and0otherwise.The default value is
0.Example
int imageNumberOfZChannels = 1;imageSupportRemoteAccess
Definition
BOOLEAN imageSupportRemoteAccessDescription
This variable defines whether your plug-in supports remote file access. If so, set this to
TRUE. Otherwise, Maya will perform remote file access where possible, and remove any leadingremotehost:from filenames before passing them to your plug-in.The default value is
FALSE.Example
BOOLEAN imageSupportRemoteAccess = TRUE;imageSupportsActiveWindow
Definition
int imageSupportsActiveWindowDescription
This variable indicates whether your format supports the notion of an active window. The default value is
FALSE.Example
int imageSupportsActiveWindow = FALSE;Look-up table (LUT) reading function
Definition
int your_lut_read_func
(
POINTER data,
IMF_LUT **imf_lut
)
Description
Maya calls this function to read the image file's color look-up table. Since LUTs usually use little space, it is recommended that they be read by
imageReadOpenand stored in the private data associated with the image. This way,your_lut_read_funconly needs to allocate a newIMF_LUTand copy it to the stored LUT data.
- Allocate the LUT:
if ( ( *imf_lut = IMF_lut_alloc(
data->your_color_map_size ) ) == NULL )
{
return( FALSE );
}
- Set
(*imf_lut)->imu_maximumto the maximum value of each LUT entry. For example, if your file format stores each LUT entry as 12 bits of red, 12 bits of green, and 12 bits of blue, use 4095 forimu_maximum.- Set
(*imf_lut)->imu_gammato be the gamma of the color look-up table if it is stored in the file, or the default input gamma value usingFMT_def_input_gamma. This should be the gamma that was applied to the LUT entries when they were written.- Fill in each
(*imf_lut)->imu_lut[i].ile_red, (*imf_lut)->imu_lut[i].ile_green, etc. entry. SeeIMF_LUTfor a description of theIMF_LUTstructure. Each LUT entry should range from 0 to theimu_maximumentry set in step 2.- Return
TRUEif successful, andFALSEif an error occurred.Library Functions
imf__build_handle
Definition
char *imf__build_handle
(
char *path,
char *handle,
char *ext
)
Parameter Type DescriptionInput
The search path to use.
Input
The filename.
extInput
The filename extension.
Return Value
The completed filename.
Description
This function constructs a filename from
path,handle, andext. Use the returned string when opening the file.Examples
char *filename;
FILE *fp = NULL;
...
*info = &imf->info;
if ( info->handle_complete )
{
filename = info->handle;
}
else
{
filename = imf__build_handle( NULL, info->handle,
info->ext );
if ( ( fp = fopen( filename, "rb" ) ) == NULL )
{
filename = imf__build_handle( getenv(
"WF_IMG_DIR" ),
info->handle, info->ext );
}
}
if ( fp == NULL )
{
fp = fopen( filename, "rb" );
}IMF_chan_alloc
Definition
POINTER *IMF_chan_alloc
(
IMF_IMAGE *image,
int res,
char *key,
int *size
)
Description
- This function allocates a set of scanline buffers that are used to pass one scanline of data between Maya and your scanline reading and writing functions. The buffer is set up as an array of pointers to scanline buffers, with the first rows containing color channel data (red, green, and then blue), followed by a matte channel and a z channel (if defined by your plug-in). Call this function from your
imageReadOpenroutine.IMF_chan_allocdepends on theimageBitsPerPaletteEntry,imageBitsPerChannel,imageBitsPerMatte, andimageBitsPerZChannelentry points that you define at the top of your plug-in code. If your entry point defines 1 to 8 bits per channel, then byte-sized pixels are allocated. If 9 to 16 bits per channel are defined, then 16-bitshortpixels are allocated. For 17 to 32 bits per channel, 32-bitlongpixels are allocated. All values are inunsignedform. Your scanline reading and writing functions must know whether to interpret channel data as 8-bit unsigned chars, 16-bit shorts, or 32-bit longs.Example
This sample code fragment shows how to allocate and access a scanline buffer allocated by
IMF_chan_alloc. There are 3 color channels with 8 bits per pixel, 1 matte channel with 12 bits per pixel, and 1 z channel with 32 bits per pixel.imfis theIMF_OBJECTstructure passed into yourimageReadOpenfunction. Note thatimageWriteOpenshould not callIMF_chan_allocbecause the Maya application allocates the scanline buffer passed into the scanline writing function.
POINTER *p_buffer;
p_buffer = IMF_chan_alloc( imf->info.image,
image_width, imf->info.key, NULL);In your scanline reading function, store data into the buffer as follows:
unsigned char *p_red = p_buffer[0];
unsigned char *p_blue = p_buffer[1];
unsigned char *p_green = p_buffer[2];
unsigned short *p_matte = p_buffer[3];
unsigned long *p_z = p_buffer[4];
for ( i = 0; i < image_width; ++i )
{
p_red[i] = red_values[i];
p_blue[i] = blue_values[i];
p_green[i] = green_values[i];
p_matte[i] = matte_values[i];
p_z[i] = z_values[i];
}Your scanline writing function should access the buffer in a similar way.
Related Functions
IMF_chan_freeIMF_chan_free
Definition
int IMF_chan_free
(
POINTER *chan_data
)
Parameter Type DescriptionModified
The address of a pointer to a scanline buffer allocated by IMF_chan_alloc.
Return Value
Unused.
Description
This function de-allocates a set of scanline buffers that were previously allocated by
IMF_chan_alloc.Example
If
data->bufferpoints to your scanline buffer, free the buffer using:
IMF_chan_free( data->buffer );Related Functions
IMF_chan_allocimf__free_obj
Definition
int imf__free_obj
(
IMF_OBJECT *imf
)
Parameter Type DescriptionModified
Structure storing image characteristics such as width and height.
Return Value
Unused.
Description
This function de-allocates space occupied by the
IMF_OBJECTstructure. This function should be called in your close function.If
imf->datais notNULL, thenimf__free_objfrees the space pointed to byimf->data[0]and then freesimf->data. Therefore, if you have allocatedimf->data[1]or any other extra space, then your close function and your error-handling routines inimageReadOpenandimageWriteOpenmust deallocate the space to avoid a memory leak.In the event of a failed attempt at opening an image file, Maya calls
imf__free_obj( imf )to free theIMF_OBJECTpassed toimageReadOpen. Therefore, you must not callimf__free_objin your error-handling code. If you call your close function to perform the error-handling and clean-up, your close function must distinguish between a close after a failed open attempt and a close after having successfully read an image file. Your close function must callimf__free_objonly if the image file was successfully read.Example
imf__free_obj( imf );Related Functions
imf__init_ifdimf__init_ifd
Definition
int imf__init_ifd
(
IMF_OBJECT *imf
)
Parameter Type DescriptionModified
Structure storing image characteristics such as width and height.
Return Value
Unused.
Description
This function initializes the image file descriptor structure pointed to by
imf->info.image. This function should be called in yourimageReadOpenfunction. Note that theimf->info.imagefield must have been allocated by your function before invokingimf__init_ifd.The following defines the default values of the
IMF_IMAGEstructure:
usage: IMF_C_GENERICcurve.usage: IMF_C_CORRECTION_GAMMAcurve.gamma: fmt_def_gammacurve.info.name: NULLcurve.info.count: 1curve.info.elems: 256curve.info.type: IMF_C_INTEGERcurve.info.bits: LOG( fmt__gamma_tab_res ) / LOG( 2.0 )curve.response: NULLaspect.name: NULLchan_format: NULLmatte_format: NULLaux_format: NULLindex_format: NULLchan_config: IMF_C_PLANAR_SEPARATEchan_orient: IMF_C_BOT_LEFTchan_count: 0chan_type: IMF_C_INTEGERchan_bits: 8matte_count: 0matte_type: IMF_C_INTEGERmatte_bits: 8aux_count: 0aux_type: IMF_C_INTEGERaux_bits: 8index_count: 0index_type: IMF_C_INTEGERindex_bits: 8Example
imf__init_ifd( imf );Related Functions
imf__free_objCapability settings
When you implement an image plug-in, you need to decide what file format features your plug-in supports, and whether and how the user can specify them in the file browsers used to access image files. Maya automatically passes these features, called capability settings, to your image plug-in when it accesses a file. For example, when writing an image to disk, you may allow the user to select the type of compression to be used. Sometimes, your file format has no special features and does not require capability settings.
The user interface supports two pre-defined capability types:
List-presents an option menu with a list of names (strings)Number-displays a numeric field and a thumbwheel for an unbounded number, or numeric field and a slider for a bounded number.For more information, see imageCapability and IMF_CAPABILITY.
Data structures
IMF_CAPABILITY
Definition
typedef struct imf_capability
{
U_SHORT imc_code;
char *imc_name;
MSGCAT_DEFN imc_name_msg;
U_CHAR imc_type;
POINTER imc_value;
U_CHAR imc_when_avail;
} IMF_CAPABILITY;Purpose
For those image files with special, type-specific parameters, use the
IMF_CAPABILITYstructure to define the type-specific capabilities of the driver. The capabilities are stored as an array, with one entry per capability. For example, the SGI driver has two capabilities: one for the compression mode (raw vs. RGB), and one for defining whether a matte channel should be created in the file.Description
The
capabilitiesare generic parameters. WhenimageReadOpenorimageWriteOpenis called, the specific user-defined instances of the capabilities are passed in assettings. This sample code fragment shows you how to extract the meanings of these settings:static BOOLEAN your_get_capability_settings(IMF_OBJECT *imf,int *mode){IMF_CAPABILITY *capability;IMF_CAP_SETTING *setting;IMF_CAP_SETTING **settings;if ( ( settings = imf->info.settings ) == NULL ){return( TRUE );}for ( /* Nothing */; setting = *settings; ++settings ){/** Lookup the capability by code.*/for ( capability = your__capabilities; capability->imc_name_msg.mcd_set!= 0; ++capability ){if ( capability->imc_code == setting->imcs_code ){break;}}if ( capability->imc_name_msg.mcd_set == 0 ){ERR_printf( "Bad capability found." );return( FALSE );}switch ( capability->imc_code ){case YOUR_CAPABILITY_IMC_CODE:*mode =setting->imcs_value.imcs_list;break;case ANOTHER_CAPABILITY_IMC_CODE:...;break;case ...:default:ERR_printf( "Bad capability found.");return( FALSE );}}return( TRUE );}IMF_CAPABILITY_ENTRY
Definition
typedef struct imf_capability_entry
{
U_SHORT ice_code;
char *ice_name;
MSGCAT_DEFN ice_name_msg;
} IMF_CAPABILITY_ENTRY;Purpose
This structure is used to define a single entry of a
IMF_CAPABILITY_LIST.Description
IMF_CAPABILITY_LIST
Definition
typedef struct imf_capability_list
{
int icl_default;
int icl_n_entries;
IMF_CAPABILITY_ENTRY *icl_entries;
} IMF_CAPABILITY_LIST;Purpose
When an
IMF_CAPABILITYrecord is of typeIMF_CAPABILITY_TYPE_LIST, theimc_valuefield points to anIMF_CAPABILITY_LISTrecord whose icl_entries pointer is an array ofIMF_CAPABILITY_ENTRYrecords.Description
Field DescriptionThe
ice_codeof the default list entry.
icl_n_entriesThe number of entries in the list.
icl_entriesThe list of entries.
IMF_CAPABILITY_NUMBER
Definition
typedef struct imf_capability_number
{
float icn_default;
BOOLEAN icn_minimum_dfnd;
float icn_minimum;
BOOLEAN icn_maximum_dfnd;
float icn_maximum;
floay icn_increment;
} IMF_CAPABILITY_NUMBER;Purpose
If the
IMF_CAPABILITYrecord has typeIMF_CAPABILITY_TYPE_NUMBER, this structure is used to define the default value and the range of values allowed for the capability.Description
If
icn_minimum_dfndandicn_maximum_dfndare bothTRUE, a slider is displayed beside the text field. Otherwise, a thumbwheel is displayed.IMF_CAP_SETTING
Definition
typedef struct imf_cap_setting
{
U_SHORT imcs_code;
union
{
float imcs_number;
int imcs_list;
} imcs_value;
} IMF_CAP_SETTING;Purpose
This structure is used to pass the current settings of the capabilities to your plug-in when opening a file.
IMF_IMAGE
Definition
typedef struct
{
int usage;
IMF_COLOR_RESPONSE curve;
FMT_ASPECT_INFO aspect;
WINDOW_I window;
WINDOW_I active;
int chan_config;
int chan_orient;
char *chan_format;
int chan_count;
int chan_type;
int chan_bits;
char *matte_format;
int matte_count;
int matte_type;
int matte_bits;
char *aux_format;
int aux_count;
int aux_type;
int aux_bits;
char *index_format;
int index_count;
int index_type;
int index_bits;