LFile::TransformFileCallBack

#include "ltwrappr.h"

virtual L_INT LFile::TransformFileCallBack (uMarker, uMarkerSize, pMarkerData, uTransform, pfnLEADCallback, pLEADUserData)

L_UINT uMarker;

/* ID of the JPEG marker */

L_UINT uMarkerSize;

/* size of the JPEG marker */

L_UCHAR * pMarkerData;

/* marker data */

L_UINT uTransform;

/* transformation to perform */

LEADMARKERCALLBACK pfnLEADCallback;

/* pointer to a LEAD callback function */

L_VOID * pLEADUserData;

/* pointer to additional parameters for pfnLEADCallback */

Handles the processing of every JPEG marker present in the file transformed by LFile::TransformFile.

Parameter

Description

uMarker

ID of the JPEG marker. The JPEG markers are uniquely identified by a byte value. Possible values are 1 to 254. (0 and 255 are not allowed.)

uMarkerSize

Size of the JPEG marker. The size will be less than 65535. If this value is 0, then the marker does not have any extra data.

pMarkerData

Pointer to a buffer containing the marker data. This parameter is valid only if the uMarkerSize is > 0.

uTransform

Binary flags that indicate the transform to be performed. These are the same flags passed to the LFIle::TransformFile function. Possible values are:

 

Value

Meaning

 

FILE_TRANSFORM_FLIP

[0x0001] Flip the image.

 

FILE_TRANSFORM_REVERSE

[0x0002] Reverse the image.

 

FILE_TRANSFORM_ROTATE90

[0x0004] Rotate the image clockwise by 90 degrees.

 

FILE_TRANSFORM_ROTATE180

[0x0008] Rotate the image clockwise by 180 degrees.

 

FILE_TRANSFORM_ROTATE270

[0x000C] Rotate the image clockwise by 270 degrees.

pfnLEADCallback

Pointer to a callback function, provided by LEADTOOLS, for writing transformed markers.

 

The callback function adheres to the function prototype described in LEADMARKERCALLBACK Function.

pLEADUserData

Void pointer that you can use to pass one or more additional parameters that the LEADMARKERCALLBACK function needs.

 

To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID *. The callback function, which receives the address in its own pLEADUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure.

 

If the additional parameters are not needed, you can pass NULL in this parameter.

Returns

SUCCESS

The function was successful. The default processing for this marker can be performed.

SUCCESS_IGNOREMARKER

The function was successful. Do not process this marker and do not write it to the file.

< 1

An error occurred. Refer to Return Codes.

Comments

This callback function is called by the LFile::TransformFile function. The LFile implementation for this callback function simply returns SUCCESS; it does nothing else. Refer to the LFile::TransformFile function for more information.

This callback can also be used to enumerate the markers in a JPEG file. The last marker enumerated by this function is always the SOS (0xDA) marker.

If the marker data is transformed, make sure the size of the marker data is less than 0xFFFE.

Note that uMarkerSize is the size of the data contained in the pMarkerData buffer. It does not include the size of the marker size (like the size stored in the file). If you are not familiar with JPEG markers and the previous didnt make sense to you, then you can safely ignore this paragraph.

If the marker data is transformed, it should be written by calling the pfnLEADCallback function. Then, SUCCESS_IGNOREMARKER should be returned by the LFile::TransformFileCallBack function. If SUCCESS is returned by the LFile::TransformFileCallBack function instead of SUCCESS_IGNOREMARKER, LEADTOOLS will perform the default transformation and will also write this marker information to the file. Therefore, there will be two copies of the marker in the file.

As an example, if a user-defined marker that contains a stamp of the image is stored in a file and that file is transformed, the stamp should be transformed in the same way and resaved.

pfnLEADCallback is a pointer to a callback function that is provided by LEADTOOLS. The code for this function resides entirely within LEADTOOLS; no code for it is provided by the user. The function is used to write the updated marker data to the destination file specified in the LFile::TransformFile function. This is the prototype of the function (named here as FunctionName):

L_INT pEXT_CALLBACK FunctionName(L_UINT uMarker, L_UINT uMarkerSize, L_UCHAR * pMarkerData, L_VOID * pLEADUserData);

 

where the marker data passed to the function is supposed to be updated. The void pointer pLEADUserData received by LFile::TransformFileCallBack is used to pass required data to the pfnLEADCallback function, so just pass the pointer to it. If successful, the pfnLEADCallback function returns SUCCESS. Otherwise, it returns an error. 

If LFile::TransformFileCallBack returns an error code, the transformation is aborted and LFile::TransformFile will return the error code returned by this callback function.

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.

See Also

Functions

LFile::TransformFile, LEADMARKERCALLBACK, Class Members

Example

#define APP0 0xE0
class UserFile : public LFile
{
   virtual L_INT TransformFileCallBack(
                    L_UINT uMarker,
                    L_UINT uMarkerSize,
                    L_UCHAR * pMarkerData,
                    L_UINT uTransform,
                    LEADMARKERCALLBACK pfnLEADCallback,
                    L_VOID * pLEADUserData)
   {
      UNREFERENCED_PARAMETER(uTransform);
      // We will transform only the APP0 marker
      if (uMarker != APP0)
         return SUCCESS;
      /* Transform the marker data. Do your transformation here... */
      // Write the transformed data
      L_INT nRet = pfnLEADCallback(uMarker, uMarkerSize, pMarkerData, 
                                   pLEADUserData);
      if (nRet != SUCCESS)
         return nRet;
      // Since we wrote the marker, tell LEADTOOLS not to transform it
      return SUCCESS_IGNOREMARKER;
   }
};
L_INT LFile__TransformFileCallBackExample(L_TCHAR * pszFileSrc, L_TCHAR * pszFileDst)
{
   L_INT nRet;
   UserFile File;
   File.SetFileName(pszFileSrc);
   nRet = File.TransformFile(pszFileDst, FILE_TRANSFORM_ROTATE90);
   if(nRet != SUCCESS)
      return nRet;
   return SUCCESS;
}