OldSchool Library
Image placement

Macros

#define oslSetImageTile(img, x0, y0, x1, y1)
 Sets the source rectangle of the image to be displayed.
 
#define oslSetImageTileSize(img, x0, y0, x1, y1)
 Sets the source rectangle of the image to be displayed using tile size.
 
#define oslResetImageTile(img)
 Resets the image rectangle to its full (original) size.
 
#define oslMirrorImageH(img)
 Mirrors an image (or an image tile) horizontally.
 
#define oslMirrorImageV(img)
 Mirrors an image (or an image tile) vertically.
 
#define oslImageIsMirroredH(img)
 Returns whether the image is mirrored horizontally.
 
#define oslImageIsMirroredV(img)
 Returns whether the image is mirrored vertically.
 
#define oslImageRotMoveX(img, x)
 Calculates the x-coordinate for moving an image so that its top-left corner is at the specified position when no rotation is applied.
 
#define oslImageRotMoveY(img, y)
 Calculates the y-coordinate for moving an image so that its top-left corner is at the specified position when no rotation is applied.
 
#define oslSetImageRotCenter(img)
 Sets the rotation center of an image to its center.
 
#define oslImageSetRotCenter   oslSetImageRotCenter
 Alias for oslSetImageRotCenter.
 
#define oslCorrectImageHalfBorder(img)
 Crops 0.5 pixel from each corner of the image.
 
#define oslResetImageHalfBorder(img)
 Undoes the effect of oslCorrectImageHalfBorder.
 
#define oslGetImageWidth(img)
 Returns the width of the image, considering the current frame or tile.
 
#define oslGetImageHeight(img)
 Returns the height of the image, considering the current frame or tile.
 
#define oslGetImageSizeX   oslGetImageWidth
 Returns the width of the image, considering the current frame or tile.
 
#define oslGetImageSizeY   oslGetImageHeight
 Returns the height of the image, considering the current frame or tile.
 

Detailed Description

Image placement in OSLib.

Macro Definition Documentation

◆ oslSetImageTile

#define oslSetImageTile ( img,
x0,
y0,
x1,
y1 )
Value:
({ (img)->offsetX0=(float)x0, (img)->offsetY0=(float)y0, (img)->offsetX1=(float)x1, (img)->offsetY1=(float)y1; (img)->stretchX = oslAbs((int)((float)((img)->offsetX1) - (float)((img)->offsetX0))), (img)->stretchY = oslAbs((int)((float)((img)->offsetY1) - (float)((img)->offsetY0))); })
#define oslAbs(x)
Returns the absolute value of a number.
Definition oslib.h:500

Sets the source rectangle of the image to be displayed.

This macro allows you to define a sub-region of a larger image to be rendered. This is useful when you have an image that contains multiple sprites or tiles arranged in a grid.

For example, if you have a 128x128 image containing 16 sprites of 32x32 each, you can use this macro to select and display a specific sprite:

oslSetImageTile(image, 0, 0, 32, 32);
oslDrawImage(image);
void oslDrawImage(OSL_IMAGE *img)
Draws an image at its current position.
#define oslSetImageTile(img, x0, y0, x1, y1)
Sets the source rectangle of the image to be displayed.
Definition drawing.h:1487

This will display the portion of the image starting at (0,0) and ending at (32,32), rendering a 32x32 sprite. To display the next sprite to the right, you would use:

oslSetImageTile(image, 32, 0, 64, 32);
Parameters
imgThe image from which a tile is to be extracted.
x0The x-coordinate of the top-left corner of the tile.
y0The y-coordinate of the top-left corner of the tile.
x1The x-coordinate of the bottom-right corner of the tile (exclusive).
y1The y-coordinate of the bottom-right corner of the tile (exclusive).
Note
The specified coordinates are used to define the source rectangle within the image. The image will be drawn with the specified tile dimensions.
See also
Refer to oslDrawImage for rendering the Images with the selected tile.

◆ oslSetImageTileSize

#define oslSetImageTileSize ( img,
x0,
y0,
x1,
y1 )
Value:
({ (img)->offsetX0 = (float)(x0), (img)->offsetY0 = (float)(y0), (img)->offsetX1 = (float)(x0) + (float)(x1), (img)->offsetY1 = (float)(y0) + (float)(y1), (img)->stretchX = (int)(x1), (img)->stretchY = (int)(y1); })

Sets the source rectangle of the image to be displayed using tile size.

This macro allows you to define a sub-region of a larger image to be rendered by specifying the size of the tile directly. This simplifies the process of defining a tile or sprite within an image.

For example, if you have a 128x128 image containing 32x32 sprites, you can use this macro to select and display a specific sprite by setting the size of the tile:

oslSetImageTileSize(image, 0, 0, 32, 32);
oslDrawImage(image);
#define oslSetImageTileSize(img, x0, y0, x1, y1)
Sets the source rectangle of the image to be displayed using tile size.
Definition drawing.h:1524

This will display a 32x32 tile starting from (0,0) and ending at (32,32). To display a sprite starting at (32,0) with the same size, you would use:

oslSetImageTileSize(image, 32, 0, 32, 32);
Parameters
imgThe image from which a tile is to be extracted.
x0The x-coordinate of the top-left corner of the tile.
y0The y-coordinate of the top-left corner of the tile.
x1The width of the tile.
y1The height of the tile.
Note
The specified coordinates define the starting position and size of the tile within the image. The image will be drawn with the specified tile dimensions.
See also
Refer to oslDrawImage for rendering the Images with the selected tile.

◆ oslResetImageTile

#define oslResetImageTile ( img)
Value:
({ (img)->offsetX0=0, (img)->offsetY0=0, (img)->offsetX1=(img)->sizeX, (img)->offsetY1=(img)->sizeY; (img)->stretchX = (img)->sizeX, (img)->stretchY = (img)->sizeY; })

Resets the image rectangle to its full (original) size.

This macro resets the portion of the image to be drawn to cover the entire image. It effectively cancels any previous tile or sub-region settings, allowing you to draw the full image again.

For example, if you previously set a specific tile or sub-region of the image using oslSetImageTile or oslSetImageTileSize, you can use this macro to revert to displaying the entire image.

oslSetImageTile(image, 0, 0, 32, 32);
oslDrawImage(image);
// Reset to full image
oslDrawImage(image);
#define oslResetImageTile(img)
Resets the image rectangle to its full (original) size.
Definition drawing.h:1550
Parameters
imgThe image whose rectangle is to be reset.
Note
After calling this macro, the image will be rendered using its full dimensions (sizeX and sizeY), effectively ignoring any previously set tile or sub-region settings.
See also
Refer to oslSetImageTile and oslSetImageTileSize for setting specific sub-regions of an Images.

◆ oslMirrorImageH

#define oslMirrorImageH ( img)
Value:
({ float ___tmp; ___tmp = (img)->offsetX0; (img)->offsetX0 = (img)->offsetX1; (img)->offsetX1 = ___tmp; })

Mirrors an image (or an image tile) horizontally.

This macro flips the image horizontally by swapping the offsetX0 and offsetX1 coordinates of the image. It effectively mirrors the image along the vertical axis. If this macro is used in a loop or multiple times, make sure to reset the mirroring after drawing the image to avoid undesired effects, as each application of this macro will mirror the image again.

For example, if you want to mirror an image horizontally and then reset it to its original orientation, you might use:

oslDrawImage(image);
oslResetImageTile(image); // Reset after drawing
#define oslMirrorImageH(img)
Mirrors an image (or an image tile) horizontally.
Definition drawing.h:1575
Parameters
imgThe image to be mirrored.
Note
Mirroring an image twice will revert it to its original orientation. If you are applying mirroring in a loop, ensure to reset the mirroring state after drawing to maintain correct orientation.
See also
Use oslMirrorImageV to mirror an Images vertically.

◆ oslMirrorImageV

#define oslMirrorImageV ( img)
Value:
({ float ___tmp; ___tmp = (img)->offsetY0; (img)->offsetY0 = (img)->offsetY1; (img)->offsetY1 = ___tmp; })

Mirrors an image (or an image tile) vertically.

This macro flips the image vertically by swapping the offsetY0 and offsetY1 coordinates of the image. It effectively mirrors the image along the horizontal axis. If this macro is used in a loop or multiple times, make sure to reset the mirroring after drawing the image to avoid undesired effects, as each application of this macro will mirror the image again.

For example, if you want to mirror an image vertically and then reset it to its original orientation, you might use:

oslDrawImage(image);
oslResetImageTile(image); // Reset after drawing
#define oslMirrorImageV(img)
Mirrors an image (or an image tile) vertically.
Definition drawing.h:1600
Parameters
imgThe image to be mirrored.
Note
Mirroring an image twice will revert it to its original orientation. If you are applying mirroring in a loop, ensure to reset the mirroring state after drawing to maintain correct orientation.
See also
Use oslMirrorImageH to mirror an Images horizontally.

◆ oslImageIsMirroredH

#define oslImageIsMirroredH ( img)
Value:
((img)->offsetX1 > (img)->offsetX0)

Returns whether the image is mirrored horizontally.

This macro checks if the image has been mirrored horizontally. An image is considered to be mirrored horizontally if the x-coordinate of the bottom-right corner (offsetX1) is greater than the x-coordinate of the top-left corner (offsetX0).

Parameters
imgThe image to check for horizontal mirroring.
Returns
Returns true if the image was mirrored horizontally, false otherwise.
See also
Use oslMirrorImageH to mirror the Images horizontally.

◆ oslImageIsMirroredV

#define oslImageIsMirroredV ( img)
Value:
((img)->offsetY1 > (img)->offsetY0)

Returns whether the image is mirrored vertically.

This macro checks if the image has been mirrored vertically. An image is considered to be mirrored vertically if the y-coordinate of the bottom-right corner (offsetY1) is greater than the y-coordinate of the top-left corner (offsetY0).

Parameters
imgThe image to check for vertical mirroring.
Returns
Returns true if the image was mirrored vertically, false otherwise.
See also
Use oslMirrorImageV to mirror the Images vertically.

◆ oslImageRotMoveX

#define oslImageRotMoveX ( img,
x )
Value:
((((x) + (img)->centerX * (img)->stretchX) / (img)->sizeX))

Calculates the x-coordinate for moving an image so that its top-left corner is at the specified position when no rotation is applied.

This macro computes the x-coordinate for positioning an image's top-left corner at (x, y) considering the image's rotation parameters. It takes into account the rotation center and the size of the image.

Parameters
imgThe image to position.
xThe desired x-coordinate for the top-left corner of the image.
Returns
The x-coordinate adjusted for the rotation center.
See also
Use oslImageRotMoveY for the y-coordinate.

◆ oslImageRotMoveY

#define oslImageRotMoveY ( img,
y )
Value:
((((y) + (img)->centerY * (img)->stretchY) / (img)->sizeY))

Calculates the y-coordinate for moving an image so that its top-left corner is at the specified position when no rotation is applied.

This macro computes the y-coordinate for positioning an image's top-left corner at (x, y) considering the image's rotation parameters. It takes into account the rotation center and the size of the image.

Parameters
imgThe image to position.
yThe desired y-coordinate for the top-left corner of the image.
Returns
The y-coordinate adjusted for the rotation center.
See also
Use oslImageRotMoveX for the x-coordinate.

◆ oslSetImageRotCenter

#define oslSetImageRotCenter ( img)
Value:
((img)->centerX = (int)oslAbs((img)->offsetX1 - (img)->offsetX0) >> 1, (img)->centerY = (int)oslAbs((img)->offsetY1 - (img)->offsetY0) >> 1)

Sets the rotation center of an image to its center.

This macro sets the rotation center (centerX, centerY) to the middle of the image. This is useful for rotation operations where the center of rotation is typically the middle of the image.

Parameters
imgThe image to modify.
See also
Use oslImageSetRotCenter as an alias for this macro.

◆ oslImageSetRotCenter

#define oslImageSetRotCenter   oslSetImageRotCenter

Alias for oslSetImageRotCenter.

This macro is an alias for oslSetImageRotCenter, setting the rotation center to the middle of the image.

Parameters
imgThe image to modify.
See also
Use oslSetImageRotCenter for detailed documentation.

◆ oslCorrectImageHalfBorder

#define oslCorrectImageHalfBorder ( img)
Value:
((img)->offsetX0 = (img)->offsetX0 + 0.5f, (img)->offsetY0 = (img)->offsetY0 + 0.5f, (img)->offsetX1 = (img)->offsetX1 - 0.5f, (img)->offsetY1 = (img)->offsetY1 - 0.5f, img->stretchX--, img->stretchY--)

Crops 0.5 pixel from each corner of the image.

This macro adjusts the image's borders to eliminate visual artifacts caused by bilinear filtering when the image is stretched. By cropping 0.5 pixel from each corner, it helps prevent unwanted borders that might appear around the image.

Parameters
imgThe image to correct.
Note
This is a hacky routine and should be used carefully. It's intended for use with bilinear filtering and stretched images.

◆ oslResetImageHalfBorder

#define oslResetImageHalfBorder ( img)
Value:
((img)->offsetX0 = (img)->offsetX0 - 0.5f, (img)->offsetY0 = (img)->offsetY0 - 0.5f, (img)->offsetX1 = (img)->offsetX1 + 0.5f, (img)->offsetY1 = (img)->offsetY1 + 0.5f, img->stretchX++, img->stretchY++)

Undoes the effect of oslCorrectImageHalfBorder.

This macro reverts the adjustments made by oslCorrectImageHalfBorder. It should be used with caution, as calling it without a preceding oslCorrectImageHalfBorder or calling it multiple times may lead to incorrect image adjustments.

Parameters
imgThe image to reset.
Note
Prefer using oslResetImageTile for more consistent behavior.

◆ oslGetImageWidth

#define oslGetImageWidth ( img)
Value:
((int)oslAbs((img)->offsetX1 - (img)->offsetX0))

Returns the width of the image, considering the current frame or tile.

This macro computes the width of the image based on the current frame or tile settings. To retrieve the full image width, use image->sizeX.

Parameters
imgThe image to measure.
Returns
The width of the image frame or tile.

◆ oslGetImageHeight

#define oslGetImageHeight ( img)
Value:
((int)oslAbs((img)->offsetY1 - (img)->offsetY0))

Returns the height of the image, considering the current frame or tile.

This macro computes the height of the image based on the current frame or tile settings. To retrieve the full image height, use image->sizeY.

Parameters
imgThe image to measure.
Returns
The height of the image frame or tile.

◆ oslGetImageSizeX

#define oslGetImageSizeX   oslGetImageWidth

Returns the width of the image, considering the current frame or tile.

This macro is an alias for oslGetImageWidth, providing the width of the image based on the current frame or tile settings. To get the full image width, use image->sizeX.

Parameters
imgThe image to measure.
Returns
The width of the image frame or tile.

◆ oslGetImageSizeY

#define oslGetImageSizeY   oslGetImageHeight

Returns the height of the image, considering the current frame or tile.

This macro is an alias for oslGetImageHeight, providing the height of the image based on the current frame or tile settings. To get the full image height, use image->sizeY.

Parameters
imgThe image to measure.
Returns
The height of the image frame or tile.