[xiph-cvs] cvs commit: w3d/tools deinterlace.c Makefile

Holger Waechtler holger at xiph.org
Tue Aug 7 07:18:08 PDT 2001



holger      01/08/07 07:18:08

  Modified:    tools    Makefile
  Added:       tools    deinterlace.c
  Log:
  The deinterlacer. Works, but can still get better ...

Revision  Changes    Path
1.4       +4 -1      w3d/tools/Makefile

Index: Makefile
===================================================================
RCS file: /usr/local/cvsroot/w3d/tools/Makefile,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Makefile	2001/08/06 10:40:05	1.3
+++ Makefile	2001/08/07 14:18:07	1.4
@@ -4,7 +4,7 @@
 CFLAGS = -g -O0 -Wall -I.. -DTYPE=uint16_t
 LFLAGS = -g
 
-TARGETS = ppmdiff yuv2ppm
+TARGETS = ppmdiff yuv2ppm deinterlace
 
 OBJS = $(TARGETS:=.o) ../pnm.o
 SRCS = $(OBJS:.o=.c)
@@ -17,6 +17,9 @@
 
 yuv2ppm: yuv2ppm.o ../pnm.o
         $(CC) $(LFLAGS) yuv2ppm.o ../pnm.o -o $@
+
+deinterlace: deinterlace.o ../pnm.o
+	$(CC) $(LFLAGS) deinterlace.o ../pnm.o -o $@
 
 .c.o: .depend
         $(CC) $(CFLAGS) -c $< -o $@

1.1                  w3d/tools/deinterlace.c

Index: deinterlace.c
===================================================================

#include <stdint.h>
#include <stdio.h>
#include "../pnm.h"
#include "../mem.h"

static
void usage (char *progname)
{
   printf ("\n"
           "usage: %s <in.ppm> <out.ppm>\n"
           "\n"
           "        where <in.ppm> is the input filename template\n"
           "        and <out.ppm> is a template like image%%03d.ppm\n"
           "\n", progname);
   exit (-1);
}

/**
 *  w in bytes ( == width * channels)
 */
static
void write_even_scanlines (uint8_t *in, uint8_t *out, int w, int h)
{
   uint8_t *prev, *next, *this;
   int i, j;

   for (i=0; i<h; i+=2)
      memcpy (out + i * w * sizeof(uint8_t), in + i * w * sizeof(uint8_t),
              w * sizeof(uint8_t));

   for (j=1; j<h-1; j+=2) {
      this = out + j*w;
      next = this + w;
      prev = this - w;

      for (i=0; i<w; i++)
         this[i] = (prev[i] + next[i]) / 2;
   }

   this = out + (h-1) * w;
   prev = this - w;
   for (i=0; i<w; i++)
      this[i] = prev[i];
}

static
void write_odd_scanlines (uint8_t *in, uint8_t *out, int w, int h)
{
   uint8_t *prev, *next, *this;
   int i, j;

   for (i=1; i<h; i+=2)
      memcpy (out + i * w * sizeof(uint8_t), in + i * w * sizeof(uint8_t),
              w * sizeof(uint8_t));

   this = out;
   next = this + w;
   for (i=0; i<w; i++)
      this[i] = next[i];

   for (j=2; j<h; j+=2) {
      this = out + j*w;
      next = this + w;
      prev = this - w;

      for (i=0; i<w; i++)
         this[i] = (prev[i] + next[i]) / 2;
   }
}

int main (int argc, char **argv)
{
   int odd_lines_first = 1;
   int channels;
   int w, h;
   uint8_t *in, *out;
   int frame = 0;
   char fname[256];

   if (argc != 3)
      usage (argv[0]);

   snprintf (fname, 256, argv[1], 0);
   channels = read_pnm_header (fname, &w, &h);

   if (h == 576)
      odd_lines_first = 0;
   else if (h == 486) {
   } else {
      printf ("\n"
              "could not determine wheter odd scanlines come temporally\n"
              "earlier or later. Input files should have height 525 or 625 !\n"
              "\n"
              "assume odd lines first.\n"
              "\n");
   }

   in = (uint8_t*) MALLOC (channels * w * h * sizeof(uint8_t));
   out = (uint8_t*) MALLOC (channels * w * h * sizeof(uint8_t));

   do {
      snprintf (fname, 256, argv[1], frame);
      printf ("read '");
      printf (fname, frame);
      printf ("'");
      if (read_pnm (fname, in) < 0)
      {
         printf (" failed.\n");
         break;
      }
      printf ("\n");

      if (odd_lines_first) {
         write_odd_scanlines (in, out, w * channels, h);
         snprintf (fname, 256, argv[2], 2*frame);
         write_pnm (fname, out, w, h);
         write_even_scanlines (in, out, w * channels, h);
         snprintf (fname, 256, argv[2], 2*frame + 1);
         write_pnm (fname, out, w, h);
      } else {
         write_even_scanlines (in, out, w * channels, h);
         snprintf (fname, 256, argv[2], 2*frame);
         write_pnm (fname, out, w, h);
         write_odd_scanlines (in, out, w * channels, h);
         snprintf (fname, 256, argv[2], 2*frame + 1);
         write_pnm (fname, out, w, h);
      }
      frame++;
   } while (1);

   FREE(in);
   FREE(out);

   return 0;
}

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list