class Codec
class Codec
lib/image/codec.tya:4
Codec provides the image/Codec standard library API.
Source
# Codec provides the image/Codec standard library API.
class Codec
# Codec.value stores instance state.
# @type Nil
value: nil
# Codec.initialize stores image data or a path.
# @param value String value value.
# @return Self the initialized object.
initialize: value = nil ->
self.value = value
# Codec.identify is a compatibility alias for Codec.metadata.
# @param data Array data value.
# @return Any the resulting value.
identify: data = nil ->
self.metadata(data)
# Codec.identify_file is a compatibility alias for Codec.metadata_file.
# @param path String path value.
# @return Any the resulting value.
identify_file: path = nil ->
self.metadata_file(path)
# Codec.metadata reads image metadata from encoded bytes.
# @param data Array data value.
# @return Any the resulting value.
metadata: data = nil ->
if data == nil
data = self.value
text = bytes_text(data)
parts = text.split("\n")
if parts.len() == 0
raise error("image.identify: unsupported or malformed image")
header = parts[0].split(":")
if header.len() != 6 or header[0] != "TYAIMG"
raise error("image.identify: unsupported or malformed image")
format = header[1]
if not Codec(nil).supported_format?(format)
raise error("image.identify: unsupported format " + format)
{ format: format, width: header[2].to_i(), height: header[3].to_i(), frames: header[5].to_i(), animated: header[5].to_i() > 1, has_alpha: header[4] == "1", color_space: "srgb" }
# Codec.metadata_file reads image metadata from a file.
# @param path String path value.
# @return Any the resulting value.
metadata_file: path = nil ->
if path == nil
path = self.value
Codec(nil).metadata(file.File(path).read_bytes())
# Codec.supported_format? provides the image/Codec standard library operation.
# @param format String format value.
# @return Boolean whether the condition is true.
supported_format?: format ->
format == "png" or format == "jpeg" or format == "gif" or format == "bmp" or format == "ppm"
Instance Variables
value
Codec.value
lib/image/codec.tya:7
Codec.value stores instance state.
Source
# Codec.value stores instance state.
# @type Nil
value: nil
Methods
identify
Codec.identify(data = nil)
lib/image/codec.tya:18
Codec.identify is a compatibility alias for Codec.metadata.
Source
# Codec.identify is a compatibility alias for Codec.metadata.
# @param data Array data value.
# @return Any the resulting value.
identify: data = nil ->
self.metadata(data)
identify_file
Codec.identify_file(path = nil)
lib/image/codec.tya:24
Codec.identify_file is a compatibility alias for Codec.metadata_file.
Source
# Codec.identify_file is a compatibility alias for Codec.metadata_file.
# @param path String path value.
# @return Any the resulting value.
identify_file: path = nil ->
self.metadata_file(path)
initialize
Codec.initialize(value = nil)
lib/image/codec.tya:12
Codec.initialize stores image data or a path.
Source
# Codec.initialize stores image data or a path.
# @param value String value value.
# @return Self the initialized object.
initialize: value = nil ->
self.value = value
metadata
Codec.metadata(data = nil)
lib/image/codec.tya:30
Codec.metadata reads image metadata from encoded bytes.
Source
# Codec.metadata reads image metadata from encoded bytes.
# @param data Array data value.
# @return Any the resulting value.
metadata: data = nil ->
if data == nil
data = self.value
text = bytes_text(data)
parts = text.split("\n")
if parts.len() == 0
raise error("image.identify: unsupported or malformed image")
header = parts[0].split(":")
if header.len() != 6 or header[0] != "TYAIMG"
raise error("image.identify: unsupported or malformed image")
format = header[1]
if not Codec(nil).supported_format?(format)
raise error("image.identify: unsupported format " + format)
{ format: format, width: header[2].to_i(), height: header[3].to_i(), frames: header[5].to_i(), animated: header[5].to_i() > 1, has_alpha: header[4] == "1", color_space: "srgb" }
metadata_file
Codec.metadata_file(path = nil)
lib/image/codec.tya:48
Codec.metadata_file reads image metadata from a file.
Source
# Codec.metadata_file reads image metadata from a file.
# @param path String path value.
# @return Any the resulting value.
metadata_file: path = nil ->
if path == nil
path = self.value
Codec(nil).metadata(file.File(path).read_bytes())
supported_format?
Codec.supported_format?(format)
lib/image/codec.tya:56
Codec.supported_format? provides the image/Codec standard library operation.
Source
# Codec.supported_format? provides the image/Codec standard library operation.
# @param format String format value.
# @return Boolean whether the condition is true.
supported_format?: format ->
format == "png" or format == "jpeg" or format == "gif" or format == "bmp" or format == "ppm"