#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "rle.h"
Go to the source code of this file.
|
#define | MAXCOLORMAPSIZE 256 |
|
#define | TRUE 1 |
|
#define | FALSE 0 |
|
#define | CM_RED 0 |
|
#define | CM_GREEN 1 |
|
#define | CM_BLUE 2 |
|
#define | MAX_LWZ_BITS 12 |
|
#define | ReadOK(file, buffer, len) (fread(buffer,len,1,file)!=0) |
|
#define | EasyFail(str, status) {fprintf(stderr,str);return(status);} |
|
#define | HardFail(str, status) {fprintf(stderr,str);exit (status);} |
|
#define | LM_to_uint(a, b) (((b)<<8)|(a)) |
|
|
int | ReadGIF () |
|
int | ReadColorMap () |
|
int | IgnoreExtention () |
|
int | GetCode () |
|
int | LWZReadByte () |
|
int | ReadRaster () |
|
void | main (int argc, char **argv) |
|
int | ReadGIF (char *filename) |
|
int | ReadColorMap (FILE *fd, int number, buffer) |
|
int | IgnoreExtention (FILE *fd) |
|
int | GetCode (FILE *fd, int code_size, int flag) |
|
int | LWZReadByte (FILE *fd, int flag, int input_code_size) |
|
int | ReadRaster (int interlace, FILE *fd, int len, int height, cmap) |
|
#define LM_to_uint |
( |
|
a, |
|
|
|
b |
|
) |
| (((b)<<8)|(a)) |
#define MAXCOLORMAPSIZE 256 |
#define ReadOK |
( |
|
file, |
|
|
|
buffer, |
|
|
|
len |
|
) |
| (fread(buffer,len,1,file)!=0) |
int GetCode |
( |
FILE * |
fd, |
|
|
int |
code_size, |
|
|
int |
flag |
|
) |
| |
Definition at line 212 of file giftorle.c.
217 static unsigned char buf[280];
218 static int curbit,lastbit,
done,last_byte;
229 if ( (curbit+code_size) >= lastbit) {
232 EasyFail(
"Ran off the end of my bits\n",-1);
234 buf[0] = buf[last_byte-2];
235 buf[1] = buf[last_byte-1];
237 EasyFail(
"Error in getting buffer size\n",-1);
241 }
else if (!
ReadOK(
fd,&buf[2],count))
242 EasyFail(
"Error in getting buffer\n",-1);
243 last_byte = 2 + count;
244 curbit = (curbit - lastbit) + 16;
245 lastbit = (2+count)*8 ;
249 for( i = curbit, j = 0; j < code_size; i++, j++ )
250 ret |= ((buf[ i / 8 ] & (1 << (i % 8))) != 0) << j;
#define EasyFail(str, status)
#define ReadOK(file, buffer, len)
int IgnoreExtention |
( |
FILE * |
fd | ) |
|
Definition at line 195 of file giftorle.c.
198 static char buf[256];
206 if (read(
fd,buf,(
int) c)!=(
int) c)
#define EasyFail(str, status)
#define ReadOK(file, buffer, len)
int LWZReadByte |
( |
FILE * |
fd, |
|
|
int |
flag, |
|
|
int |
input_code_size |
|
) |
| |
Definition at line 258 of file giftorle.c.
263 static int fresh=
FALSE;
265 static int code_size,set_code_size;
266 static int max_code,max_code_size;
267 static int firstcode,oldcode;
268 static int clear_code,end_code;
274 set_code_size = input_code_size;
275 code_size = set_code_size+1;
276 clear_code = 1 << set_code_size ;
277 end_code = clear_code + 1;
278 max_code_size = 2*clear_code;
279 max_code = clear_code+2;
285 for (
i=0;
i<clear_code;
i++) {
290 table[0][
i] = table[1][0] = 0;
300 }
while (firstcode == clear_code);
308 if (code == clear_code) {
309 for (
i=0;
i<clear_code;
i++) {
314 table[0][
i] = table[1][
i] = 0;
315 code_size = set_code_size+1;
316 max_code_size = 2*clear_code;
317 max_code = clear_code+2;
322 }
else if (code == end_code) {
326 while (
ReadOK(
fd,&count,1) && (count!=0))
327 while (count-->0 &&
ReadOK(
fd,&junk,1));
329 EasyFail(
"missing EOD in data stream (common occurance)\n",-3);
335 if (code >= max_code) {
340 while (code >= clear_code) {
341 *sp++ = table[1][code];
342 if (code == table[0][code])
343 EasyFail(
"Circular table entry BIG ERROR\n",-1);
344 code = table[0][code];
347 *sp++ = firstcode = table[1][code];
350 table[0][code] = oldcode;
351 table[1][code] = firstcode;
353 if ((max_code >= max_code_size) &&
#define EasyFail(str, status)
#define ReadOK(file, buffer, len)
void main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Definition at line 75 of file giftorle.c.
79 int oflag = 0, nfname = 0;
80 char *outfname = NULL, **
infname = NULL;
84 if (
scanargs( argc, argv,
"% c%- o%-outfile.rle!s infile.gif%*s",
86 &nfname, &infname ) == 0 )
97 while ( nfname-- > 0 )
static int output_colormap
int scanargs(int argc, char **argv, const char *format,...)
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
char * cmd_name(char **argv)
Definition at line 176 of file giftorle.c.
182 unsigned char rgb[3];
184 for (i=0;i<number;i++) {
#define EasyFail(str, status)
#define ReadOK(file, buffer, len)
int ReadGIF |
( |
char * |
filename | ) |
|
Definition at line 103 of file giftorle.c.
106 unsigned char buf[16];
110 int use_global_colormap;
118 if (strncmp((
char *)buf,
"GIF87a",6)!=0)
119 EasyFail(
"bad magic number (version mismatch?)\n",
TRUE);
124 Screen.BitPixel = 2<<(buf[4]&0x07);
125 Screen.ColorResolution = (((buf[4]&0x70)>>3)+1);
126 Screen.Background = buf[5];
127 if ((buf[4]&0x80)==0x80) {
145 fprintf(stderr,
"Bogus character ignoring '%c'\n",c);
156 if ((buf[8]&0x80)==0x80)
157 use_global_colormap =
FALSE ;
159 use_global_colormap =
TRUE ;
161 bit_pixel = 1<<((buf[8]&0x07)+1);
163 if (! use_global_colormap) {
170 use_global_colormap?
Screen.ColorMap:LocalColorMap))
#define EasyFail(str, status)
#define ReadOK(file, buffer, len)
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
Definition at line 369 of file giftorle.c.
382 int ypos=0,
pass=interlace ? 0 : 4;
388 EasyFail(
"Unable to malloc space for pixels #1\n",1);
394 if (scanline[j][i]!=NULL) free(scanline[i]);
395 EasyFail(
"Unable to malloc space for pixels #2\n",1);
408 for (i=0;i<(1<<8);i++) {
421 hdr.
ymax = height - 1;
432 scanline[
RLE_RED][ypos][xpos] = v ;
452 fprintf( stderr,
"%s: Data past end of image.\n", hdr.
cmd );
455 if (ypos >= height) {
471 for ( i = height - 1; i >= 0; i-- ) {
483 if (scanline[0][i]!=NULL) free(scanline[0][i]);
486 if (scanline[1][i]!=NULL) free(scanline[1][i]);
487 if (scanline[2][i]!=NULL) free(scanline[2][i]);
static int output_colormap
#define RLE_SET_BIT(glob, bit)
#define EasyFail(str, status)
#define ReadOK(file, buffer, len)
void rle_putrow(rle_pixel *rows[], int rowlen, rle_hdr *the_hdr)
void rle_puteof(rle_hdr *the_hdr)
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
static rle_map out_map[3 *(1<< 8)]
void rle_put_setup(rle_hdr *the_hdr)
unsigned char scanline[4][1280]
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
unsigned char ColorMap[3][256] |
unsigned int ColorResolution |
const char* MY_NAME = "giftorle" |
char rcsid[] = "$Id: giftorle.c,v 3.0.1.4 1992/04/30 13:56:24 spencer Exp spencer $" |
|
static |