Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/FreeImage/PluginRAS.cpp view on Meta::CPAN
// THIS DISCLAIMER.
//
// Use at your own risk!
// ==========================================================
#include "FreeImage.h"
#include "Utilities.h"
// ----------------------------------------------------------
// Constants + headers
// ----------------------------------------------------------
#ifdef _WIN32
#pragma pack(push, 1)
#else
#pragma pack(1)
#endif
typedef struct tagSUNHEADER {
DWORD magic; // Magic number
DWORD width; // Image width in pixels
DWORD height; // Image height in pixels
DWORD depth; // Depth (1, 8, 24 or 32 bits) of each pixel
DWORD length; // Image length (in bytes)
DWORD type; // Format of file (see RT_* below)
DWORD maptype; // Type of colormap (see RMT_* below)
DWORD maplength; // Length of colormap (in bytes)
} SUNHEADER;
#ifdef _WIN32
#pragma pack(pop)
#else
#pragma pack()
#endif
// ----------------------------------------------------------
// Following the header is the colormap, for maplength bytes (unless maplength is zero),
// then the image. Each row of the image is rounded to 2 bytes.
#define RAS_MAGIC 0x59A66A95 // Magic number for Sun rasterfiles
// Sun supported type's
#define RT_OLD 0 // Old format (raw image in 68000 byte order)
#define RT_STANDARD 1 // Raw image in 68000 byte order
#define RT_BYTE_ENCODED 2 // Run-length encoding of bytes
#define RT_FORMAT_RGB 3 // XRGB or RGB instead of XBGR or BGR
#define RT_FORMAT_TIFF 4 // TIFF <-> standard rasterfile
#define RT_FORMAT_IFF 5 // IFF (TAAC format) <-> standard rasterfile
#define RT_EXPERIMENTAL 0xffff // Reserved for testing
// These are the possible colormap types.
// if it's in RGB format, the map is made up of three byte arrays
// (red, green, then blue) that are each 1/3 of the colormap length.
#define RMT_NONE 0 // maplength is expected to be 0
#define RMT_EQUAL_RGB 1 // red[maplength/3], green[maplength/3], blue[maplength/3]
#define RMT_RAW 2 // Raw colormap
#define RESC 128 // Run-length encoding escape character
// ----- NOTES -----
// Each line of the image is rounded out to a multiple of 16 bits.
// This corresponds to the rounding convention used by the memory pixrect
// package (/usr/include/pixrect/memvar.h) of the SunWindows system.
// The ras_encoding field (always set to 0 by Sun's supported software)
// was renamed to ras_length in release 2.0. As a result, rasterfiles
// of type 0 generated by the old software claim to have 0 length; for
// compatibility, code reading rasterfiles must be prepared to compute the
// TRUE length from the width, height, and depth fields.
// ==========================================================
// Internal functions
// ==========================================================
static void
ReadData(FreeImageIO *io, fi_handle handle, BYTE *buf, DWORD length, BOOL rle) {
// Read either Run-Length Encoded or normal image data
static BYTE repchar, remaining= 0;
if (rle) {
// Run-length encoded read
while(length--) {
if (remaining) {
remaining--;
*(buf++)= repchar;
} else {
io->read_proc(&repchar, 1, 1, handle);
if (repchar == RESC) {
io->read_proc(&remaining, 1, 1, handle);
if (remaining == 0) {
*(buf++)= RESC;
} else {
io->read_proc(&repchar, 1, 1, handle);
*(buf++)= repchar;
}
} else {
*(buf++)= repchar;
}
}
}
} else {
// Normal read
io->read_proc(buf, length, 1, handle);
}
}
// ==========================================================
// Plugin Interface
// ==========================================================
static int s_format_id;
// ==========================================================
( run in 0.584 second using v1.01-cache-2.11-cpan-b50b6a40fd4 )