1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
 * @file ImageJPEG.h
 *
 * Declaration of class Image
 */

#ifndef IMAGE_JPEG_H
#define IMAGE_JPEG_H

#include "Image.h"
#include <vector>

class ImageJPEG
{
private:
  //HACK: we wrap the image object here
  naoth::Image* image = nullptr;

public:
  // HACK: wrap the image
  // in the future ImageJPEG should have access to the black board
  void set(naoth::Image& image) {
    this->image = &image;
  }

  const naoth::Image& get() const { return *image; }

  void compressYUYV() const;
  void decompressYUYV(const std::string& data, unsigned int width, unsigned int height);

  const uint8_t* getJPEG() const { return jpeg.data(); }
  size_t getJPEGSize() const { return jpeg_size; }

private:
  // IDEA: would it make sense to make it a parameter?
  // TODO: experiment with quality
  static const int quality = 75;

  mutable std::vector<uint8_t> jpeg;
  mutable size_t jpeg_size = 0;
};

class ImageJPEGTop: public ImageJPEG {};

namespace naoth
{
template<>
class Serializer<ImageJPEG>
{
public:
  static void serialize(const ImageJPEG& representation, std::ostream& stream);<--- Function 'serialize' argument 1 names different: declaration 'representation' definition 'parent'.
  static void deserialize(std::istream& stream, ImageJPEG& representation);
};

template<> class Serializer<ImageJPEGTop> : public Serializer<ImageJPEG> {};

} // end namespace naoth

#endif //_ImageJPEG_h_