File: example.c

package info (click to toggle)
imgstar 1.1-4
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 972 kB
  • ctags: 529
  • sloc: ansic: 7,264; makefile: 111
file content (54 lines) | stat: -rw-r--r-- 2,018 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/****************************************************************************/
/*                                                                          */
/* Program:   example.c                                                     */
/* Author:    Simon A.J. Winder                                             */
/* Date:      Thu Oct 20 20:45:30 1994                                      */
/* Copyright (C) 1994 Simon A.J. Winder                                     */
/*                                                                          */
/* Demonstration program to invert the pixels in a pgm image.               */
/* compile with:                                                            */
/*     gcc example.c -o example -ILibSrc -LLibSrc -limg                     */
/* or  gcc example.c -o example LibSrc/libimg.a -ILibSrc                    */
/* If you have xv and an image then test with:                              */
/*     example <venice.pgm |xv -                                            */
/*                                                                          */
/****************************************************************************/

#include <stdio.h>
#include "image.h"

int main(void)
{
  it_image *image;
  int x,y,width,height,pix;

  /* Read in the image from stdin */
  image=i_read_image_file(stdin,IT_BYTE,IM_CONTIG);
  if(image==NULL)
    {
      /* Error case - Note that to print messages you need to */
      /* use stderr because stdout is already used to output  */
      /* the image. */
      fprintf(stderr,"Error: failed to import image file.\n");
      return(1);
    }

  /* Find out how big it is */
  width=image->width;
  height=image->height;

  /* Invert the pixels */
  for(y=0;y<height;y++)
    for(x=0;x<width;x++)
      {
	pix=im_byte_value(image,x,y);
	pix=255-pix;
	im_byte_value(image,x,y)=pix;
      }

  /* Write the image out to stdout */
  i_write_image_file(stdout,image,IF_BINARY);

  return(0);
}
/* Version 1.1 (Nov 1994) */