LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2787|回复: 0

XPM文件格式分析

[复制链接]
发表于 2006-10-11 16:09:43 | 显示全部楼层 |阅读模式
该文翻译自XPM: Summary from the Encyclopedia of Graphics File Formats

XPM文件的基本结构是
/* XPM */
static char * <pixmap_name>[] = {
<Values>
<Colors>
<ixels>
<Extensions>
};

其中Values部分相当于图像文件的文件头,它由
<width> <height> <numcolors> <cpp> [ <x_hotspot> <y_hotspot> ] [ XPMEXT ]
构成,其中x_hotspot,y_hotspot,XPMEXT是可选的。
        width:图像的宽度,像素为单位
        height:图像的高度,像素为单位
        numcolors:颜色数
        cpp:每个像素占用的字符长度
        x_hotspot:热点的X轴位置
        y_hotspot:热点的Y轴位置

Colors部分定义的是调色板的信息,它由
<character> { <key> <color> } { <key> <color> }构成
        character是颜色索引值,key是关键字,color是颜色值
        key可以有以下几种选项:
                m:单色
                s:符号名称
                g4:4级灰度
                g:灰度
                c:彩色
        color也可以由以下几种构成:
                颜色名称
                #开头的十六进制数表示RGB空间颜色值
                %开头的十六禁止数表示HSV空间颜色值
                符号名称
                字符串NONE,表示该颜色是透明色

Pixels部分表示实际的像素,全部采用调色板中定义的索引,由等同于图像像素高度的行构成。

Extension部分可以自己定义一些图像附件信息,如作者,标题等,形如
XPMEXT <extension_name> <extension_data_string>单行的扩展
XPMEXT <extension_name>
                <extension_data_string1>
                <extension_data_string2>
多行的扩展
Extension部分必须以XPMENDEXT标志结束。
例子如:
/* XPM */
static char * plaid[] =
{
/* plaid pixmap */
/* width height ncolors chars_per_pixel */
"22 22 4 2 0 0 XPMEXT",
/* colors */
"   c red       m white  s light_color",
"Y  c green     m black  s ines_in_mix",
"+  c yellow    m white  s lines_in_dark ",
"x              m black  s dark_color ",
/* pixels */
"x   x   x x x   x   x x x x x x + x x x x x ",
"  x   x   x   x   x   x x x x x x x x x x x ",
"x   x   x x x   x   x x x x x x + x x x x x ",
"  x   x   x   x   x   x x x x x x x x x x x ",
"x   x   x x x   x   x x x x x x + x x x x x ",
"Y Y Y Y Y x Y Y Y Y Y + x + x + x + x + x + ",
"x   x   x x x   x   x x x x x x + x x x x x ",
"  x   x   x   x   x   x x x x x x x x x x x ",
"x   x   x x x   x   x x x x x x + x x x x x ",
"  x   x   x   x   x   x x x x x x x x x x x ",
"x   x   x x x   x   x x x x x x + x x x x x ",
"          x               x x x Y x x x ",
"          x             x   x   Y   x   x   ",
"          x               x x x Y x x x ",
"          x             x   x   Y   x   x   ",
"          x               x x x Y x x x ",
"x x x x x x x x x x x x x x x x x x x x x x ",
"          x               x x x Y x x x ",
"          x             x   x   Y   x   x   ",
"          x               x x x Y x x x ",
"          x             x   x   Y   x   x   ",
"          x               x x x Y x x x ",
"XPMEXT ext1 data1",
"XPMEXT ext2",
"data2_1",
"data2_2",
"XPMEXT ext3",
"data3",
"XPMEXT",
"data4",
"XPMENDEXT"
};
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表