Libav
mpegvideoencdsp.c
Go to the documentation of this file.
1 /*
2  * This file is part of Libav.
3  *
4  * Libav is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * Libav is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with Libav; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <assert.h>
20 #include <stdint.h>
21 #include <string.h>
22 
23 #include "config.h"
24 #include "libavutil/attributes.h"
25 #include "libavutil/imgutils.h"
26 #include "avcodec.h"
27 #include "imgconvert.h"
28 #include "me_cmp.h"
29 #include "mpegvideoencdsp.h"
30 
31 static int try_8x8basis_c(int16_t rem[64], int16_t weight[64],
32  int16_t basis[64], int scale)
33 {
34  int i;
35  unsigned int sum = 0;
36 
37  for (i = 0; i < 8 * 8; i++) {
38  int b = rem[i] + ((basis[i] * scale +
39  (1 << (BASIS_SHIFT - RECON_SHIFT - 1))) >>
41  int w = weight[i];
42  b >>= RECON_SHIFT;
43  assert(-512 < b && b < 512);
44 
45  sum += (w * b) * (w * b) >> 4;
46  }
47  return sum >> 2;
48 }
49 
50 static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale)
51 {
52  int i;
53 
54  for (i = 0; i < 8 * 8; i++)
55  rem[i] += (basis[i] * scale +
56  (1 << (BASIS_SHIFT - RECON_SHIFT - 1))) >>
58 }
59 
60 static int pix_sum_c(uint8_t *pix, int line_size)
61 {
62  int s = 0, i, j;
63 
64  for (i = 0; i < 16; i++) {
65  for (j = 0; j < 16; j += 8) {
66  s += pix[0];
67  s += pix[1];
68  s += pix[2];
69  s += pix[3];
70  s += pix[4];
71  s += pix[5];
72  s += pix[6];
73  s += pix[7];
74  pix += 8;
75  }
76  pix += line_size - 16;
77  }
78  return s;
79 }
80 
81 static int pix_norm1_c(uint8_t *pix, int line_size)
82 {
83  int s = 0, i, j;
84  uint32_t *sq = ff_square_tab + 256;
85 
86  for (i = 0; i < 16; i++) {
87  for (j = 0; j < 16; j += 8) {
88 #if 0
89  s += sq[pix[0]];
90  s += sq[pix[1]];
91  s += sq[pix[2]];
92  s += sq[pix[3]];
93  s += sq[pix[4]];
94  s += sq[pix[5]];
95  s += sq[pix[6]];
96  s += sq[pix[7]];
97 #else
98 #if HAVE_FAST_64BIT
99  register uint64_t x = *(uint64_t *) pix;
100  s += sq[x & 0xff];
101  s += sq[(x >> 8) & 0xff];
102  s += sq[(x >> 16) & 0xff];
103  s += sq[(x >> 24) & 0xff];
104  s += sq[(x >> 32) & 0xff];
105  s += sq[(x >> 40) & 0xff];
106  s += sq[(x >> 48) & 0xff];
107  s += sq[(x >> 56) & 0xff];
108 #else
109  register uint32_t x = *(uint32_t *) pix;
110  s += sq[x & 0xff];
111  s += sq[(x >> 8) & 0xff];
112  s += sq[(x >> 16) & 0xff];
113  s += sq[(x >> 24) & 0xff];
114  x = *(uint32_t *) (pix + 4);
115  s += sq[x & 0xff];
116  s += sq[(x >> 8) & 0xff];
117  s += sq[(x >> 16) & 0xff];
118  s += sq[(x >> 24) & 0xff];
119 #endif
120 #endif
121  pix += 8;
122  }
123  pix += line_size - 16;
124  }
125  return s;
126 }
127 
128 /* draw the edges of width 'w' of an image of size width, height */
129 // FIXME: Check that this is OK for MPEG-4 interlaced.
130 static void draw_edges_8_c(uint8_t *buf, int wrap, int width, int height,
131  int w, int h, int sides)
132 {
133  uint8_t *ptr = buf, *last_line;
134  int i;
135 
136  /* left and right */
137  for (i = 0; i < height; i++) {
138  memset(ptr - w, ptr[0], w);
139  memset(ptr + width, ptr[width - 1], w);
140  ptr += wrap;
141  }
142 
143  /* top and bottom + corners */
144  buf -= w;
145  last_line = buf + (height - 1) * wrap;
146  if (sides & EDGE_TOP)
147  for (i = 0; i < h; i++)
148  // top
149  memcpy(buf - (i + 1) * wrap, buf, width + w + w);
150  if (sides & EDGE_BOTTOM)
151  for (i = 0; i < h; i++)
152  // bottom
153  memcpy(last_line + (i + 1) * wrap, last_line, width + w + w);
154 }
155 
157  AVCodecContext *avctx)
158 {
161 
162  c->shrink[0] = av_image_copy_plane;
163  c->shrink[1] = ff_shrink22;
164  c->shrink[2] = ff_shrink44;
165  c->shrink[3] = ff_shrink88;
166 
167  c->pix_sum = pix_sum_c;
168  c->pix_norm1 = pix_norm1_c;
169 
171 
172  if (ARCH_ARM)
173  ff_mpegvideoencdsp_init_arm(c, avctx);
174  if (ARCH_PPC)
175  ff_mpegvideoencdsp_init_ppc(c, avctx);
176  if (ARCH_X86)
177  ff_mpegvideoencdsp_init_x86(c, avctx);
178 }
int(* try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale)
#define ARCH_ARM
Definition: config.h:14
#define RECON_SHIFT
static int pix_norm1_c(uint8_t *pix, int line_size)
misc image utilities
void(* shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height)
void(* add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale)
#define ARCH_X86
Definition: config.h:33
av_cold void ff_mpegvideoencdsp_init_ppc(MpegvideoEncDSPContext *c, AVCodecContext *avctx)
#define EDGE_TOP
uint32_t ff_square_tab[512]
Definition: me_cmp.c:27
Macro definitions for various function/variable attributes.
av_cold void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c, AVCodecContext *avctx)
uint8_t
#define av_cold
Definition: attributes.h:66
#define b
Definition: input.c:52
void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height)
Definition: imgconvert.c:196
static void draw_edges_8_c(uint8_t *buf, int wrap, int width, int height, int w, int h, int sides)
#define wrap(func)
Definition: neontest.h:62
void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height)
Definition: imgconvert.c:227
void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height)
Definition: imgconvert.c:163
int(* pix_sum)(uint8_t *pix, int line_size)
static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale)
static int width
Definition: utils.c:156
Libavcodec external API header.
av_cold void ff_mpegvideoencdsp_init_arm(MpegvideoEncDSPContext *c, AVCodecContext *avctx)
main external API structure.
Definition: avcodec.h:1050
int(* pix_norm1)(uint8_t *pix, int line_size)
static int pix_sum_c(uint8_t *pix, int line_size)
#define ARCH_PPC
Definition: config.h:24
#define BASIS_SHIFT
int height
Definition: gxfenc.c:72
void ff_mpegvideoencdsp_init_x86(MpegvideoEncDSPContext *c, AVCodecContext *avctx)
static int16_t basis[64][64]
void(* draw_edges)(uint8_t *buf, int wrap, int width, int height, int w, int h, int sides)
#define EDGE_BOTTOM
static int try_8x8basis_c(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale)
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
Definition: imgutils.c:254