MythTV  master
RTjpegN.h
Go to the documentation of this file.
1 /*
2  RTjpeg (C) Justin Schoeman 1998 (justin@suntiger.ee.up.ac.za)
3 
4  With modifications by:
5  (c) 1998, 1999 by Joerg Walter <trouble@moes.pmnet.uni-oldenburg.de>
6  and
7  (c) 1999 by Wim Taymans <wim.taymans@tvd.be>
8 
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13 
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23 
24 #ifndef RTJPEG_H
25 #define RTJPEG_H
26 
27 #include "mythconfig.h"
28 #include "mythtvexp.h"
29 #include <cstdint>
30 
31 /*
32  * Macros and definitions used internally to RTjpeg
33  */
34 
35 #define RTJPEG_FILE_VERSION 0
36 #define RTJPEG_HEADER_SIZE 12
37 
38 using RTjpegData16 = std::array<int16_t,64>;
39 using RTjpegData32 = std::array<int32_t,64>;
40 
41 #if HAVE_BIGENDIAN
42 #define RTJPEG_SWAP_WORD(a) ( ((a) << 24) | \
43  (((a) << 8) & 0x00ff0000) | \
44  (((a) >> 8) & 0x0000ff00) | \
45  ((unsigned long)(a) >>24) )
46 #define RTJPEG_SWAP_HALFWORD(a) ( (((a) << 8) & 0xff00) | \
47  (((a) >> 8) & 0x00ff) )
48 #else
49 #define RTJPEG_SWAP_WORD(a) (a)
50 #define RTJPEG_SWAP_HALFWORD(a) (a)
51 #endif
52 
53 #if HAVE_STDINT_H
54 #include <cstdint>
55 #endif
56 
57 #ifdef MMX
58 #include "ffmpeg-mmx.h"
59 #endif
60 
61 /* Format definitions */
62 
63 #define RTJ_YUV420 0
64 #define RTJ_YUV422 1
65 #define RTJ_RGB8 2
66 
67 class RTjpeg
68 {
69  public:
70  RTjpeg();
71  ~RTjpeg();
72 
73  int SetQuality(int *quality);
74  int SetFormat(const int *fmt);
75  int SetSize(const int *w, const int *h);
76  int SetIntra(int *key, int *lm, int *cm);
77 
78  int Compress(int8_t *sp, uint8_t **planes);
79  void Decompress(int8_t *sp, uint8_t **planes);
80 
81  void SetNextKey(void);
82 
83 private:
84  static int b2s(const RTjpegData16 &data, int8_t *strm, uint8_t bt8);
85  static int s2b(RTjpegData16 &data, const int8_t *strm, uint8_t bt8, RTjpegData32 &qtbla);
86 
87  void QuantInit(void);
88  static void Quant(RTjpegData16 &block, RTjpegData32 &qtbl);
89 
90  void DctInit(void);
91  void DctY(uint8_t *idata, int rskip);
92 
93  void IdctInit(void);
94  void Idct(uint8_t *odata, RTjpegData16 &data, int rskip);
95 
96  void CalcTbls(void);
97 
98  inline int compressYUV420(int8_t *sp, uint8_t **planes);
99  inline int compressYUV422(int8_t *sp, uint8_t **planes);
100  inline int compress8(int8_t *sp, uint8_t **planes);
101 
102  int mcompressYUV420(int8_t *sp, uint8_t **planes);
103  int mcompressYUV422(int8_t *sp, uint8_t **planes);
104  int mcompress8(int8_t *sp, uint8_t **planes);
105 
106  void decompressYUV422(int8_t *sp, uint8_t **planes);
107  void decompressYUV420(int8_t *sp, uint8_t **planes);
108  void decompress8(int8_t *sp, uint8_t **planes);
109 
110 #ifdef MMX
111  static int bcomp(RTjpegData16 &rblock, int16_t *old, mmx_t *mask);
112 #else
113  static int bcomp(RTjpegData16 &rblock, int16_t *old, uint16_t *mask);
114 #endif
115 
116  alignas(32) RTjpegData16 m_block {0};
117  alignas(32) std::array<int32_t,64*4> m_ws {0};
118  alignas(32) RTjpegData32 m_lqt {0};
119  alignas(32) RTjpegData32 m_cqt {0};
120  alignas(32) RTjpegData32 m_liqt {0};
121  alignas(32) RTjpegData32 m_ciqt {0};
122  int32_t m_lB8 {0};
123  int32_t m_cB8 {0};
124  int32_t m_yWidth {0};
125  int32_t m_cWidth {0};
126  int32_t m_ySize {0};
127  int32_t m_cSize {0};
128  int16_t *m_old {nullptr};
129  int16_t *m_oldStart {nullptr};
130  int m_keyCount {0};
131 
132  int m_width {0};
133  int m_height {0};
134  int m_q {0};
135  int m_f {0};
136 #ifdef MMX
137  mmx_t m_lMask {};
138  mmx_t m_cMask {};
139 #else
140  uint16_t m_lMask {0};
141  uint16_t m_cMask {0};
142 #endif
143  int m_keyRate {0};
144 };
145 
147  uint32_t framesize;
148  uint8_t headersize;
149  uint8_t version;
152  uint8_t quality;
153  uint8_t key;
154  uint8_t data;
155 };
156 
157 #endif // RTJPEG_H
RTjpeg_frameheader::headersize
uint8_t headersize
Definition: RTjpegN.h:148
RTjpeg::mcompressYUV422
int mcompressYUV422(int8_t *sp, uint8_t **planes)
Definition: RTjpegN.cpp:3180
RTjpeg::s2b
static int s2b(RTjpegData16 &data, const int8_t *strm, uint8_t bt8, RTjpegData32 &qtbla)
Definition: RTjpegN.cpp:279
RTjpeg::DctY
void DctY(uint8_t *idata, int rskip)
Definition: RTjpegN.cpp:597
RTjpeg_frameheader::key
uint8_t key
Definition: RTjpegN.h:153
RTjpegData16
std::array< int16_t, 64 > RTjpegData16
Definition: RTjpegN.h:38
RTjpeg::m_lB8
int32_t m_lB8
Definition: RTjpegN.h:122
RTjpeg::m_yWidth
int32_t m_yWidth
Definition: RTjpegN.h:124
RTjpeg::compress8
int compress8(int8_t *sp, uint8_t **planes)
Definition: RTjpegN.cpp:2879
mythtvexp.h
RTjpeg::m_lMask
mmx_t m_lMask
Definition: RTjpegN.h:137
RTjpeg::m_ySize
int32_t m_ySize
Definition: RTjpegN.h:126
RTjpeg::b2s
static int b2s(const RTjpegData16 &data, int8_t *strm, uint8_t bt8)
Definition: RTjpegN.cpp:111
RTjpeg::m_oldStart
int16_t * m_oldStart
Definition: RTjpegN.h:129
RTjpeg::SetNextKey
void SetNextKey(void)
Definition: RTjpegN.cpp:3265
RTjpeg::m_q
int m_q
Definition: RTjpegN.h:134
RTjpeg_frameheader
Definition: RTjpegN.h:146
RTjpeg_frameheader::width
uint16_t width
Definition: RTjpegN.h:150
RTjpeg::m_height
int m_height
Definition: RTjpegN.h:133
RTjpeg_frameheader::quality
uint8_t quality
Definition: RTjpegN.h:152
RTjpeg::m_cB8
int32_t m_cB8
Definition: RTjpegN.h:123
RTjpeg::DctInit
void DctInit(void)
Definition: RTjpegN.cpp:588
RTjpeg::CalcTbls
void CalcTbls(void)
Definition: RTjpegN.cpp:2636
RTjpeg::QuantInit
void QuantInit(void)
Definition: RTjpegN.cpp:513
RTjpeg::bcomp
static int bcomp(RTjpegData16 &rblock, int16_t *old, mmx_t *mask)
Definition: RTjpegN.cpp:3043
RTjpeg::mcompress8
int mcompress8(int8_t *sp, uint8_t **planes)
Definition: RTjpegN.cpp:3239
ffmpeg-mmx.h
RTjpeg::mcompressYUV420
int mcompressYUV420(int8_t *sp, uint8_t **planes)
Definition: RTjpegN.cpp:3098
RTjpeg::compressYUV420
int compressYUV420(int8_t *sp, uint8_t **planes)
Definition: RTjpegN.cpp:2785
RTjpeg::decompress8
void decompress8(int8_t *sp, uint8_t **planes)
Definition: RTjpegN.cpp:3017
RTjpeg::m_cWidth
int32_t m_cWidth
Definition: RTjpegN.h:125
RTjpeg::Idct
void Idct(uint8_t *odata, RTjpegData16 &data, int rskip)
Definition: RTjpegN.cpp:1518
RTjpeg::m_width
int m_width
Definition: RTjpegN.h:132
RTjpeg::m_ws
std::array< int32_t, 64 *4 > m_ws
Definition: RTjpegN.h:117
RTjpeg::~RTjpeg
~RTjpeg()
Definition: RTjpegN.cpp:2780
RTjpeg
Definition: RTjpegN.h:68
RTjpeg::Quant
static void Quant(RTjpegData16 &block, RTjpegData32 &qtbl)
Definition: RTjpegN.cpp:528
RTjpeg::m_block
RTjpegData16 m_block
Definition: RTjpegN.h:116
RTjpeg::decompressYUV420
void decompressYUV420(int8_t *sp, uint8_t **planes)
Definition: RTjpegN.cpp:2955
RTjpeg::SetIntra
int SetIntra(int *key, int *lm, int *cm)
Definition: RTjpegN.cpp:2725
RTjpeg::m_lqt
RTjpegData32 m_lqt
Definition: RTjpegN.h:118
planes
static uint planes(VideoFrameType Type)
Definition: mythframe.h:574
RTjpeg_frameheader::version
uint8_t version
Definition: RTjpegN.h:149
RTjpeg::m_keyCount
int m_keyCount
Definition: RTjpegN.h:130
RTjpeg_frameheader::height
uint16_t height
Definition: RTjpegN.h:151
RTjpeg::SetFormat
int SetFormat(const int *fmt)
Definition: RTjpegN.cpp:2684
RTjpeg::m_ciqt
RTjpegData32 m_ciqt
Definition: RTjpegN.h:121
RTjpeg::m_old
int16_t * m_old
Definition: RTjpegN.h:128
RTjpeg::m_keyRate
int m_keyRate
Definition: RTjpegN.h:143
RTjpeg::SetSize
int SetSize(const int *w, const int *h)
Definition: RTjpegN.cpp:2690
RTjpeg::IdctInit
void IdctInit(void)
Definition: RTjpegN.cpp:1509
RTjpeg::decompressYUV422
void decompressYUV422(int8_t *sp, uint8_t **planes)
Definition: RTjpegN.cpp:2907
RTjpeg::Decompress
void Decompress(int8_t *sp, uint8_t **planes)
Definition: RTjpegN.cpp:3307
RTjpeg_frameheader::framesize
uint32_t framesize
Definition: RTjpegN.h:147
RTjpeg::compressYUV422
int compressYUV422(int8_t *sp, uint8_t **planes)
Definition: RTjpegN.cpp:2836
RTjpeg_frameheader::data
uint8_t data
Definition: RTjpegN.h:154
uint16_t
unsigned short uint16_t
Definition: iso6937tables.h:3
RTjpeg::m_cSize
int32_t m_cSize
Definition: RTjpegN.h:127
RTjpeg::m_cMask
mmx_t m_cMask
Definition: RTjpegN.h:138
RTjpeg::m_cqt
RTjpegData32 m_cqt
Definition: RTjpegN.h:119
RTjpeg::m_liqt
RTjpegData32 m_liqt
Definition: RTjpegN.h:120
RTjpeg::SetQuality
int SetQuality(int *quality)
Definition: RTjpegN.cpp:2667
RTjpeg::Compress
int Compress(int8_t *sp, uint8_t **planes)
Definition: RTjpegN.cpp:3270
RTjpegData32
std::array< int32_t, 64 > RTjpegData32
Definition: RTjpegN.h:39
RTjpeg::m_f
int m_f
Definition: RTjpegN.h:135
RTjpeg::RTjpeg
RTjpeg()
Definition: RTjpegN.cpp:2767