|
OldSchool Library 1.6.0
|
Enumerations | |
| enum | OSL_WRITE_FLAGS { OSL_WRI_ALPHA = 1 } |
Functions | |
| OSL_IMAGE * | oslCreateImageTile (OSL_IMAGE *img, int offsetX0, int offsetY0, int offsetX1, int offsetY1) |
| OSL_IMAGE * | oslCreateImageTileSize (OSL_IMAGE *img, int offsetX0, int offsetY0, int width, int height) |
| OSL_IMAGE * | oslConvertImageTo (OSL_IMAGE *imgOriginal, int newLocation, int newFormat) |
| OSL_IMAGE * | oslCreateImageCopy (OSL_IMAGE *src, int newLocation) |
| OSL_IMAGE * | oslCreateSwizzledImage (OSL_IMAGE *src, int newLocation) |
| void | oslCopyImageTo (OSL_IMAGE *imgDst, OSL_IMAGE *imgSrc) |
| void | oslSwizzleImage (OSL_IMAGE *img) |
| void | oslUnswizzleImage (OSL_IMAGE *img) |
| void | oslSwizzleImageTo (OSL_IMAGE *imgDst, OSL_IMAGE *imgSrc) |
| bool | oslMoveImageTo (OSL_IMAGE *img, int newLocation) |
| void | oslClearImage (OSL_IMAGE *img, int color) |
| int | oslWriteImageFile (OSL_IMAGE *img, const char *filename, int flags) |
| int | oslWriteImageFilePNG (OSL_IMAGE *img, const char *filename, int flags) |
| void | oslResetImageProperties (OSL_IMAGE *img) |
| void | oslScaleImage (OSL_IMAGE *dstImg, OSL_IMAGE *srcImg, int newX, int newY, int newWidth, int newHeight) |
| OSL_IMAGE * | oslScaleImageCreate (OSL_IMAGE *img, short newLocation, int newWidth, int newHeight, short newPixelFormat) |
Image manipulation in OSLib.
| enum OSL_WRITE_FLAGS |
Enum for specifying write flags when saving an image to a file.
The flags determine how the image data is processed when written to a file. For example, flags can control whether the alpha channel is included in the output file.
| Enumerator | |
|---|---|
| OSL_WRI_ALPHA | Writes the alpha channel of the image. If set, the alpha channel data will be included in the output file. |
|
extern |
Creates an alternate image referencing a part (tile) of another one.
| img | The original image from which a tile will be created. |
| offsetX0 | The starting x position of the image part to reference. |
| offsetY0 | The starting y position of the image part to reference. |
| offsetX1 | The ending x position of the image part to reference. |
| offsetY1 | The ending y position of the image part to reference. |
This will return a pointer to a new image, but the data will not be copied to the new image. Instead, it will reference the original image data. When you delete the new image, the original image will be left unchanged; only the size of an OSL_IMAGE will be freed from memory (about 80 bytes). However, if you delete the original image, the new one will be unusable. Attempting to draw it may result in corrupt data, and writing to it may cause a crash.
Example usage:
This routine was meant to create individual "sprite" images from a big one and manipulate them easily. However, as it's not very clear, it's advised to avoid using it. An alternative approach would be:
|
extern |
Creates an alternate image referencing a part (tile) of another one using width and height.
| img | The original image from which a tile will be created. |
| offsetX0 | The starting x position of the image part to reference. |
| offsetY0 | The starting y position of the image part to reference. |
| width | The width of the image part to reference. |
| height | The height of the image part to reference. |
This function returns a pointer to a new image, but the data will not be copied to the new image. Instead, it will reference the original image data. When you delete the new image, the original image will be left unchanged; only the size of an OSL_IMAGE will be freed from memory (about 80 bytes). However, if you delete the original image, the new one will be unusable. Attempting to draw it may result in corrupt data, and writing to it may cause a crash.
Example usage:
This routine was designed to create individual "sprite" images from a large image using width and height specifications. An alternative approach for creating image tiles is using coordinates with the oslSetImageTile function.
Converts an image to another pixel format and places it in another location.
| imgOriginal | The original image to be converted. |
| newLocation | The location where the converted image should be placed. Common locations include OSL_IN_RAM and OSL_IN_VRAM. |
| newFormat | The pixel format to convert the image to, such as OSL_PF_5551, OSL_PF_8888, etc. |
On success, this function deletes the original image and returns the converted image. On allocation failure, it returns NULL and leaves the original image unchanged and owned by the caller.
Example usage:
After a successful conversion, imgOriginal must no longer be used. Delete the returned image when it is no longer needed.
Creates a copy of an image.
| src | The source image to be copied. |
| newLocation | The location where the copied image should be placed. Common locations include OSL_IN_RAM and OSL_IN_VRAM. |
This function creates a complete copy of the source image, including its image data. The returned image is a new instance, independent of the original. Changes to the copied image will not affect the source image and vice versa.
Example usage:
Both the original and copied images are not linked together. Ensure to manage and free the memory for both images as needed.
Creates a copy of an image and swizzles the new one.
| src | The source image to be copied. |
| newLocation | The location where the swizzled image should be placed. Common locations include OSL_IN_RAM and OSL_IN_VRAM. |
This function creates a complete copy of the source image and applies swizzling to the new image. Swizzling is a technique used to improve texture performance by rearranging the image data. The returned image is a new instance, independent of the original.
Example usage:
Both the original and swizzled images are not linked together. Ensure to manage and free the memory for both images as needed.
Copies the content of one image to another.
| imgDst | The destination image where the content will be copied to. |
| imgSrc | The source image from which the content will be copied. |
This function copies the image data from imgSrc to imgDst. Both images must have the same dimensions (width and height) and pixel format. If the formats do not match, the copy operation will fail, and the destination image may not be updated correctly.
Note: This function only copies the image data and does not change the properties of imgDst. Ensure that imgDst has been properly initialized and allocated with the same format and size as imgSrc.
Example usage:
Ensure both images have the same properties before calling this function to avoid unexpected behavior.
|
extern |
Swizzles an image to improve drawing performance.
| img | The image to be swizzled. |
Swizzling is a process that optimizes image drawing performance by reorganizing the image data into a format that is more efficient for the GPU to handle. After swizzling, the image can be drawn much faster. However, swizzled images cannot be modified directly due to their special format.
If you need to modify the image after swizzling, you will need to unswizzle it, which can be slow. Therefore, it is recommended to swizzle images that are stored in RAM and are not intended to be modified frequently.
Hint: When loading images, use the OSL_SWIZZLED bit to automatically swizzle images for convenience.
Example usage:
Be cautious with unswizzling images frequently, as it can impact performance. Use swizzling for images that are primarily used for rendering and do not require modifications.
|
extern |
Restores an image from its swizzled format to its original format.
| img | The swizzled image to be unswizzled. |
This function performs the opposite operation of oslSwizzleImage, converting the swizzled image back to its original format. After unswizzling, the image will be accessible for raw reading and writing.
Note that unswizzling an image can be a slow process, so it should be used judiciously. It's generally best to swizzle images for performance improvements and avoid frequent unswizzling unless necessary.
Example usage:
Make sure to only unswizzle images that were previously swizzled to avoid potential issues with image data integrity.
Swizzles an image and writes the result to another image.
| imgDst | The destination image where the swizzled data will be written. This image must have enough memory allocated to hold the swizzled data. |
| imgSrc | The source image that will be swizzled. |
This function swizzles the imgSrc image and writes the swizzled result to imgDst. This routine is considered outdated. For modern usage, it is recommended to use oslSwizzleImage which operates directly on a single image.
Example usage:
Note: Ensure that imgDst has been properly allocated and has sufficient size to accommodate the swizzled image data from imgSrc.
Moves an image to a new location in memory.
| img | The image to be moved. |
| newLocation | The new location where the image should be moved. This can be either OSL_IN_RAM or OSL_IN_VRAM. |
This function relocates an image to a new memory location. The new location can be either RAM or VRAM. After moving, the image can be used in its new location, but note that moving images between different memory types might have implications for performance and accessibility.
Example usage:
Returns true if the move was successful, and false otherwise.
|
extern |
Clears an image with a specific value.
| img | The image to be cleared. This image must be properly allocated and must have a format compatible with the provided color value. |
| color | The color value used to clear the image. The format of this color value depends on the pixel format of the image. For example:
|
This function fills the entire image with the specified color value. The color is applied according to the image's pixel format. For instance, in a OSL_PF_4444 format, you might use a 16-bit color value where each channel has 4 bits.
Example usage:
Note: The color parameter must be appropriate for the image's pixel format. The provided value should match the format's bit depth and channel order.
|
extern |
Writes an image to a file.
| img | The image to be written to the file. This image must not be swizzled; if it is, the function will not perform any operation. |
| filename | The path to the file where the image will be saved. The file type is determined based on the file extension. |
| flags | Either 0 or OSL_WRI_ALPHA, see oslWriteImageFilePNG. |
This function saves the provided image to the specified file. The file type is picked from the extension, in any case; PNG (.png) is the only format OSLib writes.
Note: If the image is swizzled, the function will not perform any action. To write a swizzled image, you must first unswizzle it using the oslUnswizzleImage function.
Example usage:
|
extern |
Writes an image to a PNG file. Same remarks as oslWriteImageFile apply.
| img | The image you want to write. |
| filename | The name of the file that you want to write to. |
| flags | Either 0 or OSL_WRI_ALPHA. If OSL_WRI_ALPHA is specified, the alpha will be written to the PNG image file, making it semi-transparent. Else, alpha is ignored and always set to opaque. |
You can pass for example OSL_SECONDARY_BUFFER (the buffer which is currently displayed on the screen) to take a screenshot.
Note: The same considerations as oslWriteImageFile apply.
|
extern |
Resets the properties of an image, including its position, tile settings, angle, rotation center, and stretching.
| img | The image whose properties will be reset. |
This function resets the following properties of the image:
oslSetImageTile) will be cleared.Example usage:
|
extern |
Draws srcImg to dstImg with scaling applied.
| dstImg | The destination image where the scaled source image will be drawn. |
| srcImg | The source image to be scaled and drawn. |
| newX | The x-coordinate for the position of the scaled source image in the destination image. |
| newY | The y-coordinate for the position of the scaled source image in the destination image. |
| newWidth | The width of the scaled source image. |
| newHeight | The height of the scaled source image. |
This function scales the source image (srcImg) and draws it onto the destination image (dstImg) at the specified position and with the specified dimensions.
Example usage:
|
extern |
Creates a scaled copy of an image.
| img | The image to be scaled and copied. |
| newLocation | The location where the new scaled image will be stored (e.g., in RAM or VRAM). |
| newWidth | The width of the scaled image. |
| newHeight | The height of the scaled image. |
| newPixelFormat | The pixel format of the new scaled image. |
This function creates a new image that is a scaled version of the original image (img). The new image will have the specified dimensions and pixel format.
Example usage: