Allow size-specific resizers
[jpcrr.git] / streamtools / resize.hpp
blob9ef50cae814db8b9f5bc9c81fe0b7908facdc108
1 #ifndef _resize__hpp__included__
2 #define _resize__hpp__included__
4 #include <stdint.h>
5 #include <string>
6 #include "newpacket.hpp"
8 class resizer
10 public:
11 virtual ~resizer();
12 virtual void operator()(uint8_t* target, uint32_t twidth, uint32_t theight,
13 const uint8_t* source, uint32_t swidth, uint32_t sheight) = 0;
16 class resizer_factory
18 public:
19 resizer_factory(const std::string& type);
20 virtual ~resizer_factory();
21 static resizer& make_by_type(const std::string& type);
22 virtual resizer& make(const std::string& type) = 0;
23 private:
24 static std::map<std::string, resizer_factory*>* factories;
25 friend std::string get_resizer_list();
28 class simple_resizer : public resizer_factory
30 public:
31 simple_resizer(const std::string& type, void(*resize_fn)(uint8_t* target, uint32_t twidth, uint32_t theight,
32 const uint8_t* source, uint32_t swidth, uint32_t sheight));
33 simple_resizer(const std::string& type, void(*resize_fn)(uint8_t* target, uint32_t twidth, uint32_t theight,
34 const uint8_t* source, uint32_t swidth, uint32_t sheight, int algo), int algo);
35 resizer& make(const std::string& type);
36 private:
37 void(*resize_fn)(uint8_t* target, uint32_t twidth, uint32_t theight, const uint8_t* source, uint32_t swidth,
38 uint32_t sheight);
39 void(*resize_fn2)(uint8_t* target, uint32_t twidth, uint32_t theight, const uint8_t* source, uint32_t swidth,
40 uint32_t sheight, int algo);
41 int algo;
45 struct image_frame_rgbx
47 public:
48 image_frame_rgbx(uint32_t width, uint32_t height);
49 image_frame_rgbx(struct packet& p);
50 ~image_frame_rgbx();
51 image_frame_rgbx(const image_frame_rgbx& x);
52 image_frame_rgbx& operator=(const image_frame_rgbx& x);
53 uint32_t get_height() const;
54 uint32_t get_width() const;
55 unsigned char* get_pixels(); //RGBx data.
56 const unsigned char* get_pixels() const; //RGBx data.
57 size_t get_data_size() const; //Bytes.
58 //This returns the frame itself if it is already of suitable size.
59 image_frame_rgbx& resize(uint32_t nwidth, uint32_t nheight, resizer& using_resizer);
60 private:
61 uint32_t width;
62 uint32_t height;
63 unsigned char* imagedata; //RGBx.
66 std::string get_resizer_list();
68 #endif