Title: | Read and Write 'wal' Bitmap Image Files and Other 'Quake' Assets |
---|---|
Description: | Read 'Quake' assets including bitmap images and textures in 'wal' file format. This package also provides support for extracting these assets from 'WAD' and 'PAK' file archives. It can also read models in 'MDL' and 'MD2' formats. |
Authors: | Tim Schäfer [aut, cre] |
Maintainer: | Tim Schäfer <[email protected]> |
License: | GPL-2 |
Version: | 0.1.1 |
Built: | 2024-10-29 04:31:52 UTC |
Source: | https://github.com/dfsp-spirit/wal |
Find closest color from a palette for given colors. The similarity method used to define 'closest' is deltaE, and the input RGB colors are transformed to LAB space for the computation, assuming they are given in sRGB space.
closest.color.from.palette(colors_rgb, fixed_palette_rgb)
closest.color.from.palette(colors_rgb, fixed_palette_rgb)
colors_rgb |
n x 3 integer matrix, the truecolor (arbitrary) input RGB colors for which you want to find the most similar colors included in the fixed palette. Range 0..255. |
fixed_palette_rgb |
the fixed palette, an n x 3 matrix of integers, representing the fixed palette colors in RGB values in range 0..255. |
vector of n integers, the index of the closest color into the palette for each of the colors_rgb
.
colors_rgb = matrix(c(255, 0, 0, 100, 100, 100, 10, 10, 10, 5, 5, 5), ncol = 3, byrow = TRUE); fixed_palette_rgb = matrix(c(255, 0, 0, 255, 5, 0, 11, 11, 11, 0, 0, 0, 255, 255, 255), ncol = 3, byrow = TRUE); pal_similar_colors = closest.color.from.palette(colors_rgb, fixed_palette_rgb);
colors_rgb = matrix(c(255, 0, 0, 100, 100, 100, 10, 10, 10, 5, 5, 5), ncol = 3, byrow = TRUE); fixed_palette_rgb = matrix(c(255, 0, 0, 255, 5, 0, 11, 11, 11, 0, 0, 0, 255, 255, 255), ncol = 3, byrow = TRUE); pal_similar_colors = closest.color.from.palette(colors_rgb, fixed_palette_rgb);
Convert an input RGB image to a WAL instance, re-mapping its colors to the WAL palette in the process and generating the mipmaps.
img.to.wal(in_image, apply_palette = wal::pal_q2(), wal = wal.template())
img.to.wal(in_image, apply_palette = wal::pal_q2(), wal = wal.template())
in_image |
numeric matrix with 3 dimensions: widt, height, channels. Values must be in range 0..1. This is the image format returned by |
apply_palette |
n x 3 integer matrix, the palette for the WAL image. This is not saved to the wal image, but still required because the colors from the |
wal |
a wal instance. Note that 1 will be substracted from the data when it is written, as indices are stored 0-based in the file. |
wal instance
## Not run: wal = img.to.wal(jpeg::readJPEG("~/mytex.jpg")); ## End(Not run)
## Not run: wal = img.to.wal(jpeg::readJPEG("~/mytex.jpg")); ## End(Not run)
Check whether object is a Quake 1 or 2 alias model.
is.quakemodel(x)
is.quakemodel(x)
x |
any R object |
Check whether object is Quake 2 MD2 model
is.quakemodel_md2(x)
is.quakemodel_md2(x)
x |
any R object |
Check whether object is Quake 1 MDL model
is.quakemodel_mdl(x)
is.quakemodel_mdl(x)
x |
any R object |
Extract PAK contents into existing directory.
pak.extract(pak_filepath, outdir = getwd())
pak.extract(pak_filepath, outdir = getwd())
pak_filepath |
character string, path to input PAK file. |
outdir |
character string, the output directory in which the files should be created. Must be writeable. The sub directories and filenames are derived from the data in the WAD. |
PAK files can contain a directory structure, and new subdirectories will be created under outdir
as needed to preserve it.
Get Q1 palette.
pal_q1()
pal_q1()
256 x 3 integer matrix, representing the RGB color values for an index into the palette.
pal = pal_q1(); dim(pal);
pal = pal_q1(); dim(pal);
Get Q2 palette.
pal_q2()
pal_q2()
256 x 3 integer matrix, representing the RGB color values for an index into the palette.
pal = pal_q2(); dim(pal);
pal = pal_q2(); dim(pal);
S3 plot function for wal image.
## S3 method for class 'wal' plot(x, ...)
## S3 method for class 'wal' plot(x, ...)
x |
a wal instance. |
... |
extra args, not used. |
Plot a mipmap level from a WAL image.
plotwal.mipmap(wal, mip_level = 0L, apply_palette = wal::pal_q2())
plotwal.mipmap(wal, mip_level = 0L, apply_palette = wal::pal_q2())
wal |
a WAL image instance, as returned by |
mip_level |
integer in range 0..3, the mipmap to plot. Level 0 is the original full-size image, the other ones get smaller and smaller (by factor 2 on each dimension, so 1/4th the size of their predecessor). |
apply_palette |
optional 256 x 3 integer matrix, the palette. Must contain values in range 0..255. Pass NULL if you do not want to apply any palette. The resulting |
## Not run: walf = '~/data/q2_pak0_extracted/textures/e1u2/basic1_7.wal'; wal = read.wal(walf); plotwal.mipmap(wal, mip_level = 3); ## End(Not run)
## Not run: walf = '~/data/q2_pak0_extracted/textures/e1u2/basic1_7.wal'; wal = read.wal(walf); plotwal.mipmap(wal, mip_level = 3); ## End(Not run)
Plot raw pixel index data as image.
plotwal.rawdata(raw_data, width, height, apply_palette = wal::pal_q2())
plotwal.rawdata(raw_data, width, height, apply_palette = wal::pal_q2())
raw_data |
integer vector in containing width * height values in range 0..255, and optionally additional mipmap data at the end (which will be ignored). The raw image data. Can be a Q2 WAL data, Q1 miptex data, or anything else. |
width |
positive integer, the image width. |
height |
positive integer, the image height. |
apply_palette |
optional 256 x 3 integer matrix, the palette. Must contain values in range 0..255. Pass NULL if you do not want to apply any palette. The resulting |
## Not run: # Plot the Q1 shambler skin: mdl = read.quake.mdl("~/data/q1_pak/progs/shambler.mdl"); plotwal.rawdata(mdl$skins$skin_pic, mdl$header$skin_width, mdl$header$skin_height, apply_palette = pal_q1()); ## End(Not run)
## Not run: # Plot the Q1 shambler skin: mdl = read.quake.mdl("~/data/q1_pak/progs/shambler.mdl"); plotwal.rawdata(mdl$skins$skin_pic, mdl$header$skin_width, mdl$header$skin_height, apply_palette = pal_q1()); ## End(Not run)
S3 print function for WAD
## S3 method for class 'wad' print(x, ...)
## S3 method for class 'wad' print(x, ...)
x |
wad instance |
... |
extra arguments, ignored |
Extract any of the supported Quake archives.
qarchive.extract(filepath, outdir, format = "auto", do_pre_checks = TRUE)
qarchive.extract(filepath, outdir, format = "auto", do_pre_checks = TRUE)
filepath |
character string, path to existing and readable file in PAK or WAD2 format. |
outdir |
character string, path to an existing and writeable output directory into which to extract the archive. |
format |
character string, of one 'auto' to detect from filename, 'QARCHIVE_TYPE_WAD' for WAD2, or 'QARCHIVE_TYPE_PAK' for PACK. |
do_pre_checks |
logical, whether to perform extra sanity checks on the other parameters. |
Convert Quake Model to 'fs.surface' instance.
quakemodel.to.fs.surface(quakemodel, frame_idx = 1L)
quakemodel.to.fs.surface(quakemodel, frame_idx = 1L)
quakemodel |
an instance of |
frame_idx |
integer, the frame to export. Quake models may contain animations made up of several frames. The mesh connectivity is unaltered between frames, but the vertex positions differ. |
fs.surface
mesh instance, as used by the freesurferformats
package.
Read Quake PAK archive.
read.pak(filepath)
read.pak(filepath)
filepath |
character string, path to the file including extension. |
a 'pak' instance.
## Not run: pakf = '~/.steam/steam/steamapps/common/Quake/Id1/PAK0.PAK'; pak = read.pak(pakf); ## End(Not run)
## Not run: pakf = '~/.steam/steam/steamapps/common/Quake/Id1/PAK0.PAK'; pak = read.pak(pakf); ## End(Not run)
Read Quake II model in MD2 format.
read.quake.md2(filepath, anim = FALSE)
read.quake.md2(filepath, anim = FALSE)
filepath |
character string, the path to the MD2 file |
anim |
logical, whether to load the whole animation (if present). Returns a list of models, the animation frames. If FALSE, only the first frame is returned. |
Ignore this function, it will be moved to a different package.
Read Quake model in MDL format.
read.quake.mdl(filepath, do_checks = FALSE)
read.quake.mdl(filepath, do_checks = FALSE)
filepath |
character string, the path to the MDL file |
do_checks |
logical, whether to perform some sanity checks on the data and warn on suspicious results. |
Ignore this function, it will be moved to a different package.
## Not run: mdlf = "~/data/q1_pak/progs/quaddama.mdl" mdl = read.quake.mdl(mdlf); ## End(Not run)
## Not run: mdlf = "~/data/q1_pak/progs/quaddama.mdl" mdl = read.quake.mdl(mdlf); ## End(Not run)
Read a Quake mipmap texture from a WAD2 file.
read.quake1miptex(filepath, at_offset = 0L)
read.quake1miptex(filepath, at_offset = 0L)
filepath |
character string, path to WAD file. |
at_offset |
integer, the index in the WAD file where the texture starts. |
a 'qmiptex' instance, its like a wall with shorter name field (16 instead of 32) and some fields (anim_name, flags, contents, value) missing.
## Not run: qm = read.quake1miptex("~/knave.wad", at_offset = 1317632); plotwal.mipmap(qm, apply_palette = pal_q1()); ## End(Not run)
## Not run: qm = read.quake1miptex("~/knave.wad", at_offset = 1317632); plotwal.mipmap(qm, apply_palette = pal_q1()); ## End(Not run)
Read Quake WAD file.
read.wad(filepath)
read.wad(filepath)
filepath |
character string, path to the file. |
a wad instance, can be used to extract data or list contents.
## Not run: wadf = '~/knave.wad'; wad = read.wad(wadf); wad.contents(wad); ## End(Not run)
## Not run: wadf = '~/knave.wad'; wad = read.wad(wadf); wad.contents(wad); ## End(Not run)
Read bitmap file in WAL format.
read.wal(filepath, hdr = TRUE, hdr_only = FALSE, apply_palette = wal::pal_q2())
read.wal(filepath, hdr = TRUE, hdr_only = FALSE, apply_palette = wal::pal_q2())
filepath |
character string, path to the file including extension |
hdr |
logical, whether to return full list with header |
hdr_only |
logical, whether to read only the header |
apply_palette |
optional 256 x 3 integer matrix, the palette. Must contain values in range 0..255. Pass NULL if you do not want to apply any palette. The resulting |
integer pixel matrix, each pixel value is in range 0-255 and refers to an index in a palette. The palette is NOT included in the file, so you will need to define one or get it from elsewhere to see the final image.
## Not run: walf = '~/data/q2_pak0_extracted/textures/e1u2/basic1_7.wal'; wal = read.wal(walf); plot(wal); ## End(Not run)
## Not run: walf = '~/data/q2_pak0_extracted/textures/e1u2/basic1_7.wal'; wal = read.wal(walf); plot(wal); ## End(Not run)
Read a bitmap image in WAL format, and return data in the same format as png::readPNG
and jpeg::readJPEG
do.
readWAL(filepath, apply_palette = wal::pal_q2())
readWAL(filepath, apply_palette = wal::pal_q2())
filepath |
character string, path to the file including extension |
apply_palette |
optional 256 x 3 integer matrix, the palette. Must contain values in range 0..255. Pass NULL if you do not want to apply any palette. The resulting |
numeric matrix with dimension width x height x channels, with all color values in range 0..1.
read.wal
if you want to read the header and have more control.
## Not run: walf = '~/data/q2_pak0_extracted/textures/e1u2/basic1_7.wal'; wal_image = readWAL(walf); dim(wal_image); ## End(Not run)
## Not run: walf = '~/data/q2_pak0_extracted/textures/e1u2/basic1_7.wal'; wal_image = readWAL(walf); dim(wal_image); ## End(Not run)
List WAD file contents.
wad.contents(wad)
wad.contents(wad)
wad |
a wad instance, see |
data.frame, info on the files inside the wad.
Extract WAD contents into existing directory.
wad.extract( wad_filepath, outdir = getwd(), file_ext_mapping = wad_dir.fileext.mapping() )
wad.extract( wad_filepath, outdir = getwd(), file_ext_mapping = wad_dir.fileext.mapping() )
wad_filepath |
character string, path to input WAD file. |
outdir |
character string, the output directory in which the files should be created. The filenames are derived from the data in the WAD. |
file_ext_mapping |
named list, with keys corresponding to the type names and values are file extensions, including the dot, to use for them. |
One can read extracted textures with read.quake1miptex()
.
Export wal instance to JPEG format image file.
wal.export.to.jpeg(wal, filepath, apply_palette = wal::pal_q2(), ...)
wal.export.to.jpeg(wal, filepath, apply_palette = wal::pal_q2(), ...)
wal |
a wal instance, as returned by |
filepath |
character string, path to the JPEG file to write, including the file extension. |
apply_palette |
optional 256 x 3 integer matrix, the palette. Must contain values in range 0..255. Pass NULL if you do not want to apply any palette. The resulting |
... |
extra parameters passed to |
## Not run: walf = '~/data/q2_pak0_extracted/textures/e1u2/basic1_7.wal'; wal = read.wal(walf); wal.export.to.jpeg(wal, "~/basic1_7.jpg"); ## End(Not run)
## Not run: walf = '~/data/q2_pak0_extracted/textures/e1u2/basic1_7.wal'; wal = read.wal(walf); wal.export.to.jpeg(wal, "~/basic1_7.jpg"); ## End(Not run)
Export wal instance to PNG format image file.
wal.export.to.png(wal, filepath, apply_palette = wal::pal_q2(), ...)
wal.export.to.png(wal, filepath, apply_palette = wal::pal_q2(), ...)
wal |
a wal instance, as returned by |
filepath |
character string, path to the PNG file to write, including the file extension. |
apply_palette |
optional 256 x 3 integer matrix, the palette. Must contain values in range 0..255. Pass NULL if you do not want to apply any palette. The resulting |
... |
extra parameters passed to |
## Not run: walf = '~/data/q2_pak0_extracted/textures/e1u2/basic1_7.wal'; wal = read.wal(walf); wal.export.to.png(wal, "~/basic1_7.png"); ## End(Not run)
## Not run: walf = '~/data/q2_pak0_extracted/textures/e1u2/basic1_7.wal'; wal = read.wal(walf); wal.export.to.png(wal, "~/basic1_7.png"); ## End(Not run)
Write WAL instance to bitmap file in WAL format.
writeWAL(filepath, wal)
writeWAL(filepath, wal)
filepath |
character string, path to the file including extension |
wal |
a wal instance. Note that 1 will be substracted from the data when it is written, as indices are stored 0-based in the file. |
## Not run: walf = '~/data/q2_pak0_extracted/textures/e1u2/basic1_7.wal'; wal = read.wal(walf); writeWAL(tempfile(fileext = ".wal"), wal); ## End(Not run)
## Not run: walf = '~/data/q2_pak0_extracted/textures/e1u2/basic1_7.wal'; wal = read.wal(walf); writeWAL(tempfile(fileext = ".wal"), wal); ## End(Not run)