Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
Data Structures | Macros | Functions
rletotarga.c File Reference
#include <stdio.h>
#include <sys/types.h>
#include "rle.h"
Include dependency graph for rletotarga.c:

Go to the source code of this file.

Data Structures

struct  targafile
 

Macros

#define PUTBYTE(N)   putc((N)&0xff,outfile)
 
#define PUTSHORT(N)   (putc((N)&0xff,outfile),putc(((N)>>8)&0xff,outfile))
 

Functions

void main (int argc, argv)
 

Macro Definition Documentation

#define PUTBYTE (   N)    putc((N)&0xff,outfile)

Definition at line 44 of file rletotarga.c.

#define PUTSHORT (   N)    (putc((N)&0xff,outfile),putc(((N)>>8)&0xff,outfile))

Definition at line 45 of file rletotarga.c.

Function Documentation

void main ( int  argc,
argv   
)

Definition at line 66 of file rletotarga.c.

69 {
70  FILE *outfile;
71  char *infname=NULL,
72  *outfname=NULL;
73  int aflag=0;
74  unsigned i, j;
75  rle_hdr hdr;
76  rle_pixel **inprows;
77  struct targafile tga_head;
78 
79  if ( scanargs( argc, argv, "% o!-outfile!s infile%s\n(\
80 \tConvert RLE file to TARGA format.\n\
81 \tNote that output file name is required.)", &i, &outfname, &infname ) == 0 )
82  exit( 1 );
83 
84  hdr = *rle_hdr_init( (rle_hdr *)NULL );
85  rle_names( &hdr, cmd_name( argv ), infname, 0 );
86 
87  /* Open specified input file (or stdin if none) */
88  hdr.rle_file = rle_open_f(hdr.cmd, infname, "r");
89  outfile = rle_open_f(hdr.cmd, outfname, "w");
90 
91  /* Read the image header */
92 
93  rle_get_setup_ok(&hdr, NULL, NULL);
94 
95  /* Fill in the TARGA image header */
96 
98  tga_head.cmap_type = 0;
99 
100  tga_head.cmap_origin = 0;
101  tga_head.cmap_length = 0;
102  tga_head.cmap_size = 0;
103 
106  tga_head.image_width = hdr.xmax - hdr.xmin + 1;
107  tga_head.image_height = hdr.ymax - hdr.ymin + 1;
108 
110 
111  switch (hdr.ncolors)
112  {
113  case 1: /* Black and White image type */
114  tga_head.image_type = 3;
116  break;
117 
118  case 3: /* Real-Color image */
119  tga_head.image_type = 2;
121  if (hdr.alpha)
122  {
123  aflag = 1;
125  tga_head.image_descriptor = 0x08; /* Indicate 8 alpha bits */
126  }
127  break;
128 
129  default:
130  fprintf(stderr,"%s: Invalid number of color channels (%d).\n",
131  hdr.cmd, hdr.ncolors);
132  exit(1);
133  }
134 
135  /* Allocate pixel buffer */
136 
137  if (rle_row_alloc(&hdr,&inprows))
138  {
139  fprintf(stderr,"%s: Not enough memory.\n", hdr.cmd);
140  exit(1);
141  }
142 
143  /* Write the TARGA image header */
144 
148 
152 
158 
160 
161  /* Process the RLE image data */
162 
163  for (i=0;i<tga_head.image_height;i++)
164  {
165  rle_getrow(&hdr,inprows);
166 
167  if (tga_head.image_pix_size==8)
168  fwrite(inprows[0],1,tga_head.image_width,outfile);
169  else
170  for (j=0;j<tga_head.image_width;j++)
171  {
172  PUTBYTE(inprows[2][j]); /* Blue plane */
173  PUTBYTE(inprows[1][j]); /* Green plane */
174  PUTBYTE(inprows[0][j]); /* Red plane */
175  if (aflag) PUTBYTE(inprows[-1][j]); /* Alpha plane */
176  }
177  }
178 
179  fclose(hdr.rle_file);
180  fclose(outfile);
181 }
int xmin
Definition: rle.h:100
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
FILE * outfile
Definition: giftorle.c:61
unsigned char image_pix_size
Definition: rletotarga.c:61
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
Definition: rle_row_alc.c:56
unsigned short image_width
Definition: rletotarga.c:57
unsigned char image_descriptor
Definition: rletotarga.c:61
rle_hdr hdr
Definition: iristorle.c:35
int ymin
Definition: rle.h:100
unsigned char cmap_type
Definition: rletotarga.c:51
string infname
Definition: getbob.c:68
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
#define PUTSHORT(N)
Definition: rletotarga.c:45
#define PUTBYTE(N)
Definition: rletotarga.c:44
const char * cmd
Definition: rle.h:133
Definition: rle.h:96
int xmax
Definition: rle.h:100
unsigned char image_type
Definition: rletotarga.c:51
unsigned short cmap_origin
Definition: rletotarga.c:54
int ymax
Definition: rle.h:100
unsigned short image_x_origin
Definition: rletotarga.c:57
unsigned char rle_pixel
Definition: rle.h:56
int i
Definition: rletorla.c:82
int alpha
Definition: rle.h:100
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
unsigned short cmap_length
Definition: rletotarga.c:54
char * cmd_name(char **argv)
Definition: cmd_name.c:31
struct targafile tga_head
Definition: targatorle.c:111
unsigned char num_char_id
Definition: rletotarga.c:51
unsigned short image_height
Definition: rletotarga.c:57
unsigned char cmap_size
Definition: rletotarga.c:56
void rle_get_setup_ok(rle_hdr *the_hdr, const char *prog_name, const char *file_name)
int rle_getrow(rle_hdr *the_hdr, rle_pixel *scanline[])
unsigned short image_y_origin
Definition: rletotarga.c:57
FILE * rle_file
Definition: rle.h:114
int ncolors
Definition: rle.h:100
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267