changeset 49:abd56818e135

Added support for reading greyscale files with 16-bit dynamic range.
author tpikonen
date Fri, 14 Nov 2003 16:45:19 +0000
parents 7490019977b5
children 1700d06fcc74
files imread.m
diffstat 1 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/imread.m
+++ b/imread.m
@@ -211,11 +211,20 @@
 
 # get max component value
    if bpp==8
-      max_component= sscanf( fgetl(fid), '%d' );
+     max_component= sscanf( fgetl(fid), '%d' );
+     if (max_component > 255)
+       # The PGM standard supports only values below 65536
+       bpp = 16;
+     endif
    end
 
    if bindata
-      data= fread(fid);
+      if(bpp == 16)
+         # PGM format has MSB first, i.e. little endian
+         data = fread(fid, "uint16", 0, "ieee-le");
+      else
+         data = fread(fid);
+      endif
       numdata= size(data,1);
 
       if bpp==1
@@ -326,6 +335,9 @@
 
 #
 # $Log$
+# Revision 1.7  2003/11/14 16:45:19  tpikonen
+# Added support for reading greyscale files with 16-bit dynamic range.
+#
 # Revision 1.6  2003/09/12 14:22:42  adb014
 # Changes to allow use with latest CVS of octave (do_fortran_indexing, etc)
 #