class
PixelUtility
Utility methods for converting and managing pixel data and formats.
Public
Methods
staticGetElementByteCount
Returns the size of a single pixel of the provided pixel format, in bytes.
staticGetBlockSize
Returns the size of a single compressed block, in bytes.
Returns pixel size if the format is not block compressed.
staticGetBlockDimensions
Returns the dimensions of a single compressed block, in number of pixels.
Returns 1x1 for non-block-compressed formats.
staticGetElementBitCount
Returns the size of a single pixel of the provided pixel format, in bits.
staticGetMemorySize
Returns the size of the memory region required to hold pixels of the provided size ana format.
staticGetSizeForMipLevel
Calculates the size of a mip level of a texture with the provided size.
staticGetPitch
Calculates row and depth pitch for a texture surface of the specified size and format.
For most formats row pitch will equal the number of bytes required for storing "width" pixels, and slice pitch will equal the number of bytes required for storing "width*height" pixels. But some texture formats (especially compressed ones) might require extra padding. Input width/height/depth values are in pixels, while output pitch values are in bytes.
staticGetFlags
Returns property flags for this pixel format.
staticHasAlpha
Checks if the provided pixel format has an alpha channel.
staticIsFloatingPoint
Checks is the provided pixel format a floating point format.
staticIsCompressed
Checks is the provided pixel format compressed.
staticIsDepth
Checks is the provided pixel format a depth/stencil buffer format.
staticIsNormalized
Checks does the provided format store data in normalized range.
staticCheckFormat
Checks is the provided format valid for the texture type and usage.
Caller should still check for platform-specific unsupported formats.
- format
- Format to check. If format is not valid the method will update this with the closest relevant format.
- textureType
- Type of the texture the format will be used for.
- usage
- A set of TextureUsage flags that define how will a texture be used.
Returns: True if the format is valid, false if not.
staticIsValidExtent
Checks are the provided dimensions valid for the specified pixel format.
Some formats (like BC) require width/height to be multiples of four and some formats dont allow depth larger than 1.
staticGetBitDepths
Returns the number of bits per each element in the provided pixel format.
This will return all zero for compressed and depth/stencil formats.
staticGetBitMasks
Returns bit masks that determine in what bit range is each channel stored.
staticGetBitShifts
Returns number of bits you need to shift a pixel element in order to move it to the start of the data type.
staticGetFormatName
Returns the name of the pixel format.
staticIsAccessible
Returns true if the pixel data in the format can be directly accessed and read.
This is generally not true for compressed formats.
staticGetElementType
Returns the type of an individual pixel element in the provided format.
staticGetElementCount
Returns the number of pixel elements in the provided format.
staticGetMipmapCount
Returns the maximum number of mip maps that can be generated until we reach the minimum size possible.
This does not count the base level.
staticPackColor
Writes the color to the provided memory location.
staticPackColor
Writes the color to the provided memory location.
If the destination format is floating point, the byte values will be converted into [0.0, 1.0] range.
staticPackColor
Writes the color to the provided memory location.
If the destination format in non-floating point, the float values will be assumed to be in [0.0, 1.0] which will be converted to integer range. ([0, 255] in the case of bytes)
staticUnpackColor
Reads the color from the provided memory location and stores it into the provided color object.
staticUnpackColor
Reads the color from the provided memory location and stores it into the provided color elements, as bytes clamped to [0, 255] range.
staticUnpackColor
Reads the color from the provided memory location and stores it into the provided color elements.
If the format is not natively floating point a conversion is done in such a way that returned values range [0.0, 1.0].
staticPackDepth
Writes a depth value to the provided memory location.
Depth should be in range [0, 1].
staticUnpackDepth
Reads the depth from the provided memory location.
Value ranges in [0, 1].
staticBulkPixelConversion
Converts pixels from one format to another.
Provided pixel data objects must have previously allocated buffers of adequate size and their sizes must match.
staticFlipComponentOrder
Flips the order of components in each individual pixel.
For example RGBA -> ABGR.
staticConvertFormat
staticCompress
Compresses the provided data using the specified compression options.
staticCompress
staticGenerateMipmaps
Generates mip-maps from the provided source data using the specified compression options.
Returned list includes the base level.
Returns: A list of calculated mip-map data. First entry is the largest mip and other follow in order from largest to smallest.
staticScale
Scales pixel data in the source buffer and stores the scaled data in the destination buffer.
Provided pixel data objects must have previously allocated buffers of adequate size. You may also provided a filtering method to use when scaling.
staticScale
Scales pixel data in the source buffer according to the provided size and filtering method.
staticMirror
Mirrors the contents of the provided object along the X, Y and/or Z axes.
staticCopy
Copies the contents of the buffer into the buffer.
The size of the copied contents is determined by the size of the buffer. First pixel copied from is determined by offset provided in ,
and parameters.
staticLinearToSrgb
Converts pixel data in linear space to one in sRGB space.
Only converts the RGB components.
staticSRGBToLinear
Converts pixel data in sRGB space to one in linear space.
Only converts the RGB components.
staticSaveImage
Saves pixel data to an image file.
- pixelData
- Pixel data to save. Must be non-null with valid dimensions.
- outputPath
- Output file path. Extension will be set based on format.
- format
- Image format to save as (PNG, JPG, BMP, TGA).
- ignoreAlpha
- If true, alpha channel will be set to fully opaque (255) in the output.
Returns: True if save succeeded, false on error (with log message).