Skip to main content

ImageData

A mutable non-drawable 2-dimensional array of pixel data.

info

To display/draw it, convert it into an image first using imagedata:image.

Creation

imagedata

Load existing pixel data in a new object. It can accept a .lk12 raw string, or a .png one.

note

All transparent pixels and all colors that are not from the palette will be loaded as 0.

loadedImageData = imagedata(data)
ParameterTypeDefaultNote
datastring⚠️ requiredin the .lk12 image format. or in .png format.
ReturnTypeNote
loadedImageDataImageData

screenshot

Take a screenshot of the screen (without the cursor) or a region of it. And get the resulting pixel data.

info

Although this function can be considered expensive. It usually doesn't affect the FPS when taking a single shot every frame.

capturedImageData = screenshot(x, y, width, height)
ParameterTypeDefaultNote
xnumber0of the region you wish to capture.
ynumber0of the region you wish to capture.
widthnumberscreen widthof the region you wish to capture.
heightnumberscreen heightof the region you wish to capture.
ReturnTypeNote
capturedImageDataImageData

getLabelImage

Get the pixel data of the label image. Which is the image displayed in the exported .png game disks.

The image is captured by pressing F6.

info

The object provided by this function has a shared pixel data.

Which means when it's mutated, it's mutated in all objects obtained from this same function.

This also applies when a new image is captured using F6.

labelImage = getLabelImage()
ReturnTypeNote
labelImageImageData

Retrieved from a loaded image

Every loaded image originates from an ImageData object. That object can be retrieved using image:data.

Methods

caution

Object methods should be called using the : operator. Which passes the object itself as a parameter before all the other specified parameters. That is necessary for object methods to work efficiently.

For example to call the method shutdown on the object myComputer the both ways would work:

myComputer:shutdown()

imageData:getPixel

Get the value of a pixel.

colorId = imageData:getPixel(x, y)
ParameterTypeDefaultNote
xnumber⚠️ required
ynumber⚠️ required
ReturnTypeNote
colorIdnumberan integer in range [0, 15].

imageData:setPixel

Set the value of a pixel.

imageData = imageData:setPixel(x, y, colorId)
ParameterTypeDefaultNote
xnumber⚠️ required
ynumber⚠️ required
colorIdnumber⚠️ requiredan integer in range [0, 15].
ReturnTypeNote
imageDataImageDatathe object itself. allows to do chain calls.

imageData:width

Get the width of the pixel data.

width = imageData:width()
ReturnTypeNote
widthnumber

imageData:height

Get the height of the pixel data.

height = imageData:height()
ReturnTypeNote
heightnumber

imageData:size

Get the dimensions of the pixel data.

width, height = imageData:size()
ReturnTypeNote
widthnumber
heightnumber

imageData:image

Load the pixel data into an image. Which can be displayed into the screen.

info

The created image can refresh (update) it's pixel data from the ImageData which created it by calling image:refresh.

caution

The calls of this function are performance expensive, unlike image:data.

caution

Use a different name than image for storing the value in. As that might confuse it with the image function.

image = imageData:image()
ReturnTypeNote
imageImage

imageData:enlarge

Scale up the pixel data by a specific integer.

info

This method doesn't mutate the object. But instead creates a new one with the mutation.

enlargedImageData = imageData:enlarge(scale)
ParameterTypeDefaultNote
scalenumber⚠️ requiredmust be a positive integer
ReturnTypeNote
enlargedImageDataImageData

imageData:map

Transform the pixel data by applying a function to every pixel.

imageData:map(pixelFunction)
ParameterTypeDefaultNote
pixelFunctionPixelFunction⚠️ requiredcheck the definition below.

PixelFunction

A function which is called for every pixel in a pixel data.

info

The scanline order is followed. Starting with the top-left corner and going in horizontal lines till the bottom-right corner.

The signature of the function is:

function pixelFunction(x, y, colorId)
--Logic here for modifying the colorId.
return colorId;
end
ParameterTypeNote
xnumber
ynumber
colorIdnumberan integer in the range [0, 15].
ReturnTypeNote
colorIdnumberthe new pixel value. an integer in the range [0, 15].

imageData:paste

Copy pixel data from one object into this object.

imageData = imageData:paste(source, destinationX, destinationY, sourceX, sourceY, regionWidth, regionHeight)
ParameterTypeDefaultNote
sourceImageData⚠️ required
destinationXnumber0
destinationYnumber0
sourceXnumber0
sourceYnumber0
regionWidthnumbersource image width
regionHeightnumbersource image height
ReturnTypeNote
imageDataImageDatathe object itself. allows to do chain calls.

imageData:quad

Create a new quad representing a region from this pixel data.

info

The result quad should work fine when used on an image loaded from this object.

createdQuad = imageData:quad(x, y, width, height)
ParameterTypeDefaultNote
xnumber⚠️ requiredof the region to represent.
ynumber⚠️ requiredof the region to represent.
widthnumber⚠️ requiredof the region to represent.
heightnumber⚠️ requiredof the region to represent.
ReturnTypeNote
createdQuadQuad

imageData:encode

Encode the pixel data into a .lk12 raw string.

data = imageData:encode()
ReturnTypeNote
datastring

imageData:export

Export the pixel data to a .png raw string.

info

All pixels with a color set as transparent using palt will be transparent in the result png.

rawPNGString = imageData:export()
ReturnTypeNote
rawPNGStringstring

imageData:exportOpaque

Export the pixel data to a .png raw string.

info

All the pixels are made opaque using this method.

rawPNGString = imageData:exportOpaque()
ReturnTypeNote
rawPNGStringstring

imageData:type

Get the type of the object as a string.

danger

This method most likely will be removed in a future version.

objectType = imageData:type()
ReturnTypeNote
objectTypestringGPU.imagedata

imageData:typeOf

Checks whether an object is of a certain type. If the object has the type with the specified name in its hierarchy, this function will return true.

danger

This method most likely will be removed in a future version.

isIt = imageData:typeOf(type)
ParameterTypeDefaultNote
typestring⚠️ required
ReturnTypeNote
isItboolean'GPU', 'imageData', 'GPU.imageData', 'LK12' would give true.