LFile::TransformFileCallBack

Summary

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

Syntax

#include "ltwrappr.h"

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

Parameters

L_UINT 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.)

L_UINT 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.

L_UCHAR * pMarkerData

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

L_UINT 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.

LEADMARKERCALLBACK 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.

L_VOID * 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

Value Meaning
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

Platforms

Win32, x64.

See Also

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; 
} 
Help Version 22.0.2023.2.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.