ftp.nice.ch/pub/next/graphics/convertors/CmdLineGIFeditor.s.tar.gz#/GIFeditor/main.c

This is main.c in view mode; [Download] [Up]

/*
 *  gifmod.c
 *  
 *  Jim W Kiraly
 *  July 27 1991
 *
 *  This program can be used to modify gif files colors maps.
 *  
 *  Usage:
 *    gifmod [-iscrgb] [[+/-]##] infile outfile
 *
 *  options:
 *   -i		invert color map (negative look)
 *   -s		grey scale an image
 *   -c 	contrast image by ##
 *   -r|g|b	set red, green, blue to absolute ## or add/sub value
 *		from each red, green, blue value
 *
 *  Examples:
 *  
 *    gifmod -i in.gif out.gif   -   Inverts an image
 *    gifmod -r 40 -g -1d -b +2B in.gif out.gif
 *
 *    -options can not be mixed with the exception of r|g|b.
 */


/*
 *  includes and other things
 *
 */


#include <stdio.h>
#include <math.h>
#include "gifver.h"

int ParseArgs();
int invertImage();
int greyImage();
int rgbImage();
int openFiles();
int contImage();

FILE *in, *out;
char *jargv[6];

/*
 * main - call parse args, and then do appropriate set ups
 *
 */


main ( argc, argv )
int argc;
char **argv;
{
  int routine;
  char *version=GIFVER;
  int count, colors;
  unsigned char byte;

  routine = ParseArgs ( argc, argv );

  if (routine==0) {
    fprintf ( stderr, "gifmod - version %s - by Jim Kiraly\n\n", version );
    fprintf ( stderr, "usage:\t%s [-isrgb] [{+/-}XX] in out\n\n", argv[0] );
    fprintf ( stderr, "\t -i - invert an image\n" );
    fprintf ( stderr, "\t -s - grey scale an image\n" );
    fprintf ( stderr, "\t -c {+/-} ## - adjust contrast by hex value\n" );
    fprintf ( stderr, "\t -r {+/-} ## - adjust red by hex value\n" );
    fprintf ( stderr, "\t -g or -b - same as red, for green and blue\n" );
    exit(0);
  }

  openFiles ( jargv[1], jargv[2] );

  for (count=1; count<=11; count++) {
    byte = getc(in);
    putc ( byte, out );
  }

  colors = byte & 0x07;
  colors++;
  colors = pow ( (double) 2.0, (double) colors );

  fprintf ( stderr, "%s: %d color image\n", argv[0], colors );

  byte = getc(in); 	putc ( byte, out );
  byte = getc(in);	putc ( byte, out );

  if (routine==1)
    invertImage ( colors );
 
  if (routine==2)
    greyImage ( colors );

  if (routine==3)
    rgbImage ( colors, jargv[3], jargv[4], jargv[5] ); 

  if (routine==4)
    contImage ( colors, jargv[3] );

  while (!feof(in)) {
    byte = getc(in);
    if (!feof(in))
      putc (byte, out);
  }
   
  fclose (in);
  fclose (out);
}



/*
 * openFiles - open the files and report errors
 *
 */


int openFiles ( inf, outf )
char *inf;
char *outf;
{

  in = (FILE *) fopen ( inf, "rb" );
  out = (FILE *) fopen ( outf, "wb" );

  if (in==(FILE *) NULL) {
    fprintf ( stderr, "error opening %s\n", inf );
    exit (-1);
  }

  if (out==(FILE *) NULL) {
    fprintf ( stderr, "error opening %s\n", outf );
    exit (-1);
  }
  return 1;
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.