[Top][All Lists]
[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: |
Fri, 05 Nov 2010 15:09:52 +0000 |
CVSROOT: /cvsroot/libcvd
Module name: libcvd
Changes by: Edward Rosten <edrosten> 10/11/05 15:09:52
Modified files:
cvd/internal/io: png.h
pnm_src : png.cc
Log message:
PIMPlify PNG reader.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/internal/io/png.h?cvsroot=libcvd&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/libcvd/pnm_src/png.cc?cvsroot=libcvd&r1=1.12&r2=1.13
Patches:
Index: cvd/internal/io/png.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/internal/io/png.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- cvd/internal/io/png.h 21 Mar 2010 19:02:02 -0000 1.10
+++ cvd/internal/io/png.h 5 Nov 2010 15:09:52 -0000 1.11
@@ -23,6 +23,7 @@
#include <iostream>
#include <vector>
#include <string>
+#include <memory>
#include <cvd/image.h>
#include <cvd/internal/load_and_save.h>
@@ -39,6 +40,7 @@
using CVD::Internal::Head;
+class PNGPimpl;
class png_reader
{
@@ -69,17 +71,7 @@
Head> > > > > > >
Types;
private:
-
- std::istream& i;
- std::string type;
- unsigned long row;
- png_struct_def* png_ptr;
- png_info_struct* info_ptr, *end_info;
-
- std::string error_string;
- ImageRef my_size;
-
- template<class C> void read_pixels(C*);
+ std::auto_ptr<PNGPimpl> p;
};
Index: pnm_src/png.cc
===================================================================
RCS file: /cvsroot/libcvd/libcvd/pnm_src/png.cc,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- pnm_src/png.cc 21 Mar 2010 19:02:03 -0000 1.12
+++ pnm_src/png.cc 5 Nov 2010 15:09:52 -0000 1.13
@@ -4,6 +4,7 @@
#include <png.h>
#include <cstdlib>
+#include <iostream>
using namespace CVD;
using namespace CVD::Exceptions;
@@ -49,35 +50,56 @@
////////////////////////////////////////////////////////////////////////////////
//
+// Implementation of PNGPimpl
+//
+
+
+class CVD::PNG::PNGPimpl
+{
+
+ public:
+ template<class C> void read_pixels(C*);
+ PNGPimpl(std::istream& in);
+ ~PNGPimpl();
+ std::string datatype();
+ std::string name();
+ ImageRef size();
+
+ private:
+ std::istream& i;
+ std::string type;
+ unsigned long row;
+ png_struct_def* png_ptr;
+ png_info_struct* info_ptr, *end_info;
+
+ std::string error_string;
+ ImageRef my_size;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+//
// PNG reading functions
//
-string png_reader::datatype()
+string PNGPimpl::datatype()
{
return type;
}
-string png_reader::name()
+string PNGPimpl::name()
{
return "PNG";
}
-ImageRef png_reader::size()
+ImageRef PNGPimpl::size()
{
return my_size;
}
-//Mechanically generate the pixel reading calls.
-#define GEN1(X) void png_reader::get_raw_pixel_line(X*d){read_pixels(d);}
-#define GEN3(X) GEN1(X) GEN1(Rgb<X>) GEN1(Rgba<X>)
-GEN1(bool)
-GEN3(unsigned char)
-GEN3(unsigned short)
+#define LOG(X) do{ cerr << X; }while(0)
-
-
-template<class P> void png_reader::read_pixels(P* data)
+template<class P> void PNGPimpl::read_pixels(P* data)
{
if(datatype() != PNM::type_name<P>::name())
throw ReadTypeMismatch(datatype(), PNM::type_name<P>::name());
@@ -97,7 +119,7 @@
-png_reader::png_reader(std::istream& in)
+PNGPimpl::PNGPimpl(std::istream& in)
:i(in),type(""),row(0),png_ptr(0),info_ptr(0),end_info(0)
{
//Read the header and make sure it really is a PNG...
@@ -108,6 +130,7 @@
if(png_sig_cmp(header, 0, 8))
throw Exceptions::Image_IO::MalformedImage("Not a PNG image");
+ LOG("PNG header found\n");
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL,
NULL);
@@ -204,7 +227,7 @@
#endif
}
-png_reader::~png_reader()
+PNGPimpl::~PNGPimpl()
{
//Clear the stream of any remaining PNG bits.
//It doesn't matter if there's an error here
@@ -218,10 +241,47 @@
////////////////////////////////////////////////////////////////////////////////
//
+// Implementation of PNG reader class
+//
+
+png_reader::~png_reader()
+{
+}
+
+png_reader::png_reader(istream& i)
+:p(new PNGPimpl(i))
+{
+}
+
+string png_reader::datatype()
+{
+ return p->datatype();
+}
+
+string png_reader::name()
+{
+ return p->name();
+}
+
+ImageRef png_reader::size()
+{
+ return p->size();
+}
+
+
+//Mechanically generate the pixel reading calls.
+#define GEN1(X) void png_reader::get_raw_pixel_line(X*d){p->read_pixels(d);}
+#define GEN3(X) GEN1(X) GEN1(Rgb<X>) GEN1(Rgba<X>)
+GEN1(bool)
+GEN3(unsigned char)
+GEN3(unsigned short)
+
+////////////////////////////////////////////////////////////////////////////////
+//
// PNG writing functions.
//
-png_writer::png_writer(ostream& out, ImageRef sz, const string& type_, const
std::map<std::string, Parameter<> >& p)
+png_writer::png_writer(ostream& out, ImageRef sz, const string& type_, const
std::map<std::string, Parameter<> >&)
:row(0),o(out),size(sz),type(type_)
{
//Create required structs
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libcvd-members] libcvd cvd/internal/io/png.h pnm_src/png.cc,
Edward Rosten <=