changeset 1524:35848bbe96e4

New filters for unsigned integers
author neelin <neelin>
date Fri, 28 Feb 2003 03:00:29 +0000 (2003-02-28)
parents 62fb81643bb7
children c5d41c18f917
files conversion/image_filters/ftoui.c conversion/image_filters/uitof.c
diffstat 2 files changed, 80 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/conversion/image_filters/ftoui.c
@@ -0,0 +1,45 @@
+/* ----------------------------- MNI Header -----------------------------------
+@NAME       : ftoui.c
+@INPUT      : (none)
+@OUTPUT     : (none)
+@DESCRIPTION: Reads binary values from standard input and writes the 
+              floating point equivalent on standard output.
+@METHOD     : 
+@GLOBALS    : (none)
+@CALLS      : 
+@CREATED    : December 4,1991 (Peter Neelin)
+@MODIFIED   : January 13,1991 (P.N.)
+                 -read values into large array for optimization
+---------------------------------------------------------------------------- */
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#define  MAX( x, y )  ( ((x) >= (y)) ? (x) : (y) )
+#define  MIN( x, y )  ( ((x) <= (y)) ? (x) : (y) )
+
+#define ARRSIZE 1500
+#define INTYPE float
+#define OUTTYPE unsigned short int
+#define ROUND( x ) ( (signed long int) ( ((x) > (0)) ? (x)+0.5 : (x)-0.5 ))
+#define MAXVAL USHRT_MAX
+#define MINVAL 0
+
+main()
+{
+   INTYPE value[ARRSIZE], temp;
+   OUTTYPE output[ARRSIZE];
+   int i,nread;
+
+   while ((nread = fread(value, sizeof(INTYPE), 
+                         sizeof(value)/sizeof(INTYPE), stdin)) > 0) {
+      for (i=0; i < nread; i++) {
+         temp = ROUND(value[i]);
+         temp = MIN(MAXVAL, temp);
+         temp = MAX(MINVAL, temp);
+         output[i] = (OUTTYPE) temp;
+      }
+      (void) fwrite(output, sizeof(OUTTYPE), nread, stdout);
+   }
+   return 0;
+}
new file mode 100644
--- /dev/null
+++ b/conversion/image_filters/uitof.c
@@ -0,0 +1,35 @@
+/* ----------------------------- MNI Header -----------------------------------
+@NAME       : uitof.c
+@INPUT      : (none)
+@OUTPUT     : (none)
+@DESCRIPTION: Reads binary values from standard input and writes the 
+              floating point equivalent on standard output.
+@METHOD     : 
+@GLOBALS    : (none)
+@CALLS      : 
+@CREATED    : December 4,1991 (Peter Neelin)
+@MODIFIED   : January 13,1991 (P.N.)
+                 - read values into large array for optimization
+---------------------------------------------------------------------------- */
+#include <stdio.h>
+#include <stdlib.h>
+
+#define ARRSIZE 1500
+#define INTYPE unsigned short int
+#define OUTTYPE float
+
+main()
+{
+   INTYPE value[ARRSIZE];
+   OUTTYPE output[ARRSIZE];
+   int i,nread;
+
+   while ((nread = fread(value, sizeof(INTYPE), 
+                         sizeof(value)/sizeof(INTYPE), stdin)) > 0) {
+      for (i=0; i < nread; i++) {
+         output[i] = (OUTTYPE) value[i];
+      }
+      (void) fwrite(output, sizeof(OUTTYPE), nread, stdout);
+   }
+   return 0;
+}