FFmpeg
mss34dsp.c
Go to the documentation of this file.
1 /*
2  * Common stuff for some Microsoft Screen codecs
3  * Copyright (C) 2012 Konstantin Shishkov
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <stdint.h>
23 #include "libavutil/common.h"
24 #include "mss34dsp.h"
25 #include "jpegquanttables.h"
26 
27 void ff_mss34_gen_quant_mat(uint16_t *qmat, int quality, int luma)
28 {
29  int i;
31 
32  if (quality >= 50) {
33  int scale = 200 - 2 * quality;
34 
35  for (i = 0; i < 64; i++)
36  qmat[i] = (qsrc[i] * scale + 50) / 100;
37  } else {
38  for (i = 0; i < 64; i++)
39  qmat[i] = (5000 * qsrc[i] / quality + 50) / 100;
40  }
41 }
42 
43 #define DCT_TEMPLATE(blk, step, SOP, shift) \
44  const unsigned t0 =-39409U * blk[7 * step] - 58980U * blk[1 * step]; \
45  const unsigned t1 = 39410U * blk[1 * step] - 58980U * blk[7 * step]; \
46  const unsigned t2 =-33410U * blk[5 * step] -167963U * blk[3 * step]; \
47  const unsigned t3 = 33410U * blk[3 * step] -167963U * blk[5 * step]; \
48  const unsigned t4 = blk[3 * step] + blk[7 * step]; \
49  const unsigned t5 = blk[1 * step] + blk[5 * step]; \
50  const unsigned t6 = 77062U * t4 + 51491U * t5; \
51  const unsigned t7 = 77062U * t5 - 51491U * t4; \
52  const unsigned t8 = 35470U * blk[2 * step] - 85623U * blk[6 * step]; \
53  const unsigned t9 = 35470U * blk[6 * step] + 85623U * blk[2 * step]; \
54  const unsigned tA = SOP(blk[0 * step] - blk[4 * step]); \
55  const unsigned tB = SOP(blk[0 * step] + blk[4 * step]); \
56  \
57  blk[0 * step] = (int)( t1 + t6 + t9 + tB) >> shift; \
58  blk[1 * step] = (int)( t3 + t7 + t8 + tA) >> shift; \
59  blk[2 * step] = (int)( t2 + t6 - t8 + tA) >> shift; \
60  blk[3 * step] = (int)( t0 + t7 - t9 + tB) >> shift; \
61  blk[4 * step] = (int)(-(t0 + t7) - t9 + tB) >> shift; \
62  blk[5 * step] = (int)(-(t2 + t6) - t8 + tA) >> shift; \
63  blk[6 * step] = (int)(-(t3 + t7) + t8 + tA) >> shift; \
64  blk[7 * step] = (int)(-(t1 + t6) + t9 + tB) >> shift; \
65 
66 #define SOP_ROW(a) (((a) * (1U << 16)) + 0x2000)
67 #define SOP_COL(a) (((a) + 32) * (1U << 16))
68 
69 void ff_mss34_dct_put(uint8_t *dst, ptrdiff_t stride, int *block)
70 {
71  int i, j;
72  int *ptr;
73 
74  ptr = block;
75  for (i = 0; i < 8; i++) {
76  DCT_TEMPLATE(ptr, 1, SOP_ROW, 13);
77  ptr += 8;
78  }
79 
80  ptr = block;
81  for (i = 0; i < 8; i++) {
82  DCT_TEMPLATE(ptr, 8, SOP_COL, 22);
83  ptr++;
84  }
85 
86  ptr = block;
87  for (j = 0; j < 8; j++) {
88  for (i = 0; i < 8; i++)
89  dst[i] = av_clip_uint8(ptr[i] + 128);
90  dst += stride;
91  ptr += 8;
92  }
93 }
ff_mss34_gen_quant_mat
void ff_mss34_gen_quant_mat(uint16_t *qmat, int quality, int luma)
Generate quantisation matrix for given quality.
Definition: mss34dsp.c:27
quality
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about quality
Definition: rate_distortion.txt:12
SOP_COL
#define SOP_COL(a)
Definition: mss34dsp.c:67
jpegquanttables.h
mss34dsp.h
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
common.h
DCT_TEMPLATE
#define DCT_TEMPLATE(blk, step, SOP, shift)
Definition: mss34dsp.c:43
ff_mjpeg_std_chrominance_quant_tbl
const uint8_t ff_mjpeg_std_chrominance_quant_tbl[64]
Definition: jpegquanttables.c:45
stride
#define stride
Definition: h264pred_template.c:537
ff_mjpeg_std_luminance_quant_tbl
const uint8_t ff_mjpeg_std_luminance_quant_tbl[64]
Definition: jpegquanttables.c:35
av_clip_uint8
#define av_clip_uint8
Definition: common.h:106
SOP_ROW
#define SOP_ROW(a)
Definition: mss34dsp.c:66
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
ff_mss34_dct_put
void ff_mss34_dct_put(uint8_t *dst, ptrdiff_t stride, int *block)
Transform and output DCT block.
Definition: mss34dsp.c:69