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_JPEG_H 00022 #define PNM_JPEG_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/internal/convert_pixel_types.h> 00032 #include <cvd/internal/load_and_save.h> 00033 00034 namespace CVD 00035 { 00036 namespace JPEG 00037 { 00038 00039 using CVD::Internal::TypeList; 00040 using CVD::Internal::Head; 00041 00042 00043 class ReadPimpl; 00044 class reader 00045 { 00046 public: 00047 reader(std::istream&); 00048 ~reader(); 00049 00050 ImageRef size(); 00051 00052 void get_raw_pixel_line(unsigned char*); 00053 void get_raw_pixel_line(Rgb<unsigned char>*); 00054 00055 std::string datatype(); 00056 std::string name(); 00057 00058 00059 typedef TypeList<byte, 00060 TypeList<Rgb<byte>, 00061 Head> > Types; 00062 00063 private: 00064 std::auto_ptr<ReadPimpl> t; 00065 }; 00066 00067 00068 class WritePimpl; 00069 00070 class writer 00071 { 00072 public: 00073 writer(std::ostream&, ImageRef size, const std::string& type, const std::map<std::string, Parameter<> >& p); 00074 ~writer(); 00075 00076 void write_raw_pixel_line(const byte*); 00077 void write_raw_pixel_line(const Rgb<byte>*); 00078 00079 template<class Incoming> struct Outgoing 00080 { 00081 typedef byte type; 00082 }; 00083 00084 protected: 00085 std::auto_ptr<WritePimpl> t; 00086 }; 00087 00088 template<class C> struct writer::Outgoing<Rgb<C> > 00089 { 00090 typedef Rgb<byte> type; 00091 }; 00092 00093 00094 template<class C> struct writer::Outgoing<Rgba<C> > 00095 { 00096 typedef Rgb<byte> type; 00097 }; 00098 00099 template<> struct writer::Outgoing<Rgb8> 00100 { 00101 typedef Rgb<byte> type; 00102 }; 00103 00104 } 00105 } 00106 00107 #endif