Accounting for View Perspective

Many LEADTOOLS functions reference bitmap coordinates, which are often different from the display coordinates of an image. For example, in Windows, the first pixel of a displayed image is always in the top-left corner, but in the bitmap of the same image, the first pixel in memory is often the bottom-left corner of the image. The arrangement of pixels in the bitmap is called the view perspective.

For information on changing bitmap coordinates, based on view perspective, refer to Translating to or from Bitmap Coordinates.

LEADTOOLS keeps track of the view perspective in the ViewPerspective field of the bitmap handle.

Possible values are:

Value Meaning
All toolkits:
TOP_LEFT [1] Top-left of image is first in memory.
BOTTOM_LEFT [4] Bottom-left of image is first in memory.
Document and Medical Imaging toolkits:
TOP_RIGHT [2] Top-right of image is first in memory.
BOTTOM_RIGHT [3] Bottom-right of image is first in memory.
RIGHT_TOP [6] First row is the right side, first column is top side.
TOP_LEFT90 [6] Same as RIGHT_TOP, which is TOP_LEFT rotated clockwise by 90 degrees.
LEFT_BOTTOM [8] First row is the left side, first column is the bottom side.
TOP_LEFT270 [8] Same as LEFT_BOTTOM, which is TOP_LEFT rotated clockwise by 270 degrees.
BOTTOM_LEFT180 [2] Same as TOP_RIGHT, which is BOTTOM_LEFT rotated clockwise by 180 degrees.
TOP_LEFT180 [3] Same as BOTTOM_RIGHT, which is TOP_LEFT rotated clockwise by 180 degrees.
LEFT_TOP [5] First row is the left side, first column is the top side
BOTTOM_LEFT90 [5] Same as LEFT_TOP, which is BOTTOM_LEFT rotated clockwise by 90 degrees
RIGHT_BOTTOM [7] First row is the right side, first column is the bottom side
BOTTOM_LEFT270 [7] Same as RIGHT_BOTTOM, which is BOTTOM_LEFT rotated clockwise by 270 degrees

The functions that display images account for the view perspective, so that the displayed image has the proper orientation. Nevertheless, when getting the bitmap width and height, you must consider the possibility that the bitmap may have a rotated view perspective. Also, in some cases, you must translate to or from bitmap coordinates.

Interpreting the Bitmap Width and Height (Document and Medical Imaging toolkits)

In the LEADTOOLS Document and Medical toolkit, a bitmap can have a rotated view perspective if you load it with the ELO_ROTATED flag set in the LOADFILEOPTION structure, or if you use the L_RotateBitmapViewPerspective function for fast rotation.

In such cases, the Width and Height fields in the BITMAPHANDLE or FILEINFO structure may not match the displayed orientation of the image. This is an important consideration in any calculations of the image's aspect ratio. LEADTOOLS provides the following macros (in Ltkrnl.h) to help you with the interpretation:

Macro Usage
ISROTATED(pBitmap) Takes a pointer to the BITMAPHANDLE and returns TRUE if the view perspective is rotated, or FALSE if it is not.
BITMAPWIDTH(pBitmap) Takes a pointer to the BITMAPHANDLE and returns the bitmap width that matches the displayed orientation.
BITMAPHEIGHT(pBitmap) Takes a pointer to the BITMAPHANDLE and returns the bitmap height that matches the displayed orientation.
INFOROTATED(pInfo) Takes a pointer to the FILEINFO structure and returns TRUE if the view perspective is rotated, or FALSE if it is not.
INFOWIDTH(pInfo) Takes a pointer to the FILEINFO structure and returns the bitmap width that matches the displayed orientation.
INFOHEIGHT(pInfo) Takes a pointer to the FILEINFO structure and returns the bitmap height that matches the displayed orientation.

Translating to and from Bitmap Coordinates

In some situations you must translate to or from bitmap coordinates. For example, suppose you are using the L_GetPixelColor function to get the color at the current mouse position. Because L_GetPixelColor uses bitmap coordinates, you must translate the mouse coordinates.

Similarly, if you are working with two bitmaps that have different view perspectives, you may need to translate the bitmap coordinates from one to the other. LEADTOOLS provides the following functions to simplify the translation:

If necessary, you can also use the following function to rotate and flip the bitmap data as necessary to achieve a different view perspective:

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.