00001 /* 00002 This file is part of the CVD Library. 00003 00004 Copyright (C) 2005 The Authors 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the Free Software 00018 Foundation, Inc., 00019 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 #ifndef PNM_CVDIMAGE_H 00022 #define PNM_CVDIMAGE_H 00023 00024 #include <iostream> 00025 #include <string> 00026 #include <vector> 00027 #include <memory> 00028 00029 #include <cvd/image.h> 00030 #include <cvd/byte.h> 00031 #include <cvd/colourspaces.h> 00032 #include <cvd/internal/convert_pixel_types.h> 00033 #include <cvd/internal/load_and_save.h> 00034 00035 namespace CVD 00036 { 00037 namespace CVDimage 00038 { 00039 00040 using CVD::Internal::TypeList; 00041 using CVD::Internal::Head; 00042 00043 00044 class ReadPimpl; 00045 class reader 00046 { 00047 public: 00048 reader(std::istream&); 00049 ~reader(); 00050 00051 ImageRef size(); 00052 00053 void get_raw_pixel_line(unsigned char*); 00054 void get_raw_pixel_line(bayer_bggr*); 00055 void get_raw_pixel_line(bayer_rggb*); 00056 void get_raw_pixel_line(bayer_grbg*); 00057 void get_raw_pixel_line(bayer_gbrg*); 00058 void get_raw_pixel_line(Rgb<unsigned char>*); 00059 void get_raw_pixel_line(Rgba<unsigned char>*); 00060 00061 std::string datatype(); 00062 std::string name(); 00063 00064 00065 typedef TypeList<byte, 00066 TypeList<bayer_bggr, 00067 TypeList<bayer_rggb, 00068 TypeList<bayer_grbg, 00069 TypeList<bayer_gbrg, 00070 TypeList<Rgb<byte>, 00071 TypeList<Rgba<byte>, 00072 Head> > > > > > > Types; 00073 00074 private: 00075 std::auto_ptr<ReadPimpl> t; 00076 }; 00077 00078 00079 class WritePimpl; 00080 00081 class writer 00082 { 00083 public: 00084 writer(std::ostream&, ImageRef size, const std::string& type, const std::map<std::string, Parameter<> >& p); 00085 ~writer(); 00086 00087 void write_raw_pixel_line(const byte*); 00088 void write_raw_pixel_line(const bayer_bggr*); 00089 void write_raw_pixel_line(const bayer_rggb*); 00090 void write_raw_pixel_line(const bayer_grbg*); 00091 void write_raw_pixel_line(const bayer_gbrg*); 00092 void write_raw_pixel_line(const Rgb<byte>*); 00093 void write_raw_pixel_line(const Rgba<byte>*); 00094 00095 template<class Incoming> struct Outgoing 00096 { 00097 typedef byte type; 00098 }; 00099 00100 protected: 00101 std::auto_ptr<WritePimpl> t; 00102 }; 00103 00104 template <> struct writer::Outgoing<bayer_bggr> 00105 { 00106 typedef bayer_bggr type; 00107 }; 00108 00109 template <> struct writer::Outgoing<bayer_rggb> 00110 { 00111 typedef bayer_rggb type; 00112 }; 00113 00114 template <> struct writer::Outgoing<bayer_grbg> 00115 { 00116 typedef bayer_grbg type; 00117 }; 00118 00119 template <> struct writer::Outgoing<bayer_gbrg> 00120 { 00121 typedef bayer_gbrg type; 00122 }; 00123 00124 template<class C> struct writer::Outgoing<Rgb<C> > 00125 { 00126 typedef Rgb<byte> type; 00127 }; 00128 00129 template<class C> struct writer::Outgoing<Rgba<C> > 00130 { 00131 typedef Rgba<byte> type; 00132 }; 00133 00134 template<> struct writer::Outgoing<Rgb8> 00135 { 00136 typedef Rgb<byte> type; 00137 }; 00138 00139 } 00140 } 00141 00142 #endif