博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Stellaris Graphics Library : Image Format
阅读量:5112 次
发布时间:2019-06-13

本文共 4274 字,大约阅读时间需要 14 分钟。

Images are stored as an array of unsigned characters. Ideally, they would be in a structure,

but the limitations of C prevents an efficient definition of a structure for an image
while still allowing a compile-time declaration of the data for an image.
The effective definition of the structure is as follows (with no padding between members):

typedef struct{//// Specifies the format of the image data; will be one of// IMAGE_FMT_1BPP_UNCOMP, IMAGE_FMT_4BPP_UNCOMP, IMAGE_FMT_8BPP_UNCOMP,// IMAGE_FMT_1BPP_COMP, IMAGE_FMT_4BPP_COMP, or IMAGE_FMT_8BPP_COMP. // The xxx_COMP varieties indicate that the image data is compressed.//unsigned char ucFormat;//// The width of the image in pixels.//unsigned short usWidth;//// The height of the image in pixels.//unsigned short usHeight;//// The image data. This is the structure member that C can not handle// efficiently at compile time.//unsigned char pucData[]; // 1bpp : No Palette in pucData[] : < use Context->ulBackground and Context->ulForeground // 4bpp : ulPaletteColorNum : PaletteColor[0][3] .. PaletteColor[15][3] // 8bpp : ulPaletteColorNum : PaletteColor[0][3] .. PaletteColor[255][3] 
} tImage;

The format of the image data is dependent upon the number of bits per pixel

and the use of compression.

When compression is used, the uncompressed data will match the data

that would appear in the image data for non-compressed images.

For 1 bit per pixel images,

the image data is simply a sequence of bytes that describe the pixels in the image.

Bits that are on represent pixels that should be drawn in the foreground color,
and bits that are off represent pixels that should be drawn in the background color.
The data is organized in row major order,
with the first byte containing the left-most 8 pixels of the first scan line.
The most significant bit of each byte corresponds to the left-most pixel,
and padding bits are added at the end each scan line (if required)
in order to ensure that each scan line starts at the beginning of a byte.

For 4 bits per pixel images,

the first byte of the image data is the number of actual palette entries

which is actually stored as N - 1; in other words, an 8 entry palette will have 7 in this byte.
The next bytes are the palette for the image, which each entry being organized as
a blue byte followed by a green byte followed by a red byte. < B G R >
 
Following the palette is the actual image data, where each nibble corresponds to an entry in the palette.
The bytes are organized the same as for 1 bit per pixel images,
and the most significant nibble of each byte corresponds to the left-most pixel.

For 8 bits per pixel images, 

the format is the same as 4 bits per pixel images 

with a larger palette and each byte containing exactly one pixel.

When the image data is compressed, the Lempel-Ziv-Storer-Szymanski algorithm < LZSS >
is used to compress the data.
This algorithm was originally published in the Journal of the ACM, 29(4):928-951, October 1982.
The essence of this algorithm is to use the N most recent output bytes as a dictionary;
the next encoded byte is either a literal byte (which is directly output) or
a dictionary reference of up to M sequential bytes.
For highly regular images (such as would be used for typical graphical controls), this works very well.
The compressed data is arranged as a sequence of 9 byte chunks.
The first byte is a set of flags that indicate if the next 8 bytes
are literal or dictionary references (one bit per byte).

The most significant bit of the flags corresponds to the first byte.

If the flag is clear, the byte is a literal;
if it is set, the byte is a dictionary reference
where the upper five bits are the dictionary offset and
the lower three bits are the reference length (where 0 is 2 bytes, 1 is 3 bytes, and so on).
Since a one byte dictionary reference takes one byte to encode, it is always stored as a literal
so that length is able to range from 2 through 9 (providing a longer possible dictionary reference).
The last 9 byte chunk may be truncated if all 8 data bytes are not required to encode the entire data sequence.
A utility (pnmtoc) is provided to assist in converting images into this format; it is documented in chapter 13.

 

转载于:https://www.cnblogs.com/shangdawei/archive/2013/05/15/3080682.html

你可能感兴趣的文章
Python入门-函数
查看>>
[HDU5727]Necklace(二分图最大匹配,枚举)
查看>>
距离公式汇总以及Python实现
查看>>
设计模式之装饰者模式
查看>>
一道不知道哪里来的容斥题
查看>>
Blender Python UV 学习
查看>>
window添加右键菜单
查看>>
入手腾龙SP AF90mm MACRO
查看>>
Window7上搭建symfony开发环境(PEAR)
查看>>
Linux内核态、用户态简介与IntelCPU特权级别--Ring0-3
查看>>
第23月第24天 git命令 .git-credentials git rm --cached git stash clear
查看>>
java SE :标准输入/输出
查看>>
一些方便系统诊断的bash函数
查看>>
jquery中ajax返回值无法传递到上层函数
查看>>
css3之transform-origin
查看>>
[转]JavaScript快速检测浏览器对CSS3特性的支持
查看>>
Master选举原理
查看>>
[ JAVA编程 ] double类型计算精度丢失问题及解决方法
查看>>
小别离
查看>>
微信小程序-发起 HTTPS 请求
查看>>