forked from chikuzen/MPEG2DecPlus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstore.cpp
183 lines (169 loc) · 6.31 KB
/
store.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
* MPEG2Dec3 : YV12 & PostProcessing
*
* Copyright (C) 2002-2003 Marc Fauconneau <[email protected]>
*
* based of the intial MPEG2Dec Copyright (C) Chia-chen Kuo - April 2001
*
* This file is part of MPEG2Dec3, a free MPEG-2 decoder
*
* MPEG2Dec3 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* MPEG2Dec3 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include "color_convert.h"
//#include "postprocess.h"
#include "misc.h"
#include "MPEG2Decoder.h"
// Write 2-digits numbers in a 16x16 zone.
static void write_quants(uint8_t* dst, int stride, int mb_width, int mb_height,
const int* qp)
{
const uint8_t rien[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
const uint8_t nums[10][8] = {
{ 1, 4, 4, 4, 4, 4, 1, 0 },
{ 3, 3, 3, 3, 3, 3, 3, 0 },
{ 1, 3, 3, 1, 2, 2, 1, 0 },
{ 1, 3, 3, 1, 3, 3, 1, 0 },
{ 4, 4, 4, 1, 3, 3, 3, 0 },
{ 1, 2, 2, 1, 3, 3, 1, 0 },
{ 1, 2, 2, 1, 4, 4, 1, 0 },
{ 1, 3, 3, 3, 3, 3, 3, 0 },
{ 1, 4, 4, 1, 4, 4, 1, 0 },
{ 1, 4, 4, 1, 3, 3, 1, 0 },
};
auto write = [](const uint8_t* num, uint8_t* dst, const int stride) {
for (int y = 0; y < 7; ++y) {
if (num[y] == 1) {
dst[1 + y * stride] = 0xFF;
dst[2 + y * stride] = 0xFF;
dst[3 + y * stride] = 0xFF;
dst[4 + y * stride] = 0xFF;
}
if (num[y] == 2) {
dst[1 + y * stride] = 0xFF;
}
if (num[y] == 3) {
dst[4 + y * stride] = 0xFF;
}
if (num[y] == 4) {
dst[1 + y * stride] = 0xFF;
dst[4 + y * stride] = 0xFF;
}
}
};
for (int y = 0; y < mb_height; ++y) {
for (int x = 0; x < mb_width; ++x) {
int number = qp[x + y * mb_width];
uint8_t* dstp = dst + static_cast<int64_t>(x) * 16 + static_cast<int64_t>(3) * stride;
int c = (number / 100) % 10;
const uint8_t* num = nums[c]; // x00
if (c == 0) num = rien;
write(num, dstp, stride);
dstp += 5;
int d = (number / 10) % 10;
num = nums[d]; // 0x0
if (c == 0 && d == 0) num = rien;
write(num, dstp, stride);
dstp += 5;
num = nums[number % 10]; // 00x
write(num, dstp, stride);
}
dst += static_cast<int64_t>(16) * stride;
}
}
static void set_qparams(const int* qp, size_t mb_size, int& minquant,
int& maxquant, int& avgquant)
{
int minq = qp[0], maxq = qp[0], sum = qp[0];
for (size_t i = 1; i < mb_size; ++i) {
int q = qp[i];
if (q < minq) minq = q;
if (q > maxq) maxq = q;
sum += q;
}
minquant = minq;
maxquant = maxq;
avgquant = static_cast<int>(static_cast<float>(sum) / mb_size + 0.5f);
}
void CMPEG2Decoder::assembleFrame(uint8_t* src[], int pf, YV12PICT& dst)
{
dst.pf = pf;
#if 0
if (pp_mode != 0)
{
uint8_t* ppptr[3];
if (!(upConv > 0 && chroma_format == 1))
{
ppptr[0] = dst->y;
ppptr[1] = dst->u;
ppptr[2] = dst->v;
}
else
{
ppptr[0] = dst->y;
ppptr[1] = u422;
ppptr[2] = v422;
}
bool iPPt;
if (iPP == 1 || (iPP == -1 && pf == 0)) iPPt = true;
else iPPt = false;
postprocess(src, this->Coded_Picture_Width, this->Chroma_Width,
ppptr, dst->ypitch, dst->uvpitch, this->Coded_Picture_Width,
this->Coded_Picture_Height, this->QP, this->mb_width, pp_mode, moderate_h, moderate_v,
chroma_format == 1 ? false : true, iPPt);
if (upConv > 0 && chroma_format == 1)
{
if (iCC == 1 || (iCC == -1 && pf == 0))
{
conv420to422I(ppptr[1], dst->u, dst->uvpitch, dst->uvpitch, Coded_Picture_Width, Coded_Picture_Height);
conv420to422I(ppptr[2], dst->v, dst->uvpitch, dst->uvpitch, Coded_Picture_Width, Coded_Picture_Height);
}
else
{
conv420to422P(ppptr[1], dst->u, dst->uvpitch, dst->uvpitch, Coded_Picture_Width, Coded_Picture_Height);
conv420to422P(ppptr[2], dst->v, dst->uvpitch, dst->uvpitch, Coded_Picture_Width, Coded_Picture_Height);
}
}
}
else
#endif
{
fast_copy(src[0], Coded_Picture_Width, dst.y, dst.ypitch, Coded_Picture_Width, Coded_Picture_Height);
if (upConv > 0 && chroma_format == 1) {
if (iCC == 1 || (iCC == -1 && pf == 0)) {
conv420to422I(src[1], dst.u, Chroma_Width, dst.uvpitch, Coded_Picture_Width, Coded_Picture_Height);
conv420to422I(src[2], dst.v, Chroma_Width, dst.uvpitch, Coded_Picture_Width, Coded_Picture_Height);
}
else {
conv420to422P(src[1], dst.u, Chroma_Width, dst.uvpitch, Coded_Picture_Width, Coded_Picture_Height);
conv420to422P(src[2], dst.v, Chroma_Width, dst.uvpitch, Coded_Picture_Width, Coded_Picture_Height);
}
}
else {
fast_copy(src[1], Chroma_Width, dst.u, dst.uvpitch, Chroma_Width, Chroma_Height);
fast_copy(src[2], Chroma_Width, dst.v, dst.uvpitch, Chroma_Width, Chroma_Height);
}
}
if (has_prop || info == 1 || info == 2 || showQ) {
// Re-order quant data for display order.
const int* qp = (picture_coding_type == B_TYPE) ? auxQP : backwardQP;
if (has_prop || info == 1 || info == 2) {
set_qparams(qp, static_cast<int64_t>(mb_width) * mb_height, minquant, maxquant, avgquant);
}
if (showQ) {
write_quants(dst.y, dst.ypitch, mb_width, mb_height, qp);
}
}
}