L_LoadChannel

#include "l_bitmap.h"

L_LTFIL_API L_INT L_LoadChannel(pszFile, pBitmap, uStructSize, nBitsPerPixel, nOrder, nChannel, pChannelInfo, pLoadOptions)

L_TCHAR* pszFile;

/* name of a file */

pBITMAPHANDLE pBitmap;

/* pointer to the target bitmap handle */

L_UINT uStructSize;

/* size in bytes, of the structure pointed to by pBitmap */

L_INT nBitsPerPixel;

/* resulting bitmap pixel depth */

L_INT nOrder;

/* color order for 16-, 24-, 32-, 48, and 64-bit bitmaps */

L_INT nChannel;

/* index of the channel to load */

pCHANNELINFO pChannelInfo;

/* pointer to a structure */

pLOADFILEOPTION pLoadOptions;

/* pointer to optional extended load options */

Loads the specified channel from the specified file. Currently only PSD files support channels.

Parameter

Description

pszFile

Character string containing the name of the file from which to load the channel.

pBitmap

Pointer to the bitmap handle referencing the target bitmap.

uStructSize

Size in bytes, of the structure pointed to by pBitmap, for versioning. Use sizeof(BITMAPHANDLE).

nBitsPerPixel

Resulting bitmap pixel depth. The following are valid values:

 

Value

Meaning

 

0

Keep the original file's pixel depth (Do not convert). A special note about loading 12 and 16-bit grayscale images.

 

1 to 8

The specified bits per pixel in the resultant bitmap.

 

12

12 bits per pixel in the resultant bitmap.

 

16

16 bits per pixel in the resultant bitmap.

 

24

24 bits per pixel in the resultant bitmap.

 

32

32 bits per pixel in the resultant bitmap.

 

48

48 bits per pixel in the resultant bitmap.

 

64

64 bits per pixel in the resultant bitmap.

 

nOrder

Color order for 16-, 24-, 32-, 48-, and 64-bit bitmaps. If the resultant bitmap is less than 16 bits per pixel, this will have no effect since palletized images have no order. The following are valid values:

 

Value

Meaning

 

ORDER_RGB

[0] Red, green, and blue color order in memory

 

ORDER_BGR

[1] Blue, green, and red color order in memory

 

ORDER_GRAY

[2] 12 or 16-bit grayscale image. 12 and 16-bit grayscale images are only supported in Document and Medical Imaging toolkits.

 

ORDER_RGBORGRAY

[3] Load the image as red, green, blue OR as a 12 or 16-bit grayscale image. 12 and 16-bit grayscale images are supported in Document and Medical Imaging toolkits.

 

ORDER_BGRORGRAY

[4] Load the image as blue, green, red OR as a 12 or 16-bit grayscale image. 12 and 16-bit grayscale images are supported in Document and Medical Imaging toolkits.

 

ORDER_ROMM

[5] ROMM order. ROMM only supports 24 and 48-bit images.

 

ORDER_BGRORGRAYORROMM

[6] Load the image as red, green, blue OR as a 12 or 16-bit grayscale image OR as ROMM. 12 and 16-bit grayscale images are supported in Document and Medical Imaging toolkits. ROMM only supports 24 and 48-bit color images.

nChannel

Index of the channel to load. This index is zero-based. Pass 0 to load the first channel, 1 to load the second channel, etc.

pChannelInfo

Pointer to a CHANNELINFO structure to be updated with information about the loaded channel. The uStructSize member should be set to the sizeof (CHANNELINFO) before calling this function.

pLoadOptions

Pointer to optional extended load options. Pass NULL to use the default load options.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

Support for 12 and 16-bit grayscale images is only available in Document and Medical Imaging toolkits.

Currently, only the PSD file format supports channels.

This function works similarly to the L_LoadBitmap function, except that it loads only a channel from a file. It loads the channel specified in nChannel.

Before calling this function, you may need to get or set file information, such as the number of channels on the file. Refer to Getting and Setting File Information.

The number of channels in a file is indicated in FILEINFO.Channels. If FILEINFO.Channels is 0, the file does not contains any channels and this function should not be called.

Since the function allocates storage to hold the image, it is up to you to free this storage by calling L_FreeBitmap.

Required DLLs and Libraries

LTFIL
File format DLLs

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Win32, x64.

See Also

Functions:

L_LoadBitmap, L_FileInfo, L_LoadLayer

Topics:

Raster Image Functions: Loading Files

 

Loading and Saving Images

Example

This example loads all channels from a file.

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName


 L_INT LoadAllChannelsExample(L_VOID)
{
   L_INT nRet = 0;
   FILEINFO FileInfo;
   BITMAPHANDLE Bitmap;
   CHANNELINFO ChannelInfo;
   L_INT nIndex = 0;
   L_TCHAR *pszChannel = NULL;

   memset(&FileInfo, 0, sizeof(FILEINFO));
   FileInfo.uStructSize = sizeof(FileInfo);

   if(L_FileInfo(MAKE_IMAGE_PATH(TEXT("Bear.psd")), &FileInfo, sizeof(FILEINFO), 0, NULL) == SUCCESS)
   {
      for(nIndex= 0; nIndex < FileInfo.Channels; nIndex++)
      {
         memset(&ChannelInfo, 0, sizeof(CHANNELINFO));
         ChannelInfo.uStructSize = sizeof(CHANNELINFO);
         nRet = L_LoadChannel(MAKE_IMAGE_PATH(TEXT("Bear.psd")), &Bitmap, sizeof(BITMAPHANDLE), 0, ORDER_RGB, nIndex, &ChannelInfo, NULL); 
         if(nRet != SUCCESS)
            return nRet;

         wsprintf (pszChannel, MAKE_IMAGE_PATH(TEXT("Channel_%d.bmp")), nIndex);
         nRet = L_SaveBitmap(pszChannel, &Bitmap, FILE_BMP, 8, 0, NULL);
         if(nRet != SUCCESS)
            return nRet;
      }
   }
   return SUCCESS;
}