| 1 | #ifndef PNM_JPEG_H |
| 2 | #define PNM_JPEG_H |
| 3 | |
| 4 | #include <iostream> |
| 5 | #include <memory> |
| 6 | #include <string> |
| 7 | #include <vector> |
| 8 | |
| 9 | #include <cvd/byte.h> |
| 10 | #include <cvd/image.h> |
| 11 | #include <cvd/internal/convert_pixel_types.h> |
| 12 | #include <cvd/internal/load_and_save.h> |
| 13 | |
| 14 | namespace CVD |
| 15 | { |
| 16 | namespace JPEG |
| 17 | { |
| 18 | |
| 19 | using CVD::Internal::Head; |
| 20 | using CVD::Internal::TypeList; |
| 21 | |
| 22 | class ReadPimpl; |
| 23 | class Reader |
| 24 | { |
| 25 | public: |
| 26 | Reader(std::istream&); |
| 27 | ~Reader(); |
| 28 | |
| 29 | ImageRef size(); |
| 30 | bool top_row_first(); |
| 31 | |
| 32 | void get_raw_pixel_line(unsigned char*); |
| 33 | void get_raw_pixel_line(Rgb<unsigned char>*); |
| 34 | |
| 35 | std::string datatype(); |
| 36 | std::string name(); |
| 37 | |
| 38 | typedef TypeList<byte, |
| 39 | TypeList<Rgb<byte>, |
| 40 | Head>> |
| 41 | Types; |
| 42 | |
| 43 | static bool first_byte_matches(const int b) |
| 44 | { |
| 45 | return b == 0xff; |
| 46 | } |
| 47 | |
| 48 | private: |
| 49 | std::unique_ptr<ReadPimpl> t; |
| 50 | }; |
| 51 | |
| 52 | class WritePimpl; |
| 53 | |
| 54 | class writer |
| 55 | { |
| 56 | public: |
| 57 | writer(std::ostream&, ImageRef size, const std::string& type, const std::map<std::string, Parameter<>>& p); |
| 58 | ~writer(); |
| 59 | |
| 60 | void write_raw_pixel_line(const byte*); |
| 61 | void write_raw_pixel_line(const Rgb<byte>*); |
| 62 | |
| 63 | template <class Incoming> |
| 64 | struct Outgoing |
| 65 | { |
| 66 | typedef byte type; |
| 67 | }; |
| 68 | |
| 69 | static const int top_row_first = 1; |
| 70 | |
| 71 | protected: |
| 72 | std::unique_ptr<WritePimpl> t; |
| 73 | }; |
| 74 | |
| 75 | template <class C> |
| 76 | struct writer::Outgoing<Rgb<C>> |
| 77 | { |
| 78 | typedef Rgb<byte> type; |
| 79 | }; |
| 80 | |
| 81 | template <class C> |
| 82 | struct writer::Outgoing<Rgba<C>> |
| 83 | { |
| 84 | typedef Rgb<byte> type; |
| 85 | }; |
| 86 | |
| 87 | template <> |
| 88 | struct writer::Outgoing<Rgb8> |
| 89 | { |
| 90 | typedef Rgb<byte> type; |
| 91 | }; |
| 92 | |
| 93 | } |
| 94 | } |
| 95 | #endif |