libcvd-members
[Top][All Lists]
Advanced

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

[libcvd-members] libcvd pnm_src/tiffwrite.cc test/test_images.cxx


From: Edward Rosten
Subject: [libcvd-members] libcvd pnm_src/tiffwrite.cc test/test_images.cxx
Date: Tue, 05 Aug 2008 19:35:49 +0000

CVSROOT:        /cvsroot/libcvd
Module name:    libcvd
Changes by:     Edward Rosten <edrosten>        08/08/05 19:35:49

Modified files:
        pnm_src        : tiffwrite.cc 
        test           : test_images.cxx 

Log message:
        Floating point TIFF loading and saving now works!  Bool tiff loading 
and saving
        works. This uses the very efficient G4 compression, so the resukting 
files are
        very small.
        
        test/test_images passes all visual tests. Note that floating point 
tiffs are
        not viewable using XV or GIMP. ImageMagick's display tool does work, 
however.
        All image types also pass the new save/load tests to make sure that 
images are
        saved and loaded without loss on the native types supported by each 
image file
        format.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/pnm_src/tiffwrite.cc?cvsroot=libcvd&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/libcvd/test/test_images.cxx?cvsroot=libcvd&r1=1.11&r2=1.12

Patches:
Index: pnm_src/tiffwrite.cc
===================================================================
RCS file: /cvsroot/libcvd/libcvd/pnm_src/tiffwrite.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- pnm_src/tiffwrite.cc        5 Aug 2008 02:12:46 -0000       1.2
+++ pnm_src/tiffwrite.cc        5 Aug 2008 19:35:48 -0000       1.3
@@ -32,6 +32,7 @@
 using namespace CVD::Exceptions::Image_IO;
 using namespace std;
 
+
 
////////////////////////////////////////////////////////////////////////////////
 //
 // Private implementation of TIFF reading
@@ -82,16 +83,63 @@
 
 toff_t TIFFWritePimpl::seek(thandle_t vis, toff_t off, int dir)
 {
-       TIFFWritePimpl* o = (TIFFWritePimpl*)vis;
+       TIFFWritePimpl* p = (TIFFWritePimpl*)vis;
+       ostream& o(p->o);
        
        if(dir == SEEK_SET)
-               o->o.seekp(off, ios_base::beg);
+               o.seekp(off, ios_base::beg);
        else if(dir == SEEK_CUR)
-               o->o.seekp(off, ios_base::cur);
+               o.seekp(off, ios_base::cur);
        else if(dir == SEEK_END)
-               o->o.seekp(off, ios_base::end);
+               o.seekp(off, ios_base::end);
+       
+
+       //From comments in libtiff:
+
+       // Attempt to workaround problems with seeking past the end of the
+       // stream.  ofstream doesn't have a problem with this but
+       // ostrstream/ostringstream does. In that situation, add intermediate
+       // '\0' characters.
+       if(o.fail()) 
+       {
+               ios::iostate    old_state = o.rdstate();
+               ios::iostate    safe_state = old_state & ~ios_base::failbit;
+               streamoff               crnt=0;
+
+               // clear the fail bit so else tellp() works
+               o.clear(safe_state);
+               if(dir == SEEK_SET)
+                       crnt = 0;
+               else if (dir == SEEK_CUR)
+                       crnt = o.tellp();
+               else if(dir == SEEK_END)
+               {
+                       o.seekp(0, ios_base::end);
+                       crnt = o.tellp();
+               }
+
+               // restore original stream state
+               o.clear(old_state);     
+
+               // only do something if desired seek position is valid
+               if( crnt + off > 0 ) {
 
-       return o->o.tellp();
+                       // clear the fail bit 
+                       o.clear(safe_state);
+
+                       // extend the stream by writing zeros
+                       o.seekp(0, ios::end);
+                       streamoff extra = crnt + off - o.tellp();
+                       for(streamoff i = 0; i < extra; i++ )
+                               o.put(0);
+
+                       // retry the seek, just to make sure.
+                       o.seekp(crnt + off, ios_base::beg);
+               }
+       }
+
+
+       return o.tellp();
 }
 
 toff_t TIFFWritePimpl::size(thandle_t vis)
@@ -100,10 +148,8 @@
        return ii->length;
 }
 
-int TIFFWritePimpl::close(thandle_t vis)
+int TIFFWritePimpl::close(thandle_t)
 {
-       TIFFWritePimpl* o = (TIFFWritePimpl*)vis;
-       o->o << flush;
        return 0;
 }
 
@@ -337,3 +383,25 @@
 GEN3(unsigned short)
 GEN3(float)
 GEN3(double)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

Index: test/test_images.cxx
===================================================================
RCS file: /cvsroot/libcvd/libcvd/test/test_images.cxx,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- test/test_images.cxx        5 Aug 2008 02:12:46 -0000       1.11
+++ test/test_images.cxx        5 Aug 2008 19:35:49 -0000       1.12
@@ -47,7 +47,7 @@
 {
        static double r()
        {
-               return rand() * 1./RAND_MAX;
+               return rand() * 10./RAND_MAX - 5;
        }
 };
 
@@ -55,7 +55,7 @@
 {
        static float r()
        {
-               return rand() * 1./RAND_MAX;
+               return rand() * 10./RAND_MAX - 5;
        }
 };
 
@@ -121,21 +121,21 @@
        o.close();
 
        //Save it
-       #ifdef CVD_IMAGE_HAVE_JPEG
+       #ifdef CVD_HAVE_JPEG
                fout=make_output_file_name<T>(fin, "jpg");
                cout << "Writing: " << fout << endl << endl;
                o.open(fout.c_str());
                img_save(im, o, ImageType::JPEG);
                o.close();
        #endif
-       #ifdef CVD_IMAGE_HAVE_PNG
+       #ifdef CVD_HAVE_PNG
                fout=make_output_file_name<T>(fin, "png");
                cout << "Writing: " << fout << endl << endl;
                o.open(fout.c_str());
                img_save(im, o, ImageType::PNG);
                o.close();
        #endif
-       #ifdef CVD_IMAGE_HAVE_TIFF
+       #ifdef CVD_HAVE_TIFF
                fout=make_output_file_name<T>(fin, "tiff");
                cout << "Writing: " << fout << endl << endl;
                o.open(fout.c_str());
@@ -276,7 +276,7 @@
                          TypeList<Rgb<unsigned short>,
                                       Head> > > > >::exec(ImageType::PNM);
 
-       #ifdef CVD_IMAGE_HAVE_PNG
+       #ifdef CVD_HAVE_PNG
        cerr << "Testing PNG (type " << ImageType::PNG << ")\n";
        randtest<
                          TypeList<bool,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]