about summary refs log tree commit diff
path: root/converter/other/fiasco/input/read.c
diff options
context:
space:
mode:
Diffstat (limited to 'converter/other/fiasco/input/read.c')
-rw-r--r--converter/other/fiasco/input/read.c354
1 files changed, 177 insertions, 177 deletions
diff --git a/converter/other/fiasco/input/read.c b/converter/other/fiasco/input/read.c
index c3aa77a8..50e271e5 100644
--- a/converter/other/fiasco/input/read.c
+++ b/converter/other/fiasco/input/read.c
@@ -1,7 +1,7 @@
 /*
- *  read.c:		Input of WFA files
+ *  read.c:             Input of WFA files
  *
- *  Written by:		Ullrich Hafner
+ *  Written by:         Ullrich Hafner
  *
  *  This file is part of FIASCO (Fractal Image And Sequence COdec)
  *  Copyright (C) 1994-2000 Ullrich Hafner
@@ -46,17 +46,17 @@
 
 /*****************************************************************************
 
-				prototypes
+                                prototypes
 
 *****************************************************************************/
 
 static void
 read_tiling (tiling_t *tiling, unsigned image_width, unsigned image_height,
-	     unsigned image_level, bitfile_t *input);
+             unsigned image_level, bitfile_t *input);
 
 /*****************************************************************************
 
-				public code
+                                public code
 
 *****************************************************************************/
 
@@ -66,14 +66,14 @@ open_wfa (const char *filename, wfa_info_t *wi)
  *  Open WFA file 'filename' and read header information.
  *
  *  Return value:
- *	Pointer to input stream (fileposition: first WFA frame)
+ *      Pointer to input stream (fileposition: first WFA frame)
  *
  *  Side effects:
- *	The values of the header of 'filename' are copied to 'wfainfo'.
+ *      The values of the header of 'filename' are copied to 'wfainfo'.
  *
  */
 {
-   bitfile_t *input;			/* pointer to WFA bitfile */
+   bitfile_t *input;                    /* pointer to WFA bitfile */
 
    assert (filename && wi);
 
@@ -83,7 +83,7 @@ open_wfa (const char *filename, wfa_info_t *wi)
     *  Check whether 'filename' is a regular WFA file
     */
    {
-      unsigned 	n;
+      unsigned  n;
       const char     *str;
 
       if (!(input = open_bitfile (filename, "FIASCO_DATA", READ_ACCESS)))
@@ -92,57 +92,57 @@ open_wfa (const char *filename, wfa_info_t *wi)
       for (str = FIASCO_MAGIC, n = strlen (FIASCO_MAGIC); n; n--)
           if (get_bits (input, 8) != (unsigned) *str++)
               error ("Input file %s is not a valid FIASCO file!", filename);
-      get_bits (input, 8);		/* fetch newline */
+      get_bits (input, 8);              /* fetch newline */
    }
 
    /*
     *  Read WFA header information
     */
    {
-      char	      basis_name [MAXSTRLEN]; /* temp. buffer */
-      const unsigned  rice_k = 8; 	/* parameter of Rice Code */
-      char     	     *str    = basis_name;
+      char            basis_name [MAXSTRLEN]; /* temp. buffer */
+      const unsigned  rice_k = 8;       /* parameter of Rice Code */
+      char           *str    = basis_name;
 
       while ((*str++ = get_bits (input, 8)) != 0
-	     && str < basis_name + MAXSTRLEN)
-	 ;
+             && str < basis_name + MAXSTRLEN)
+         ;
       if (str == basis_name + MAXSTRLEN)
-	 error ("Input file %s is not a valid FIASCO file!", filename);
+         error ("Input file %s is not a valid FIASCO file!", filename);
 
       {
-	 wi->release = read_rice_code (rice_k, input);
+         wi->release = read_rice_code (rice_k, input);
 
-	 if (wi->release > FIASCO_BINFILE_RELEASE)
-	    error ("Can't decode FIASCO files of file format release `%d'."
-		   "\nCurrent file format release is `%d'.", wi->release,
-		   FIASCO_BINFILE_RELEASE);
+         if (wi->release > FIASCO_BINFILE_RELEASE)
+            error ("Can't decode FIASCO files of file format release `%d'."
+                   "\nCurrent file format release is `%d'.", wi->release,
+                   FIASCO_BINFILE_RELEASE);
       }
 
       if (wi->release > 1)
       {
-	 header_type_e type;
-
-	 while ((type = read_rice_code (rice_k, input)) != HEADER_END)
-	 {
-	    char     buffer [MAXSTRLEN];
-	    unsigned n = 0;
-
-	    switch (type)
-	    {
-	       case HEADER_TITLE:
-		  while ((buffer [n++] = get_bits (input, 8)))
-		     ;
-		  wi->title = strdup (buffer);
-		  break;
-	       case HEADER_COMMENT:
-		  while ((buffer [n++] = get_bits (input, 8)))
-		     ;
-		  wi->comment = strdup (buffer);
-		  break;
-	       default:			/* should not happen */
-		  break;
-	    }
-	 }
+         header_type_e type;
+
+         while ((type = read_rice_code (rice_k, input)) != HEADER_END)
+         {
+            char     buffer [MAXSTRLEN];
+            unsigned n = 0;
+
+            switch (type)
+            {
+               case HEADER_TITLE:
+                  while ((buffer [n++] = get_bits (input, 8)))
+                     ;
+                  wi->title = strdup (buffer);
+                  break;
+               case HEADER_COMMENT:
+                  while ((buffer [n++] = get_bits (input, 8)))
+                     ;
+                  wi->comment = strdup (buffer);
+                  break;
+               default:                 /* should not happen */
+                  break;
+            }
+         }
       }
 
       wi->basis_name = strdup (basis_name);
@@ -155,65 +155,65 @@ open_wfa (const char *filename, wfa_info_t *wi)
        *  Compute bintree level
        */
       {
-	 unsigned lx = log2 (wi->width - 1) + 1;
-	 unsigned ly = log2 (wi->height - 1) + 1;
+         unsigned lx = log2 (wi->width - 1) + 1;
+         unsigned ly = log2 (wi->height - 1) + 1;
 
-	 wi->level = MAX(lx, ly) * 2 - ((ly == lx + 1) ? 1 : 0);
+         wi->level = MAX(lx, ly) * 2 - ((ly == lx + 1) ? 1 : 0);
       }
       wi->chroma_max_states = wi->color ? read_rice_code (rice_k, input) : -1;
       wi->p_min_level       = read_rice_code (rice_k, input);
       wi->p_max_level       = read_rice_code (rice_k, input);
       wi->frames            = read_rice_code (rice_k, input);
-      wi->smoothing	    = read_rice_code (rice_k, input);
+      wi->smoothing         = read_rice_code (rice_k, input);
 
       /*
        *  Read RPF models from disk
        */
       {
-	 unsigned 	    mantissa;
-	 fiasco_rpf_range_e range;
-
-	 mantissa = get_bits (input, 3) + 2;
-	 range    = get_bits (input, 2);
-	 wi->rpf  = alloc_rpf (mantissa, range);
-
-	 if (get_bit (input))		/* different DC model */
-	 {
-	    mantissa   = get_bits (input, 3) + 2;
-	    range      = get_bits (input, 2);
-	    wi->dc_rpf = alloc_rpf (mantissa, range);
-	 }
-	 else				/* use same model for DC coefficients */
-	    wi->dc_rpf = alloc_rpf (wi->rpf->mantissa_bits,
-				    wi->rpf->range_e);
-
-	 if (get_bit (input))		/* different delta model */
-	 {
-	    mantissa  = get_bits (input, 3) + 2;
-	    range     = get_bits (input, 2);
-	    wi->d_rpf = alloc_rpf (mantissa, range);
-	 }
-	 else
-	    wi->d_rpf = alloc_rpf (wi->rpf->mantissa_bits,
-				   wi->rpf->range_e);
-
-	 if (get_bit (input))		/* different DC delta model */
-	 {
-	    mantissa  	 = get_bits (input, 3) + 2;
-	    range     	 = get_bits (input, 2);
-	    wi->d_dc_rpf = alloc_rpf (mantissa, range);
-	 }
-	 else
-	    wi->d_dc_rpf = alloc_rpf (wi->dc_rpf->mantissa_bits,
-				      wi->dc_rpf->range_e);
+         unsigned           mantissa;
+         fiasco_rpf_range_e range;
+
+         mantissa = get_bits (input, 3) + 2;
+         range    = get_bits (input, 2);
+         wi->rpf  = alloc_rpf (mantissa, range);
+
+         if (get_bit (input))           /* different DC model */
+         {
+            mantissa   = get_bits (input, 3) + 2;
+            range      = get_bits (input, 2);
+            wi->dc_rpf = alloc_rpf (mantissa, range);
+         }
+         else                           /* use same model for DC coefficients */
+            wi->dc_rpf = alloc_rpf (wi->rpf->mantissa_bits,
+                                    wi->rpf->range_e);
+
+         if (get_bit (input))           /* different delta model */
+         {
+            mantissa  = get_bits (input, 3) + 2;
+            range     = get_bits (input, 2);
+            wi->d_rpf = alloc_rpf (mantissa, range);
+         }
+         else
+            wi->d_rpf = alloc_rpf (wi->rpf->mantissa_bits,
+                                   wi->rpf->range_e);
+
+         if (get_bit (input))           /* different DC delta model */
+         {
+            mantissa     = get_bits (input, 3) + 2;
+            range        = get_bits (input, 2);
+            wi->d_dc_rpf = alloc_rpf (mantissa, range);
+         }
+         else
+            wi->d_dc_rpf = alloc_rpf (wi->dc_rpf->mantissa_bits,
+                                      wi->dc_rpf->range_e);
       }
 
-      if (wi->frames > 1)		/* motion compensation stuff */
+      if (wi->frames > 1)               /* motion compensation stuff */
       {
-	 wi->fps           = read_rice_code (rice_k, input);
-	 wi->search_range  = read_rice_code (rice_k, input);
-	 wi->half_pixel    = get_bit (input) ? YES : NO;
-	 wi->B_as_past_ref = get_bit (input) ? YES : NO;
+         wi->fps           = read_rice_code (rice_k, input);
+         wi->search_range  = read_rice_code (rice_k, input);
+         wi->half_pixel    = get_bit (input) ? YES : NO;
+         wi->B_as_past_ref = get_bit (input) ? YES : NO;
       }
    }
 
@@ -230,12 +230,12 @@ read_basis (const char *filename, wfa_t *wfa)
  *  No return value.
  *
  *  Side effects:
- *	wfa->into, wfa->weights, wfa->final_distribution, wfa->basis_states
- *	wfa->domain_type wfa->wfainfo->basis_name, are filled with the
- *	values of the WFA basis.
+ *      wfa->into, wfa->weights, wfa->final_distribution, wfa->basis_states
+ *      wfa->domain_type wfa->wfainfo->basis_name, are filled with the
+ *      values of the WFA basis.
  */
 {
-   FILE	*input;				/* ASCII WFA initial basis file */
+   FILE *input;                         /* ASCII WFA initial basis file */
 
    assert (filename && wfa);
 
@@ -243,27 +243,27 @@ read_basis (const char *filename, wfa_t *wfa)
        !streq (wfa->wfainfo->basis_name, filename))
    {
       if (wfa->wfainfo->basis_name)
-	 Free (wfa->wfainfo->basis_name);
+         Free (wfa->wfainfo->basis_name);
       wfa->wfainfo->basis_name = strdup (filename);
    }
 
    if (get_linked_basis (filename, wfa))
-      return;				/* basis is linked with executable */
+      return;                           /* basis is linked with executable */
 
    /*
     *  Check whether 'wfa_name' is a regular ASCII WFA initial basis file
     */
    {
-      char magic [MAXSTRLEN];		/* WFA magic number */
+      char magic [MAXSTRLEN];           /* WFA magic number */
 
       if (!(input = open_file (filename, "FIASCO_DATA", READ_ACCESS)))
-	 file_error(filename);
+         file_error(filename);
 
       if (fscanf (input, MAXSTRLEN_SCANF, magic) != 1)
-	 error ("Format error: ASCII FIASCO initial basis file %s", filename);
+         error ("Format error: ASCII FIASCO initial basis file %s", filename);
       else if (!streq (FIASCO_BASIS_MAGIC, magic))
-	 error ("Input file %s is not an ASCII FIASCO initial basis!",
-		filename);
+         error ("Input file %s is not an ASCII FIASCO initial basis!",
+                filename);
    }
 
    /*
@@ -273,74 +273,74 @@ read_basis (const char *filename, wfa_t *wfa)
     *        Don't define any transitions of state 0 in an initial basis.
     *
     *  Header:
-    *   type		|description
-    *	----------------+-----------
-    *   string		|MAGIC Number "Wfa"
-    *	int		|Number of basis states 'N'
-    *	bool_t-array[N]	|use vector in linear combinations,
-    *			|0: don't use vector (auxiliary state)
-    *			|1: use vector in linear combinations
-    *	float-array[N]	|final distribution of every state
+    *   type            |description
+    *   ----------------+-----------
+    *   string          |MAGIC Number "Wfa"
+    *   int             |Number of basis states 'N'
+    *   bool_t-array[N] |use vector in linear combinations,
+    *                   |0: don't use vector (auxiliary state)
+    *                   |1: use vector in linear combinations
+    *   float-array[N]  |final distribution of every state
     *
     *  Transitions:
     *
-    *      <state 1>			current state
-    *      <label> <into> <weight>	transition 1 of current state
-    *      <label> <into> <weight>	transition 2 of current state
+    *      <state 1>                    current state
+    *      <label> <into> <weight>      transition 1 of current state
+    *      <label> <into> <weight>      transition 2 of current state
     *      ...
-    *      <-1>				last transition marker
+    *      <-1>                         last transition marker
     *      <state 2>
     *      ...
-    *      <-1>				last transition marker
+    *      <-1>                         last transition marker
     *      <state N>
     *      ...
     *
-    *      <-1>				last transition marker
-    *      <-1>				last state marker
+    *      <-1>                         last transition marker
+    *      <-1>                         last state marker
     */
    {
       unsigned state;
 
       if (fscanf (input ,"%u", &wfa->basis_states) != 1)
-	 error ("Format error: ASCII FIASCO initial basis file %s", filename);
+         error ("Format error: ASCII FIASCO initial basis file %s", filename);
 
       /*
        *  State 0 is assumed to be the constant function f(x, y) = 128.
        */
       wfa->domain_type [0]        = USE_DOMAIN_MASK;
       wfa->final_distribution [0] = 128;
-      wfa->states 		  = wfa->basis_states;
+      wfa->states                 = wfa->basis_states;
       wfa->basis_states++;
 
       append_edge (0, 0, 1.0, 0, wfa);
       append_edge (0, 0, 1.0, 1, wfa);
 
       for (state = 1; state < wfa->basis_states; state++)
-	 wfa->domain_type [state]
-	    = read_int (input) ? USE_DOMAIN_MASK : AUXILIARY_MASK;
+         wfa->domain_type [state]
+            = read_int (input) ? USE_DOMAIN_MASK : AUXILIARY_MASK;
 
       for (state = 1; state < wfa->basis_states; state++)
-	 wfa->final_distribution[state] = read_real (input);
+         wfa->final_distribution[state] = read_real (input);
 
       /*
        *  Read transitions
        */
       for (state = 1; state < wfa->basis_states; state++)
       {
-	 unsigned domain;
-	 int      label;
-	 real_t   weight;
-
-	 if (read_int (input) != (int) state)
-	    error ("Format error: ASCII FIASCO initial basis file %s",
-		   filename);
-
-	 while((label = read_int (input)) != -1)
-	 {
-	    domain = read_int (input);
-	    weight = read_real (input);
-	    append_edge (state, domain, weight, label, wfa);
-	 }
+         unsigned domain;
+         int      label;
+         real_t   weight;
+
+         if (read_int (input) != (int) state)
+            error ("Format error: ASCII FIASCO initial basis file %s",
+                   filename);
+
+         while((label = read_int (input)) != -1)
+         {
+            domain = read_int (input);
+            weight = read_real (input);
+            append_edge (state, domain, weight, label, wfa);
+         }
       }
    }
 
@@ -357,13 +357,13 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input)
  *  No return value.
  *
  *  Side effects:
- *	wfa->into, wfa->weights, wfa->final_distribution, wfa->states
- *	wfa->x, wfa->y, wfa->level_of_state, wfa->domain_type
+ *      wfa->into, wfa->weights, wfa->final_distribution, wfa->states
+ *      wfa->x, wfa->y, wfa->level_of_state, wfa->domain_type
  *      mt->type, mt->number are filled with the values of the WFA file.
  */
 {
-   tiling_t tiling;			/* tiling information */
-   unsigned frame_number;		/* current frame number */
+   tiling_t tiling;                     /* tiling information */
+   unsigned frame_number;               /* current frame number */
 
    assert (wfa && input);
 
@@ -371,14 +371,14 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input)
     *  Frame header information
     */
    {
-      const unsigned rice_k = 8;	/* parameter of Rice Code */
+      const unsigned rice_k = 8;        /* parameter of Rice Code */
 
       wfa->states     = read_rice_code (rice_k, input);
       wfa->frame_type = read_rice_code (rice_k, input);
       frame_number    = read_rice_code (rice_k, input);
    }
 
-   if (wfa->wfainfo->release > 1)	/* no alignment in version 1 */
+   if (wfa->wfainfo->release > 1)       /* no alignment in version 1 */
    {
       INPUT_BYTE_ALIGN (input);
    }
@@ -386,9 +386,9 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input)
    /*
     *  Read image tiling info
     */
-   if (get_bit (input))			/* tiling performed ? */
+   if (get_bit (input))                 /* tiling performed ? */
       read_tiling (&tiling, wfa->wfainfo->width, wfa->wfainfo->height,
-		   wfa->wfainfo->level, input);
+                   wfa->wfainfo->level, input);
    else
       tiling.exponent = 0;
 
@@ -404,30 +404,30 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input)
       unsigned state;
 
       for (state = wfa->basis_states; state < wfa->states; state++)
-	 if ((!wfa->wfainfo->color
-	      || (int) state <= wfa->tree [wfa->tree [wfa->root_state][0]][0])
-	     &&
-	     (!tiling.exponent ||
-	      wfa->level_of_state [state] <= (wfa->wfainfo->level
-					      - tiling.exponent))
-	     && ((wfa->x [state][0]
-		 + width_of_level (wfa->level_of_state [state]))
-		 <= wfa->wfainfo->width)
-	     && ((wfa->y [state][0]
-		 + height_of_level (wfa->level_of_state [state]))
-		 <= wfa->wfainfo->height))
-	    wfa->domain_type [state] = USE_DOMAIN_MASK;
-	 else
-	    wfa->domain_type [state] = 0;
+         if ((!wfa->wfainfo->color
+              || (int) state <= wfa->tree [wfa->tree [wfa->root_state][0]][0])
+             &&
+             (!tiling.exponent ||
+              wfa->level_of_state [state] <= (wfa->wfainfo->level
+                                              - tiling.exponent))
+             && ((wfa->x [state][0]
+                 + width_of_level (wfa->level_of_state [state]))
+                 <= wfa->wfainfo->width)
+             && ((wfa->y [state][0]
+                 + height_of_level (wfa->level_of_state [state]))
+                 <= wfa->wfainfo->height))
+            wfa->domain_type [state] = USE_DOMAIN_MASK;
+         else
+            wfa->domain_type [state] = 0;
    }
 
    if (tiling.exponent)
       Free (tiling.vorder);
 
-   if (get_bit (input))			/* nondeterministic prediction used */
+   if (get_bit (input))                 /* nondeterministic prediction used */
       read_nd (wfa, input);
 
-   if (wfa->frame_type != I_FRAME)	/* motion compensation used */
+   if (wfa->frame_type != I_FRAME)      /* motion compensation used */
       read_mc (wfa->frame_type, wfa, input);
 
    locate_delta_images (wfa);
@@ -439,7 +439,7 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input)
       unsigned edges = read_matrices (wfa, input);
 
       if (edges)
-	 read_weights (edges, wfa, input);
+         read_weights (edges, wfa, input);
    }
 
    /*
@@ -449,8 +449,8 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input)
       unsigned state;
 
       for (state = wfa->basis_states; state <= wfa->states; state++)
-	 wfa->final_distribution[state]
-	    = compute_final_distribution (state, wfa);
+         wfa->final_distribution[state]
+            = compute_final_distribution (state, wfa);
    }
 
    return frame_number;
@@ -458,13 +458,13 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input)
 
 /*****************************************************************************
 
-				private code
+                                private code
 
 *****************************************************************************/
 
 static void
 read_tiling (tiling_t *tiling, unsigned image_width, unsigned image_height,
-	     unsigned image_level, bitfile_t *input)
+             unsigned image_level, bitfile_t *input)
 /*
  *  Read image tiling information from the given file 'input'
  *  and store parameters in struct 'tiling'.
@@ -472,32 +472,32 @@ read_tiling (tiling_t *tiling, unsigned image_width, unsigned image_height,
  *  No return value.
  */
 {
-   const unsigned rice_k = 8;		/* parameter of Rice Code */
+   const unsigned rice_k = 8;           /* parameter of Rice Code */
 
    tiling->exponent = read_rice_code (rice_k, input);
 
-   if (get_bit (input))			/* variance order */
+   if (get_bit (input))                 /* variance order */
    {
-      unsigned tile;			/* current image tile */
-      unsigned x0, y0;			/* NW corner of image tile */
-      unsigned width, height;		/* size of image tile */
+      unsigned tile;                    /* current image tile */
+      unsigned x0, y0;                  /* NW corner of image tile */
+      unsigned width, height;           /* size of image tile */
 
       tiling->vorder = Calloc (1 << tiling->exponent, sizeof (int));
       for (tile = 0; tile <  1U << tiling->exponent; tile++)
       {
-	 locate_subimage (image_level, image_level - tiling->exponent, tile,
-			  &x0, &y0, &width, &height);
-	 if (x0 < image_width && y0 < image_height)
-	    tiling->vorder [tile] = get_bits (input, tiling->exponent);
-	 else
-	    tiling->vorder [tile] = -1;
+         locate_subimage (image_level, image_level - tiling->exponent, tile,
+                          &x0, &y0, &width, &height);
+         if (x0 < image_width && y0 < image_height)
+            tiling->vorder [tile] = get_bits (input, tiling->exponent);
+         else
+            tiling->vorder [tile] = -1;
       }
    }
-   else					/* spiral order */
+   else                                 /* spiral order */
    {
       tiling->vorder = Calloc (1 << tiling->exponent, sizeof (int));
       compute_spiral (tiling->vorder, image_width, image_height,
-		      tiling->exponent, get_bit (input) ? YES : NO);
+                      tiling->exponent, get_bit (input) ? YES : NO);
    }
 }