Difference between revisions of "ImageData"

m (Merging queries)
Line 3: Line 3:
 
You can't draw ImageData directly to screen. See [[Image]] for that.
 
You can't draw ImageData directly to screen. See [[Image]] for that.
 
== Functions ==
 
== Functions ==
{{#ask: [[Category:Functions]] [[parent::ImageData]]
+
{{#ask: [[Category:Functions]] [[parent::ImageData]] OR [[Category:Functions]] [[parent::Data]] OR [[Category:Functions]] [[parent::Object]]
| headers=hide
 
| ?Description
 
}}
 
{{#ask: [[Category:Functions]] [[parent::Data]]
 
| headers=hide
 
| ?Description
 
}}
 
{{#ask: [[Category:Functions]] [[parent::Object]]
 
 
| headers=hide
 
| headers=hide
 
| ?Description
 
| ?Description
Line 43: Line 35:
 
* [[Image]]
 
* [[Image]]
 
[[Category:Types]]
 
[[Category:Types]]
{{#set:Description=Raw (decoded) image data.
+
{{#set:Description=Raw (decoded) image data.}}
}}
 
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|ImageData}}
 
{{i18n|ImageData}}

Revision as of 20:33, 20 February 2011

Raw (decoded) image data.

You can't draw ImageData directly to screen. See Image for that.

Functions

Data:cloneCreates a new copy of the Data object.
Data:getFFIPointerGets an FFI pointer to the Data.
Data:getPointerGets a pointer to the Data.
Data:getSizeGets the Data's size in bytes.
Data:getStringGets the full Data as a string.
ImageData:encodeEncodes the ImageData to a file format and optionally writes it to the save directory.
ImageData:getDimensionsGets the width and height of the ImageData in pixels.
ImageData:getFormatGets the pixel format of the ImageData.
ImageData:getHeightGets the height of the ImageData in pixels.
ImageData:getPixelGets the color of a pixel.
ImageData:getStringGets the full ImageData as a string.
ImageData:getWidthGets the width of the ImageData in pixels.
ImageData:mapPixelTransform an image by applying a function to every pixel.
ImageData:pastePaste into ImageData from another source ImageData.
ImageData:setPixelSets the color of a pixel.
Object:releaseImmediately destroys the object's Lua reference.
Object:typeGets the type of the object as a string.
Object:typeOfChecks whether an object is of a certain type.

Examples

Images that have dimensions that are not a 2^n will display incorrectly as a white rectangle on some graphics chipsets. This function pads images so they will display correctly.

function newPaddedImage(filename)
	local source = love.image.newImageData(filename)
	local w, h = source:getWidth(), source:getHeight()
	
	-- Find closest power-of-two.
	local wp = math.pow(2, math.ceil(math.log(w)/math.log(2)))
	local hp = math.pow(2, math.ceil(math.log(h)/math.log(2)))
	
	-- Only pad if needed:
	if wp ~= w or hp ~= h then
		local padded = love.image.newImageData(wp, hp)
		padded:paste(source, 0, 0)
		return love.graphics.newImage(padded)
	end
	
	return love.graphics.newImage(source)
end

Supertypes

Data Object

See Also

Other Languages