📄 index2ppm.c
字号:
/*****************************************************************************/
/* Copyright 1999, Sharp Labs. of America. */
/* All rights reserved */
/* File: "index2ppm.c" */
/* Description: convert index map and table to ppm file */
/* Author: Wenjun Zeng */
/* Affiliation: Sharp Labs. of America., zengw@sharplabs.com */
/* Version: VM6.0 */
/* Last Revised: 4 Jan, 2000 */
/*****************************************************************************/
/*_______________________________________________________________
| |
| |
| reconstruct a .ppm file from the index image (in .pgx format)|
| and the color palette table |
| currently limited to max. of 256 colors |
| (i.e., bitdepth of pgx file <=8) |
| |
_______________________________________________________________*/
#include <stdio.h>
#include "palette.h"
main( int argc, char **argv)
{
FILE *ptin;
unsigned int rows, cols;
int *buff,*ptr;
int i,j;
int *buff_tbl, *buff_rgb, *ptr_rgb;
int entries, comp, length;
/* CheckUsage */
if (argc!=4)
{
fprintf(stderr,"usage: index2ppm input(.pgx) input(.tbl) output(.ppm), \n");
exit(-1);
}
/* open index image in pgx format */
ptin =read_pgx_header (argv[1],&rows,&cols);
buff=(unsigned int *)alloc_int1(rows*cols);
read_int_1D_raw(ptin,buff,rows*cols);
/* open table file (one header line following by raw data) */
ptin =read_tbl_header(argv[2],&entries,&comp);
length=entries*comp;
buff_tbl=(unsigned int *)alloc_int1(length);
read_int_1D_raw(ptin,buff_tbl,length);
buff_rgb=(unsigned int *)alloc_int1(rows*cols*comp);
ptr_rgb=buff_rgb;
ptr=buff;
for (i=0; i<rows*cols; i++)
{
for (j=0; j<comp;j++)
*ptr_rgb++= *(buff_tbl+(*ptr) * comp+j);
ptr++;
}
write_int_1D_ppm(argv[3],buff_rgb,rows,cols);
free_int1(buff_tbl);
free_int1(buff_rgb);
free_int1(buff);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -