Virtual Testbed
Ship dynamics simulator for extreme conditions
jpeg.hh
1 #ifndef VTESTBED_JPEG_JPEG_HH
2 #define VTESTBED_JPEG_JPEG_HH
3 
4 #include <stdio.h>
5 #include <jpeglib.h>
6 
7 namespace vtb {
8 
10  namespace jpeg {
11 
12  using byte_type = JSAMPLE;
13 
14  enum class Color_space: int {
15  Unknown = JCS_UNKNOWN,
16  Grayscale = JCS_GRAYSCALE,
17  RGB = JCS_RGB,
18  RGBA = JCS_EXT_RGBA,
19  YUV = JCS_YCbCr,
20  CMYK = JCS_CMYK,
21  YCCK = JCS_YCCK,
22  };
23 
24  class jpeg_compress: ::jpeg_compress_struct {
25 
26  private:
27  ::jpeg_error_mgr _err;
28  FILE* _outfile = nullptr;
29 
30  public:
31 
33  const char* filename,
34  Color_space colorspace,
35  int width,
36  int height,
37  int quality,
38  int ncomponents
39  );
40 
41  ~jpeg_compress();
42 
43  void write(const byte_type* bytes);
44  void write_reverse(const byte_type* bytes);
45 
46  private:
47  inline void start() { ::jpeg_start_compress(this, TRUE); }
48  inline void finish() { ::jpeg_finish_compress(this); }
49  inline void close() { ::fclose(this->_outfile); }
50  inline void destroy() { ::jpeg_destroy_compress(this); }
51 
52  };
53 
54  }
55 
56 }
57 
58 #endif // vim:filetype=cpp
Main namespace.
Definition: convert.hh:9