Module OCX.OCImage
Library for loading, editing (scaling, color changes) and displaying raster and displayed (OC-adapted) images with OCDraw.
The difference between the two types of image is that a DisplayableImage uses characters, while a RasterImage is all pixels.
Functions
registerImageFormat (format) | Register a new image format |
getFormat (file) | Detects the image format the given file is in or returns null if it corresponds to no registered image format |
create (width, height[, bpp[, alpha]]) | Creates a displayable image with the given parameters |
convertFromRaster (image, opts) | Converts a raster image into a displayable image. |
scale (image, tw, th) | Scales a raster image to the given dimensions, this uses nearest neighbour scaling. |
load (path) | Loads a displayable image from the given path. |
loadRaster (path) | Loads a raster image from the given path. |
getAspectRatio (image) | Returns the aspect ratio of the given image. |
drawGPU (image, gpu, x, y) | Draws a displayable image using the given GPU driver or component instance. |
drawImage (image, ctxn) | Draws a displayable image to the given OCDraw context |
Functions
- registerImageFormat (format)
-
Register a new image format
Parameters:
- format format The image format to register
- getFormat (file)
-
Detects the image format the given file is in or returns null if it corresponds to no registered image format
Parameters:
- file file The file containing an image
Returns:
-
optional format
The detected image format
- create (width, height[, bpp[, alpha]])
-
Creates a displayable image with the given parameters
Parameters:
- width int The width of the image, or 1
- height int The height of the image, or 1
- bpp int The number of bits per pixel in the image, or 8 (optional)
- alpha bool The presence of an alpha channel, or false (optional)
Returns:
-
DisplayableImage
the newly created image
- convertFromRaster (image, opts)
-
Converts a raster image into a displayable image. This is necessary in order to display a raster image.
Parameters:
- image RasterImage The image to convert
- opts Image conversion options
- advancedDithering bool Whether to dither using the current GPU palette or by assuming all RGB colors are available. Enabling this will result in a major slow down! (optional)
- dithering string The dithering method to use. Either "floyd-steinberg", "basic" or nil. (optional)
Returns:
-
DisplayableImage
the converted image
- scale (image, tw, th)
-
Scales a raster image to the given dimensions, this uses nearest neighbour scaling.
Parameters:
- image RasterImage The image to be scaled
- tw int The new width of the image
- th int The new height of the image
Returns:
-
RasterImage
The scaled image
- load (path)
-
Loads a displayable image from the given path. If the file actually contains
a raster image, it will be converted to a displayable image. Returns an error if
the image type is not recognised.
Parameters:
- path string The path of the image to load
Returns:
-
DisplayableImage
The loaded image
- loadRaster (path)
-
Loads a raster image from the given path. Returns an error if
the image type is not recognised or if it is a displayable image type.
(while it is technically possible to convert a displayable image to a raster
image, it would require packing in OpenComputers's font which would make the
library size huge for a feature that's gonna be rarely used)
Parameters:
- path string The path of the image to load
Returns:
-
RasterImage
The loaded image
- getAspectRatio (image)
-
Returns the aspect ratio of the given image.
Parameters:
- image RasterImage or DisplayableImage
- drawGPU (image, gpu, x, y)
-
Draws a displayable image using the given GPU driver or component instance. This can be useful
for using OCImage on OpenOS or other operating systems, and it's also used during boot for the
Concert splash screen.
Parameters:
- image DisplayableImage The image to draw
- gpu driver or component Instance of the GPU driver or component to use
- x int The X position where the image will be drawn
- y int The Y position where the image will be drawn
- drawImage (image, ctxn)
-
Draws a displayable image to the given OCDraw context
Parameters:
- image DisplayableImage The image to draw
- ctxn int The ID of the draw context