GithubHelp home page GithubHelp logo

classicvalues / pcx Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dfsp-spirit/pcx

0.0 1.0 0.0 799 KB

Read PCX bitmap image files in R and convert to other formats.

License: GNU General Public License v3.0

R 100.00%

pcx's Introduction

pcx

Read pcx bitmap image files in R.

About

The PCX (Picture Exchange) format is an old bitmap image format that is compressed using runlength encoding and typically indexed, i.e. used with a fixed palette. It was used together with the WAL format for parts of the assets (skybox textures, model skins, UI pictures, sprites) in the early Quake series games (id tech1 and tech2 engines).

Package API

This is work in progress, but here is the current state:

# Read a PCX image from a file at filepath:
pcx = pcx::read.pcx(filepath);

# print information from the PCX header
pcx;

Here are some ideas on what to do with your image:

# show the image using 'imager' package
plot(imager::as.cimg(pcx$colors));

# plot the palette (indexed images with VGA palette only):
plot(1:nrow(pcx$palette), col=rgb(pcx$palette, maxColorValue = 255));

# export the image to JPEG format (requires the 'jpeg' package):
jpeg::writeJPEG(pcx$colors/255., target = '~/myimage.jpg');

Return value details

The returned pcx object in the example code above is a named list with the following entries:

  • colors: this is what you want, the image. An array of integers in range 0-255 representing RGB colors, with three dimensions in the following order: width, height, channels. The channels are in order R, G, B. If the image is indexed, this has been created by applying the palette to the data (see below).
  • header: named list, containing the header fields and values from the file.
  • palette: the optional VGA image palette (256 fixed colors), a vector of intensities (for images with 1 channel) or a matrix of RGB colors (for multi-channel images). This is NULL if the file does not contain a VGA palette. Note that for very old PCX files (CGA/EGA with <= 16 fixed colors), the palette is stored in the header$ega_palette field instead.
  • data: the raw image data, as read from the file. The palette has not been applied to this. Usually not needed, but you could use this to apply a custom palette to the image data.

A note on the interpretation of indexed PCX color data

The interpretation of indexed PCX images, especially in CGA/EGA mode, is not well defined and thus the same image may be displayed differently by different viewers, as explained in the references. If the colors returned by this package do not match your expectations, feel free to apply your own interpretation using the header information and data.

However, if you know the PCX specs well and feel confident enough that the interpretation of this package is definitely wrong for a file, please open an issue and attach the file together with a detailed description of your expectations. If possible, please include a screenshot of the rendering of the image in some standard software that matches your expectations.

References

Unit tests and CI

R-CMD-check

AppVeyor build status AppVeyor CI under Windows

pcx's People

Contributors

dfsp-spirit avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.