libcvd-members
[Top][All Lists]
Advanced

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

[libcvd-members] libcvd cvd/internal/io/png.h pnm_src/png.cc


From: Edward Rosten
Subject: [libcvd-members] libcvd cvd/internal/io/png.h pnm_src/png.cc
Date: Wed, 10 Aug 2011 15:48:36 +0000

CVSROOT:        /cvsroot/libcvd
Module name:    libcvd
Changes by:     Edward Rosten <edrosten>        11/08/10 15:48:36

Modified files:
        cvd/internal/io: png.h 
        pnm_src        : png.cc 

Log message:
        PIMPLify png writing.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/internal/io/png.h?cvsroot=libcvd&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/libcvd/pnm_src/png.cc?cvsroot=libcvd&r1=1.16&r2=1.17

Patches:
Index: cvd/internal/io/png.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/internal/io/png.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- cvd/internal/io/png.h       20 Apr 2011 11:32:58 -0000      1.13
+++ cvd/internal/io/png.h       10 Aug 2011 15:48:36 -0000      1.14
@@ -29,10 +29,6 @@
 #include <cvd/internal/load_and_save.h>
 #include <cvd/internal/convert_pixel_types.h>
 
-struct png_struct_def;
-struct png_info_struct;
-
-
 namespace CVD{
 namespace PNG{
 
@@ -41,6 +37,7 @@
 
 
 class PNGPimpl;
+class WriterPimpl;
 
 class png_reader
 {
@@ -150,18 +147,7 @@
                static const int top_row_first=1;
 
        private:
-
-               template<class P> void write_line(const P*);
-
-       long row;
-       std::ostream& o;
-       ImageRef size;
-       std::string type;
-       std::string error_string;
-
-       png_struct_def* png_ptr;
-       png_info_struct* info_ptr, *end_info;
-
+               std::auto_ptr<WriterPimpl> p;
 };
 
 

Index: pnm_src/png.cc
===================================================================
RCS file: /cvsroot/libcvd/libcvd/pnm_src/png.cc,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- pnm_src/png.cc      1 Apr 2011 17:18:21 -0000       1.16
+++ pnm_src/png.cc      10 Aug 2011 15:48:36 -0000      1.17
@@ -327,7 +327,28 @@
 // PNG writing functions.
 //
 
-png_writer::png_writer(ostream& out, ImageRef sz, const string& type_, const 
std::map<std::string, Parameter<> >&)
+class CVD::PNG::WriterPimpl
+{
+       public:
+               WriterPimpl(std::ostream&, ImageRef size, const std::string& 
type);
+               ~WriterPimpl();
+               template<class P> void write_line(const P*);
+
+       private:
+
+       long row;
+       std::ostream& o;
+       ImageRef size;
+       std::string type;
+       std::string error_string;
+
+       png_struct_def* png_ptr;
+       png_info_struct* info_ptr, *end_info;
+
+};
+
+
+WriterPimpl::WriterPimpl(ostream& out, ImageRef sz, const string& type_)
 :row(0),o(out),size(sz),type(type_)
 {
        //Create required structs
@@ -420,18 +441,12 @@
 
 }
 
-//Mechanically generate the pixel writing calls.
-#undef GEN1
-#undef GEN3
-#define GEN1(X) void png_writer::write_raw_pixel_line(const 
X*d){write_line(d);}
-#define GEN3(X) GEN1(X) GEN1(Rgb<X>) GEN1(Rgba<X>)
-GEN1(bool)
-GEN1(Rgb8)
-GEN3(unsigned char)
-GEN3(unsigned short)
-
+////////////////////////////////////////////////////////////////////////////////
+//
+// Main interface funtions
+//
 
-template<class P> void png_writer::write_line(const P* data)
+template<class P> void WriterPimpl::write_line(const P* data)
 {
        unsigned char* chardata = const_cast<unsigned 
char*>(reinterpret_cast<const unsigned char*>(data));
 
@@ -455,8 +470,26 @@
        row++;
 }
 
-png_writer::~png_writer()
+WriterPimpl::~WriterPimpl()
 {
        png_write_end(png_ptr, info_ptr);
        png_destroy_write_struct(&png_ptr, &info_ptr);
 }
+
+png_writer::png_writer(std::ostream&o, ImageRef size, const std::string& type, 
const std::map<std::string, Parameter<> >&)
+:p(new WriterPimpl(o, size, type))
+{
+}
+
+png_writer::~png_writer()
+{
+}
+//Mechanically generate the pixel writing calls.
+#undef GEN1
+#undef GEN3
+#define GEN1(X) void png_writer::write_raw_pixel_line(const 
X*d){p->write_line(d);}
+#define GEN3(X) GEN1(X) GEN1(Rgb<X>) GEN1(Rgba<X>)
+GEN1(bool)
+GEN1(Rgb8)
+GEN3(unsigned char)
+GEN3(unsigned short)



reply via email to

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