Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
Functions | Variables
rletogif.c File Reference
#include <stdio.h>
#include "rle.h"
#include "rletogif.h"
Include dependency graph for rletogif.c:

Go to the source code of this file.

Functions

int get_scanlines ()
 
int get_color_bits ()
 
void GIFEncode ()
 
void main (int argc, argv)
 
int get_color_bits (char **comments)
 
int getpixel (int x, int y)
 
void error (char *s)
 

Variables

const char * MY_NAME = "rletogif"
 
static rle_hdr in_hdr
 
static rle_pixel ** scan
 
static gif_pixel ** scanbuf
 
static int pix_mask
 

Function Documentation

void error ( char *  s)

Definition at line 160 of file rletogif.c.

162 {
163  fprintf(stderr,"%s\n", s);
164  exit(2);
165 }
_urt_stack * s
Definition: rleClock.c:919
int get_color_bits ( )
int get_color_bits ( char **  comments)

Definition at line 134 of file rletogif.c.

136 {
137  int i, color_bits, num_colors;
138 
139  color_bits = 8;
140  if (comments == NULL) return (color_bits);
141  for (i = 0; comments[i]; i++) {
142  if (!strncmp(comments[i],"color_map_length=",17)) {
143  num_colors = atoi(&(comments[i][17]));
144  for (color_bits = 1; num_colors >> color_bits; color_bits++);
145  if (num_colors == (1<<(color_bits-1))) color_bits--;
146  break;
147  }
148  }
149  if ((color_bits < 0) || (color_bits > 8))
150  error("invalid number of color bits");
151  return (color_bits);
152 }
char ** comments
Definition: read98721.c:74
int i
Definition: rletorla.c:82
void error(char *s)
Definition: rletogif.c:160
void get_scanlines ( )

Definition at line 102 of file rletogif.c.

References in_hdr, rle_getrow(), rle_row_alloc(), scan, scanbuf, rle_hdr::xmax, rle_hdr::ymax, and rle_hdr::ymin.

103 {
104  int i;
105  rle_pixel *save_scan_0;
106 
107 
108  if (sizeof(rle_pixel) != sizeof(gif_pixel))
109  error("rle pixel size not 8 bits");
110  if (rle_row_alloc(&in_hdr, &scan) < 0)
111  error("can't allocate scan");
112  save_scan_0 = scan[0];
113  scanbuf = (gif_pixel**)
114  malloc(sizeof(gif_pixel*)*(in_hdr.ymax-in_hdr.ymin+1));
115  if (scanbuf == NULL)
116  error("can't allocate scanbuf");
117  for (i = 0; i <= in_hdr.ymax - in_hdr.ymin; i++) {
118  scan[0] = (rle_pixel*)malloc(sizeof(rle_pixel)*(in_hdr.xmax+1));
119  if (scan[0] == NULL)
120  error("can't allocate current scanline");
123  }
124  scan[0] = save_scan_0;
125  return (1);
126 }
static rle_hdr in_hdr
Definition: rletogif.c:37
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
Definition: rle_row_alc.c:56
unsigned char gif_pixel
Definition: rletogif.h:10
static gif_pixel ** scanbuf
Definition: rletogif.c:39
int ymin
Definition: rle.h:100
int xmax
Definition: rle.h:100
int ymax
Definition: rle.h:100
unsigned char rle_pixel
Definition: rle.h:56
void * malloc()
int i
Definition: rletorla.c:82
static rle_pixel ** scan
Definition: rletogif.c:38
void error(char *s)
Definition: rletogif.c:160
int rle_getrow(rle_hdr *the_hdr, rle_pixel *scanline[])

Here is the call graph for this function:

int getpixel ( int  x,
int  y 
)

Definition at line 154 of file rletogif.c.

156 {
157  return pix_mask & (int)scanbuf[y][x];
158 }
static gif_pixel ** scanbuf
Definition: rletogif.c:39
static int y
Definition: getami.c:691
static int x
Definition: getami.c:691
static int pix_mask
Definition: rletogif.c:41
int
Definition: getami.c:848
void GIFEncode ( )
void main ( int  argc,
argv   
)

Definition at line 48 of file rletogif.c.

51 {
52  char *outfname = NULL,
53  *infname = NULL;
54  int oflag = 0;
55  int i, color_bits;
56 
57  MY_NAME = cmd_name( argv );
58 
59  if ( scanargs( argc, argv, "% o%-outfile.gif!s infile.rle%s",
60  &oflag, &outfname, &infname ) == 0 )
61  exit( 1 );
62 
63  in_hdr = *rle_hdr_init( (rle_hdr *)NULL );
64  rle_names( &in_hdr, MY_NAME, infname, 0 );
65  in_hdr.rle_file = rle_open_f( MY_NAME, infname, "r" );
66 
67  rle_get_setup_ok( &in_hdr, NULL, NULL);
69  in_hdr.xmin = 0;
70 
71  if (in_hdr.ncolors > 1) error("Input file should have only 1 channel.");
72 
73  get_scanlines();
74  color_bits = get_color_bits(in_hdr.comments);
75  if ( in_hdr.ncmap && color_bits > in_hdr.cmaplen )
76  color_bits = in_hdr.cmaplen;
77  else if ( in_hdr.ncmap == 0 )
78  {
79  in_hdr.cmap = (rle_map *)malloc( sizeof(rle_map) * (1 << color_bits) );
80  in_hdr.cmaplen = color_bits;
81  for ( i = 0; i < (1 << color_bits); i++ )
82  in_hdr.cmap[i] = i << (16 - color_bits);
83  }
84  pix_mask = (1 << color_bits) - 1;
85 
86  GIFEncode( outfname, in_hdr.xmax - in_hdr.xmin + 1,
87  in_hdr.ymax - in_hdr.ymin + 1, 0, 0,
88  color_bits, &in_hdr.cmap[0],
89  &in_hdr.cmap[in_hdr.ncmap > 1 ? 1 << in_hdr.cmaplen : 0],
90  &in_hdr.cmap[in_hdr.ncmap > 2 ? 2 << in_hdr.cmaplen : 0],
91  getpixel );
93  for (i = 0; i <= in_hdr.ymax - in_hdr.ymin; i++ ) free(scanbuf[i]);
94  free(scanbuf);
95 }
int getpixel(int x, int y)
Definition: rletogif.c:154
void GIFEncode()
void rle_row_free(rle_hdr *the_hdr, rle_pixel **scanp)
Definition: rle_row_alc.c:114
int get_color_bits()
int xmin
Definition: rle.h:100
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
static rle_hdr in_hdr
Definition: rletogif.c:37
const char ** comments
Definition: rle.h:113
rle_map * cmap
Definition: rle.h:112
static gif_pixel ** scanbuf
Definition: rletogif.c:39
int ymin
Definition: rle.h:100
string infname
Definition: getbob.c:68
int get_scanlines()
Definition: rletogif.c:102
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
Definition: rle.h:96
int xmax
Definition: rle.h:100
const char * MY_NAME
Definition: rletogif.c:35
static int pix_mask
Definition: rletogif.c:41
int ncmap
Definition: rle.h:100
int ymax
Definition: rle.h:100
void * malloc()
int cmaplen
Definition: rle.h:100
int i
Definition: rletorla.c:82
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
unsigned short rle_map
Definition: rle.h:57
static rle_pixel ** scan
Definition: rletogif.c:38
char * cmd_name(char **argv)
Definition: cmd_name.c:31
void error(char *s)
Definition: rletogif.c:160
int oflag
Definition: painttorle.c:45
void rle_get_setup_ok(rle_hdr *the_hdr, const char *prog_name, const char *file_name)
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

Variable Documentation

rle_hdr in_hdr
static

Definition at line 37 of file rletogif.c.

Referenced by get_scanlines().

const char* MY_NAME = "rletogif"

Definition at line 35 of file rletogif.c.

int pix_mask
static

Definition at line 41 of file rletogif.c.

rle_pixel** scan
static

Definition at line 38 of file rletogif.c.

Referenced by get_scanlines().

gif_pixel** scanbuf
static

Definition at line 39 of file rletogif.c.

Referenced by get_scanlines().