[giv] Added support for float and 16-bit color images in tiff plugin.



commit 08fb7aa307756b9429d808e725ce35465a2b7606
Author: Dov Grobgeld <dov grobgeld gmail com>
Date:   Wed Apr 6 14:41:29 2011 +0300

    Added support for float and 16-bit color images in tiff plugin.

 ChangeLog                                          |   12 ++
 doc/giv-m51-with-contrast-tool-screenshot.png      |  Bin 0 -> 121074 bytes
 doc/giv.html                                       |   30 +++-
 doc/giv.phtml                                      |   27 +++-
 src/givimage.c                                     |   73 +++++++--
 .../dcmtk/config/include/dcmtk/config/cfunix.h     |    2 +-
 src/plugins/dcmtk/dcmdata/libsrc/SConscript        |  174 ++++++++++----------
 src/plugins/tiff.c                                 |   35 ++++-
 8 files changed, 230 insertions(+), 123 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 4b087bb..4849c09 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
+2011-04-06  Dov Grobgeld  <dov grobgeld gmail com>
+
+        * plugins/dcmtk/dcmdata/libsrc/SConscript: Turned of autogeneration of dcdictbi.cc.
+
+        * tiff.c, giv_image.c, giv_image.h : Added support for 16 bit tiff images.
+
+        * tiff.c : Added support for float (SAMPLEFORMAT_IEEEFP) images.
+
+        * cfunix.h : Erased definition of size_to to fix Linux64 bit compilatin.
+
 2011-04-05  Dov Grobgeld  <dov grobgeld gmail com>
 
+        * Released version 0.9.18
+
         * Sconstruct: Created a dist command for generating distributions.
 
         * giv-win.gob : Created ifdef for windows as pango_cairo was severely broken.
diff --git a/doc/giv-m51-with-contrast-tool-screenshot.png b/doc/giv-m51-with-contrast-tool-screenshot.png
new file mode 100644
index 0000000..6d25fcb
Binary files /dev/null and b/doc/giv-m51-with-contrast-tool-screenshot.png differ
diff --git a/doc/giv.html b/doc/giv.html
index 3fa1f4f..9d40562 100644
--- a/doc/giv.html
+++ b/doc/giv.html
@@ -18,11 +18,11 @@
 </center>
 <h2 align=center>
     <img src="giv-logo-150.png"><br>
-    <font size=+2>Version 0.9.17</font><br>
+    <font size=+2>Version 0.9.18</font><br>
     <font size=-1>Dov Grobgeld</font><br>
     <font size=-1>Homepage: <a href="http://giv.sourceforge.net/giv";>http://giv.sourceforge.net/giv</a></font><br>
     <font size=-1><a href="mailto:dov grobgeld gmail com">dov grobgeld gmail com</a></font><br>
-    <font size=-1>Last modified: 2010-02-25   </font>
+    <font size=-1>Last modified: 2011-04-05   </font>
 </h2>
 
 <h2><a name="SEC1">1. Description</a></h2>
@@ -454,20 +454,36 @@ giv. The result is shown in the screenshow below.
       <td colspan="2" align="center"><img src="giv-m51-with-contrast-tool-screenshot.png" width=600></td>
     </tr>
     <tr>
-    <td colspan="2" align="center">The Contrast Tool with a 16-bit image</td>
+    <td colspan="2" align="center">The Contrast Tool with a 16-bit image<br></td>
+    </tr>
+
+    <!----->
+    <tr>
+      <td colspan="2" align="center"><img src="giv-calib-and-measure.png" width=600></td>
+    </tr>
+    <tr>
+    <td colspan="2" align="center">The measurement caliper and the calibration tool<br></td>
     </tr>
   </table>
 </blockquote>
 
-<h2><a name="SEC4">4. Future plans</a></h2>
+<h2><a name="SEC4">4. Plugins</a></h2>
+
+Giv supports plugins for loading 8-bit, 16-bit, 32-bit and floating point images. Currently there are
+loaders for the following formats:
+<ul>
+<li>Dicom
+<li>FITS
+<li>Tiff
+</ul>
+
+<h2><a name="SEC5">5. Future plans</a></h2>
 
 <blockquote>
   Here is a list of possible future development. The direction taken
   depends on user feedback!
   <UL>
-    <LI> Support 16-bit, 32-bit, float, and double images. </LI>
-    <LI> Create a framework for external image loader DLL's. </LI>
-    <LI> Create loaders for HDF5 and Dicom. </LI>
+    <LI> Create loaders for HDF5. </LI>
     <LI> Create a property window to show meta data. E.g. data from a dicom file. </LI>
     <LI> Speed up dealing with huge datasets. </LI>
     <LI> Create a measuring tool for measuring areas, histograms, etc. </LI>
diff --git a/doc/giv.phtml b/doc/giv.phtml
index e333eaa..d820689 100644
--- a/doc/giv.phtml
+++ b/doc/giv.phtml
@@ -94,11 +94,11 @@ sub code_snippet {   # usage: code_snippet($filename, title)
 </center>
 <h2 align=center>
     <img src="giv-logo-150.png"><br>
-    <font size=+2>Version 0.9.17</font><br>
+    <font size=+2>Version 0.9.18</font><br>
     <font size=-1>Dov Grobgeld</font><br>
     <font size=-1>Homepage: <a href="http://giv.sourceforge.net/giv";>http://giv.sourceforge.net/giv</a></font><br>
     <font size=-1><a href="mailto:dov grobgeld gmail com">dov grobgeld gmail com</a></font><br>
-    <font size=-1>Last modified: 2010-02-25   </font>
+    <font size=-1>Last modified: 2011-04-05   </font>
 </h2>
 
 <: section("Description") :>
@@ -374,19 +374,34 @@ giv. The result is shown in the screenshow below.
       <td colspan="2" align="center"><img src="giv-m51-with-contrast-tool-screenshot.png" width=600></td>
     </tr>
     <tr>
-    <td colspan="2" align="center">The Contrast Tool with a 16-bit image</td>
+    <td colspan="2" align="center">The Contrast Tool with a 16-bit image<br></td>
+    </tr>
+
+    <!----->
+    <tr>
+      <td colspan="2" align="center"><img src="giv-calib-and-measure.png" width=600></td>
+    </tr>
+    <tr>
+    <td colspan="2" align="center">The measurement caliper and the calibration tool<br></td>
     </tr>
   </table>
 </blockquote>
 
+<: section("Plugins") :>
+Giv supports plugins for loading 8-bit, 16-bit, 32-bit and floating point images. Currently there are
+loaders for the following formats:
+<ul>
+<li>Dicom
+<li>FITS
+<li>Tiff
+</ul>
+
 <: section("Future plans") :>
 <blockquote>
   Here is a list of possible future development. The direction taken
   depends on user feedback!
   <UL>
-    <LI> Support 16-bit, 32-bit, float, and double images. </LI>
-    <LI> Create a framework for external image loader DLL's. </LI>
-    <LI> Create loaders for HDF5 and Dicom. </LI>
+    <LI> Create loaders for HDF5. </LI>
     <LI> Create a property window to show meta data. E.g. data from a dicom file. </LI>
     <LI> Speed up dealing with huge datasets. </LI>
     <LI> Create a measuring tool for measuring areas, histograms, etc. </LI>
diff --git a/src/givimage.c b/src/givimage.c
index c35075e..98f185c 100644
--- a/src/givimage.c
+++ b/src/givimage.c
@@ -13,6 +13,16 @@
 #include "givregex.h"
 
 #define GIV_IMAGE_ERROR g_spawn_error_quark ()
+
+static guint8 clip_u8(double f)
+{
+    if (f < 0)
+        return 0;
+    if (f > 255)
+        return 255;
+    return (int)f;
+}
+
 GQuark
 giv_image_error_quark (void)
 {
@@ -414,7 +424,15 @@ double giv_image_get_value(GivImage *img,
     case GIVIMAGE_RGBA_U8:
         return (((GivImageRgbAlpha8*)row_start)[x_idx]).red;
     case GIVIMAGE_RGB_U16:
-        return (((GivImageRgb16*)row_start)[x_idx]).red;
+        {
+            GivImageRgb16 rgb = (((GivImageRgb16*)row_start)[x_idx]);
+            int max = rgb.red;
+            if (rgb.green > max)
+                max = rgb.green;
+            if (rgb.blue > max)
+                max = rgb.blue;
+            return max;
+        }
     case GIVIMAGE_RGBA_U16:
         return (((GivImageRgbAlpha16*)row_start)[x_idx]).red;
     default:
@@ -446,6 +464,16 @@ GivImageRgb16 giv_image_get_rgb_value(GivImage *img,
         rgb.green = img->buf.rgba8_buf[idx].green;
         rgb.blue = img->buf.rgba8_buf[idx].blue;
         break;
+    case GIVIMAGE_RGB_U16:
+        rgb.red = img->buf.rgb16_buf[idx].red;
+        rgb.green = img->buf.rgb16_buf[idx].green;
+        rgb.blue = img->buf.rgb16_buf[idx].blue;
+        break;
+    case GIVIMAGE_RGBA_U16:
+        rgb.red = img->buf.rgba16_buf[idx].red;
+        rgb.green = img->buf.rgba16_buf[idx].green;
+        rgb.blue = img->buf.rgba16_buf[idx].blue;
+        break;
     default:
         ;
     }
@@ -588,16 +616,33 @@ GdkPixbuf *giv_image_get_pixbuf(GivImage *img,
         int row_stride = img->row_stride;
 
         // Silently ignore 16 bit images at the moment
-        for (row_idx=0; row_idx<height; row_idx++) {
-            for (col_idx=0; col_idx<width; col_idx++) {
-                int ch_idx;
-                for (ch_idx=0; ch_idx<num_ch_per_pixel; ch_idx++) {
-                    pbuf[row_idx * pb_rowstride
-                         + col_idx * num_ch_per_pixel
-                         + ch_idx]
-                        = buf[row_idx * row_stride
-                              +col_idx * num_ch_per_pixel
-                              + ch_idx]; 
+        if (img->img_type == GIVIMAGE_RGB_U16) {
+            for (row_idx=0; row_idx<height; row_idx++) {
+                gchar *row = pbuf + row_idx * pb_rowstride;
+                for (col_idx=0; col_idx<width; col_idx++) {
+                    GivImageRgb16 rgb16
+                        = giv_image_get_rgb_value(img,
+                                                  col_idx,
+                                                  row_idx,
+                                                  slice_idx);
+                    row[col_idx * 3] = clip_u8((rgb16.red-min)*255/(max-min));
+                    row[col_idx * 3+1] = clip_u8((rgb16.green-min)*255/(max-min));
+                    row[col_idx * 3+2] = clip_u8((rgb16.blue-min)*255/(max-min));
+                }
+            }
+        }
+        else {
+            for (row_idx=0; row_idx<height; row_idx++) {
+                for (col_idx=0; col_idx<width; col_idx++) {
+                    int ch_idx;
+                    for (ch_idx=0; ch_idx<num_ch_per_pixel; ch_idx++) {
+                        pbuf[row_idx * pb_rowstride
+                             + col_idx * num_ch_per_pixel
+                             + ch_idx]
+                            = buf[row_idx * row_stride
+                                  +col_idx * num_ch_per_pixel
+                                  + ch_idx]; 
+                    }
                 }
             }
         }
@@ -613,11 +658,7 @@ GdkPixbuf *giv_image_get_pixbuf(GivImage *img,
                 if (max == min)
                     val = 128;
                 else
-                    val = 255.0 * (val-min)/(max-min);
-                if (val<=0)
-                    val = 0;
-                if (val >= 255)
-                    val = 255;
+                    val = clip_u8(255.0 * (val-min)/(max-min));
                 for (ch_idx=0; ch_idx<3; ch_idx++) 
                     pbuf[row_idx * pb_rowstride
                          + col_idx * 3
diff --git a/src/plugins/dcmtk/config/include/dcmtk/config/cfunix.h b/src/plugins/dcmtk/config/include/dcmtk/config/cfunix.h
index 32dbcbb..b0017fd 100644
--- a/src/plugins/dcmtk/config/include/dcmtk/config/cfunix.h
+++ b/src/plugins/dcmtk/config/include/dcmtk/config/cfunix.h
@@ -332,7 +332,7 @@ typedef int pid_t;
 #endif
 
 /* Define `size_t' to `unsigned' if <sys/types.h> does not define. */
-#define HAVE_NO_TYPEDEF_SIZE_T 1
+#undef HAVE_NO_TYPEDEF_SIZE_T 
 #ifdef HAVE_NO_TYPEDEF_SIZE_T
 typedef unsigned size_t;
 #endif
diff --git a/src/plugins/dcmtk/dcmdata/libsrc/SConscript b/src/plugins/dcmtk/dcmdata/libsrc/SConscript
index d899c54..cccd69e 100644
--- a/src/plugins/dcmtk/dcmdata/libsrc/SConscript
+++ b/src/plugins/dcmtk/dcmdata/libsrc/SConscript
@@ -7,90 +7,90 @@ lib = env.Library('dcmdata',
 env.Install('${OUTLIBDIR}',
             lib)
 
-if not ARGUMENTS.get('mingw', 0):
-    env.Command("dcdictbi.cc",
-                ["dicom.dic",
-                 "private.dic",
-                 "mkdictbi"
-                 ],
-                ["${TARGET.dir}/mkdictbi ${TARGET.dir}/*.dic > ${TARGET}"],
-                )
-    
-    env.Program('mkdictbi',
-                ['mkdictbi.cc',
-                 'cmdlnarg.cc',
-                 'dcbytstr.cc',
-                 'dcchrstr.cc',
-                 'dccodec.cc',
-                 'dcdatset.cc',
-                 'dcddirif.cc',
-                 'dcdebug.cc',
-                 'dcdicdir.cc',
-                 'dcdicent.cc',
-                 'dcdict.cc',
-                 'dcdictzz.cc',
-                 'dcdirrec.cc',
-                 'dcelem.cc',
-                 'dcerror.cc',
-                 'dcfilefo.cc',
-                 'dchashdi.cc',
-                 'dcistrma.cc',
-                 'dcistrmb.cc',
-                 'dcistrmf.cc',
-                 'dcistrmz.cc',
-                 'dcitem.cc',
-                 'dclist.cc',
-                 'dcmetinf.cc',
-                 'dcobject.cc',
-                 'dcostrma.cc',
-                 'dcostrmb.cc',
-                 'dcostrmf.cc',
-                 'dcostrmz.cc',
-                 'dcpcache.cc',
-                 'dcpixel.cc',
-                 'dcpixseq.cc',
-                 'dcpxitem.cc',
-                 'dcrleccd.cc',
-                 'dcrlecce.cc',
-                 'dcrlecp.cc',
-                 'dcrledrg.cc',
-                 'dcrleerg.cc',
-                 'dcrlerp.cc',
-                 'dcsequen.cc',
-                 'dcstack.cc',
-                 'dcswap.cc',
-                 'dctag.cc',
-                 'dctagkey.cc',
-                 'dctypes.cc',
-                 'dcuid.cc',
-                 'dcvm.cc',
-                 'dcvrae.cc',
-                 'dcvras.cc',
-                 'dcvrat.cc',
-                 'dcvr.cc',
-                 'dcvrcs.cc',
-                 'dcvrda.cc',
-                 'dcvrds.cc',
-                 'dcvrdt.cc',
-                 'dcvrfd.cc',
-                 'dcvrfl.cc',
-                 'dcvris.cc',
-                 'dcvrlo.cc',
-                 'dcvrlt.cc',
-                 'dcvrobow.cc',
-                 'dcvrof.cc',
-                 'dcvrpn.cc',
-                 'dcvrpobw.cc',
-                 'dcvrsh.cc',
-                 'dcvrsl.cc',
-                 'dcvrss.cc',
-                 'dcvrst.cc',
-                 'dcvrtm.cc',
-                 'dcvrui.cc',
-                 'dcvrul.cc',
-                 'dcvrulup.cc',
-                 'dcvrus.cc',
-                 'dcvrut.cc',
-                 'dcxfer.cc'
-                 ],
-                LIBS=['ofstd'])
+#if not ARGUMENTS.get('mingw', 0):
+#    env.Command("dcdictbi.cc",
+#                ["dicom.dic",
+#                 "private.dic",
+#                 "mkdictbi"
+#                 ],
+#                ["${TARGET.dir}/mkdictbi ${TARGET.dir}/*.dic > ${TARGET}"],
+#                )
+#    
+#    env.Program('mkdictbi',
+#                ['mkdictbi.cc',
+#                 'cmdlnarg.cc',
+#                 'dcbytstr.cc',
+#                 'dcchrstr.cc',
+#                 'dccodec.cc',
+#                 'dcdatset.cc',
+#                 'dcddirif.cc',
+#                 'dcdebug.cc',
+#                 'dcdicdir.cc',
+#                 'dcdicent.cc',
+#                 'dcdict.cc',
+#                 'dcdictzz.cc',
+#                 'dcdirrec.cc',
+#                 'dcelem.cc',
+#                 'dcerror.cc',
+#                 'dcfilefo.cc',
+#                 'dchashdi.cc',
+#                 'dcistrma.cc',
+#                 'dcistrmb.cc',
+#                 'dcistrmf.cc',
+#                 'dcistrmz.cc',
+#                 'dcitem.cc',
+#                 'dclist.cc',
+#                 'dcmetinf.cc',
+#                 'dcobject.cc',
+#                 'dcostrma.cc',
+#                 'dcostrmb.cc',
+#                 'dcostrmf.cc',
+#                 'dcostrmz.cc',
+#                 'dcpcache.cc',
+#                 'dcpixel.cc',
+#                 'dcpixseq.cc',
+#                 'dcpxitem.cc',
+#                 'dcrleccd.cc',
+#                 'dcrlecce.cc',
+#                 'dcrlecp.cc',
+#                 'dcrledrg.cc',
+#                 'dcrleerg.cc',
+#                 'dcrlerp.cc',
+#                 'dcsequen.cc',
+#                 'dcstack.cc',
+#                 'dcswap.cc',
+#                 'dctag.cc',
+#                 'dctagkey.cc',
+#                 'dctypes.cc',
+#                 'dcuid.cc',
+#                 'dcvm.cc',
+#                 'dcvrae.cc',
+#                 'dcvras.cc',
+#                 'dcvrat.cc',
+#                 'dcvr.cc',
+#                 'dcvrcs.cc',
+#                 'dcvrda.cc',
+#                 'dcvrds.cc',
+#                 'dcvrdt.cc',
+#                 'dcvrfd.cc',
+#                 'dcvrfl.cc',
+#                 'dcvris.cc',
+#                 'dcvrlo.cc',
+#                 'dcvrlt.cc',
+#                 'dcvrobow.cc',
+#                 'dcvrof.cc',
+#                 'dcvrpn.cc',
+#                 'dcvrpobw.cc',
+#                 'dcvrsh.cc',
+#                 'dcvrsl.cc',
+#                 'dcvrss.cc',
+#                 'dcvrst.cc',
+#                 'dcvrtm.cc',
+#                 'dcvrui.cc',
+#                 'dcvrul.cc',
+#                 'dcvrulup.cc',
+#                 'dcvrus.cc',
+#                 'dcvrut.cc',
+#                 'dcxfer.cc'
+#                 ],
+#                LIBS=['ofstd'])
diff --git a/src/plugins/tiff.c b/src/plugins/tiff.c
index 76a07a2..e018b50 100644
--- a/src/plugins/tiff.c
+++ b/src/plugins/tiff.c
@@ -54,7 +54,7 @@ GivImage *giv_plugin_load_file(const char *filename,
     GivImageType image_type;
 
     if (tif) {
-	uint32 w, h, config=9999, bps=9999, spp=9999;
+        uint32 w, h, config=9999, bps=9999, spp=9999, sample_format=9999;
 	size_t npixels;
 	uint8* raster;
         gboolean has_colormap = FALSE;
@@ -65,11 +65,15 @@ GivImage *giv_plugin_load_file(const char *filename,
 	TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &config);
         TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bps);
         TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &spp);
+        TIFFGetField(tif, TIFFTAG_SAMPLEFORMAT, &sample_format);
+
         if (TIFFGetField(tif, TIFFTAG_COLORMAP, &rmap, &gmap, &bmap))
             has_colormap = TRUE;
+#if 0
         printf("has_colormap= %d\n", has_colormap);
         
         printf("bps spp=%d %d\n", bps, spp);
+#endif
 
 	raster = (uint8*) _TIFFmalloc(TIFFScanlineSize(tif));
         if (config == PLANARCONFIG_CONTIG) {
@@ -88,20 +92,39 @@ GivImage *giv_plugin_load_file(const char *filename,
 
             // TBD - Support more types.
             if (spp == 3 || has_colormap) {
-                image_type = GIVIMAGE_RGB_U8;
+                if (bps == 8)
+                    image_type = GIVIMAGE_RGB_U8;
+                else if (bps == 16)
+                    image_type = GIVIMAGE_RGB_U16;
                 dst_spp = 3;
             }
-            else
+            else if(spp == 1
+                    && bps == 32
+                    && sample_format == SAMPLEFORMAT_IEEEFP) {
+                image_type = GIVIMAGE_FLOAT;
+            }
+            else if (bps == 8)
                 image_type = GIVIMAGE_U8;
+            else if (bps == 16)
+                image_type = GIVIMAGE_U16;
+            else if (bps == 32)
+                image_type = GIVIMAGE_I32;
+            else {
+                printf("Unknown Tiff type!\n");
+                return NULL;
+            }
+
             img = giv_image_new(image_type, w, h);
             guchar *dst = img->buf.buf;
-            
+            int dst_bpp = giv_image_type_get_size(image_type);
+            int dst_row_stride = giv_image_get_row_stride(img);
+
             // Copy the tiff data to the img structure. This can
             // be made more memory conservative by using scanlines.
             for (row_idx=0; row_idx<h; row_idx++) {
                 TIFFReadScanline(tif, raster, row_idx, 0);
                 guchar *src_ptr = raster;
-                guchar *dst_ptr = dst + row_idx * w * dst_spp;
+                guchar *dst_ptr = dst + row_idx * dst_row_stride;
 
                 // Split between colormap and not colormap per row which
                 // is sufficiently fast.
@@ -115,7 +138,7 @@ GivImage *giv_plugin_load_file(const char *filename,
                 }
                 else {
                     for (col_idx=0; col_idx<w; col_idx++) {
-                        for (clr_idx=0; clr_idx<spp; clr_idx++) {
+                        for (clr_idx=0; clr_idx<spp*bps/8; clr_idx++) {
                             *dst_ptr++ = *src_ptr++;
                         }
                     }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]